/* Founder Panel — Data-Dense Dashboard design system
   Every pixel serves a purpose. 13px base, tabular numerals, compact spacing. */

:root {
  --color-text: #1F2937;
  --color-panel: #FFFFFF;
  --color-accent: #3B82F6;
  --color-up: #10B981;
  --color-down: #EF4444;
  --color-warn: #F59E0B;
  --color-border: #E5E7EB;
  --color-canvas: #F3F4F6;
  --color-muted: #6B7280;

  /* darkened variants that meet AA (4.5:1) as text on white, tints and row highlights */
  --text-up: #047857;
  --text-down: #B91C1C;
  --text-warn: #B45309;
  --text-accent: #1D4ED8;

  --head: #F9FAFB;
  --shell: #1F2937;
  --shell-2: #111827;
  --r: 0.25rem;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--color-canvas);
  color: var(--color-text);
  font: 13px/1.4 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
a { color: var(--text-accent); }
button, input, select, textarea { font: inherit; font-variant-numeric: tabular-nums; color: inherit; }

:is(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  border-radius: 2px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 6px; border: 2px solid var(--color-canvas); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------- shell */

.app {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--shell-2);
  color: #F9FAFB;
  padding: 0 0.5rem;
  height: 34px;
  border-bottom: 1px solid #000;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 700;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.brand b { color: var(--color-warn); font-weight: 700; }
.brand .mark {
  display: grid;
  place-items: center;
  width: 18px; height: 18px;
  background: var(--color-warn);
  color: var(--shell-2);
  border-radius: 3px;
  font-size: 0.625rem;
  font-weight: 800;
}

.portalbar {
  display: flex;
  align-items: stretch;
  gap: 1px;
  background: var(--shell);
  overflow-x: auto;
  scrollbar-width: none;
  height: 28px;
}
.portalbar::-webkit-scrollbar { display: none; }

.portaltab {
  background: transparent;
  border: 0;
  color: #D1D5DB;
  padding: 0 0.625rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.portaltab:hover { background: #374151; color: #fff; }
.portaltab[aria-current="true"] {
  color: #fff;
  background: var(--color-canvas);
  color: var(--color-text);
  font-weight: 600;
  border-bottom-color: var(--color-accent);
}

.modbar {
  display: flex;
  align-items: stretch;
  gap: 1px;
  background: var(--color-panel);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  scrollbar-width: none;
  height: 30px;
}
.modbar::-webkit-scrollbar { display: none; }

.modtab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--color-muted);
  padding: 0 0.625rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.modtab:hover { background: var(--head); color: var(--color-text); }
.modtab[aria-current="true"] {
  color: var(--text-accent);
  border-bottom-color: var(--color-accent);
  font-weight: 600;
}

.main { overflow: auto; }

.topbar .spacer { flex: 1; }

.whoami {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: #D1D5DB;
}
.whoami .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--color-up); }

.iconbtn {
  background: transparent;
  border: 1px solid #374151;
  color: #E5E7EB;
  border-radius: var(--r);
  height: 20px;
  padding: 0 0.375rem;
  font-size: 0.6875rem;
  cursor: pointer;
}
.iconbtn:hover { background: #374151; }

/* ---------------------------------------------------------------- layout */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  grid-auto-flow: dense;
  gap: 0.5rem;
  padding: 0.5rem;
}
.grid.tight { padding: 0 0.5rem 0.5rem; }
.grid.k6 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid.k8 { grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); }

.cols {
  display: grid;
  gap: 0.5rem;
  padding: 0 0.5rem 0.5rem;
}
.cols.c2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.cols.c3 { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.cols.sidebar { grid-template-columns: minmax(0, 1fr) 320px; }
@media (max-width: 1100px) { .cols.sidebar { grid-template-columns: 1fr; } }

.card {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--r);
  padding: 0.5rem;
  min-width: 0;
}
.card.pad0 { padding: 0; }
.card.scroll { max-height: 420px; overflow: auto; }

.card-label {
  font-size: 0.75rem;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.card-value { font-size: 1.125rem; font-weight: 700; line-height: 1.2; }
.card-sub { font-size: 0.6875rem; color: var(--color-muted); }

.card.kpi { display: flex; flex-direction: column; gap: 0.125rem; }
.card.kpi.clickable { cursor: pointer; }
.card.kpi.clickable:hover { border-color: var(--color-accent); }
.card.kpi[aria-pressed="true"] { border-color: var(--color-accent); box-shadow: inset 0 0 0 1px var(--color-accent); }

.delta-up { color: var(--text-up); }
.delta-down { color: var(--text-down); }
.value-warn { color: var(--text-warn); }
.value-accent { color: var(--text-accent); }
.muted { color: var(--color-muted); }

.panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--head);
  border-radius: var(--r) var(--r) 0 0;
  flex-wrap: wrap;
}
.panel-header > :is(h2, h3) {
  order: -1;
  margin: 0 auto 0 0;
  font-size: 0.8125rem;
}
.panel-header .meta { font-size: 0.6875rem; color: var(--color-muted); }
.panel-body { padding: 0.5rem; }
.panel-body.pad0 { padding: 0; }

.pagehead {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  flex-wrap: wrap;
}
.pagehead h1 { font-size: 0.9375rem; margin-right: auto; }
.pagehead .crumb { font-size: 0.6875rem; color: var(--color-muted); }

/* ---------------------------------------------------------------- tables */

.tablewrap { overflow: auto; max-height: calc(100vh - 230px); }
.tablewrap.short { max-height: 320px; }

.table { width: 100%; border-collapse: collapse; }

.table th {
  background: var(--head);
  color: var(--color-muted);
  font-size: 0.75rem;
  font-weight: 500;
  position: sticky;
  top: 0;
  z-index: 2;
  white-space: nowrap;
}

.table th,
.table td {
  padding: 0.375rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  text-align: right;
}

.table th:first-child,
.table td:first-child { text-align: left; }
.table :is(th, td).l { text-align: left; }
.table :is(th, td).c { text-align: center; }

.table tbody tr:hover { background: var(--head); }
.table tbody tr:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }
.table tbody tr.sel { background: #EFF6FF; }
.table tfoot td { font-weight: 700; background: var(--head); border-top: 1px solid var(--color-border); }

.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--color-text); }
.table th .sortmark { font-size: 0.625rem; color: var(--color-accent); }

.table.compact :is(th, td) { padding: 0.25rem 0.5rem; }
.table .num { font-variant-numeric: tabular-nums; }
.table .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.75rem; }
.table .trunc { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* a link or chip inside a truncating cell has to clip with it, not spill past the border;
   block children (a sub-line under the name) keep their own line */
.table td.trunc > :is(a, button, span) { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.table td.trunc > div { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.rowlink {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--text-accent); font-weight: 600; text-align: left;
}
.rowlink:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- bits */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.0625rem 0.375rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  border: 1px solid var(--color-border);
  background: var(--head);
  white-space: nowrap;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--color-muted); }
.chip.ok { background: #ECFDF5; border-color: #A7F3D0; color: var(--text-up); }
.chip.ok .dot { background: var(--color-up); }
.chip.bad { background: #FEF2F2; border-color: #FECACA; color: var(--text-down); }
.chip.bad .dot { background: var(--color-down); }
.chip.warn { background: #FFFBEB; border-color: #FDE68A; color: var(--text-warn); }
.chip.warn .dot { background: var(--color-warn); }
.chip.info { background: #EFF6FF; border-color: #BFDBFE; color: var(--text-accent); }
.chip.info .dot { background: var(--color-accent); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--r);
  padding: 0.1875rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--head); border-color: #D1D5DB; }
.btn[aria-pressed="true"], .btn.on {
  background: var(--shell);
  border-color: var(--shell);
  color: #fff;
}
/* #3B82F6 stays the accent for borders, fills and focus; text on it needs the darker blue */
.btn.primary { background: var(--text-accent); border-color: var(--text-accent); color: #fff; }
.btn.primary:hover { background: #1E40AF; }
.btn.danger { color: var(--text-down); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.xs { padding: 0.0625rem 0.3125rem; font-size: 0.6875rem; }

.btngroup { display: inline-flex; }
.btngroup .btn { border-radius: 0; margin-left: -1px; }
.btngroup .btn:first-child { border-radius: var(--r) 0 0 var(--r); margin-left: 0; }
.btngroup .btn:last-child { border-radius: 0 var(--r) var(--r) 0; }

.field {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--r);
  padding: 0.1875rem 0.375rem;
  font-size: 0.75rem;
  min-width: 0;
  width: 100%;
}
.field:hover { border-color: #D1D5DB; }
input.field[type="date"], input.field[type="datetime-local"] { padding: 0.125rem 0.25rem; }

.search { position: relative; flex: 1; min-width: 180px; }
.search .field { padding-left: 1.5rem; }
.search::before {
  content: "⌕";
  position: absolute;
  left: 0.375rem; top: 50%;
  transform: translateY(-50%);
  color: var(--color-muted);
  font-size: 0.875rem;
}

.lbl {
  display: block;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  margin-bottom: 0.125rem;
}

.formgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.375rem 0.5rem;
}
.formgrid .wide { grid-column: 1 / -1; }

.bar {
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--color-accent); }
.bar > i.ok { background: var(--color-up); }
.bar > i.warn { background: var(--color-warn); }
.bar > i.bad { background: var(--color-down); }

.spark { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.5rem;
  background: var(--color-panel);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.filterbar {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.5rem;
  background: var(--head);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}
.filterbar .lbl { margin: 0 0.125rem 0 0; }

.empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--color-muted);
  font-size: 0.75rem;
}

.collapsible > .panel-header { cursor: pointer; }
.collapsible[data-open="false"] > .panel-body,
.collapsible[data-open="false"] > .tablewrap { display: none; }
.caret { font-size: 0.625rem; color: var(--color-muted); width: 10px; }

.stackbar { display: flex; height: 8px; border-radius: 2px; overflow: hidden; background: var(--color-border); }
.stackbar > i { display: block; height: 100%; }

.legend { display: flex; gap: 0.5rem; flex-wrap: wrap; font-size: 0.6875rem; color: var(--color-muted); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 0.1875rem; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.125rem 0.5rem; font-size: 0.75rem; }
.kv dt { color: var(--color-muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }

/* ---------------------------------------------------------------- drawer */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.4);
  z-index: 40;
}

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(780px, 94vw);
  background: var(--color-panel);
  border-left: 1px solid var(--color-border);
  z-index: 41;
  display: grid;
  grid-template-rows: auto 1fr auto;
  box-shadow: -8px 0 24px rgba(17, 24, 39, 0.12);
}
.drawer header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  background: var(--shell-2);
  color: #fff;
  flex-wrap: wrap;
}
.drawer header h2 { font-size: 0.8125rem; margin-right: auto; }
.drawer .body { overflow: auto; padding: 0.5rem; display: grid; gap: 0.5rem; }
.drawer footer {
  display: flex;
  gap: 0.375rem;
  padding: 0.375rem 0.5rem;
  border-top: 1px solid var(--color-border);
  background: var(--head);
  justify-content: flex-end;
}

.modal {
  position: fixed;
  z-index: 41;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, 94vw);
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--r);
  box-shadow: 0 12px 32px rgba(17, 24, 39, 0.2);
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-height: 86vh;
}
.modal header { display: flex; align-items: center; gap: 0.5rem; padding: 0.375rem 0.5rem; border-bottom: 1px solid var(--color-border); background: var(--head); }
.modal header h2 { font-size: 0.8125rem; margin-right: auto; }
.modal .body { padding: 0.5rem; overflow: auto; display: grid; gap: 0.5rem; }
.modal footer { display: flex; gap: 0.375rem; justify-content: flex-end; padding: 0.375rem 0.5rem; border-top: 1px solid var(--color-border); }

.toast {
  position: fixed;
  bottom: 0.75rem; left: 50%;
  transform: translateX(-50%);
  background: var(--shell-2);
  color: #fff;
  padding: 0.3125rem 0.75rem;
  border-radius: var(--r);
  font-size: 0.75rem;
  z-index: 60;
  box-shadow: 0 6px 18px rgba(17, 24, 39, 0.3);
}

[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--shell-2);
  color: #fff;
  font-size: 0.6875rem;
  white-space: pre;
  padding: 0.1875rem 0.375rem;
  border-radius: 3px;
  z-index: 50;
  pointer-events: none;
}

.checkline { display: flex; align-items: center; gap: 0.375rem; font-size: 0.75rem; padding: 0.125rem 0; }

@media (prefers-reduced-motion: no-preference) {
  .drawer { animation: slidein 0.14s ease-out; }
  @keyframes slidein { from { transform: translateX(16px); opacity: 0.6; } to { transform: none; opacity: 1; } }
}

/* ---------------------------------------------------------------- print */

@media print {
  .topbar, .portalbar, .modbar, .toolbar, .filterbar, .no-print { display: none !important; }
  body { background: #fff; }
  .app { height: auto; overflow: visible; }
  .main { overflow: visible; }
}
