/* RMR — styles. Tokens and rules from DESIGN.md (dark bento house style).
   Elevation = lighter surface, never shadows. One accent. */

:root {
  /* surfaces — never pure black */
  --bg-base:        #0A0A0B;
  --surface:        #141416;
  --surface-raised: #1C1C1F;
  --surface-glass:  rgba(255,255,255,0.06);

  /* lines */
  --border:         #26262A;
  --border-strong:  #35353B;

  /* text */
  --text-primary:   #EDEDEF;
  --text-secondary: #A1A1AA;
  --text-muted:     #8A8A93;

  /* accent — single accent, used sparingly */
  --accent:         #6366F1;
  --accent-hover:   #7C7FF2;
  --accent-subtle:  rgba(99,102,241,0.12);

  /* status */
  --success:        #34D399;
  --warning:        #FBBF24;
  --danger:         #F87171;

  /* type scale — fluid */
  --step--1: clamp(0.83rem, 0.80rem + 0.15vw, 0.90rem);
  --step-0:  clamp(1.00rem, 0.95rem + 0.25vw, 1.13rem);
  --step-1:  clamp(1.25rem, 1.15rem + 0.50vw, 1.50rem);
  --step-2:  clamp(1.56rem, 1.35rem + 1.05vw, 2.25rem);
  --step-3:  clamp(1.95rem, 1.55rem + 2.00vw, 3.38rem);
  --step-4:  clamp(2.44rem, 1.70rem + 3.70vw, 5.06rem);

  --radius: 16px;
  --gap: 20px;

  /* categorical chart palette — validated dark steps (dataviz reference) */
  --cat-1: #3987e5;  /* Leads */
  --cat-2: #d95926;  /* Pacemakers */
  --cat-3: #199e70;  /* ICD */
  --cat-4: #c98500;  /* CRT */
  --cat-5: #d55181;  /* ICM */
  --cat-other: #6b7280;

  color-scheme: dark;
}

/* Light mode — designed in parallel, not an inversion. Neutral cool lights,
   same accent, darker status + validated light chart steps. */
:root[data-theme="light"] {
  --bg-base:        #FAFAFB;
  --surface:        #FFFFFF;
  --surface-raised: #F2F2F4;
  --surface-glass:  rgba(0,0,0,0.04);

  --border:         #E4E4E8;
  --border-strong:  #C9C9D1;

  --text-primary:   #1A1A1E;
  --text-secondary: #52525B;
  --text-muted:     #6E6E76;

  --accent:         #5457E0;
  --accent-hover:   #4346C9;
  --accent-subtle:  rgba(84,87,224,0.10);

  --success:        #0E9F6E;
  --warning:        #B45309;
  --danger:         #DC2626;

  --cat-1: #2a78d6;
  --cat-2: #eb6834;
  --cat-3: #1baf7a;
  --cat-4: #eda100;
  --cat-5: #e87ba4;
  --cat-other: #8a8a93;

  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: var(--step-0);
  line-height: 1.6;
  min-height: 100vh;
}

.mono, .num {
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { font-weight: 600; line-height: 1.2; }
h1 { font-size: var(--step-3); letter-spacing: -0.02em; }
h2 { font-size: var(--step-1); }
h3 { font-size: var(--step-0); }

a { color: var(--accent); }

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

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px clamp(64px, 8vw, 128px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.brand {
  font-weight: 700;
  font-size: var(--step-1);
  letter-spacing: -0.02em;
}
.brand span { color: var(--text-muted); font-weight: 400; }

.whoami {
  color: var(--text-secondary);
  font-size: var(--step--1);
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.login {
  max-width: 400px;
  margin: clamp(64px, 14vh, 160px) auto 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login h1 { font-size: var(--step-2); }
.login p  { color: var(--text-secondary); }

/* ---------- bento ---------- */

.bento {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}

.tile {
  border-radius: var(--radius);
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 180ms ease-out, border-color 180ms ease-out;
  min-width: 0;
}
.tile--lg   { grid-column: span 2; grid-row: span 2; }
.tile--wide { grid-column: span 2; }

.tile[data-hoverable]:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
}

@media (max-width: 900px) { .bento { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) {
  .bento { grid-template-columns: 1fr; }
  .tile--lg, .tile--wide { grid-column: span 1; }
}

.tile .label {
  color: var(--text-muted);
  font-size: var(--step--1);
  margin-bottom: 8px;
}

.kpi {
  font-size: var(--step-3);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.kpi--ok     { color: var(--success); }
.kpi--danger { color: var(--danger); }

.kpi-sub { color: var(--text-secondary); font-size: var(--step--1); margin-top: 4px; }

/* rep progress rows inside a tile */
.rep-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.rep-row:last-child { border-bottom: none; }
.rep-row .counts { display: flex; gap: 4px; align-items: baseline; }
.count-ok     { color: var(--success); }
.count-bad    { color: var(--danger); }
.count-sep    { color: var(--text-muted); }

.bar {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-raised);
  overflow: hidden;
  flex: 1;
  max-width: 160px;
}
.bar > div { height: 100%; background: var(--success); }

/* transfer list */
.xfer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--step--1);
}
.xfer:last-child { border-bottom: none; }
.xfer .route { color: var(--text-primary); }
.xfer .what  { color: var(--text-secondary); }
.xfer time   { color: var(--text-muted); white-space: nowrap; }

/* ---------- forms & buttons ---------- */

label { font-size: var(--step--1); color: var(--text-secondary); }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  min-height: 44px;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-primary);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: transform 100ms, background 180ms ease-out;
}
button:active { transform: scale(0.98); }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover { background: var(--accent-hover); }

button.ghost { background: transparent; }

.error {
  color: var(--danger);
  font-size: var(--step--1);
  min-height: 1.4em;
}

.note { color: var(--text-muted); font-size: var(--step--1); }

.hidden { display: none !important; }

/* scroll containers — wide content scrolls inside, never the page */
.scroll-x { overflow-x: auto; }

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

/* ---------- tabs ---------- */

.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 8px 14px;
  border-radius: 10px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--step--1);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.tabs a:hover { background: var(--surface); color: var(--text-primary); }
.tabs a[aria-current="page"] {
  background: var(--accent-subtle);
  color: var(--accent);
}

/* ---------- inventory table (linear layout — not bento, per DESIGN.md) ---------- */

.table-tools {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.table-tools input[type="search"] { max-width: 380px; }
.table-tools select { max-width: 200px; }

.inv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step--1);
}
.inv-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.inv-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.inv-table th.num, .inv-table td.num { text-align: right; }
.cell-desc { color: var(--text-secondary); max-width: 340px; }

.status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: var(--step--1);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.status--have        { color: var(--success); border-color: rgba(52,211,153,0.35); }
.status--missing     { color: var(--danger);  border-color: rgba(248,113,113,0.35); }
.status--implanted   { color: #7DD3FC; border-color: rgba(125,211,252,0.35); }
.status--sentBack    { color: var(--warning); border-color: rgba(251,191,36,0.35); }
.status--transferred { color: #C4B5FD; border-color: rgba(196,181,253,0.35); }

/* ---------- misc ---------- */

.narrow { max-width: 640px; }
.scroll-y { max-height: 420px; overflow-y: auto; }

/* ---------- theme toggle ---------- */

.login { position: relative; }
.login-theme { position: absolute; top: -48px; right: 0; }

/* ---------- MIF-style status grid ---------- */

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  min-height: 44px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: var(--step--1);
  color: var(--text-secondary);
}
.stat .num { font-size: var(--step-1); font-weight: 700; line-height: 1.1; }
.stat--have .num        { color: var(--success); }
.stat--missing .num     { color: var(--danger); }
.stat--implanted .num   { color: var(--cat-1); }
.stat--sentBack .num    { color: var(--warning); }
.stat--transferred .num { color: var(--cat-5); }
.stat--left .num        { color: var(--text-primary); }

/* ---------- map ---------- */

.map { width: 100%; height: auto; display: block; }
.map .pod { cursor: pointer; }
.map .pod:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.map .pod:hover circle:nth-of-type(2) { stroke: var(--accent); }
.pod-count { fill: var(--text-primary); font-size: 13px; font-weight: 700; }
.pod-name  { fill: var(--text-secondary); font-size: 11px; }

/* ---------- charts ---------- */

.mix { width: 100%; height: auto; display: block; }
.axis-label { fill: var(--text-secondary); font-size: 12px; }
.bar-total  { fill: var(--text-muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-secondary); font-size: var(--step--1);
}
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.spark { width: 100%; max-width: 220px; height: auto; display: block; margin-top: 12px; }

.age-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.age-label { flex: 0 0 150px; font-size: var(--step--1); color: var(--text-secondary); }
.age-bar { max-width: none; }
.age-bar > div { background: var(--warning); }
.age-num { flex: 0 0 52px; text-align: right; color: var(--text-muted); font-size: var(--step--1); }

/* ---------- movements (MIF-style day buckets) ---------- */

.day-head {
  display: flex; justify-content: space-between;
  font-size: var(--step--1); font-weight: 600;
  padding: 10px 0 4px;
  color: var(--text-primary);
}
.xfer-card {
  padding: 10px 12px;
  margin: 6px 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: var(--step--1);
}
.xfer-card .route { font-weight: 600; }
.xfer-card .what { color: var(--text-secondary); }

/* ---------- intake ---------- */

.stack { display: flex; flex-direction: column; gap: 12px; }
.check-row { display: flex; gap: 10px; align-items: center; }
.check-row input { width: auto; min-height: auto; }

.buckets { display: flex; flex-wrap: wrap; gap: 8px; }
.bucket {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  font-size: var(--step--1);
  color: var(--text-secondary);
  min-width: 110px;
}
.bucket .num { font-size: var(--step-1); font-weight: 700; color: var(--text-primary); }
.bucket--ok .num   { color: var(--success); }
.bucket--bad .num  { color: var(--danger); }
.bucket--warn .num { color: var(--warning); }

.conflict {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--step--1);
  color: var(--text-secondary);
}
.conflict .mono { color: var(--danger); margin-right: 8px; }

#up-detail h3 { margin: 16px 0 6px; }

.rep-name { flex: 0 0 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
