/**
 * Design system ported verbatim from the original FACILINK Performance360
 * single-tenant app's <style> block — same tokens, same component classes
 * (.topbar, .tabs/.tab, .card, .btn variants, .badge, .stat-tile,
 * .bar-row, table.data-table, .rate-btn, .qr-box, .chip-filter,
 * .empty-state, .banner, .kv-list, .expand-row/.expand-panel, print
 * styles for PDF export), so every page built with these classes matches
 * the original pixel-for-pixel — including its automatic light/dark
 * theming via prefers-color-scheme. Every admin-facing page in this app
 * (both /admin/ and /super-admin/) is built using these classes rather
 * than one-off inline styles, specifically so this file is the single
 * place a visual tweak belongs.
 */

  /* ============ TOKENS ============ */
  :root{
    color-scheme: light;
    --bg: #F6F8FB;
    --surface: #FFFFFF;
    --surface-2: #F0F4F9;
    --border: #E2E8F0;
    --border-strong: #C7D2E0;
    --ink: #101828;
    --ink-soft: #33415C;
    --muted: #5B6B85;
    --faint: #8996AC;

    --brand: #1A5CA8;
    --brand-ink: #ffffff;
    --brand-soft: #EAF1F9;
    --accent: #0F6E56;
    --accent-soft: #E9F5F1;

    --good: #1E8F6F;
    --good-soft: #E4F4EE;
    --warn: #B75E09;
    --warn-soft: #FCEEDD;
    --crit: #C4453D;
    --crit-soft: #FBE7E5;

    --cat-1: #1A5CA8; /* blue   - brand   */
    --cat-2: #EB6834; /* orange */
    --cat-3: #1BAF7A; /* aqua   */
    --cat-4: #EDA100; /* yellow */
    --cat-5: #E87BA4; /* magenta*/
    --cat-6: #4A3AA7; /* violet */
    --cat-7: #008300; /* green  */
    --cat-8: #E34948; /* red    */

    --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 1px rgba(16,24,40,.04);
    --shadow-md: 0 6px 20px rgba(16,24,40,.08), 0 2px 6px rgba(16,24,40,.05);
    --radius: 12px;
    --radius-sm: 8px;
    --font-display: 'Manrope', 'Segoe UI', Arial, sans-serif;
    --font-body: 'IBM Plex Sans', 'Segoe UI', Arial, sans-serif;
  }
  @media (prefers-color-scheme: dark){
    :root:not([data-theme="light"]){
      color-scheme: dark;
      --bg: #0A1220;
      --surface: #101B2D;
      --surface-2: #16233A;
      --border: #24314A;
      --border-strong: #33445F;
      --ink: #EAF0FA;
      --ink-soft: #C7D3E6;
      --muted: #93A3BF;
      --faint: #64769A;

      --brand: #4C8FDB;
      --brand-ink: #06152B;
      --brand-soft: #142B49;
      --accent: #34B594;
      --accent-soft: #123328;

      --good: #34B594;
      --good-soft: #103224;
      --warn: #E0A94A;
      --warn-soft: #3A2A0F;
      --crit: #E2716A;
      --crit-soft: #3A1613;

      --cat-1: #3987E5;
      --cat-2: #D95926;
      --cat-3: #199E70;
      --cat-4: #C98500;
      --cat-5: #D55181;
      --cat-6: #9085E9;
      --cat-7: #3FAE3F;
      --cat-8: #E66767;

      --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
      --shadow-md: 0 10px 26px rgba(0,0,0,.45);
    }
  }
  :root[data-theme="dark"]{
    color-scheme: dark;
    --bg: #0A1220;
    --surface: #101B2D;
    --surface-2: #16233A;
    --border: #24314A;
    --border-strong: #33445F;
    --ink: #EAF0FA;
    --ink-soft: #C7D3E6;
    --muted: #93A3BF;
    --faint: #64769A;

    --brand: #4C8FDB;
    --brand-ink: #06152B;
    --brand-soft: #142B49;
    --accent: #34B594;
    --accent-soft: #123328;

    --good: #34B594;
    --good-soft: #103224;
    --warn: #E0A94A;
    --warn-soft: #3A2A0F;
    --crit: #E2716A;
    --crit-soft: #3A1613;

    --cat-1: #3987E5;
    --cat-2: #D95926;
    --cat-3: #199E70;
    --cat-4: #C98500;
    --cat-5: #D55181;
    --cat-6: #9085E9;
    --cat-7: #3FAE3F;
    --cat-8: #E66767;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 10px 26px rgba(0,0,0,.45);
  }

  @media (prefers-color-scheme: dark){
    :root:not([data-theme="light"]) .brand-logo{ filter: invert(1) brightness(1.3); }
  }
  :root[data-theme="dark"] .brand-logo{ filter: invert(1) brightness(1.3); }

  *,*::before,*::after{ box-sizing:border-box; }
  html,body{ height:100%; }
  body{
    margin:0;
    background:var(--bg);
    color:var(--ink);
    font-family:var(--font-body);
    font-size:15px;
    line-height:1.5;
    -webkit-font-smoothing:antialiased;
  }
  h1,h2,h3,h4{ font-family:var(--font-display); margin:0; text-wrap:balance; color:var(--ink); }
  p{ margin:0; }
  button{ font-family:inherit; }
  input,select,textarea{ font-family:inherit; font-size:inherit; color:inherit; }
  .num{ font-variant-numeric:tabular-nums; }
  ::selection{ background:var(--brand-soft); }
  @media (prefers-reduced-motion:no-preference){
    .anim-in{ /* animation intentionally removed — this app is multi-page, so every tab click is a real page load, and the fade was playing on every single navigation instead of just meaningful data reveals */ }
  }
  @keyframes fadeUp{ from{ opacity:0; transform:translateY(4px);} to{opacity:1; transform:none;} }

  a{ color:var(--brand); }
  :focus-visible{ outline:2px solid var(--brand); outline-offset:2px; border-radius:4px; }

  .store{ display:none; }

  /* ============ LAYOUT SHELLS ============ */
  .shell-center{ min-height:100vh; display:flex; align-items:center; justify-content:center; padding:32px 16px; }
  .shell-app{ min-height:100vh; display:flex; flex-direction:column; }

  .topbar{
    display:flex; align-items:center; gap:12px; justify-content:space-between;
    padding:14px 20px; background:var(--surface); border-bottom:1px solid var(--border);
    position:sticky; top:0; z-index:20;
  }
  .brand{ display:flex; align-items:center; gap:10px; }
  .brand-logo{ height:28px; width:auto; display:block; }
  .brand-logo-client{ height:32px; width:auto; max-width:160px; display:block; border-radius:4px; }
  .brand-mark{
    width:32px; height:32px; border-radius:9px; background:var(--brand); color:var(--brand-ink);
    display:flex; align-items:center; justify-content:center; font-family:var(--font-display); font-weight:800; font-size:15px;
  }
  .brand-text{ font-family:var(--font-display); font-weight:800; font-size:16px; letter-spacing:.01em; }
  .brand-sub{ font-size:12px; color:var(--muted); }

  .tabs{ display:flex; gap:4px; overflow-x:auto; padding:0 20px; background:var(--surface); border-bottom:1px solid var(--border); }
  .tab{
    appearance:none; border:none; background:none; cursor:pointer; white-space:nowrap;
    padding:12px 14px; font-family:var(--font-display); font-weight:600; font-size:13.5px; color:var(--muted);
    border-bottom:2px solid transparent; margin-bottom:-1px; text-decoration:none; display:inline-block;
  }
  .tab:hover{ color:var(--ink); }
  .tab[aria-selected="true"]{ color:var(--brand); border-bottom-color:var(--brand); }

  .content{ flex:1; padding:24px 20px 64px; max-width:1180px; width:100%; margin:0 auto; }
  .content-narrow{ max-width:640px; margin:0 auto; padding:24px 16px 64px; width:100%; }

  .survey-header-band{ background:var(--brand); }
  .survey-header-band-inner{ max-width:640px; margin:0 auto; padding:22px 16px; }
  .survey-logo{ height:40px; width:auto; display:block; }

  /* ============ PRIMITIVES ============ */
  .card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow-sm); }
  .card-pad{ padding:20px; }
  .stack{ display:flex; flex-direction:column; gap:16px; }
  .row{ display:flex; align-items:center; gap:10px; }
  .row-between{ display:flex; align-items:center; justify-content:space-between; gap:10px; margin-top:16px; }
  .grid{ display:grid; gap:16px; }
  .grid-5{ grid-template-columns:repeat(5,1fr); }
  .grid-4{ grid-template-columns:repeat(4,1fr); }
  .grid-3{ grid-template-columns:repeat(3,1fr); }
  .grid-2{ grid-template-columns:repeat(2,1fr); }
  @media (max-width:860px){ .grid-5{ grid-template-columns:repeat(3,1fr);} .grid-4{ grid-template-columns:repeat(2,1fr);} .grid-3{ grid-template-columns:repeat(2,1fr);} }
  @media (max-width:560px){ .grid-5,.grid-4,.grid-3,.grid-2{ grid-template-columns:1fr; } }

  .btn{
    appearance:none; border:1px solid var(--border-strong); background:var(--surface); color:var(--ink);
    font-family:var(--font-display); font-weight:700; font-size:14px; border-radius:var(--radius-sm);
    padding:11px 18px; cursor:pointer; display:inline-flex; align-items:center; justify-content:center; gap:8px;
    transition:filter .12s ease, transform .05s ease;
  }
  .btn:hover{ filter:brightness(0.98); }
  .btn:active{ transform:translateY(1px); }
  .btn:disabled{ opacity:.5; cursor:not-allowed; }
  .btn-primary{ background:var(--brand); border-color:var(--brand); color:var(--brand-ink); }
  .btn-accent{ background:var(--accent); border-color:var(--accent); color:#fff; }
  .btn-ghost{ background:transparent; border-color:transparent; color:var(--muted); }
  .btn-ghost:hover{ color:var(--ink); background:var(--surface-2); }
  .btn-block{ width:100%; }
  .btn-sm{ padding:7px 12px; font-size:12.5px; }
  .btn-danger-ghost{ background:transparent; border-color:transparent; color:var(--crit); }
  .btn-danger-ghost:hover{ background:var(--crit-soft); }

  label.field-label{ display:block; font-family:var(--font-display); font-weight:700; font-size:12.5px; color:var(--ink-soft); margin-bottom:6px; letter-spacing:.01em; }
  .req{ color:var(--crit); }
  .field-hint{ font-size:12px; color:var(--muted); margin-top:5px; }
  input[type="text"],input[type="email"],input[type="tel"],input[type="password"],select,textarea{
    width:100%; background:var(--surface); border:1px solid var(--border-strong); border-radius:var(--radius-sm);
    padding:11px 12px; color:var(--ink); outline-offset:2px;
  }
  textarea{ resize:vertical; min-height:76px; }
  select{ appearance:none; background-image:linear-gradient(45deg,transparent 50%,var(--muted) 50%),linear-gradient(135deg,var(--muted) 50%,transparent 50%); background-position:calc(100% - 18px) center, calc(100% - 13px) center; background-size:5px 5px,5px 5px; background-repeat:no-repeat; padding-right:34px; }
  input:disabled,select:disabled{ background:var(--surface-2); color:var(--muted); }
  .field{ margin-bottom:16px; }

  .badge{ display:inline-flex; align-items:center; gap:5px; font-family:var(--font-display); font-weight:700; font-size:11.5px; letter-spacing:.02em; padding:4px 9px; border-radius:99px; }
  .badge-good{ background:var(--good-soft); color:var(--good); }
  .badge-warn{ background:var(--warn-soft); color:var(--warn); }
  .badge-crit{ background:var(--crit-soft); color:var(--crit); }
  .badge-neutral{ background:var(--surface-2); color:var(--muted); }
  .dot{ width:7px; height:7px; border-radius:99px; background:currentColor; flex:none; }

  .stat-tile{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:16px 18px; }
  .stat-label{ font-size:12px; font-weight:700; color:var(--muted); text-transform:uppercase; letter-spacing:.05em; margin-bottom:8px; }
  .stat-value{ font-family:var(--font-display); font-weight:800; font-size:28px; }
  .stat-sub{ font-size:12.5px; color:var(--muted); margin-top:4px; }

  table.data-table{ width:100%; border-collapse:collapse; font-size:13.5px; }
  table.data-table th{ text-align:left; font-family:var(--font-display); font-weight:700; font-size:11.5px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); padding:9px 12px; border-bottom:1px solid var(--border); white-space:nowrap; }
  table.data-table td{ padding:11px 12px; border-bottom:1px solid var(--border); vertical-align:middle; }
  table.data-table tbody tr:hover{ background:var(--surface-2); }
  .table-scroll{ overflow-x:auto; border:1px solid var(--border); border-radius:var(--radius); background:var(--surface); }
  .table-scroll table{ border:none; }
  .th-sort{ cursor:pointer; user-select:none; }
  .th-sort:hover{ color:var(--ink); }

  .bar-row{ display:grid; grid-template-columns:180px 1fr 56px; align-items:center; gap:12px; padding:9px 0; }
  .bar-row-name{ font-size:13.5px; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .bar-track{ height:10px; background:var(--surface-2); border-radius:99px; overflow:hidden; position:relative; }
  .bar-fill{ height:100%; border-radius:99px; }
  .bar-value{ font-size:13px; font-weight:700; text-align:right; font-variant-numeric:tabular-nums; }
  @media (max-width:640px){ .bar-row{ grid-template-columns:120px 1fr 44px; } }

  .rate-group{ display:flex; gap:6px; flex-wrap:wrap; }
  .rate-btn{
    width:42px; height:42px; border-radius:10px; border:1px solid var(--border-strong); background:var(--surface);
    color:var(--ink); font-family:var(--font-display); font-weight:700; font-size:15px; cursor:pointer;
  }
  .rate-btn[aria-pressed="true"]{ background:var(--brand); border-color:var(--brand); color:var(--brand-ink); }
  .rate-scale-labels{ display:flex; justify-content:space-between; font-size:11px; color:var(--faint); margin-top:6px; }

  .progress-track{ height:6px; background:var(--surface-2); border-radius:99px; overflow:hidden; }
  .progress-fill{ height:100%; background:var(--brand); border-radius:99px; transition:width .25s ease; }

  .signature-pad-wrap{ border:1.5px dashed var(--border-strong); border-radius:10px; background:#fff; touch-action:none; }
  #signature-pad{ display:block; width:100%; height:160px; cursor:crosshair; touch-action:none; border-radius:10px; }
  .signature-type-input{ font-family:'IBM Plex Sans',sans-serif; font-style:italic; font-size:19px; }

  .qr-box{ display:inline-flex; flex-direction:column; align-items:center; gap:8px; background:#fff; border:1px solid var(--border); border-radius:10px; padding:14px; }
  .qr-box svg, .qr-box img, .qr-box canvas{ display:block; }
  .qr-box .qr-caption{ font-size:11px; color:var(--muted); text-align:center; max-width:160px; }

  .chip-filter{ display:inline-flex; align-items:center; border:1px solid var(--border-strong); border-radius:99px; padding:7px 14px; font-size:13px; font-weight:600; color:var(--ink-soft); background:var(--surface); cursor:pointer; }
  .chip-filter[aria-pressed="true"]{ background:var(--brand-soft); border-color:var(--brand); color:var(--brand); }

  .empty-state{ text-align:center; padding:48px 20px; color:var(--muted); }
  .empty-state h3{ color:var(--ink); margin-bottom:6px; font-size:17px; }
  .empty-state p{ font-size:13.5px; max-width:420px; margin:0 auto; }

  .banner{ display:flex; gap:10px; align-items:flex-start; padding:12px 14px; border-radius:var(--radius-sm); font-size:13px; border:1px solid; }
  .banner-info{ background:var(--brand-soft); border-color:var(--brand); color:var(--ink-soft); }
  .banner-warn{ background:var(--warn-soft); border-color:var(--warn); color:var(--ink-soft); }
  .banner-crit{ background:var(--crit-soft); border-color:var(--crit); color:var(--ink-soft); }

  .kv-list{ display:flex; flex-direction:column; gap:10px; }
  .kv-row{ display:flex; justify-content:space-between; gap:12px; font-size:13.5px; }
  .kv-row .k{ color:var(--muted); }
  .kv-row .v{ font-weight:600; }

  .delta-up{ color:var(--good); }
  .delta-down{ color:var(--crit); }
  .delta-flat{ color:var(--muted); }

  .expand-row{ cursor:pointer; }
  .expand-panel{ background:var(--surface-2); border-top:1px solid var(--border); padding:16px; }

  hr.hair{ border:none; border-top:1px solid var(--border); margin:0; }

  .link-btn{ background:none; border:none; padding:0; color:var(--brand); font-weight:600; cursor:pointer; font-size:inherit; font-family:inherit; }
  .link-btn:hover{ text-decoration:underline; }

  /* ============ EXPORT (PDF / CSV) ============ */
  .export-bar{ display:flex; justify-content:flex-end; gap:8px; margin-bottom:10px; }
  .print-header{ display:none; }
  /* Full Report tab: every other tab's own Export CSV/PDF bar comes along
     for free since each section is literally that tab's render function —
     hide them here so the one pair of buttons at the top is all you see. */
  .full-report-body .export-bar{ display:none; }
  @media print{
    /* Each concatenated section (Overview, By Customer, every segment,
       Trends) starts on its own page in the printed/PDF full report. */
    .full-report-body .report-section{ page-break-before:always; }
    .full-report-body .report-section:first-child{ page-break-before:avoid; }
    /* Browsers strip background colors/images by default when printing
       (to save ink) — that's what was hiding the colored FTXI bars,
       trend chart bars, and status badges. This turns that back on so
       the exported PDF actually shows them. */
    *{ -webkit-print-color-adjust:exact !important; print-color-adjust:exact !important; color-adjust:exact !important; }
    /* Force a clean, light, printable look regardless of the viewer's
       theme — printed reports shouldn't come out dark-mode-black. */
    :root{
      --bg:#ffffff !important; --surface:#ffffff !important; --surface-2:#f2f4f7 !important;
      --border:#d0d5dd !important; --border-strong:#aab4c4 !important;
      --ink:#101828 !important; --ink-soft:#33415c !important; --muted:#475467 !important; --faint:#667085 !important;
      --shadow-sm:none !important; --shadow-md:none !important;
    }
    body{ background:#fff; }
    .topbar, .tabs, .no-print{ display:none !important; }
    .content{ max-width:100%; padding:0; }
    .card{ border:1px solid #d0d5dd; box-shadow:none; }
    .card, .stat-tile{ break-inside:avoid; }
    .print-header{ display:block !important; margin-bottom:18px; }
  }
