/* eFolio Reports — shared UI styling. Neutral palette, single accent, accessible. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #4f46e5;
  --accent-2: #7c3aed;     /* gradient partner — adds energy without losing professionalism */
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --up: #059669;
  --down: #dc2626;
  /* Semantic status colors (tier badges, alerts, stat chips) */
  --ok: #059669;   --ok-soft: #ecfdf5;
  --info: #2563eb; --info-soft: #eff6ff;
  --warn: #d97706; --warn-soft: #fffbeb;
  --risk: #dc2626; --risk-soft: #fef2f2;
  --total-bg: #f3f4f6;
  --group-bg: #eef2ff;
  --group-alt: #f7f8ff;
  --surface-2: #fafbfc;
  --label: #374151;        /* form section labels */
  /* Solid accent table headers */
  --th-bg: #4f46e5;        /* line-of-business (group) row + sticky corner */
  --th-bg-2: #4338ca;      /* metric / single header row */
  --th-alt: #5b54ec;       /* alternating-group tint on the header */
  --th-text: #ffffff;
  --th-border: rgba(255,255,255,.22);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 6px 20px rgba(16,24,40,.10);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
       font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .6rem;
          padding: .8rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent)); }
.topbar .dot { width: 12px; height: 12px; border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.topbar h1 { font-size: 1.05rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.topbar .sub { color: var(--muted); font-size: .85rem; }

/* Shared page navigation in the top bar */
.topnav { display: flex; gap: .25rem; margin-left: .9rem; }
.topnav a { padding: .35rem .8rem; border-radius: 8px; text-decoration: none; font-weight: 600;
  font-size: .86rem; color: var(--muted); transition: background .12s, color .12s; }
.topnav a:hover { color: var(--accent-hover); background: var(--accent-soft); }
.topnav a.active { color: var(--accent-hover); background: var(--accent-soft); }

.page { max-width: 760px; margin: 1.5rem auto; padding: 0 1.25rem; }
.page.wide { max-width: 1200px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        box-shadow: var(--shadow); padding: 1.4rem 1.5rem; }

/* Saved-presets bar */
.presets { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  margin: 0 0 1.1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.presets select { width: auto; flex: 1 1 200px; min-width: 160px; }
.presets .mini { font: inherit; font-size: .8rem; font-weight: 600; padding: .35rem .7rem;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface);
  color: var(--text); cursor: pointer; }
.presets .mini:hover { border-color: var(--accent); color: var(--accent-hover); }

/* Sign-in / verify / set-password pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-top: 3px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 1.7rem 1.7rem 1.8rem; }
.auth-brand { display: flex; align-items: center; gap: .55rem; margin-bottom: 1.5rem; }
.auth-brand .dot { width: 13px; height: 13px; border-radius: 4px; background: var(--accent); }
.auth-brand strong { font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }
.auth-brand span { color: var(--muted); font-size: .8rem; }
.auth-card h2 { font-size: 1.3rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
.auth-card .meta { margin-bottom: 1.2rem; }
.auth-card form label { margin-top: 1rem; }
.auth-card form > label:first-of-type { margin-top: 0; }
.auth-card button[type="submit"] { width: 100%; margin-top: 1.4rem; }
.auth-error { background: var(--accent-soft); border: 1px solid var(--down); color: var(--down);
  border-radius: 8px; padding: .55rem .75rem; margin-bottom: 1.1rem; font-size: .88rem; }
.auth-notice { background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent);
  border-radius: 8px; padding: .55rem .75rem; margin-bottom: 1.1rem; font-size: .88rem; }
.auth-foot { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--border);
  font-size: .85rem; color: var(--muted); text-align: center; }
.auth-foot a { color: var(--accent-hover); font-weight: 600; text-decoration: none; }
.pw-reqs { list-style: none; margin: .5rem 0 0; padding: .6rem .8rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; font-size: .8rem; color: var(--muted); }
.pw-reqs li { margin: .15rem 0; padding-left: 1.1rem; position: relative; }
.pw-reqs li::before { content: "•"; position: absolute; left: .2rem; color: var(--accent); }

/* Form */
form label { display: block; margin: 1.1rem 0 .35rem; font-weight: 600; font-size: .82rem;
             letter-spacing: .02em; text-transform: uppercase; color: var(--label); }
form label .hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); font-size: .8rem; }
form > label:first-of-type, .card > form > label:first-child { margin-top: 0; }

select, input[type="number"], input[type="text"], input[type="password"], input[type="email"] {
  font: inherit; font-size: .95rem; padding: .5rem .6rem; width: 100%;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px; transition: border-color .12s, box-shadow .12s; }
select:hover, input:hover { border-color: #b6bcc6; }
select:focus, input:focus, button:focus-visible, a:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.row { display: flex; gap: 1.25rem; }
.row > div { flex: 1; }
.row label { font-size: .78rem; }

/* Chip-style multi-selects (columns / lines / years) */
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chips label { display: inline-flex; align-items: center; gap: .4rem; margin: 0; padding: .3rem .7rem;
  font-weight: 500; font-size: .85rem; text-transform: none; letter-spacing: 0; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer;
  user-select: none; transition: background .12s, border-color .12s, color .12s; }
.chips label:hover { border-color: var(--accent); }
.chips label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hover); }
.chips input { accent-color: var(--accent); margin: 0; }
.chips .mini { margin-left: .4rem; padding: .15rem .5rem; font-size: .72rem; font-weight: 600;
  border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); cursor: pointer; }

/* Stacked checkbox lists (options / nb-count) */
.opts label { display: block; margin: .35rem 0; font-weight: 400; text-transform: none; letter-spacing: 0; font-size: .92rem; color: var(--text); }
.opts .hint, .opts span { color: var(--muted); font-size: .82rem; }
.opts input { accent-color: var(--accent); margin-right: .35rem; }
/* Two-column option grid on wider screens */
.opts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.4rem; align-items: start; }
@media (max-width: 620px) { .opts-grid { grid-template-columns: 1fr; } }

/* Collapsible advanced section */
details.adv { margin-top: 1.1rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
details.adv > summary { cursor: pointer; padding: .55rem .8rem; font-weight: 600; font-size: .82rem;
  letter-spacing: .02em; text-transform: uppercase; color: var(--text); list-style: none; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before { content: "▸ "; color: var(--muted); }
details.adv[open] > summary::before { content: "▾ "; }
details.adv > summary .hint { font-weight: 400; text-transform: none; letter-spacing: 0; }
details.adv .opts { padding: 0 .8rem .6rem; }

button[type="submit"] { margin-top: 1.5rem; font: inherit; font-weight: 600; font-size: .95rem;
  padding: .6rem 1.4rem; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; border-radius: 8px; cursor: pointer;
  transition: filter .12s, transform .08s; box-shadow: 0 2px 8px rgba(79,70,229,.25); }
button[type="submit"]:hover { filter: brightness(1.08); }
button[type="submit"]:active { transform: translateY(1px); }

/* Report page actions */
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: .25rem 0 1.2rem; }
.actions a { text-decoration: none; font-size: .88rem; font-weight: 600; padding: .4rem .9rem;
  color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; }
.actions a:hover { border-color: var(--accent); color: var(--accent-hover); }
.actions a.primary { color: var(--accent-hover); border-color: var(--accent); background: var(--accent-soft); }

h1.title { font-size: 1.25rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
.meta { color: var(--muted); margin-bottom: 1rem; font-size: .9rem; }

/* Table toolbar (filter + sort hint) */
.tabletools { display: flex; align-items: center; gap: .75rem; margin: 0 0 .6rem; flex-wrap: wrap; }
.tabletools input { width: auto; min-width: 220px; flex: 0 1 280px; font-size: .9rem; padding: .4rem .6rem; }
.tabletools .hint { color: var(--muted); font-size: .8rem; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { background: var(--accent-hover); }
th .arrow { font-size: .7rem; opacity: .9; }

/* Tables — frozen panes: the table scrolls inside its own viewport, so the header rows
   stay pinned while scrolling down and the Agent column stays pinned scrolling sideways.
   Layering (z-index): body cells < agent column < header rows < the header/agent corner,
   so columns slide BEHIND the agent column and its header. */
.tablewrap { overflow: auto; max-height: calc(100vh - 110px); border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: .5rem .75rem; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums; }
thead th { position: sticky; top: 0; z-index: 2; height: 2.4rem; background: var(--th-bg-2);
  font-weight: 600; color: var(--th-text); border-bottom: 1px solid var(--th-border); }
thead tr + tr th { top: 2.4rem; }   /* second header row pins just below the first */
th.lob { text-align: center; background: var(--th-bg); color: var(--th-text);
  border-left: 1px solid var(--th-border); }
thead th.g1 { background: var(--th-alt) !important; }
th.agent, td.agent { text-align: left; position: sticky; left: 0; background: var(--surface); font-weight: 500;
  font-variant-numeric: normal; }
td.agent { z-index: 1; }                              /* above sliding body cells */
thead th.agent { background: var(--th-bg); color: var(--th-text); z-index: 3; }  /* corner on top */
tbody tr:nth-child(even) td { background: var(--surface-2); }
tbody tr:nth-child(even) td.agent { background: var(--surface-2); }
tbody tr:hover td { background: var(--accent-soft); }
tr.total td { font-weight: 700; background: var(--total-bg); border-top: 2px solid var(--border-strong); }
.g1 { background: var(--group-alt) !important; }
.pct { font-size: .72rem; font-weight: 600; display: block; }
.up { color: var(--up); }
.down { color: var(--down); }

/* Summary cards (headline totals above the report table) */
.summary { display: flex; flex-wrap: wrap; gap: .8rem; margin: 0 0 1.1rem; }
.sumcard { flex: 1; min-width: 140px; background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .7rem .9rem; display: flex; flex-direction: column; gap: .25rem; }
.sumlabel { font-size: .72rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }
.sumval { font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }

/* Trend chart (period layouts) */
.chart { margin-bottom: 1.2rem; padding: 1rem 1.2rem 1.1rem; }
.chart-title { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); margin-bottom: .5rem; }
svg.trend { display: block; width: 100%; height: 140px; }
.chart-x { display: flex; justify-content: space-between; margin-top: .25rem; gap: .25rem; }
.chart-x span { font-size: .7rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Leaderboard cards */
.grid { display: flex; flex-wrap: wrap; gap: 1.25rem; }
.lbcard { min-width: 320px; flex: 1; }
.lbcard h3 { font-size: .95rem; margin: .2rem 0 .5rem; color: var(--text); }
td.rank { text-align: center; width: 2.2rem; color: var(--muted); }
/* Proportional fill behind each leaderboard value (--fill set inline per row) */
td.bar { position: relative; isolation: isolate; }
td.bar::before { content: ""; position: absolute; top: 3px; bottom: 3px; right: 0;
  width: var(--fill, 0%); background: var(--accent-soft); border-radius: 4px 0 0 4px; z-index: 0; }
td.bar .barval { position: relative; z-index: 1; }

em { color: var(--muted); }

/* Sticky "Run report" bar */
.runbar { position: sticky; bottom: 0; margin: 1.4rem -1.5rem -1.4rem; padding: .9rem 1.5rem;
  background: var(--surface); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 -4px 12px rgba(16,24,40,.05); }
.runbar button[type="submit"] { margin: 0; }

/* Theme toggle in the top bar */
.theme-toggle { margin-left: auto; font-size: 1.1rem; line-height: 1; padding: .35rem .5rem;
  background: transparent; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; color: var(--text); }
.theme-toggle:hover { border-color: var(--accent); }
.topbar .user { color: var(--muted); font-size: .85rem; font-weight: 600; }
.topbar .logout { color: var(--accent-hover); font-size: .82rem; font-weight: 600; text-decoration: none;
  padding: .35rem .6rem; border: 1px solid var(--border); border-radius: 8px; }
.topbar .logout:hover { border-color: var(--accent); }

.notice { background: var(--accent-soft); border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem .8rem; }
.notice a { color: var(--accent-hover); font-weight: 600; text-decoration: none; }

/* Dark theme */
[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1c212b; --text: #e6e8ee; --muted: #aab3c2;
  --label: #ccd2de;
  --border: #262b36; --border-strong: #343b49;
  --accent: #818cf8; --accent-2: #a78bfa; --accent-hover: #a5b0ff; --accent-soft: #1e2440;
  --total-bg: #1c212b; --group-bg: #1e2440; --group-alt: #161b27;
  --th-bg: #3730a3; --th-bg-2: #312e81; --th-alt: #4338ca;
  --th-text: #e9ecfb; --th-border: rgba(255,255,255,.14);
  --up: #4ade80; --down: #f87171;
  --ok: #34d399;   --ok-soft: #0b2e22;
  --info: #60a5fa; --info-soft: #14233c;
  --warn: #fbbf24; --warn-soft: #33250a;
  --risk: #f87171; --risk-soft: #3a1414;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 6px 20px rgba(0,0,0,.5);
  color-scheme: dark;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
