/* ─────────────────────────────────────────────────────────────────
   Arbor base styles — opinionated defaults consumed by every page.
   ─────────────────────────────────────────────────────────────────

   This file styles HTML primitives (body, buttons, inputs, cards,
   headings, links) using ONLY tokens from arbor-tokens.css. No
   hardcoded colors, fonts, or spacing values.

   Pages that want to customize beyond these defaults override locally
   — but they should never re-define what's here.

   Load order: tokens.css FIRST, then this file.
   ───────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family-sans);
  font-size: var(--font-size-base);
  /* Brand-spec body weight is Regular. Subheadings use Medium and
     headlines use SemiBold/Bold (set on the relevant tags below). */
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height-loose);
  color: var(--color-text-secondary);
  background: var(--color-bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Smooth theme transitions: when the data-theme attribute flips,
     ease background + text colors instead of snapping. */
  transition: background-color var(--duration-normal) var(--easing-standard),
              color var(--duration-normal) var(--easing-standard);
}

/* ── Headings ──────────────────────────────────────────────
   Brand spec maps the type hierarchy as:
     Bold/SemiBold  → Headlines (h1, h2)
     Medium         → Subheadings (h3, h4)
     Regular        → Body Text (p, default)
   Letter-spacing tightens slightly on the heaviest sizes for
   visual balance — at large display sizes, default tracking
   reads loose. */

h1, h2, h3, h4, h5, h6 {
  color: var(--color-text-primary);
  letter-spacing: -0.015em;
  line-height: var(--line-height-tight);
  margin: 0;
}

h1 { font-size: var(--font-size-xxl); font-weight: var(--font-weight-bold); }
h2 { font-size: var(--font-size-xl);  font-weight: var(--font-weight-semibold); }
h3 { font-size: var(--font-size-md);  font-weight: var(--font-weight-medium); }
h4 { font-size: var(--font-size-base); font-weight: var(--font-weight-medium); }
h5 { font-size: var(--font-size-sm);  font-weight: var(--font-weight-medium); }
h6 { font-size: var(--font-size-xs);  font-weight: var(--font-weight-medium); }

/* ── Links ─────────────────────────────────────────────── */

a {
  color: var(--color-text-link);
  text-decoration: none;
  transition: color var(--duration-fast) var(--easing-standard);
}

a:hover {
  color: var(--color-brand-primary-soft);
}

[data-theme="light"] a:hover,
:root:not([data-theme="dark"]) a:hover {
  color: var(--color-brand-primary-strong);
}

/* ── Layout helpers ────────────────────────────────────── */

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

/* ── Buttons ──────────────────────────────────────────────
   Three variants:
     .btn-primary  filled brand color, for the primary action
     .btn-ghost    transparent w/ border, for secondary actions
     .btn-link     no background, link-styled, for tertiary actions
   Size variant: add .btn-lg for hero CTAs. */

.btn {
  display: inline-block;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-lg);
  font-family: var(--font-family-sans);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-base);
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--easing-standard),
              color var(--duration-fast) var(--easing-standard),
              transform var(--duration-fast) var(--easing-standard);
}

.btn-lg {
  padding: var(--space-md) var(--space-xl);
  font-size: var(--font-size-md);
}

.btn-primary {
  background: var(--color-brand-primary);
  color: var(--color-text-inverse);
  box-shadow: var(--shadow-glow-brand);
}

.btn-primary:hover {
  background: var(--color-brand-primary-strong);
  color: var(--color-text-inverse);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-primary);
  border-color: var(--color-border-strong);
}

.btn-ghost:hover {
  background: var(--color-bg-card-elevated);
  color: var(--color-text-primary);
}

.btn-link {
  background: transparent;
  color: var(--color-text-link);
  padding: var(--space-xs) var(--space-sm);
}

.btn-link:hover {
  text-decoration: underline;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Cards ────────────────────────────────────────────────
   Generic surface for grouping content. Use .card-elevated
   for hover/active state or attention-grabbing variants. */

.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
}

.card-elevated {
  background: var(--color-bg-card-elevated);
  box-shadow: var(--shadow-md);
}

.card h3 {
  margin: 0 0 var(--space-xs);
  color: var(--color-text-primary);
}

.card p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

/* ── Form controls ──────────────────────────────────────── */

label {
  display: block;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xxs);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: var(--space-xs) var(--space-sm);
  font-family: inherit;
  font-size: var(--font-size-base);
  background: var(--color-bg-input);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast) var(--easing-standard);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-brand-primary);
  box-shadow: 0 0 0 3px var(--color-info-soft);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-muted);
}

/* ── Badges + status pills ─────────────────────────────── */

.badge {
  display: inline-block;
  padding: var(--space-xxs) var(--space-sm);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.5px;
}

.badge-positive { background: var(--color-positive-soft);
                   border-color: var(--color-positive);
                   color: var(--color-positive); }
.badge-negative { background: var(--color-negative-soft);
                   border-color: var(--color-negative);
                   color: var(--color-negative); }
.badge-warning  { background: var(--color-warning-soft);
                   border-color: var(--color-warning);
                   color: var(--color-warning); }
.badge-info     { background: var(--color-info-soft);
                   border-color: var(--color-info);
                   color: var(--color-info); }

/* ── Form banners (validation errors, success messages) ───
   Inline notice that sits ABOVE a form's submit button. Differs
   from .badge in two ways:
     1. radius matches .btn (medium, not pill) so the banner reads
        as a part of the form chrome, not as a chip
     2. uses display:block + full width so the message wraps
        cleanly instead of getting truncated as a pill would

   Usage: <div class="form-banner form-banner-error">Wrong creds.</div>
   Variants: -error, -success, -warning. */

.form-banner {
  display: block;
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

.form-banner-error   {
  background: var(--color-negative-soft);
  border-color: var(--color-negative);
  color: var(--color-negative);
}
.form-banner-success {
  background: var(--color-positive-soft);
  border-color: var(--color-positive);
  color: var(--color-positive);
}
.form-banner-warning {
  background: var(--color-warning-soft);
  border-color: var(--color-warning);
  color: var(--color-warning);
}
.form-banner-info    {
  background: var(--color-info-soft);
  border-color: var(--color-info);
  color: var(--color-info);
}


/* ── Brand-page chrome ──────────────────────────────────────
   Shared header + footer for every apex portal page (login,
   forgot-password, reset-password, welcome, checkout, checkout-
   error). One source of truth so a rebrand hits a single
   surface. Each page renders its own .brand-page-main content
   between the header and footer.

   Usage: every render in scripts/stripe_webhook builds its body
   as a single <main class="brand-page-main">...</main> and wraps
   it with the constants _BRAND_PAGE_HEADER_HTML +
   _BRAND_PAGE_FOOTER_HTML defined in that module.
   */

.brand-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.brand-page-header {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-md) var(--space-lg);
  font-size: var(--font-size-md);
  border-bottom: 1px solid var(--color-border-subtle);
}

.brand-page-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl) var(--space-lg);
  background-image: var(--gradient-hero);
  background-attachment: fixed;
}

.brand-page-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border-subtle);
  text-align: center;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}
.brand-page-footer a {
  color: var(--color-text-muted);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.brand-page-footer a:hover {
  color: var(--color-text-primary);
}
.brand-page-footer .row {
  display: flex; gap: var(--space-md);
  justify-content: center; flex-wrap: wrap;
  margin-bottom: var(--space-xs);
}

@media (max-width: 640px) {
  .brand-page-header { padding: var(--space-sm) var(--space-md); }
  .brand-page-main   { padding: var(--space-lg) var(--space-md); }
  .brand-page-footer { padding: var(--space-sm) var(--space-md); }
}


/* ── Tables ─────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

th, td {
  padding: var(--space-xs) var(--space-sm);
  text-align: left;
  border-bottom: 1px solid var(--color-border-subtle);
}

th {
  color: var(--color-text-muted);
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-xs);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-family-mono);
}

/* ── Code blocks + inline code ──────────────────────────── */

code, pre {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
}

code {
  background: var(--color-bg-card-elevated);
  padding: 1px var(--space-xxs);
  border-radius: var(--radius-sm);
}

pre {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  overflow-x: auto;
}

pre code {
  background: transparent;
  padding: 0;
}

/* ── Brand wordmark ─────────────────────────────────────────
   Renders "tradingarbor" lowercase per the brand sheet. The
   wordmark gradient (cobalt → cyan) is applied via background-
   clip so the text itself becomes the brand color rather than
   sitting on top of it. SemiBold weight matches the brand
   guide's headline rung — at large display sizes it reads as
   solid and intentional rather than thin and decorative. */

.brand-wordmark {
  font-family: var(--font-family-sans);
  font-weight: var(--font-weight-semibold);
  letter-spacing: -0.02em;
  background-image: var(--gradient-wordmark);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

/* ── Brand mark (3-slash icon) ──────────────────────────────
   Inline reusable mark for headers, footers, login bars.
   Uses an SVG-shaped mask so the slashes pick up
   --gradient-brand without needing a colored asset. The
   container is a square; size it via font-size or width.

   Usage:
     <span class="brand-mark" aria-hidden="true"></span>
     <span class="brand-wordmark">tradingarbor</span> */

.brand-mark {
  display: inline-block;
  width: 1.4em;
  height: 1.4em;
  vertical-align: middle;
  background-image: var(--gradient-brand);
  -webkit-mask: var(--brand-mark-mask) no-repeat center / contain;
          mask: var(--brand-mark-mask) no-repeat center / contain;
}

/* The 3-slash mark, encoded as an inline SVG mask so it inherits
   --gradient-brand. Each slash is a parallelogram angled at the
   same diagonal sweep as the brand gradient. */
:root {
  --brand-mark-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><path d='M6 22 L11 10 L14 10 L9 22 Z M13 22 L18 10 L21 10 L16 22 Z M20 22 L25 10 L28 10 L23 22 Z' fill='black'/></svg>");
}

/* ── Legal fine print ───────────────────────────────────
   Used in every footer to inline the compliance / disclosure
   text that would otherwise need separate pages. Smaller font
   and a step lower in opacity than the surrounding footer copy
   so it reads as supplementary fine print without going
   illegible. ~50-80 words is the sweet spot; any longer and it
   gets ignored. */

.legal-fineprint {
  font-size: var(--font-size-xs);
  line-height: 1.55;
  color: var(--color-text-muted);
  opacity: 0.75;
  max-width: 720px;
  margin: var(--space-md) auto 0;
}

.legal-fineprint a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.legal-fineprint a:hover {
  color: var(--color-text-secondary);
  opacity: 1;
}

/* ── Theme toggle button ─────────────────────────────────
   Used in the trader's header. Light mode shows a moon
   (clicking switches to dark); dark mode shows a sun. */

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: var(--font-size-base);
  transition: background-color var(--duration-fast) var(--easing-standard),
              color var(--duration-fast) var(--easing-standard);
  font-family: inherit;
  padding: 0;
}

.theme-toggle:hover {
  background: var(--color-bg-card-elevated);
  color: var(--color-text-primary);
}

.theme-toggle .theme-icon-light,
.theme-toggle .theme-icon-dark {
  line-height: 1;
}

[data-theme="dark"] .theme-toggle .theme-icon-light { display: inline; }
[data-theme="dark"] .theme-toggle .theme-icon-dark  { display: none; }

[data-theme="light"] .theme-toggle .theme-icon-light,
:root:not([data-theme="dark"]) .theme-toggle .theme-icon-light { display: none; }
[data-theme="light"] .theme-toggle .theme-icon-dark,
:root:not([data-theme="dark"]) .theme-toggle .theme-icon-dark  { display: inline; }


/* ─────────────────────────────────────────────────────────────────
   Mobile responsive defaults (Phase 2.3)

   Single breakpoint at 640px. Below that we tighten spacing on
   the primitives so the marketing site, status page, and any
   shared-CSS-using surface degrades gracefully on a 360px screen.

   This complements the per-page rules in shared/web_dashboard.py
   ``_APP_SHELL_CSS`` -- those handle the auth-flow shell; these
   handle the primitives every page uses.
   ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  body {
    font-size: 15px;  /* readable without zoom on iOS Safari */
  }
  /* Headings -- tighter, but preserve hierarchy */
  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
  h3 { font-size: 16px; }

  /* Cards/panels lose their generous desktop padding */
  .card,
  .panel,
  section.panel {
    padding: 16px 14px;
  }

  /* Form inputs go full-width and gain a tap target */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px;  /* iOS will NOT zoom on focus when >= 16px */
  }

  /* Buttons reach for the tap-target minimum (44px) */
  button,
  .btn,
  input[type="submit"],
  input[type="button"] {
    min-height: 44px;
    padding: 10px 14px;
  }

  /* Tables that overflow get horizontal scroll rather than
     forcing the customer to pinch-zoom */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
