/* Capital Pulse — Client Portal shared styles.
   Used by static/portal-*.html and static/admin-kpi-audit.html.

   ── Theming ──────────────────────────────────────────────────────────────
   Colours are declared twice: once as semantic `--cp-*` tokens that are
   redefined per theme, and once as the legacy names (`--teal`, `--white`,
   `--muted`, …) aliased onto them. Several portal pages carry their own
   inline <style> blocks written against the legacy names, so keeping the
   aliases means those pages pick up light mode without being touched.

   Note `--white` is the legacy name for "primary text colour", not the
   colour white — in light mode it resolves to near-black ink. New rules
   should use `--cp-text` instead.

   Theme resolution order:
     1. `data-theme="light|dark"` on <html>  (explicit user choice)
     2. `prefers-color-scheme`                (system default)
   static/js/portal-theme.js applies (1) before first paint and renders the
   toggle. With JS off, (2) still applies.
   ──────────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ---------- Light theme (default) ---------- */
:root {
  color-scheme: light;

  --cp-bg:               #eef3f7;
  --cp-surface:          #ffffff;
  --cp-surface-2:        #f4f8fb;
  --cp-surface-3:        #e6eef5;
  --cp-line:             rgba(13, 31, 45, 0.10);
  --cp-line-2:           rgba(13, 31, 45, 0.17);
  --cp-text:             #0d1f2d;
  --cp-text-2:          #52657a;

  --cp-accent:           #0f6472;
  --cp-accent-soft:      rgba(15, 100, 114, 0.10);
  --cp-accent-soft-2:    rgba(15, 100, 114, 0.24);
  --cp-accent-fill:      #5db6bf;
  --cp-accent-fill-hi:   #7ecfd8;
  --cp-on-accent:        #06202b;

  /* Deep bronze rather than the dark theme's #d4a24c: the gold chips print
     their label over a gold-tinted background, and #8a6117 only reached
     4.23:1 there — under the 4.5:1 floor for text this small. */
  --cp-gold:             #74500f;
  --cp-gold-soft:        rgba(116, 80, 15, 0.12);
  --cp-danger:           #b3261e;
  --cp-danger-soft:      rgba(179, 38, 30, 0.10);
  --cp-success:          #1b6e3c;
  --cp-success-soft:     rgba(27, 110, 60, 0.12);

  --cp-shadow-sm:  0 1px 2px rgba(13, 31, 45, 0.06), 0 1px 3px rgba(13, 31, 45, 0.04);
  --cp-shadow:     0 2px 6px rgba(13, 31, 45, 0.05), 0 10px 28px rgba(13, 31, 45, 0.07);
  --cp-shadow-lg:  0 4px 12px rgba(13, 31, 45, 0.06), 0 24px 60px rgba(13, 31, 45, 0.13);
  --cp-ring:       0 0 0 3px rgba(15, 100, 114, 0.28);

  --cp-header-bg:  rgba(255, 255, 255, 0.82);
  --cp-pulse:      var(--cp-accent);

  /* Type + shape */
  --cp-font-display: 'DM Serif Display', Georgia, serif;
  --cp-font-body:    'Poppins', system-ui, -apple-system, sans-serif;
  --cp-radius-sm:    8px;
  --cp-radius:       12px;
  --cp-radius-lg:    18px;
}

/* ---------- Dark theme ---------- */
/* Declared twice: once for the system preference, once for the explicit
   opt-in. CSS has no way to share a declaration block across a media query
   and a plain selector, so the values are duplicated verbatim. Keep in sync. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --cp-bg:             #071624;
    --cp-surface:        #0d2137;
    --cp-surface-2:      #0a1b2c;
    --cp-surface-3:      #152d45;
    --cp-line:           rgba(125, 180, 200, 0.16);
    --cp-line-2:         rgba(125, 180, 200, 0.30);
    --cp-text:           #eaf2f7;
    --cp-text-2:        #93aabf;

    --cp-accent:         #6fc6d0;
    --cp-accent-soft:    rgba(93, 182, 191, 0.14);
    --cp-accent-soft-2:  rgba(93, 182, 191, 0.32);
    --cp-accent-fill:    #5db6bf;
    --cp-accent-fill-hi: #7ecfd8;
    --cp-on-accent:      #06202b;

    --cp-gold:           #d4a24c;
    --cp-gold-soft:      rgba(212, 162, 76, 0.16);
    --cp-danger:         #f08a80;
    --cp-danger-soft:    rgba(224, 100, 90, 0.14);
    --cp-success:        #6fd08a;
    --cp-success-soft:   rgba(93, 182, 93, 0.14);

    --cp-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --cp-shadow:    0 2px 8px rgba(0, 0, 0, 0.36), 0 12px 32px rgba(0, 0, 0, 0.34);
    --cp-shadow-lg: 0 4px 14px rgba(0, 0, 0, 0.4), 0 28px 68px rgba(0, 0, 0, 0.52);
    --cp-ring:      0 0 0 3px rgba(111, 198, 208, 0.36);

    --cp-header-bg: rgba(13, 33, 55, 0.78);
    --cp-pulse:     url(#pulseGrad);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --cp-bg:             #071624;
  --cp-surface:        #0d2137;
  --cp-surface-2:      #0a1b2c;
  --cp-surface-3:      #152d45;
  --cp-line:           rgba(125, 180, 200, 0.16);
  --cp-line-2:         rgba(125, 180, 200, 0.30);
  --cp-text:           #eaf2f7;
  --cp-text-2:        #93aabf;

  --cp-accent:         #6fc6d0;
  --cp-accent-soft:    rgba(93, 182, 191, 0.14);
  --cp-accent-soft-2:  rgba(93, 182, 191, 0.32);
  --cp-accent-fill:    #5db6bf;
  --cp-accent-fill-hi: #7ecfd8;
  --cp-on-accent:      #06202b;

  --cp-gold:           #d4a24c;
  --cp-gold-soft:      rgba(212, 162, 76, 0.16);
  --cp-danger:         #f08a80;
  --cp-danger-soft:    rgba(224, 100, 90, 0.14);
  --cp-success:        #6fd08a;
  --cp-success-soft:   rgba(93, 182, 93, 0.14);

  --cp-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --cp-shadow:    0 2px 8px rgba(0, 0, 0, 0.36), 0 12px 32px rgba(0, 0, 0, 0.34);
  --cp-shadow-lg: 0 4px 14px rgba(0, 0, 0, 0.4), 0 28px 68px rgba(0, 0, 0, 0.52);
  --cp-ring:      0 0 0 3px rgba(111, 198, 208, 0.36);

  --cp-header-bg: rgba(13, 33, 55, 0.78);
  --cp-pulse:     url(#pulseGrad);
}

/* ---------- Legacy aliases ----------
   Defined once; they point at the `--cp-*` tokens above, so they follow
   whichever theme is active. Consumed by the inline <style> blocks in
   portal-explore / portal-compare / portal-reports / portal-risk-report /
   portal-report-view. */
:root {
  --deep:        var(--cp-bg);
  --surface:     var(--cp-surface);
  --surface-hi:  var(--cp-surface-3);
  --teal:        var(--cp-accent);
  --teal-dim:    var(--cp-accent-soft);
  --teal-dim-2:  var(--cp-accent-soft-2);
  --white:       var(--cp-text);
  --muted:       var(--cp-text-2);
  --danger:      var(--cp-danger);
  --success:     var(--cp-success);
  --gold:        var(--cp-gold);
  --gold-dim:    var(--cp-gold-soft);

  /* admin-kpi-audit.html */
  --bg-primary:   var(--cp-surface-3);
  --bg-secondary: var(--cp-surface);
  --border:       var(--cp-line);
  --ok:           var(--cp-success);
  --err:          var(--cp-danger);
}

html { height: 100%; scroll-padding-top: 90px; }  /* clears the sticky .shell-header */

body {
  background: var(--cp-bg);
  min-height: 100%;
  font-family: var(--cp-font-body);
  color: var(--cp-text);
  font-size: 0.95rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; }

h1, h2, h3 { font-family: var(--cp-font-display); font-weight: 400; line-height: 1.2; }

/* Ease the swap when the theme changes, but never animate first paint or
   fight a reduced-motion preference. */
.theme-transition, .theme-transition * {
  transition: background-color 0.22s ease, border-color 0.22s ease, color 0.22s ease;
}
@media (prefers-reduced-motion: reduce) {
  .theme-transition, .theme-transition * { transition: none; }
}

/* Visible keyboard focus everywhere. The old rules killed the outline on
   inputs and replaced it with a border-colour change alone, which is easy to
   miss and fails 2.4.7. */
:focus-visible {
  outline: 2px solid var(--cp-accent);
  outline-offset: 2px;
  border-radius: var(--cp-radius-sm);
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: none;
  background: var(--cp-surface-2); color: var(--cp-text-2);
  border: 1px solid var(--cp-line); border-radius: 50%;
  cursor: pointer; transition: color 0.18s, border-color 0.18s, background 0.18s, transform 0.18s;
}
.theme-toggle:hover { color: var(--cp-accent); border-color: var(--cp-accent-soft-2); transform: translateY(-1px); }
.theme-toggle svg { width: 17px; height: 17px; display: block; }
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
/* Show the icon for the theme you'd switch *to*. */
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}
/* Auth screens have no header bar, so the toggle floats. */
/* `absolute`, not `fixed`: pinned to the viewport it rode over the form as the
   page scrolled and swallowed taps on the right edge of the inputs beneath it
   (measured: 6 controls hit at 375x812 on the register page). Absolute keeps it
   at the top of the document, over the card's logo area, and it scrolls away. */
.theme-toggle--floating {
  position: absolute; top: 18px; right: 18px; z-index: 20;
  background: var(--cp-surface); box-shadow: var(--cp-shadow-sm);
}

/* ---------- Shell / nav ---------- */
.shell-header {
  position: sticky; top: 0; z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 40px;
  background: var(--cp-header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--cp-line);
}
.shell-header .brand { display: flex; align-items: center; gap: 14px; }
.shell-header .brand img { height: 30px; }
/* The wordmark ships as white artwork, so it needs inverting on light. */
:root[data-theme="light"] .shell-header .brand img,
:root[data-theme="light"] .auth-logo img,
:root[data-theme="light"] .logo-wrap img { filter: invert(1) hue-rotate(180deg); }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .shell-header .brand img,
  :root:not([data-theme="dark"]) .auth-logo img,
  :root:not([data-theme="dark"]) .logo-wrap img { filter: invert(1) hue-rotate(180deg); }
}
.shell-header .brand-divider { width: 1px; height: 26px; background: var(--cp-line-2); }
.shell-header .brand-text .org { font-family: var(--cp-font-display); font-size: 1.05rem; line-height: 1.1; }
.shell-header .brand-text .email { font-size: 0.74rem; color: var(--cp-text-2); }

.shell-nav { display: flex; align-items: center; gap: 4px; }
.shell-nav a {
  text-decoration: none; color: var(--cp-text-2); font-size: 0.85rem; font-weight: 500;
  padding: 9px 15px; border-radius: 999px; transition: color 0.15s, background 0.15s;
}
.shell-nav a:hover { color: var(--cp-text); background: var(--cp-surface-3); }
.shell-nav a.active { color: var(--cp-accent); background: var(--cp-accent-soft); font-weight: 600; }
.shell-nav .soon {
  display: inline-flex; align-items: center; gap: 6px; color: var(--cp-text-2);
  font-size: 0.85rem; font-weight: 500; padding: 9px 15px; cursor: default;
}
/* No opacity here: 0.65 on the row multiplied by 0.85 on the tag took the gold
   down to 2.58:1. The tokens already carry the right weight on their own. */
.shell-nav .soon .soon-tag {
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--cp-gold); border: 1px solid var(--cp-gold); border-radius: 999px; padding: 1px 7px;
}

.shell-actions { display: flex; align-items: center; gap: 12px; }
.logout-link {
  color: var(--cp-text-2); font-size: 0.8rem; text-decoration: none; border: 1px solid var(--cp-line);
  padding: 9px 16px; border-radius: 999px; white-space: nowrap;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.logout-link:hover { color: var(--cp-accent); border-color: var(--cp-accent-soft-2); background: var(--cp-accent-soft); }

.shell-main { max-width: 1000px; margin: 0 auto; padding: 36px 40px 80px; }

/* ---------- EKG pulse bar (signature motif) ---------- */
.pulse-bar { width: 100%; height: 40px; display: block; overflow: visible; }
/* The inline <linearGradient id="pulseGrad"> fades to 5% opacity at its ends,
   which disappears against a light page — use a solid accent stroke there. */
.pulse-bar path { fill: none; stroke: var(--cp-pulse); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pulse-trace { stroke-dasharray: 900; stroke-dashoffset: 900; animation: draw-pulse 2.6s ease-out forwards; }
@keyframes draw-pulse { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .pulse-trace { animation: none; stroke-dashoffset: 0; } }

/* ---------- Cards / panels ---------- */
.panel {
  background: var(--cp-surface); border: 1px solid var(--cp-line); border-radius: var(--cp-radius-lg);
  padding: 30px 32px; margin-bottom: 24px; box-shadow: var(--cp-shadow-sm);
}
.panel h2 { font-size: 1.15rem; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.panel-head h2 { margin-bottom: 0; }

/* ---------- Forms / buttons ---------- */
label { display: block; font-size: 0.78rem; font-weight: 500; color: var(--cp-text-2); margin-bottom: 6px; }
/* No opacity: dimming an already-secondary token took "(optional)" to
   3.46:1. The parentheses carry the de-emphasis on their own. */
label .label-optional { text-transform: none; font-weight: 400; }
.field { margin-bottom: 18px; }
.field-hint { font-size: 0.74rem; color: var(--cp-text-2); margin-top: 6px; line-height: 1.5; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=tel], input[type=url], textarea, select {
  width: 100%; padding: 12px 14px; background: var(--cp-surface-2); border: 1px solid var(--cp-line-2);
  border-radius: var(--cp-radius-sm); color: var(--cp-text); font-family: var(--cp-font-body); font-size: 0.9rem;
  transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
}
input::placeholder, textarea::placeholder { color: var(--cp-text-2); opacity: 1; }
textarea { resize: vertical; font-family: inherit; }
input:hover, textarea:hover, select:hover { border-color: var(--cp-accent-soft-2); }
/* No `outline: none` here. This selector is (0,1,1) and would beat the global
   `:focus-visible` rule above (0,1,0), cancelling the ring it exists to draw.
   A page whose own input rule ties on specificity and loads later (see
   admin-kpi-audit.html) would also take back the border and background,
   leaving nothing — and box-shadow is discarded under forced-colors anyway.
   The outline stays; these are the decorative extras on top of it. */
input:focus, textarea:focus, select:focus {
  border-color: var(--cp-accent); background: var(--cp-surface); box-shadow: var(--cp-ring);
}
input[type=file] {
  flex: 1; min-width: 220px; color: var(--cp-text-2); font-size: 0.85rem;
  background: var(--cp-surface-2); border: 1px solid var(--cp-line-2);
  border-radius: var(--cp-radius-sm); padding: 10px 12px;
}
input[type=range] { accent-color: var(--cp-accent); }

.btn-primary {
  padding: 12px 22px; background: var(--cp-accent-fill); color: var(--cp-on-accent); font-weight: 600;
  font-size: 0.87rem; border: 1px solid transparent; border-radius: var(--cp-radius-sm); cursor: pointer;
  box-shadow: var(--cp-shadow-sm);
  transition: background 0.16s, transform 0.16s, box-shadow 0.16s;
}
.btn-primary:hover { background: var(--cp-accent-fill-hi); transform: translateY(-1px); box-shadow: var(--cp-shadow); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  padding: 12px 22px; background: transparent; color: var(--cp-accent); font-weight: 600;
  font-size: 0.87rem; border: 1px solid var(--cp-accent-soft-2); border-radius: var(--cp-radius-sm); cursor: pointer;
  transition: border-color 0.16s, background 0.16s;
}
.btn-secondary:hover { border-color: var(--cp-accent); background: var(--cp-accent-soft); }
.btn-block { width: 100%; }

.upload-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ---------- Banners ---------- */
.banner {
  border-radius: var(--cp-radius-sm); padding: 12px 14px; font-size: 0.82rem;
  margin-bottom: 22px; text-align: left; border: 1px solid transparent;
}
.banner.error   { background: var(--cp-danger-soft);  border-color: var(--cp-danger);  color: var(--cp-danger); }
.banner.success { background: var(--cp-success-soft); border-color: var(--cp-success); color: var(--cp-success); }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; font-size: 0.85rem; border-bottom: 1px solid var(--cp-line); }
th { color: var(--cp-text-2); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr { transition: background 0.14s; }
tbody tr:hover { background: var(--cp-surface-2); }
td.filename { color: var(--cp-text); word-break: break-all; }
td.muted { color: var(--cp-text-2); white-space: nowrap; }
a.download-link { color: var(--cp-accent); text-decoration: none; font-weight: 600; }
a.download-link:hover { text-decoration: underline; }
.empty-state { color: var(--cp-text-2); font-size: 0.85rem; padding: 8px 0; }

/* ---------- Provider info (NPI lookup) ---------- */
.panel h2 .muted-tag {
  font-family: var(--cp-font-body); font-size: 0.7rem; font-weight: 600; color: var(--cp-text-2);
  background: var(--cp-surface-3); border-radius: 999px; padding: 3px 10px; margin-left: 10px; vertical-align: middle;
}
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px 24px; }
.info-label { font-size: 0.72rem; color: var(--cp-text-2); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.info-value { font-size: 0.92rem; line-height: 1.5; }

/* ---------- Roadmap / coming-soon teaser ---------- */
.roadmap-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: linear-gradient(120deg, var(--cp-gold-soft), var(--cp-accent-soft));
  border: 1px solid var(--cp-line-2); border-radius: var(--cp-radius-lg); padding: 22px 28px; margin-bottom: 24px;
}
.roadmap-banner .copy p:first-child { font-weight: 600; margin-bottom: 4px; }
.roadmap-banner .copy p:last-child { color: var(--cp-text-2); font-size: 0.85rem; }
.roadmap-banner .soon-tag {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--cp-gold); border: 1px solid var(--cp-gold); border-radius: 999px; padding: 4px 12px;
  white-space: nowrap;
}

/* ---------- Auth cards (login/register/check-email) ---------- */
/* Centre the card with auto margins, NOT `align-items: center`. A card taller
   than the viewport (the register form is ~1585px) would be centred by
   `align-items`, overflowing equally off the top and bottom — and the part
   above the top edge can never be scrolled to, hiding the logo, the heading
   and the error banner. Auto margins only absorb *positive* free space, so a
   tall card pins to the top and every pixel stays reachable. */
.auth-body { display: flex; align-items: flex-start; padding: 32px 20px; }
.auth-wrap { width: 100%; max-width: 440px; margin: auto; }
.auth-card {
  background: var(--cp-surface); border: 1px solid var(--cp-line); border-radius: var(--cp-radius-lg);
  padding: 44px 40px; box-shadow: var(--cp-shadow-lg); position: relative; overflow: hidden; text-align: center;
}
.auth-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--cp-accent-fill), transparent);
}
.auth-card form { text-align: left; }
.auth-logo { margin-bottom: 24px; }
.auth-logo img { height: 40px; margin: 0 auto; }
.auth-title { font-size: 1.5rem; margin-bottom: 6px; }
.auth-sub { font-size: 0.85rem; color: var(--cp-text-2); margin-bottom: 26px; line-height: 1.6; }
.auth-sub strong { color: var(--cp-accent); font-weight: 600; }
.footer-note { margin-top: 22px; font-size: 0.8rem; color: var(--cp-text-2); text-align: center; }
.footer-note a { color: var(--cp-accent); text-decoration: none; font-weight: 600; }
.footer-note a:hover { text-decoration: underline; }
.auth-icon {
  width: 56px; height: 56px; border-radius: 50%; background: var(--cp-accent-soft);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 24px; font-size: 1.6rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .shell-header { padding: 14px 20px; gap: 12px; }
  .shell-main   { padding: 26px 20px 64px; }
  .panel        { padding: 24px 20px; border-radius: var(--cp-radius); }
  .auth-card    { padding: 34px 24px; }
  .shell-nav    { order: 3; width: 100%; overflow-x: auto; }
}

/* ---------- Registration CAPTCHA (Cloudflare Turnstile) ---------- */
/* Turnstile's flexible size has a hard 300px floor, and nothing inside its
   iframe can be styled. At 375px the auth card left a 285px form column, so
   the widget hung 15px past the inputs' right edge. Below 400px, trim the page
   and card gutters so the column clears 300px — everything stays aligned
   rather than just the widget being nudged. */
@media (max-width: 400px) {
  .auth-body { padding-left: 12px; padding-right: 12px; }
  .auth-card { padding-left: 16px; padding-right: 16px; }
}
/* On the narrowest phones (≈320px) the column is still under 300px. Centre the
   overhang instead of letting it hang off one side: the percentage resolves
   against the form's width, so this is 0 whenever the column is wide enough. */
.captcha-field { margin-left: min(0px, calc((100% - 300px) / 2));
                 margin-right: min(0px, calc((100% - 300px) / 2)); }
