:root {
  --ink: #111827;
  --body: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --bg: #f5f6f8;
  --card: #ffffff;
  --head: #f9fafb;
  --navy: #141b2d;
  --blue: #2557d6;
  --blue-soft: #e8eefc;
  --red: #c0392b;
  --red-bar: #d03a2f;
  --red-tint: #fdf2f1;
  --green: #2e7d32;
  --green-bar: #2f8a3a;
  --green-tint: #f1f8f2;
  --warn: #7a5200;
  --warn-line: #f0d48a;
  --warn-tint: #fdf6e3;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.muted { color: var(--muted); }
.error { color: var(--red); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--navy);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 22px; height: 22px; border-radius: 5px; background: #3d6af2; flex: none; }
.divider { width: 1px; height: 22px; background: rgba(255, 255, 255, 0.25); }
.app-name { color: #c7cbd6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 14px; color: #c7cbd6; white-space: nowrap; }
.topbar-right #as-of { color: #fff; }
/* topbar-link: a plain text button in the dark top bar */
.topbar-link { font: inherit; background: none; border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 6px; padding: 4px 10px; color: #fff; cursor: pointer; }
.topbar-link:hover { background: rgba(255, 255, 255, 0.1); }

.page { max-width: 1240px; margin: 0 auto; padding: 32px 24px 48px; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { background: var(--head); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d48b8; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link-btn {
  font: inherit;
  font-weight: 600;
  background: none;
  border: 0;
  padding: 0;
  color: var(--blue);
  cursor: pointer;
}

/* Account manager picker */
.manager-select { font: inherit; font-size: 0.95rem; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--ink); min-width: 160px; }
.manager-select.unassigned { color: var(--blue); border-style: dashed; border-color: var(--blue); }
.manager-select:disabled { opacity: 0.6; }

/* Sign-in page */
.auth-card { max-width: 420px; margin: 40px auto; padding: 32px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.auth-card h1 { margin: 0 0 6px; font-size: 1.6rem; }
.auth-card .error { margin: 8px 0; }
.btn.wide { width: 100%; margin-top: 8px; }
.small { font-size: 0.875rem; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-weight: 600; font-size: 0.95rem; }
.field input, .field select { font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--ink); }
.field input[readonly] { background: var(--head); color: var(--muted); }
.field .muted { font-weight: 400; }

/* Admin */
.add-user, .invite-box { padding: 20px 26px; margin-bottom: 24px; }
.add-user h2, .invite-box h2 { margin: 0 0 4px; font-size: 1.1rem; }
.add-grid { display: grid; grid-template-columns: 1.2fr 1fr 1.4fr auto; gap: 16px; align-items: end; }
.add-grid .field { margin: 10px 0 0; }
.add-grid .btn { margin-top: 10px; }
.invite-box { border-color: #c8d6f7; background: var(--blue-soft); }
.copy-row { display: flex; gap: 12px; margin-top: 12px; }
.copy-row input { flex: 1; min-width: 0; font: inherit; font-size: 0.9rem; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); }
.users-table { min-width: 720px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; background: #eef0f3; color: var(--muted); }
.pill.on { background: var(--green-tint); color: var(--green); }
td.row-actions { white-space: nowrap; font-family: inherit; font-size: inherit; }
.row-actions .link-btn + .link-btn { margin-left: 16px; }
.link-btn.danger { color: var(--red); }
@media (max-width: 860px) {
  .add-grid { grid-template-columns: 1fr; }
  .copy-row { flex-direction: column; }
  #me { display: none; }
}

/* Upload */
.upload-card {
  max-width: 760px;
  margin: 40px auto;
  padding: 40px 32px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.upload-icon {
  width: 52px; height: 52px; margin: 0 auto 20px;
  display: grid; place-items: center;
  border-radius: 10px; background: var(--blue-soft); color: var(--blue);
  font-size: 1.5rem; font-weight: 700;
}
.upload-card h2 { margin: 0 0 6px; font-size: 1.4rem; }
.upload-card > .muted { margin: 0 0 28px; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 32px 16px;
  border: 1.5px dashed #b8bdc7;
  border-radius: 10px;
  background: var(--head);
  cursor: pointer;
}
.drop .muted { font-size: 0.95rem; }
.drop.dragover { border-color: var(--blue); background: var(--blue-soft); }
.drop.done { border-style: solid; border-color: var(--green-bar); background: var(--green-tint); }
.file-name { color: var(--green); font-size: 0.9rem; font-weight: 600; word-break: break-all; }

/* Dashboard header */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.page-head h1 { margin: 0 0 4px; font-size: 2rem; letter-spacing: -0.02em; }
.page-head p { margin: 0; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 24px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 26px; }
.kpi.bad { border-top: 4px solid var(--red-bar); }
.kpi-label { color: var(--body); font-size: 0.85rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.kpi-num { font-size: 2.2rem; font-weight: 700; margin-top: 12px; font-variant-numeric: tabular-nums; }
.kpi.bad .kpi-num { color: var(--red); }

/* Table panel */
/* overflow: clip (not hidden) keeps the rounded corners without breaking the sticky header. */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: clip; }
.panel-bar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 26px; border-bottom: 1px solid var(--line); }
.filter { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.filter-select { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }
.filter-select select { font: inherit; color: var(--ink); padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); min-width: 150px; }
.period-picker { align-self: center; font-weight: 600; color: var(--body); }
.period-picker select { min-width: 190px; font-weight: 600; }
.period-note { margin: 6px 0 0; color: var(--body); }
.period-note.warn { color: var(--warn); }
.report-date { max-width: 420px; margin: 0 auto 4px; text-align: left; }
#view-upload .upload-card > .small { margin: 0 auto 20px; max-width: 520px; }
.section-head { margin-top: 40px; }
.specialist-grid { grid-template-columns: minmax(0, 420px) auto; justify-content: start; }
.search { font: inherit; padding: 7px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--ink); width: min(260px, 100%); }
.search:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.note-inner { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.note-row .legend { font-size: inherit; }
.legend { display: flex; gap: 22px; color: var(--body); font-size: 0.95rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }
.dot.red { background: var(--red-bar); }
.dot.green { background: var(--green-bar); }

.table-wrap { overflow: clip; }
/* Column headers stay at the top of the screen while scrolling the table. */
#view-pacing thead tr:first-child th { position: sticky; top: 0; z-index: 2; box-shadow: inset 0 -1px 0 var(--line-strong); }
table { width: 100%; border-collapse: collapse; min-width: 960px; }
th, td { padding: 16px 26px; text-align: left; white-space: nowrap; }
/* The dashboard table has many columns: tighter cells, and headers may wrap. */
#view-pacing th, #view-pacing td { padding: 14px 16px; }
#view-pacing th:first-child, #view-pacing td:first-child { padding-left: 26px; }
#view-pacing th { white-space: normal; vertical-align: bottom; }
#view-pacing td.client { min-width: 180px; }
#view-pacing .manager-select { min-width: 140px; }
th { background: var(--head); color: var(--body); font-size: 0.85rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
th.num { text-align: right; }
th.sorted { color: var(--ink); }
/* Header buttons look like plain header text. */
.sort-btn { font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
.sort-btn:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.sort-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 2px; }
.note-row td { background: var(--head); color: var(--body); font-size: 0.95rem; padding: 10px 26px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.note-row strong { color: var(--ink); }

tbody tr td:first-child { border-left: 4px solid transparent; }
tbody tr.behind { background: var(--red-tint); }
tbody tr.behind td:first-child { border-left-color: var(--red-bar); }
tbody tr.on-pace { background: var(--green-tint); }
tbody tr.on-pace td:first-child { border-left-color: var(--green-bar); }
tbody tr + tr td { border-top: 1px solid var(--line); }
td.num { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.95rem; }
tbody tr.behind .pace { color: var(--red); font-weight: 700; }
tbody tr.on-pace .pace { color: var(--green); font-weight: 700; }
td.client { white-space: normal; min-width: 240px; font-weight: 600; }
td.mgr { color: var(--body); }
.empty td { text-align: center; color: var(--muted); padding: 32px; }

.panel-foot { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 14px 26px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.95rem; }

/* Mapping dialog */
dialog { width: min(480px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); }
dialog::backdrop { background: rgba(17, 24, 39, 0.45); }
dialog header { padding: 22px 24px 16px; border-bottom: 1px solid var(--line); }
dialog h3 { margin: 0 0 4px; font-size: 1.25rem; }
dialog header p { margin: 0; }
.mapping-body { padding: 8px 24px 16px; max-height: 60vh; overflow-y: auto; }
.mapping-body h4 { margin: 18px 0 8px; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; }
.map-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: center; margin: 10px 0; }
.map-row select { font: inherit; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--ink); width: 100%; }
.map-row select.missing { border-color: var(--red-bar); background: var(--red-tint); color: var(--red); }
dialog footer { display: flex; justify-content: flex-end; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--line); }

/* Set by app.js when the table is wider than its box: it scrolls sideways inside
   its own box, and the header sticks to the top of that box instead of the page. */
.table-wrap.scroll-x { overflow: auto; max-height: 75vh; }

@media (max-width: 760px) {
  .topbar { padding: 12px 16px; }
  .app-name, .divider, #as-of-wrap { display: none; }
  .page { padding: 24px 16px 40px; }
  .page-head h1 { font-size: 1.6rem; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi { padding: 16px; }
  .kpi-num { font-size: 1.8rem; }
  .tabs { padding: 0 8px; }
  .panel-bar, .panel-foot { padding-left: 16px; padding-right: 16px; }
}

/* Tabs */
.tabs { display: flex; gap: 4px; padding: 0 24px; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 14px 16px; color: var(--body); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }

/* Notices */
.banner { margin: 0 0 20px; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--head); }
.page.banner { margin-top: 20px; margin-bottom: 0; }
.ok-banner { background: var(--green-tint); border-color: #b9dcbc; color: var(--green); }
.error-banner { background: var(--red-tint); border-color: #f1c2bd; color: var(--red); }
.info-banner { background: var(--blue-soft); border-color: #c8d6f7; color: var(--ink); }

.empty-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 48px 24px; text-align: center; }
.empty-card h2 { margin: 0 0 8px; font-size: 1.3rem; }
.empty-card p { margin: 0 auto 24px; max-width: 520px; }
a.btn { display: inline-block; text-decoration: none; }

/* Upload */
#view-upload .upload-card { margin-top: 0; }
#view-upload .drop { max-width: 420px; margin: 0 auto; }
.history { max-width: 760px; margin: 24px auto 0; }
.history table { min-width: 0; }
