/* ===================================================================
   app.css — base, shell and shared components for the redesign
   ===================================================================

   Loads AFTER style.css so it overrides the pre-redesign rules without
   having to unpick them first. Every colour here comes from tokens.css —
   there are no colour literals below.

   Section order:
     1. Base + typography (incl. an element-level form reset)
     2. Shared components  (.srx-*)
     3. App shell          (header, tabs, account menu, main, footer)
     4. Auth screens
     4b. The four AI Scribe rules the token alias could not fix

   The markup contract is fixed: script.js and auth.js reach into this
   page by id, by class and by data-attribute, and none of those may be
   renamed. So the redesign works by RESTYLING existing hooks and adding
   wrappers around them — .tab-btn, .auth-form-hidden, .header-user,
   .user-menu[hidden] and friends all keep their names and their jobs.
   =================================================================== */

/* ── 1. Base ─────────────────────────────────────────────────────── */

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* One visible focus style for the whole app. :focus-visible keeps it off
   mouse clicks, which is why the legacy outline:none rules were added in
   the first place — this gets the same look without losing keyboard use. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent-tint-2); color: var(--ink); }

/* Element-level form reset.
   style.css styles `input[type="text"]` and `select` as bare ELEMENT
   selectors with the old dark palette. An element+attribute selector
   out-specifies a plain class, so component rules like .pr-review-input
   lose to it and the field stays dark navy on a white card. Matching that
   specificity here, later in the cascade, fixes every such field at once;
   component rules still win because they load after this. */
input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="month"],
textarea,
select {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  font-family: inherit;
}
/* The background has to be re-stated on :focus too. style.css sets
   `background: rgba(15,23,42,1)` on `select:focus, input[type="text"]:focus`
   — so without this the field turned near-black the moment it was clicked,
   in light mode. Setting only border-color left that in place. */
input[type="text"]:focus,
input[type="search"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="month"]:focus,
textarea:focus,
select:focus {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--accent-border);
  box-shadow: none;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }

/* Legacy primary button, still used by the rule-review footer. */
.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--accent-strong);
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--on-accent);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-strong); }
.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--ink-3);
}
.ghost-btn:hover:not(:disabled) { background: var(--surface-3); }

/* The app hides a lot of things with the `hidden` ATTRIBUTE, not a class.
   Any `display:` rule on such an element's class silently overrides it and
   the element comes back — a correction banner appearing empty, a busy
   overlay stuck on. One guard is safer than remembering [hidden] on every
   component rule. */
[hidden] { display: none !important; }

/* ── 2. Shared components ────────────────────────────────────────── */

/* Buttons. Height and radius follow the canvas: 34px controls, 30px for
   the compact row actions, 9px radius on solid buttons and 8px on ghosts. */
.srx-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.srx-btn:hover { background: var(--surface-3); }
.srx-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.srx-btn--primary {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.srx-btn--primary:hover { background: var(--accent-strong); }

.srx-btn--danger { color: var(--red); }
.srx-btn--danger:hover { background: var(--red-tint); border-color: var(--red); }

/* Inputs and selects share one shape. */
.srx-input,
.srx-select {
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  min-width: 0;
}
.srx-input:focus,
.srx-select:focus { border-color: var(--accent-border); }
.srx-select { cursor: pointer; }

/* Card: the canvas's one container shape, used for every panel. */
.srx-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

/* Badge / pill. Neutral by default, with accent + warning variants. */
.srx-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.srx-badge--accent {
  background: var(--accent-tint);
  border-color: var(--accent-border-soft);
  color: var(--accent-ink);
}
.srx-badge--warn {
  background: var(--amber-tint);
  border-color: var(--amber);
  color: var(--amber-ink);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Segmented control — a track holding 2-3 options, one active. Used by
   the Appearance switcher below, and by the analytics mode toggles. */
.srx-seg {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-3);
  border-radius: var(--r-md);
}
.srx-seg > button {
  flex: 1;
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.srx-seg > button:hover { color: var(--ink); }
.srx-seg > button[aria-pressed="true"] {
  background: var(--seg-active);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px var(--shadow-sm);
}

/* Numerics — MRNs, NDCs, dates, money. The canvas sets all of these in
   mono, which is what keeps columns of figures scannable. */
.srx-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Help popover. No JavaScript: :focus-within is what makes it reachable by
   keyboard as well as by pointer, and because nothing is bound to it, it
   survives the innerHTML re-renders this codebase does constantly. */
.srx-tip {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
}
.srx-tip-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-4);
  /* A serif italic-looking "i" reads as an info affordance at 11px where a
     sans-serif one just looks like a stray character. */
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: default;
}
.srx-tip:hover .srx-tip-btn,
.srx-tip:focus-within .srx-tip-btn {
  border-color: var(--accent-border);
  background: var(--accent-tint);
  color: var(--accent-ink);
}
.srx-tip-body {
  display: none;
  position: absolute;
  top: 26px;
  left: -6px;
  z-index: 30;
  width: 272px;
  padding: 12px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px var(--shadow);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--ink-2);
  text-align: left;
  white-space: normal;
}
.srx-tip:hover .srx-tip-body,
.srx-tip:focus-within .srx-tip-body { display: block; }
/* Near the right edge the popover would otherwise run off the card. */
.srx-tip--end .srx-tip-body { left: auto; right: -6px; }

/* Empty state. The body line should name the way out, not just restate
   that there is nothing here. */
.srx-empty {
  padding: 48px 18px;
  text-align: center;
}
.srx-empty-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 4px;
}
.srx-empty-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-3);
  max-width: 420px;
  margin: 0 auto;
}
.srx-empty-action { margin-top: 16px; }

/* Sortable table headers. The indicator is a real character rather than a
   pseudo-element so the arrow reads in a screen reader's text, and the
   column keeps its width when the glyph changes. */
.srx-sort {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.srx-sort:hover { color: var(--ink); }
.srx-sort-arrow {
  display: inline-block;
  width: 1em;
  margin-left: 4px;
  text-align: center;
  font-size: 10px;
  /* --ink-5 is the dimmest ink and lands at 2.6:1 on a table header; the
     idle arrow still has to be readable, so it sits one step up. */
  color: var(--ink-4);
}
.srx-sort[aria-sort="ascending"] .srx-sort-arrow,
.srx-sort[aria-sort="descending"] .srx-sort-arrow { color: var(--accent-ink); }

/* ── 3. App shell ────────────────────────────────────────────────── */

/* The bar is full-bleed so its background and bottom rule reach the window
   edges, but its CONTENTS sit in the same 1480px container as the page —
   otherwise the logo hugs the window while everything below it is centred,
   which is what made the two look unrelated. */
.app-header {
  display: block;
  padding: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 60px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
/* The SureRX mark is a wordmark — nothing but the two words — so it is set as
   live text rather than shipped as artwork. That is what lets it follow the
   theme: "Sure" takes the page's ink, dark on a light background and light on a
   dark one, where the old PNG carried a black plate that only ever suited the
   dark theme. It also stays sharp at any zoom and is selectable and searchable.
   --accent-ink, not --accent: the flat accent is a fill colour and lands at
   2.2:1 as text on a light surface. */
.brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
  line-height: 1;
}
/* On a light surface the flat accent is only 2.2:1 as text, so light takes the
   readable accent ink; on dark the accent itself clears 10:1, so it keeps the
   vivid lime of the original mark. */
:root { --brand-rx: var(--accent-ink); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --brand-rx: var(--accent); }
}
:root[data-theme="dark"] { --brand-rx: var(--accent); }

.brand-name-rx { color: var(--brand-rx); }

/* frontera_logo.png is a partner's actual logo — an emblem plus a wordmark, not
   type we can set — so it stays an image. It carries an opaque white plate, so
   rounding it slightly makes that read as a deliberate badge rather than as
   artwork sitting on the wrong background. A transparent version would let this
   reduce to a plain <img>. */
.brand-logo-small {
  max-height: 16px;
  width: auto;
  opacity: 1;
  border-radius: 4px;
}

/* Tabs sit full-height in the bar and mark the active one with an accent
   underline — the same treatment the canvas uses for its view switcher. */
.top-tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  align-self: stretch;
  flex-wrap: wrap;
}
.tab-btn {
  position: relative;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 0 14px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}
.tab-btn:hover { background: var(--surface-3); color: var(--ink); }
.tab-btn.active { color: var(--ink); font-weight: 600; background: transparent; }
.tab-btn.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;             /* sit on top of the header's own border */
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
}
.tab-btn.active:hover { background: var(--surface-3); color: var(--ink); }

/* Account menu. .header-user must stay — auth.js closes the dropdown on
   any outside click via e.target.closest(".header-user"). */
.header-user {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}

.user-avatar-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 6px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  line-height: 0;
}
.user-avatar-btn:hover { background: var(--surface-3); }

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--ink-2);
  transition: none;
}
.user-avatar-btn:hover .user-avatar {
  transform: none;
  box-shadow: none;
  border-color: var(--border-2);
}

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 250px;
  min-width: 0;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: 0 12px 32px var(--shadow);
  text-align: left;
  z-index: 40;
}

.user-menu-info {
  display: block;
  padding: 10px 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 12px;
}
/* The large avatar in the dropdown is redundant once the trigger shows
   one; the canvas leads with the identity text instead. */
.user-menu-info .user-avatar-lg { display: none; }
.user-email {
  display: block;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  word-break: break-word;
}

.user-menu-section { padding: 0 10px 12px; }
.user-menu-label {
  display: block;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.user-menu-section .srx-seg { display: flex; width: 100%; }

.user-menu-divider {
  height: 1px;
  background: var(--line-soft);
  margin: 0 4px 6px;
}

/* Sign out is a plain menu item here, not a red-outlined button — the
   canvas treats it as one row among several. */
.logout-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.logout-btn:hover { background: var(--surface-3); color: var(--ink); }

.app-main {
  flex: 1;
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 18px 24px 40px;
  gap: 14px;
}

/* Pinned to the bottom of the viewport when the page is short — otherwise
   the copyright line ends up tucked under a half-empty table, reading as
   part of it rather than as the end of the page. #appContainer is a flex
   column and .app-main grows, which does this without a sticky hack. */
.app-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--ink-3);
}
.app-footer-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 14px 24px;
  text-align: left;
}

#appContainer {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
#appContainer.app-container-hidden { display: none; }

/* ── 4. Auth screens ─────────────────────────────────────────────── */
/* Not in the design canvas — built from the same tokens so sign-in and
   the app read as one product. auth.js drives these: it toggles
   .auth-form-hidden between the four forms, writes into .auth-error, and
   sets button.textContent while submitting — so button labels must stay
   plain text with no child elements. */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 32px 28px;
  box-shadow: 0 12px 32px var(--shadow);
}

.auth-brand { text-align: center; margin-bottom: 28px; }
/* Same wordmark, sized for the sign-in card. */
.brand-name-lg { font-size: 30px; letter-spacing: -0.03em; }

.auth-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 6px;
  text-align: center;
}
.auth-subtitle {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-2);
  margin: 0 0 20px;
  text-align: center;
}
.auth-title + .auth-field { margin-top: 20px; }

.auth-field { margin-bottom: 14px; }
.auth-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.auth-field input {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.12s ease;
}
.auth-field input:focus { border-color: var(--accent-border); }
.auth-field input::placeholder { color: var(--ink-3); }

/* Reserves its own line height so the card does not jump when an error
   appears — the field below would otherwise shift on every failed login. */
.auth-error {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--red);
  min-height: 1.3em;
  margin: 2px 0 10px;
}

.auth-btn {
  width: 100%;
  height: 40px;
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--accent-strong);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease;
}
.auth-btn:hover { background: var(--accent-strong); }
.auth-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.mfa-qr { display: flex; justify-content: center; margin: 4px 0 16px; }
/* The QR is rendered as a black-on-white <img>; it needs a white plate of
   its own so it stays scannable when the app is in dark mode. */
.mfa-qr img {
  width: 176px;
  height: 176px;
  background: #fff;
  padding: 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}
.mfa-secret {
  display: block;
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 10px;
  user-select: all;
}

/* ── 4b. AI Scribe: the four inversions the alias cannot fix ─────── */
/* .scr-page now aliases --scr-* onto the global tokens (see style.css),
   which re-themes the whole tab. These four rules used --scr-accent as a
   TEXT colour, which worked on a dark ground but not on a light one:
   #84CC16 on --accent-tint is about 1.9:1. --accent-ink is the token
   meant for accent-coloured ink and clears 4.5:1 in both themes.
   Everything else about these rules is left alone. */
.scr-appt-status.is-finished,   /* style.css:5447 */
.scr-state-pill.is-done,        /* style.css:5515 */
.scr-ai-badge,                  /* style.css:5573 — on --accent-tint */
.scr-pill-saved {               /* style.css:5805 — on --accent-tint */
  color: var(--accent-ink);
}


/* ── Processing overlay ──────────────────────────────────────────── */
/* The blue radial-gradient card was the last piece of the old visual
   language still appearing in normal use — it comes up whenever claims
   are processed or an upload is rejected. */
.loading-overlay {
  background: color-mix(in srgb, var(--ink) 45%, transparent);
  backdrop-filter: blur(3px);
}
.loading-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: 0 24px 64px var(--shadow);
  padding: 28px 30px;
  max-width: 420px;
}
.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border-2);
  border-top-color: var(--accent);
  margin: 0 auto 14px;
}
.loading-text-main {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.loading-text-sub {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-2);
}
/* Rejected upload: same card, amber rather than red — the file can be
   fixed and re-sent, so it is a correction, not a failure. */
.upload-error-card {
  background: var(--surface);
  border-color: var(--amber);
}
.upload-error-icon { font-size: 26px; line-height: 1; margin-bottom: 8px; color: var(--amber-ink); }
.upload-error-title { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.upload-error-message { font-size: 13px; line-height: 1.55; color: var(--ink-2); }
.upload-error-columns {
  margin: 12px 0 0;
  padding: 10px 12px;
  list-style: none;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
  max-height: 160px;
  overflow-y: auto;
}
.upload-error-card .cc-primary-btn { margin-top: 16px; }

/* ── Account button (design: name over role, then initials) ──────── */
.user-identity {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.3;
  white-space: nowrap;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.user-role { font-size: 11.5px; color: var(--ink-3); }
/* Nothing is known until sign-in; an empty block would leave a gap. */
.user-identity:empty, .user-name:empty + .user-role:empty { display: none; }
.user-avatar-btn .user-avatar {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-2);
}
.user-caret { color: var(--ink-5); font-size: 10px; }
