/* Familia operator console
   ------------------------------------------------------------------------
   Dark console skin. Everything is hand-rolled: no framework, no CDN.
   Colour tokens live in :root so the templ components never hardcode a hex. */

:root {
  --bg:           #0E0B1A;
  --bg-elevated:  #120F26;
  --panel:        #171233;
  --panel-hover:  #1C1740;
  --border:       #262052;
  --border-soft:  #1F1A45;
  --text:         #E8E6F5;
  --muted:        #9992C4;
  --faint:        #6C669B;

  --brand:        linear-gradient(135deg, #7B5CFF, #5B4BE1 48%, #FF6B6B);
  --brand-start:  #7B5CFF;
  --brand-mid:    #5B4BE1;
  --brand-end:    #FF6B6B;

  --success:      #22C7A9;
  --warn:         #FFB020;
  --danger:       #FF5A7A;
  --info:         #00A8E8;

  --radius:       14px;
  --radius-sm:    9px;
  --radius-pill:  999px;
  --sidebar-w:    236px;
  --speed:        150ms;

  --font: "Inter", "InterVariable", -apple-system, BlinkMacSystemFont, "Segoe UI",
          Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas,
          "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(1100px 520px at 12% -12%, rgba(123, 92, 255, 0.16), transparent 65%),
    radial-gradient(900px 460px at 96% 4%, rgba(255, 107, 107, 0.09), transparent 62%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
a:hover { color: #fff; }

.num, td.num, th.num, .stat-value, .tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ------------------------------------------------------------ progress --- */

#htmx-progress {
  position: fixed;
  inset: 0 auto auto 0;
  height: 2px;
  width: 0;
  z-index: 999;
  background: var(--brand);
  box-shadow: 0 0 12px rgba(123, 92, 255, 0.75);
  opacity: 0;
  transition: width 220ms ease, opacity 220ms ease;
  pointer-events: none;
}
#htmx-progress.active { opacity: 1; width: 72%; }
#htmx-progress.done   { opacity: 0; width: 100%; transition: width 140ms ease, opacity 320ms ease 90ms; }

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

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 14px;
  background: linear-gradient(180deg, rgba(23, 18, 51, 0.92), rgba(14, 11, 26, 0.92));
  border-right: 1px solid var(--border);
  backdrop-filter: blur(6px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 2px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 9px;
  overflow: hidden;
  display: block;
  box-shadow: 0 5px 18px rgba(91, 75, 225, 0.45);
}
.brand-mark svg { display: block; width: 100%; height: 100%; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub  { font-size: 11px; color: var(--faint); letter-spacing: 0.08em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; }
.nav-label {
  font-size: 10.5px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 10px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  border: 1px solid transparent;
  transition: background var(--speed) ease, color var(--speed) ease,
              border-color var(--speed) ease, transform var(--speed) ease;
}
.nav-item:hover { background: var(--panel-hover); color: var(--text); }
.nav-item.active {
  background: var(--brand);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 6px 20px rgba(91, 75, 225, 0.35);
}
.nav-item.active .nav-icon { opacity: 1; }
.nav-icon { width: 16px; height: 16px; flex: 0 0 16px; opacity: 0.75; }

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
  font-size: 11.5px;
  color: var(--faint);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sidebar-footer .kv { display: flex; justify-content: space-between; gap: 10px; }
.sidebar-footer .kv b { color: var(--muted); font-weight: 500; }

.main { min-width: 0; padding: 22px 26px 56px; }

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-title { margin: 0; font-size: 21px; font-weight: 640; letter-spacing: -0.015em; }
.page-sub   { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* --------------------------------------------------------------- panel --- */

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.09) 22%,
              rgba(255, 255, 255, 0.09) 78%, transparent);
  pointer-events: none;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.panel-title { font-weight: 600; font-size: 13.5px; letter-spacing: 0.01em; }
.panel-note  { font-size: 12px; color: var(--muted); }
.panel-body  { padding: 14px 16px; }
.panel + .panel, .panel + .grid, .grid + .panel { margin-top: 18px; }

.grid { display: grid; gap: 16px; align-items: start; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ----------------------------------------------------------- stat grid --- */

.stat-block { min-height: 470px; }           /* stable height: no HTMX jitter */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
  gap: 14px;
}
/* Above this width the auto-fill would give five ragged columns for the eight
   overview cards; four is the layout the numbers were designed for. */
@media (min-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.stat-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 15px 13px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform var(--speed) ease, border-color var(--speed) ease,
              background var(--speed) ease, box-shadow var(--speed) ease;
}
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.10) 20%,
              rgba(255, 255, 255, 0.10) 80%, transparent);
}
.stat-card:hover {
  transform: translateY(-1px);
  background: var(--panel-hover);
  border-color: #332C6B;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}
.stat-label {
  font-size: 11px;
  letter-spacing: 0.085em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  font-size: 28px;
  font-weight: 660;
  letter-spacing: -0.025em;
  line-height: 1.12;
}
.stat-value.accent {
  background: var(--brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stat-sub { font-size: 12px; color: var(--faint); margin-top: auto; }
.stat-sub .up   { color: var(--success); }
.stat-sub .down { color: var(--danger); }
.stat-sub .flat { color: var(--muted); }

/* ------------------------------------------------------------ sparkline --- */

.sparkline { display: block; width: 100%; height: 104px; overflow: visible; }
.sparkline .axis { stroke: var(--border); stroke-width: 1; }
.spark-legend {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--faint);
  margin-top: 6px;
}

/* --------------------------------------------------------------- table --- */

.table-scroll { overflow-x: auto; max-height: 74vh; overflow-y: auto; }
table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
table.data thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #150F31;
  text-align: left;
  font-weight: 560;
  font-size: 11px;
  letter-spacing: 0.085em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
table.data tbody tr { transition: background var(--speed) ease; }
table.data tbody tr:hover { background: var(--panel-hover); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .primary { font-weight: 560; }
table.data .dim { color: var(--muted); }
table.data .mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.row-disabled td { opacity: 0.62; }
.empty { padding: 34px 16px; text-align: center; color: var(--faint); }

.truncate { display: block; max-width: 460px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* -------------------------------------------------------------- badges --- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 560;
  letter-spacing: 0.015em;
  line-height: 1.6;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.neutral { background: rgba(153, 146, 196, 0.13); color: var(--muted);  border-color: rgba(153, 146, 196, 0.24); }
.badge.success { background: rgba( 34, 199, 169, 0.13); color: var(--success);border-color: rgba( 34, 199, 169, 0.30); }
.badge.warn    { background: rgba(255, 176,  32, 0.13); color: var(--warn);   border-color: rgba(255, 176,  32, 0.30); }
.badge.danger  { background: rgba(255,  90, 122, 0.13); color: var(--danger); border-color: rgba(255,  90, 122, 0.30); }
.badge.info    { background: rgba(  0, 168, 232, 0.13); color: var(--info);   border-color: rgba(  0, 168, 232, 0.30); }
.badge.brand   { background: rgba(123,  92, 255, 0.16); color: #B9A8FF;       border-color: rgba(123,  92, 255, 0.34); }
.badge.dot::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.delta { font-variant-numeric: tabular-nums; font-weight: 600; }
.delta.pos { color: var(--success); }
.delta.neg { color: var(--danger); }
.delta.zero { color: var(--muted); }

/* -------------------------------------------------------------- inputs --- */

.field {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font: inherit;
  font-size: 13px;
  min-width: 190px;
  transition: border-color var(--speed) ease, box-shadow var(--speed) ease;
}
.field::placeholder { color: var(--faint); }
.field:focus {
  outline: none;
  border-color: var(--brand-start);
  box-shadow: 0 0 0 3px rgba(123, 92, 255, 0.20);
}
select.field { cursor: pointer; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background var(--speed) ease, border-color var(--speed) ease,
              transform var(--speed) ease, color var(--speed) ease;
}
.btn:hover { background: var(--panel-hover); border-color: #332C6B; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--brand);
  border-color: rgba(255, 255, 255, 0.14);
  color: #fff;
  box-shadow: 0 6px 20px rgba(91, 75, 225, 0.34);
}
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: 4px 10px; font-size: 11.5px; }
.btn.danger:hover { color: var(--danger); border-color: rgba(255, 90, 122, 0.45); }
.btn.ghost { background: transparent; }

/* --------------------------------------------------------------- chips --- */

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--muted);
  font-size: 12px;
  font-weight: 540;
  cursor: pointer;
  transition: all var(--speed) ease;
}
.chip:hover { color: var(--text); border-color: #332C6B; background: var(--panel-hover); }
.chip.active {
  background: var(--brand);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 4px 14px rgba(91, 75, 225, 0.32);
}

/* ---------------------------------------------------------- pagination --- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  border-top: 1px solid var(--border-soft);
  font-size: 12.5px;
  color: var(--muted);
}
.pager-actions { display: flex; align-items: center; gap: 8px; }
.pager .btn[disabled], .pager .btn.disabled,
.pager-row .btn[disabled], .pager-row .btn.disabled { opacity: 0.38; pointer-events: none; }

/* The pager lives inside the <tbody> so one HTMX swap refreshes rows and
   pagination together — no out-of-band tricks, no partial states. */
.pager-row td {
  position: sticky;
  bottom: 0;
  z-index: 1;
  padding: 0;
  background: #150F31;
  border-top: 1px solid var(--border);
  border-bottom: 0 !important;
}
table.data tbody tr.pager-row:hover { background: transparent; }
.pager-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 9px 14px;
  font-size: 12.5px;
  color: var(--muted);
}
.pager-inner .dim { color: var(--faint); }

/* --------------------------------------------------------------- meter --- */

.meter { height: 6px; border-radius: var(--radius-pill); background: #221C4B; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--brand); }

.kv-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 18px; }
.kv-item { display: flex; flex-direction: column; gap: 2px; }
.kv-item .k { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.kv-item .v { font-size: 15px; font-weight: 580; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- login --- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 372px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 26px 24px;
  position: relative;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}
.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.14), transparent);
}
.login-mark { width: 46px; height: 46px; border-radius: 14px; overflow: hidden; margin-bottom: 16px; }
.login-mark svg { display: block; width: 100%; height: 100%; }
.login-card h1 { margin: 0 0 4px; font-size: 19px; letter-spacing: -0.015em; }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 12.5px; }
.login-card label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.085em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 5px;
}
.login-card .field { width: 100%; margin-bottom: 14px; min-width: 0; }
.login-card .btn { width: 100%; justify-content: center; padding: 9px 14px; font-size: 13px; }
.login-error {
  background: rgba(255, 90, 122, 0.12);
  border: 1px solid rgba(255, 90, 122, 0.32);
  color: #FFA9BB;
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* ------------------------------------------------------------ responsive --- */

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    overflow-x: auto;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0; flex: 0 0 auto; }
  .brand-text { display: none; }
  .nav { flex-direction: row; flex: 1 1 auto; gap: 6px; }
  .nav-label { display: none; }
  .nav-item { padding: 6px 11px; white-space: nowrap; font-size: 12.5px; }
  .sidebar-footer { display: none; }
  .main { padding: 16px 14px 40px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .stat-block { min-height: 0; }
  .truncate { max-width: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}
