/* ═══════════════════════════════════════════════════════════════
   Command Center — Design System v2
   KH2-inspired dark command interface
   Dark navy / chrome framing / cool blue glow / fantasy-tech
═══════════════════════════════════════════════════════════════ */

:root {
  /* Core palette */
  --bg:        #050c1a;
  --bg-deep:   #02070f;
  --panel:     #0a1628;
  --panel-2:   #0f1e36;
  --panel-3:   #14263f;

  /* Chrome / silver framing */
  --line:         rgba(140, 180, 240, 0.18);
  --line-bright:  rgba(170, 210, 255, 0.32);
  --line-chrome:  rgba(190, 220, 255, 0.42);

  /* Text */
  --text:      #dceeff;
  --text-soft: #b8d0ee;
  --muted:     #7a9abf;
  --muted-dim: #4e6a8a;

  /* Accent family (cool blue + teal) */
  --accent:       #4db8f8;
  --accent-glow:  rgba(77, 184, 248, 0.22);
  --accent-2:     #8cf0ee;
  --accent-2-glow: rgba(140, 240, 238, 0.18);

  /* Status */
  --ok:           #6de4a0;
  --ok-glow:      rgba(109, 228, 160, 0.16);
  --warning:      #f5c64a;
  --warning-glow: rgba(245, 198, 74, 0.16);
  --danger:       #ff7b7a;
  --danger-glow:  rgba(255, 123, 122, 0.16);

  /* Chip/tag backgrounds */
  --chip:         rgba(77, 184, 248, 0.12);
  --chip-hover:   rgba(77, 184, 248, 0.22);

  /* Glow shadow */
  --panel-shadow: 0 12px 40px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.3);
  --glow-sm:      0 0 14px rgba(77, 184, 248, 0.14);
  --glow-md:      0 0 28px rgba(77, 184, 248, 0.18);
  --glow-accent:  0 0 20px rgba(77, 184, 248, 0.28);
}

/* ── Reset ── */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(ellipse 900px 500px at 85% -5%, rgba(30, 80, 180, 0.18), transparent 55%),
    radial-gradient(ellipse 700px 400px at 5% 95%,  rgba(20, 100, 180, 0.12), transparent 60%),
    linear-gradient(180deg, #030b18 0%, #060f1e 50%, #020810 100%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ── Shell — main outer frame ── */
.shell {
  width: min(1320px, calc(100vw - 32px));
  margin: 20px auto;
  padding: 24px;
  /* Chrome-frame layered border */
  border: 1px solid var(--line-chrome);
  border-radius: 28px;
  background: linear-gradient(175deg,
    rgba(14, 28, 50, 0.95) 0%,
    rgba(8, 16, 30, 0.98) 100%
  );
  backdrop-filter: blur(18px) saturate(1.4);
  box-shadow:
    0 0 0 1px rgba(200, 225, 255, 0.06) inset,
    0 24px 70px rgba(0, 0, 0, 0.5),
    0 0 40px rgba(30, 80, 180, 0.08);
}

/* ── Auth surfaces ── */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: min(480px, calc(100vw - 32px));
  padding: 32px;
  border: 1px solid var(--line-chrome);
  border-radius: 28px;
  background: linear-gradient(170deg, rgba(14, 28, 50, 0.96), rgba(6, 14, 26, 0.98));
  backdrop-filter: blur(18px);
  box-shadow:
    0 0 0 1px rgba(200, 225, 255, 0.06) inset,
    var(--panel-shadow),
    0 0 50px rgba(30, 80, 180, 0.12);
}

.auth-card h1 { margin: 0 0 10px; }

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.auth-error {
  margin: 16px 0 0;
  padding: 12px 16px;
  border: 1px solid rgba(255, 122, 120, 0.3);
  border-radius: 14px;
  color: var(--danger);
  background: rgba(255, 122, 120, 0.06);
}

.auth-notice {
  margin: 16px 0 0;
  padding: 12px 16px;
  border: 1px solid rgba(109, 228, 160, 0.3);
  border-radius: 14px;
  color: var(--ok);
  background: rgba(109, 228, 160, 0.06);
}

/* ── Topbar ── */
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  /* Subtle separator glow */
  box-shadow: 0 1px 0 rgba(77, 184, 248, 0.08);
}

.topbar h1,
.panel h2 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar h1 {
  font-size: 1.45rem;
  background: linear-gradient(120deg, #dceeff 30%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Eyebrow label ── */
.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
}

/* ── Navigation ── */
.nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.nav-link,
button,
.button-link {
  border: 1px solid var(--line);
  background: rgba(14, 30, 56, 0.6);
  color: var(--text-soft);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 0.83rem;
  letter-spacing: 0.01em;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.nav-link:hover,
button:hover,
.button-link:hover {
  background: var(--chip-hover);
  border-color: rgba(77, 184, 248, 0.4);
  color: var(--text);
  box-shadow: 0 0 12px rgba(77, 184, 248, 0.12);
}

.nav-link.active {
  background: linear-gradient(135deg, rgba(77, 184, 248, 0.18), rgba(140, 240, 238, 0.1));
  border-color: rgba(77, 184, 248, 0.5);
  color: var(--accent);
  box-shadow: 0 0 16px rgba(77, 184, 248, 0.18), 0 0 0 1px rgba(77, 184, 248, 0.08) inset;
  font-weight: 600;
}

.button-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ── Content grid ── */
.content {
  display: grid;
  gap: 20px;
  margin-top: 24px;
}

/* ── Panel — primary content block ── */
.panel {
  background: linear-gradient(165deg,
    rgba(16, 34, 60, 0.95) 0%,
    rgba(10, 22, 42, 0.98) 100%
  );
  border: 1px solid var(--line-bright);
  border-radius: 22px;
  padding: 20px;
  box-shadow:
    0 0 0 1px rgba(200, 225, 255, 0.04) inset,
    var(--panel-shadow);
  position: relative;
}

/* Subtle top-edge highlight (chrome effect) */
.panel::before {
  content: "";
  position: absolute;
  top: 0; left: 16px; right: 16px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180, 220, 255, 0.3), transparent);
  border-radius: 999px;
  pointer-events: none;
}

.banner {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

/* ── Card grid ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

/* ── Stat card ── */
.stat-card {
  padding: 18px 20px;
  border-radius: 20px;
  background: linear-gradient(170deg,
    rgba(16, 36, 64, 0.96) 0%,
    rgba(9, 20, 38, 0.98) 100%
  );
  border: 1px solid var(--line-bright);
  box-shadow:
    0 0 0 1px rgba(200, 225, 255, 0.04) inset,
    0 8px 28px rgba(0,0,0,0.35);
  transition: box-shadow 0.2s, border-color 0.2s;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: "";
  position: absolute;
  top: 0; left: 10px; right: 10px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180, 220, 255, 0.22), transparent);
  pointer-events: none;
}

.stat-card:hover {
  border-color: rgba(77, 184, 248, 0.3);
  box-shadow:
    0 0 0 1px rgba(77, 184, 248, 0.06) inset,
    0 8px 28px rgba(0,0,0,0.4),
    var(--glow-sm);
}

.stat-card h3,
.stat-card p {
  margin: 0;
}

.stat-card h3 {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-top: 10px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* ── Panel header ── */
.panel-header,
.filter-actions {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

/* ── Chips / Status pills ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.chip.ok {
  color: var(--ok);
  background: var(--ok-glow);
  border-color: rgba(109, 228, 160, 0.22);
}

.chip.warning {
  color: var(--warning);
  background: var(--warning-glow);
  border-color: rgba(245, 198, 74, 0.22);
}

.chip.danger {
  color: var(--danger);
  background: var(--danger-glow);
  border-color: rgba(255, 123, 122, 0.22);
}

.chip.accent {
  color: var(--accent);
  background: var(--accent-glow);
  border-color: rgba(77, 184, 248, 0.28);
}

/* ── Filters ── */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.export-actions { margin-bottom: 14px; }

.export-preview-wrap { display: grid; gap: 8px; }

.export-preview {
  min-height: 220px;
  resize: vertical;
  font-family: "SF Mono", "Menlo", monospace;
  line-height: 1.45;
}

/* ── Form controls ── */
label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}

select,
input {
  width: 100%;
  min-width: 0;
  border-radius: 12px;
  border: 1px solid var(--line-bright);
  background: rgba(10, 22, 42, 0.8);
  color: var(--text);
  padding: 10px 14px;
  font: inherit;
  font-size: 0.88rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select:focus,
input:focus {
  outline: none;
  border-color: rgba(77, 184, 248, 0.5);
  box-shadow: 0 0 0 3px rgba(77, 184, 248, 0.08);
}

input::placeholder { color: var(--muted-dim); }

button.ghost { background: transparent; }

/* Primary action button */
button.btn-primary,
.btn-primary {
  background: linear-gradient(135deg, rgba(77, 184, 248, 0.22), rgba(140, 240, 238, 0.12));
  border-color: rgba(77, 184, 248, 0.5);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 0 16px rgba(77, 184, 248, 0.14);
}

button.btn-primary:hover,
.btn-primary:hover {
  background: linear-gradient(135deg, rgba(77, 184, 248, 0.32), rgba(140, 240, 238, 0.2));
  box-shadow: var(--glow-accent);
}

/* Danger button */
button.btn-danger {
  border-color: rgba(255, 123, 122, 0.4);
  color: var(--danger);
  background: var(--danger-glow);
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  border-bottom: 1px solid var(--line-bright);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

tr:hover td { background: rgba(77, 184, 248, 0.03); }

td strong { display: block; }

/* ── Empty / loading states ── */
.empty {
  color: var(--muted);
  text-align: center;
  padding: 36px 24px;
  font-size: 0.9rem;
}

.loading-shimmer {
  background: linear-gradient(90deg,
    rgba(20, 40, 70, 0.6) 25%,
    rgba(30, 60, 100, 0.6) 50%,
    rgba(20, 40, 70, 0.6) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
  border-radius: 8px;
  height: 14px;
  margin-bottom: 8px;
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

/* ── Charts ── */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.chart-box {
  background: linear-gradient(170deg, rgba(12, 26, 48, 0.95), rgba(8, 16, 32, 0.98));
  border: 1px solid var(--line-bright);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 0 0 1px rgba(200, 225, 255, 0.03) inset, 0 8px 24px rgba(0,0,0,0.3);
}

.chart-box h3 {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 14px 0;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.chart-box canvas { max-height: 280px; }

/* ── Market-specific cards ── */
.market-overview-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 18px;
}

.market-overview-card h3 { grid-column: 1 / -1; }
.market-competitor-card  { min-height: 240px; }

/* ── Memory dashboard ── */
.memory-day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.memory-day-card { transition: border-color 0.2s; }
.memory-day-card:hover { border-color: var(--accent); }

.memory-content { max-height: 600px; overflow-y: auto; }

.memory-pre {
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  background: var(--bg);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

/* ── Section divider ── */
.section-rule {
  border: none;
  border-top: 1px solid var(--line);
  margin: 20px 0;
  background: linear-gradient(90deg, transparent, rgba(77, 184, 248, 0.1), transparent);
  height: 1px;
}

/* ── KH2-style action panel (elevated call-to-action block) ── */
.action-panel {
  background: linear-gradient(155deg,
    rgba(20, 50, 90, 0.6),
    rgba(8, 20, 40, 0.8)
  );
  border: 1px solid var(--line-chrome);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow:
    0 0 0 1px rgba(180, 210, 255, 0.06) inset,
    0 4px 20px rgba(0,0,0,0.4),
    0 0 30px rgba(30, 80, 180, 0.08);
}

/* ── Urgency indicators ── */
.urgent-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  box-shadow: 0 0 6px currentColor;
}

.urgent-dot.red    { background: var(--danger);  color: var(--danger); }
.urgent-dot.yellow { background: var(--warning); color: var(--warning); }
.urgent-dot.green  { background: var(--ok);      color: var(--ok); }

/* ── Freshness badge ── */
.freshness-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.07);
  background: rgba(255,255,255,0.03);
}

/* ── Role tabs (home page) ── */
.role-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.role-tab {
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  background: rgba(14, 28, 52, 0.6);
  color: var(--text-soft);
  transition: all 0.18s ease;
}

.role-tab.active {
  background: linear-gradient(135deg, rgba(77, 184, 248, 0.2), rgba(140, 240, 238, 0.1));
  border-color: rgba(77, 184, 248, 0.55);
  color: var(--accent);
  box-shadow: 0 0 16px rgba(77, 184, 248, 0.16);
  font-weight: 600;
}

/* ── Metric tile (home dashboard) ── */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.tile {
  background: linear-gradient(165deg, rgba(14, 30, 56, 0.96), rgba(8, 18, 34, 0.98));
  border: 1px solid var(--line-bright);
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: 0 0 0 1px rgba(200, 225, 255, 0.04) inset, 0 8px 24px rgba(0,0,0,0.35);
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.tile::before {
  content: "";
  position: absolute;
  top: 0; left: 12px; right: 12px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180, 220, 255, 0.22), transparent);
  pointer-events: none;
}

.tile:hover {
  border-color: rgba(77, 184, 248, 0.28);
  box-shadow:
    0 0 0 1px rgba(77, 184, 248, 0.05) inset,
    0 8px 28px rgba(0,0,0,0.4),
    var(--glow-sm);
}

.tile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.tile-title {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

.tile-value {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  margin: 4px 0 6px;
}

.tile-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}

.tile-freshness {
  font-size: 0.7rem;
  color: var(--muted-dim);
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile-link {
  font-size: 0.72rem;
  color: var(--accent);
  text-decoration: none;
  transition: opacity 0.15s;
}

.tile-link:hover { opacity: 0.8; }

/* Health dot */
.health-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.health-dot.green  { background: var(--ok);      box-shadow: 0 0 6px var(--ok); }
.health-dot.yellow { background: var(--warning);  box-shadow: 0 0 6px var(--warning); }
.health-dot.red    { background: var(--danger);   box-shadow: 0 0 6px var(--danger); }
.health-dot.unknown { background: var(--muted-dim); }

/* ── Category badge pills (Reddit intel etc.) ── */
.cat-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 4px;
}

.cat-pricing   { background: rgba(245, 198, 74, 0.18);  color: var(--warning); border: 1px solid rgba(245,198,74,0.3); }
.cat-quality   { background: rgba(255,123,122,0.14);    color: var(--danger);  border: 1px solid rgba(255,123,122,0.3); }
.cat-praise    { background: rgba(109,228,160,0.14);    color: var(--ok);      border: 1px solid rgba(109,228,160,0.3); }
.cat-complaint { background: rgba(255,150,80,0.14);     color: #f97316;        border: 1px solid rgba(255,150,80,0.3); }
.cat-competitor{ background: rgba(168,85,247,0.14);     color: #c084fc;        border: 1px solid rgba(168,85,247,0.3); }
.cat-own       { background: rgba(77,184,248,0.14);     color: var(--accent);  border: 1px solid rgba(77,184,248,0.3); }
.cat-general   { background: rgba(255,255,255,0.06);    color: var(--muted);   border: 1px solid rgba(255,255,255,0.1); }

/* ── Signal list ── */
.signal-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.signal-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.83rem;
  line-height: 1.4;
}

.signal-list li:last-child { border-bottom: none; }

/* ── Section heading with link ── */
.section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 24px 0 12px;
}

.section-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-header a {
  font-size: 0.73rem;
  color: var(--accent);
  opacity: 0.8;
}

.section-header a:hover { opacity: 1; }

/* ── Urgency pills (reorder tables) ── */
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.pill.red    { background: rgba(255,123,122,0.14); color: var(--danger);  border-color: rgba(255,123,122,0.3); }
.pill.orange { background: rgba(255,150,80,0.14);  color: #f97316;        border-color: rgba(255,150,80,0.3); }
.pill.yellow { background: rgba(245,198,74,0.14);  color: var(--warning); border-color: rgba(245,198,74,0.3); }
.pill.green  { background: rgba(109,228,160,0.14); color: var(--ok);      border-color: rgba(109,228,160,0.3); }

/* ── QA stats ── */
.qa-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 8px;
  margin-bottom: 16px;
}

.qa-col { flex: 1; min-width: 100px; }
.qa-num { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.qa-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 2px; }

/* ── Reorder table ── */
table.rt {
  min-width: 0;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

table.rt th {
  font-size: 0.68rem;
  padding: 8px 10px;
  background: rgba(8, 18, 36, 0.9);
}

table.rt td { padding: 8px 10px; }

/* ── Summary stat boxes (vendor reorder) ── */
.summary-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.stat-box {
  background: linear-gradient(165deg, rgba(14, 30, 56, 0.96), rgba(8, 18, 34, 0.98));
  border: 1px solid var(--line-bright);
  border-radius: 18px;
  padding: 16px 18px;
  flex: 1;
  min-width: 120px;
  box-shadow: 0 0 0 1px rgba(200,225,255,0.04) inset, 0 6px 20px rgba(0,0,0,0.3);
  position: relative;
  overflow: hidden;
}

.stat-box::before {
  content: "";
  position: absolute;
  top: 0; left: 8px; right: 8px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180,220,255,0.18), transparent);
  pointer-events: none;
}

.stat-val   { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.02em; margin: 0; line-height: 1; }
.stat-label { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 4px 0 0; }

/* ── Expiry urgency pulse (≤7d) ── */
@keyframes pulse-urgent {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

/* Applied to pill elements and td cells with critical expiry */
.expiry-urgent {
  animation: pulse-urgent 2s ease-in-out infinite;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .expiry-urgent { animation: none; }
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(10,22,42,0.4); border-radius: 999px; }
::-webkit-scrollbar-thumb { background: rgba(77,184,248,0.2); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(77,184,248,0.35); }

/* ── Receiving confidence badges ── */
.confidence-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.confidence-badge.high   { background: rgba(109,228,160,0.14); color: var(--ok);     border: 1px solid rgba(109,228,160,0.28); }
.confidence-badge.medium { background: rgba(245,198,74,0.14);  color: var(--warning); border: 1px solid rgba(245,198,74,0.28); }
.confidence-badge.low    { background: rgba(255,123,122,0.14); color: var(--danger);  border: 1px solid rgba(255,123,122,0.28); }

/* ── Shared skeleton loader ── */
.skel-tile {
  background: linear-gradient(165deg, rgba(14, 30, 56, 0.96), rgba(8, 18, 34, 0.98));
  border: 1px solid var(--line-bright);
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: 0 0 0 1px rgba(200,225,255,.04) inset, 0 8px 24px rgba(0,0,0,.35);
}

.skel-line {
  background: linear-gradient(90deg,
    rgba(20,42,74,.7) 25%,
    rgba(34,70,110,.65) 50%,
    rgba(20,42,74,.7) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.7s ease-in-out infinite;
  border-radius: 6px;
}

.skel-stat {
  background: linear-gradient(165deg, rgba(14, 30, 56, 0.96), rgba(8, 18, 34, 0.98));
  border: 1px solid var(--line-bright);
  border-radius: 18px;
  padding: 16px 18px;
  flex: 1;
  min-width: 120px;
  box-shadow: 0 0 0 1px rgba(200,225,255,.04) inset, 0 6px 20px rgba(0,0,0,.3);
}

@media (prefers-reduced-motion: reduce) {
  .skel-line { animation: none; background: rgba(24,46,80,.7); }
}

/* Fade-in reveal animation */
.fade-in { animation: fadeIn 0.35s ease both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* Inline error state */
.error-banner {
  padding: 16px 20px;
  border: 1px solid rgba(255,123,122,.3);
  border-radius: 18px;
  background: rgba(255,123,122,.06);
  color: var(--danger);
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Pipeline health row (home dashboard) */
.pipeline-leg {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: .83rem;
}
.pipeline-leg:last-child { border-bottom: none; }
.pipeline-leg .leg-name  { flex: 1; font-weight: 500; }

/* Refresh / freshness status indicator */
.refresh-status {
  font-size: 0.73rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* Action hint line in tiles — "what to do next" */
.tile-action {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--accent-2);
  margin: 7px 0 0;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

/* Data freshness line */
.data-freshness {
  font-size: 0.72rem;
  color: var(--muted-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.data-freshness .freshness-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 5px var(--ok);
  flex-shrink: 0;
}
.freshness-refresh {
  margin-left: auto;
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  padding: 2px 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.freshness-refresh:hover {
  color: var(--accent);
  border-color: rgba(77, 184, 248, 0.4);
}

/* Stat value flash — brief accent pulse on update */
@keyframes stat-flash {
  0%   { color: var(--accent); opacity: 0.7; }
  100% { color: inherit;       opacity: 1;   }
}
.stat-flash { animation: stat-flash 0.7s ease; }
@media (prefers-reduced-motion: reduce) { .stat-flash { animation: none; } }

/* ── Watchlist: full-viewport app layout ── */
body[data-page="watchlist"] {
  overflow: hidden;
  height: 100vh;
}

body[data-page="watchlist"] .shell {
  height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body[data-page="watchlist"] .topbar {
  flex-shrink: 0;
}

body[data-page="watchlist"] .content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  margin-top: 14px;
  gap: 10px;
}

body[data-page="watchlist"] .wl-controls {
  flex-shrink: 0;
  padding: 12px 16px;
}

body[data-page="watchlist"] .wl-table-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  padding: 14px 18px 0;
}

body[data-page="watchlist"] .wl-table-panel .table-wrap {
  flex: 1;
  overflow: auto;
  min-height: 0;
  margin: 0 -18px;
  padding: 0 18px 14px;
}

/* Watchlist toolbar */
.wl-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
}

.wl-filter {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.wl-filter > span {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
  white-space: nowrap;
}

.wl-filter select { min-width: 110px; }
.wl-search input  { min-width: 180px; }

.wl-actions {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-left: auto;
}

.wl-meta-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ── Command Hub: tool nav grid ── */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.tool-card {
  display: block;
  padding: 14px 16px;
  background: linear-gradient(165deg, rgba(14, 30, 56, 0.88), rgba(8, 18, 34, 0.92));
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.18s, box-shadow 0.18s;
  position: relative;
  overflow: hidden;
}

.tool-card::before {
  content: "";
  position: absolute;
  top: 0; left: 10px; right: 10px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180, 220, 255, 0.12), transparent);
  pointer-events: none;
}

.tool-card:hover {
  border-color: rgba(77, 184, 248, 0.28);
  box-shadow: 0 0 16px rgba(77, 184, 248, 0.08), var(--glow-sm);
}

.tool-card-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 5px;
}

.tool-card-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}

/* Clickable table rows */
tr.row-link {
  cursor: pointer;
  transition: background 0.12s;
}
tr.row-link:hover td {
  background: rgba(77, 184, 248, 0.05);
}

/* Command Hub: location card header */
.loc-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.loc-card-header .loc-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  text-transform: none;
  margin: 0;
}

.loc-card-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  flex-shrink: 0;
}

/* ── Operational pages: content-scrolls app layout ── */
/* receiving, expiry-compliance, vendor-reorder, command-hub                 */
/* Shell = viewport container. Topbar fixed. Content region scrolls.        */

body[data-page="command-hub"],
body[data-page="home"],
body[data-page="expiry-compliance"],
body[data-page="vendor-reorder"],
body[data-page="market"] {
  overflow: hidden;
  height: 100vh;
}

body[data-page="receiving"] {
  overflow: auto;
  height: auto;
  overflow-x: hidden;
}

body[data-page="command-hub"] .shell,
body[data-page="home"] .shell,
body[data-page="expiry-compliance"] .shell,
body[data-page="vendor-reorder"] .shell,
body[data-page="market"] .shell {
  height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body[data-page="receiving"] .shell {
  height: auto;
  overflow: visible;
  max-width: calc(100vw - 32px);
  box-sizing: border-box;
}

body[data-page="command-hub"] .topbar,
body[data-page="home"] .topbar,
body[data-page="receiving"] .topbar,
body[data-page="expiry-compliance"] .topbar,
body[data-page="vendor-reorder"] .topbar,
body[data-page="market"] .topbar {
  flex-shrink: 0;
}

body[data-page="command-hub"] .content,
body[data-page="home"] .content,
body[data-page="expiry-compliance"] .content,
body[data-page="vendor-reorder"] .content,
body[data-page="market"] .content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding-bottom: 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(77, 184, 248, 0.18) transparent;
}

body[data-page="receiving"] .content {
  flex: unset;
  overflow-y: visible;
  overflow-x: hidden;
  min-height: unset;
  padding-bottom: 20px;
  min-width: 0;
}

body[data-page="receiving"] .panel,
body[data-page="receiving"] .banner,
body[data-page="receiving"] .table-wrap,
body[data-page="receiving"] .card-grid {
  max-width: 100%;
  min-width: 0;
}

body[data-page="command-hub"] .content::-webkit-scrollbar,
body[data-page="home"] .content::-webkit-scrollbar,
body[data-page="receiving"] .content::-webkit-scrollbar,
body[data-page="expiry-compliance"] .content::-webkit-scrollbar,
body[data-page="vendor-reorder"] .content::-webkit-scrollbar,
body[data-page="market"] .content::-webkit-scrollbar { width: 4px; }

body[data-page="command-hub"] .content::-webkit-scrollbar-thumb,
body[data-page="home"] .content::-webkit-scrollbar-thumb,
body[data-page="receiving"] .content::-webkit-scrollbar-thumb,
body[data-page="expiry-compliance"] .content::-webkit-scrollbar-thumb,
body[data-page="vendor-reorder"] .content::-webkit-scrollbar-thumb,
body[data-page="market"] .content::-webkit-scrollbar-thumb {
  background: rgba(77, 184, 248, 0.18);
  border-radius: 999px;
}

/* Market: layout fixes */

body[data-page="market"] .content {
  display: flex;
  flex-direction: column;
  overflow-x: clip;
}

body[data-page="market"] .market-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
  min-height: 60px;
}

body[data-page="market"] .market-filters label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 150px;
  flex: 1 1 150px;
}

body[data-page="market"] .market-filters label span {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

body[data-page="market"] .filter-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 6px;
}

body[data-page="market"] #market-meta,
body[data-page="market"] #market-refresh-meta,
body[data-page="market"] .panel-header .meta,
body[data-page="market"] #market-overview-meta {
  overflow-wrap: anywhere;
}

body[data-page="market"] #market-card-grid {
  grid-template-columns: repeat(auto-fill, minmax(240px, 360px));
}

body[data-page="market"] .market-overview-card,
body[data-page="market"] .table-wrap {
  min-width: 0;
}

/* Receiving: compact charts so they don't eat too much height */
body[data-page="receiving"] .chart-box canvas { max-height: 180px; }

/* Receiving: filter row */
.recv-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.recv-filters label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 120px;
}

.recv-filters label.recv-search { flex: 2; min-width: 180px; }

#recv-custom-dates {
  display: none;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

#recv-custom-dates label { min-width: 120px; }

/* Receiving: table toolbar (row count + export) */
.recv-table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 8px;
}

/* Receiving: keep manifest rows readable and prevent tall/broken row layout */
body[data-page="receiving"] #recv-table {
  table-layout: auto;
}

body[data-page="receiving"] #recv-table th,
body[data-page="receiving"] #recv-table td {
  vertical-align: top;
}

body[data-page="receiving"] .recv-cell-location,
body[data-page="receiving"] .recv-cell-manifest,
body[data-page="receiving"] .recv-cell-package,
body[data-page="receiving"] .recv-cell-thc,
body[data-page="receiving"] .recv-cell-weight,
body[data-page="receiving"] .recv-cell-qty,
body[data-page="receiving"] .recv-cell-date,
body[data-page="receiving"] .recv-cell-lab {
  white-space: nowrap;
}

body[data-page="receiving"] .recv-cell-package {
  min-width: 170px;
}

body[data-page="receiving"] .recv-package-code {
  font-size: 0.75em;
  white-space: nowrap;
}

body[data-page="receiving"] .recv-cell-item {
  min-width: 180px;
  max-width: 260px;
}

body[data-page="receiving"] .recv-item-link {
  color: var(--accent, #4ade80);
  text-decoration: underline;
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  overflow-wrap: anywhere;
}

body[data-page="receiving"] .recv-cell-category,
body[data-page="receiving"] .recv-cell-strain,
body[data-page="receiving"] .recv-cell-vendor {
  overflow-wrap: normal;
  word-break: normal;
}

body[data-page="receiving"] .recv-cell-category {
  min-width: 110px;
  max-width: 130px;
}

body[data-page="receiving"] .recv-cell-strain {
  min-width: 120px;
  max-width: 150px;
}

body[data-page="receiving"] .recv-cell-vendor {
  min-width: 130px;
  max-width: 180px;
}

body[data-page="receiving"] .recv-cell-date {
  min-width: 110px;
}

/* EC: error banner spacing */
#ec-error { margin-bottom: 16px; }

/* EC: filter inside panel-header — override grid to be inline */
.panel-header .filter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}

/* Vendor-reorder: banner filter bar */
.vr-filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.vr-filter-bar .vr-loc-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.vr-filter-bar .vr-loc-label span {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.vr-filter-bar input { width: 150px; }
.vr-snapshot-meta { margin-top: -8px; margin-bottom: 4px; }

/* ── Mobile ── */
@media (max-width: 860px) {
  .shell {
    width: calc(100vw - 12px);
    margin: 6px auto;
    padding: 14px;
    border-radius: 20px;
  }

  .topbar {
    flex-direction: column;
    gap: 14px;
  }

  .topbar h1 { font-size: 1.2rem; }

  .nav {
    gap: 5px;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .nav-link, button, .button-link {
    padding: 7px 11px;
    font-size: 0.78rem;
  }

  .banner,
  .panel-header,
  .filter-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .home-grid { grid-template-columns: 1fr 1fr; }
  .summary-row { flex-direction: column; }

  .tile-value { font-size: 1.6rem; }

  table { min-width: 100%; }
  th, td { padding: 8px; font-size: 0.78rem; }

  .stat-val { font-size: 1.3rem; }

  /* Watchlist: revert to normal scroll on mobile */
  body[data-page="watchlist"] {
    overflow: auto;
    height: auto;
  }
  body[data-page="watchlist"] .shell {
    height: auto;
    overflow: visible;
  }
  body[data-page="watchlist"] .content {
    flex: unset;
    overflow: visible;
    min-height: unset;
  }
  body[data-page="watchlist"] .wl-table-panel {
    flex: unset;
    overflow: visible;
    min-height: unset;
    padding-bottom: 14px;
  }
  body[data-page="watchlist"] .wl-table-panel .table-wrap {
    flex: unset;
    overflow-x: auto;
    min-height: unset;
    margin: 0;
    padding: 0;
  }
  .wl-actions { margin-left: 0; }

  /* Operational pages + command hub: revert to normal doc scroll on mobile */
  body[data-page="command-hub"],
  body[data-page="home"],
  body[data-page="receiving"],
  body[data-page="expiry-compliance"],
  body[data-page="vendor-reorder"],
  body[data-page="market"] {
    overflow: auto;
    height: auto;
  }
  body[data-page="command-hub"] .shell,
  body[data-page="home"] .shell,
  body[data-page="receiving"] .shell,
  body[data-page="expiry-compliance"] .shell,
  body[data-page="vendor-reorder"] .shell,
  body[data-page="market"] .shell {
    height: auto;
    overflow: visible;
  }
  body[data-page="command-hub"] .content,
  body[data-page="home"] .content,
  body[data-page="receiving"] .content,
  body[data-page="expiry-compliance"] .content,
  body[data-page="vendor-reorder"] .content,
  body[data-page="market"] .content {
    flex: unset;
    overflow: visible;
    min-height: unset;
    padding-bottom: 0;
  }
  .tool-grid { grid-template-columns: 1fr 1fr; }
  .recv-filters label.recv-search { flex: unset; min-width: 100%; }
}

@media (max-width: 480px) {
  .home-grid { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: 1fr; }
}
