/* Forte Connect — single stylesheet. Design system per spec §22. */

/* ---------- Tokens (§22.1) ---------- */
:root {
  --ink: #0e1620;
  --text: #1c2733;
  --muted: #64748b;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e8ee;
  --accent: #2456e6;
  --accent-hover: #1c46c2;
  --accent-soft: #edf2ff;
  --green: #178a50;
  --green-soft: #e9f6ef;
  --amber: #b7791f;
  --amber-soft: #fdf3e2;
  --red: #c0392b;
  --red-soft: #fdecea;
  --sidebar-bg: #0f1720;
  --sidebar-top: #131f2c;
  --sidebar-bottom: #0b1119;
  --sidebar-label: #9fb0c3;
  --sidebar-hover: rgba(255, 255, 255, .04);
  --sidebar-active: rgba(36, 86, 230, .16);
  --sidebar-hairline: rgba(255, 255, 255, .07);
  --radius-card: 10px;
  --radius-control: 8px;
  --radius-pill: 999px;
  --shadow: 0 1px 2px rgba(15, 23, 32, .06);
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", Consolas, monospace;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.55;
}
h1, h2, h3 { color: var(--ink); font-weight: 600; letter-spacing: -0.01em; margin: 0 0 16px; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { margin: 0 0 12px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--font-mono); font-size: 13px; }
.mini { font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }

/* ---------- Staff layout: dark sidebar + content (§22.2) ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 224px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-top), var(--sidebar-bottom));
  border-right: 1px solid var(--sidebar-hairline);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .wordmark {
  display: block; padding: 22px 20px 18px; margin-bottom: 8px;
  border-bottom: 1px solid var(--sidebar-hairline); text-decoration: none;
}
.sidebar .wordmark img { height: 40px; width: auto; display: block; }
.sidebar nav { flex: 1; padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  color: var(--sidebar-label); text-decoration: none;
  padding: 9px 13px; font-size: 13.5px; font-weight: 500;
  border-radius: var(--radius-control);
  transition: background .12s ease, color .12s ease, box-shadow .12s ease;
}
.sidebar nav a:hover { color: #fff; background: var(--sidebar-hover); }
.sidebar nav a.active {
  color: #fff; background: var(--sidebar-active);
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar .user-chip {
  padding: 14px 20px; border-top: 1px solid var(--sidebar-hairline);
  color: var(--sidebar-label); font-size: 13px;
}
.sidebar .user-chip .name { color: #fff; display: block; font-weight: 600; margin-bottom: 2px; }
.sidebar .user-chip a { color: var(--sidebar-label); font-size: 12.5px; }
.sidebar .user-chip a:hover { color: #fff; }
.content { flex: 1; min-width: 0; padding: 28px 32px; }

/* Page header row */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; gap: 16px;
}
.page-header .crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.page-header h1 { margin: 0; }
.page-header .actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---------- Portal / public layout ---------- */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; height: 60px;
}
.topbar .wordmark { display: flex; align-items: center; text-decoration: none; }
.topbar .wordmark img { height: 30px; width: auto; display: block; filter: brightness(0); opacity: .86; }
.topbar nav { display: flex; gap: 20px; align-items: center; }
.topbar nav a { color: var(--text); font-size: 14px; text-decoration: none; }
.topbar nav a.active, .topbar nav a:hover { color: var(--accent); }
.portal-content { max-width: 1040px; margin: 0 auto; padding: 32px 24px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card h3 { margin-bottom: 12px; }
.card-grid { display: grid; gap: 16px; }
.stat-card .stat-value { font-size: 28px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
.stat-card .stat-label { font-size: 13px; color: var(--muted); margin-top: 2px; }
.stat-card .stat-delta { font-size: 12.5px; margin-top: 6px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fafbfc; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Pills ---------- */
.pill {
  display: inline-block; padding: 2px 10px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.blue { background: var(--accent-soft); color: var(--accent); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.gray { background: #eef1f4; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 14px; font-weight: 500;
  padding: 8px 14px; border-radius: var(--radius-control);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background .12s ease;
}
.btn:hover { text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: #a93226; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.form-field { margin-bottom: 16px; }
.form-field label { display: block; font-size: 13.5px; font-weight: 500; color: var(--ink); margin-bottom: 5px; }
.form-field .helper { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.form-field .error { font-size: 12.5px; color: var(--red); margin-top: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], select, textarea {
  font: inherit; font-size: 14px; color: var(--text);
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 14px; }
.checkbox-row input { width: auto; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; }

/* ---------- Auth card ---------- */
.auth-wrap { min-height: calc(100vh - 60px); display: flex; align-items: flex-start; justify-content: center; padding: 64px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .card { padding: 28px; }
.auth-card h1 { font-size: 20px; margin-bottom: 20px; }

/* ---------- Alerts / flash ---------- */
.flash { padding: 11px 14px; border-radius: var(--radius-control); font-size: 14px; margin-bottom: 16px; }
.flash.success { background: var(--green-soft); color: var(--green); }
.flash.error { background: var(--red-soft); color: var(--red); }
.flash.info { background: var(--accent-soft); color: var(--accent); }
.flash.warning { background: var(--amber-soft); color: var(--amber); }

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--muted);
}
.empty-state .icon { font-size: 28px; margin-bottom: 8px; }
.empty-state p { margin-bottom: 12px; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(14, 22, 32, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: var(--radius-card);
  box-shadow: 0 8px 30px rgba(14,22,32,.2);
  width: 100%; max-width: 440px; padding: 24px;
}
.modal h3 { margin-bottom: 8px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
[hidden] { display: none !important; }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; font-size: 13.5px;
  padding: 10px 16px; border-radius: var(--radius-control);
  box-shadow: 0 4px 14px rgba(14,22,32,.25);
  animation: toast-in .18s ease;
}
.toast.error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Error pages ---------- */
.error-page main { max-width: 480px; margin: 15vh auto; text-align: center; padding: 0 24px; }
.error-page h1 { font-size: 56px; margin-bottom: 8px; }

/* ---------- Utilities ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.stack-8 > * + * { margin-top: 8px; }
.stack-16 > * + * { margin-top: 16px; }
.stack-24 > * + * { margin-top: 24px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.right { text-align: right; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }

/* ---------- Dashboard: stat grid, queue board, alerts ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 24px; }
.alerts-strip { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.alert-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--amber-soft); color: var(--amber);
  border-radius: var(--radius-control); padding: 10px 14px; font-size: 13.5px;
}
.alert-row.red { background: var(--red-soft); color: var(--red); }
.alert-row a { color: inherit; font-weight: 600; }
.queue-board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.queue-col h3 {
  font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.queue-col h3 .count {
  background: #eef1f4; color: var(--muted); border-radius: var(--radius-pill);
  font-size: 11.5px; padding: 1px 8px;
}
.queue-col .stack { display: flex; flex-direction: column; gap: 8px; }
.queue-card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow);
  padding: 12px 14px; text-decoration: none; color: var(--text);
  transition: border-color .12s ease, transform .12s ease;
}
.queue-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.queue-card .client { font-weight: 600; color: var(--ink); font-size: 14px; }
.queue-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.queue-card .due-chip { font-size: 11.5px; padding: 1px 8px; border-radius: var(--radius-pill); background: #eef1f4; }
.queue-card .due-chip.overdue { background: var(--red-soft); color: var(--red); font-weight: 600; }
.queue-col .empty {
  border: 1px dashed var(--border); border-radius: var(--radius-card);
  color: var(--muted); font-size: 13px; text-align: center; padding: 22px 12px;
}

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { width: auto; min-width: 140px; }

/* ---------- Settings ---------- */
.settings-section { margin-bottom: 28px; }
.settings-row { display: grid; grid-template-columns: 220px 1fr auto; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: 0; }
.settings-row .label { font-weight: 500; color: var(--ink); font-size: 14px; }
.settings-row .label .mini { display: block; font-weight: 400; }
.key-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.key-dot.on { background: var(--green); }
.key-dot.off { background: #cbd5e1; }

/* ---------- Review console (§16, §23) ---------- */
.console-head {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg); padding: 16px 0 12px; margin: -28px 0 16px;
  border-bottom: 1px solid var(--border);
}
.console-head .top-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.console-head h1 { font-size: 20px; margin: 0; }
.console-head .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.console-counters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.counter-chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 4px 12px; font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.counter-chip strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.counter-chip.ok strong { color: var(--green); }
.counter-chip.warn strong { color: var(--amber); }
.console-grid { display: grid; grid-template-columns: 2fr 3fr; gap: 16px; align-items: start; }
.company-list { display: flex; flex-direction: column; gap: 6px; }
.company-row {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--border); border-radius: var(--radius-control);
  padding: 10px 12px; cursor: pointer; transition: border-color .1s ease;
}
.company-row:hover { border-color: #cbd5e1; }
.company-row.selected { border-color: var(--accent); border-left-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.company-row.state-pre_approved { border-left-color: var(--green); }
.company-row.state-approved { border-left-color: var(--green); background: linear-gradient(0deg, var(--green-soft), var(--green-soft)) padding-box, var(--surface); }
.company-row.state-rejected { border-left-color: var(--red); opacity: .55; }
.company-row .row-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.company-row .name { font-weight: 600; color: var(--ink); font-size: 14px; }
.company-row .row-meta { display: flex; gap: 6px; align-items: center; margin-top: 5px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.company-panel { position: sticky; top: 92px; }
.panel-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.panel-tabs button {
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--muted);
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 8px 12px; cursor: pointer;
}
.panel-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.evidence-block { margin-bottom: 14px; }
.evidence-block h4 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; margin: 0 0 6px;
}
.contact-line {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; background: var(--bg); border-radius: var(--radius-control);
  margin-bottom: 6px; font-size: 13.5px; flex-wrap: wrap;
}
.copy-field { margin-bottom: 12px; }
.copy-field label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.copy-field textarea { font-size: 13.5px; line-height: 1.5; min-height: 120px; resize: vertical; }
.copy-field input { font-size: 13.5px; }
.panel-actions { display: flex; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.kbd {
  font-family: var(--font-mono); font-size: 11px; background: var(--bg);
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px;
  color: var(--muted);
}
.drawer-backdrop { position: fixed; inset: 0; background: rgba(14,22,32,.3); z-index: 60; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px; max-width: 90vw; z-index: 70;
  background: var(--surface); box-shadow: -8px 0 30px rgba(14,22,32,.15);
  padding: 24px; overflow-y: auto;
}
.drawer h3 { margin-bottom: 16px; }
@media (max-width: 1100px) {
  .console-grid { grid-template-columns: 1fr; }
  .company-panel { position: static; }
}

@media (max-width: 1100px) { .queue-board { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 20px 16px; }
  .grid-2, .grid-3, .queue-board { grid-template-columns: 1fr; }
  .settings-row { grid-template-columns: 1fr; gap: 6px; }
}
