/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg-primary:    #0a0e1a;
  --bg-surface:    #111827;
  --bg-surface-2:  #1a2235;
  --bg-border:     #1e2d45;

  --critical:      #ef4444;
  --critical-bg:   #1a0a0a;
  --critical-muted: rgba(239,68,68,0.15);

  --warning:       #f59e0b;
  --warning-bg:    #1a1200;
  --warning-muted: rgba(245,158,11,0.15);

  --watch:         #3b82f6;
  --watch-muted:   rgba(59,130,246,0.15);

  --healthy:       #10b981;
  --healthy-muted: rgba(16,185,129,0.15);

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #475569;

  --accent:        #6366f1;
  --accent-hover:  #818cf8;
  --accent-muted:  rgba(99,102,241,0.12);

  --cold-chain:    #06b6d4;
  --cold-muted:    rgba(6,182,212,0.15);

  --sidebar-w:     240px;
  --topbar-h:      56px;
  --radius:        8px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; font-size: 14px; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; }

.mono { font-family: 'DM Mono', monospace; }

/* ── App Shell ─────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--bg-border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--bg-border);
}

.logo-mark svg { flex-shrink: 0; }

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}

.logo-brand {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.logo-product {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 400;
  transition: all 150ms ease;
  position: relative;
}

.nav-item:hover {
  background: var(--accent-muted);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-muted);
  color: var(--accent-hover);
  font-weight: 500;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  height: 60%;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--bg-border);
}

.version-badge {
  font-size: 11px;
  font-family: 'DM Mono', monospace;
  color: var(--accent);
  background: var(--accent-muted);
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-block;
  margin-bottom: 4px;
}

.sidebar-footer-sub {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── Main Wrapper ──────────────────────────────────────────────────────────── */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
}

.page-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.last-updated {
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
}

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: 5px;
  transition: all 150ms;
  font-weight: 400;
}

.refresh-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface-2);
}

/* ── Main Content ──────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.main-content::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { background: var(--bg-border); border-radius: 3px; }

/* ── Loading / Error ───────────────────────────────────────────────────────── */
.initial-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60vh;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--bg-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  background: var(--critical-bg);
  border: 1px solid rgba(239,68,68,0.2);
  color: var(--critical);
  padding: 16px 20px;
  border-radius: var(--radius);
  font-size: 13px;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── KPI Cards ─────────────────────────────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px);
  animation: fadeSlideIn 400ms ease forwards;
}

@keyframes fadeSlideIn {
  to { opacity: 1; transform: translateY(0); }
}

.kpi-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: var(--radius) 0 0 var(--radius);
}

.kpi-card.kpi-critical::before  { background: var(--critical); }
.kpi-card.kpi-warning::before   { background: var(--warning);  }
.kpi-card.kpi-watch::before     { background: var(--watch);    }
.kpi-card.kpi-healthy::before   { background: var(--healthy);  }
.kpi-card.kpi-cold::before      { background: var(--cold-chain); }
.kpi-card.kpi-accent::before    { background: var(--accent);   }

.kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 500;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 30px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1;
  font-family: 'DM Sans', sans-serif;
  letter-spacing: -0.02em;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.kpi-sub.danger  { color: var(--critical); }
.kpi-sub.amber   { color: var(--warning);  }

/* Critical pulse animation */
.kpi-card.kpi-critical.has-value {
  animation: fadeSlideIn 400ms ease forwards, criticalPulse 3s ease-in-out 1s infinite;
}

@keyframes criticalPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
  50%       { box-shadow: 0 0 0 4px rgba(239,68,68,0.12); }
}

/* ── Charts Section ────────────────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 14px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius);
  padding: 20px;
}

.chart-title {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 500;
  margin-bottom: 16px;
}

.chart-container {
  position: relative;
  width: 100%;
}

.chart-container canvas {
  max-width: 100%;
}

/* ── Section Header ────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 500;
}

.section-action {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
}

.section-action:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Table ─────────────────────────────────────────────────────────────────── */
.table-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.data-table th {
  background: var(--bg-surface-2);
  padding: 10px 14px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--bg-border);
  white-space: nowrap;
}

.data-table td {
  padding: 11px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(30,45,69,0.5);
  vertical-align: middle;
  white-space: nowrap;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:nth-child(even) td { background: rgba(26,34,53,0.4); }

.data-table tbody tr:hover td {
  background: var(--bg-surface-2);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 150ms;
}

.data-table .col-primary {
  color: var(--text-primary);
  font-weight: 500;
}

/* ── Tier Badge ────────────────────────────────────────────────────────────── */
.tier-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'DM Mono', monospace;
  white-space: nowrap;
}

.tier-critical { color: var(--critical); background: var(--critical-muted); }
.tier-warning  { color: var(--warning);  background: var(--warning-muted);  }
.tier-watch    { color: var(--watch);    background: var(--watch-muted);    }
.tier-healthy  { color: var(--healthy);  background: var(--healthy-muted);  }

/* ── Days Left Display ─────────────────────────────────────────────────────── */
.days-left {
  font-family: 'DM Mono', monospace;
  font-size: 15px;
  font-weight: 500;
}

.days-critical { color: var(--critical); }
.days-warning  { color: var(--warning);  }
.days-watch    { color: var(--watch);    }
.days-healthy  { color: var(--healthy);  }

/* ── Cold Chain Tag ────────────────────────────────────────────────────────── */
.cold-tag {
  color: var(--cold-chain);
  font-size: 11px;
  margin-left: 4px;
}

/* ── Action Button ─────────────────────────────────────────────────────────── */
.btn-action {
  font-size: 12px;
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid rgba(99,102,241,0.2);
  background: var(--accent-muted);
  cursor: pointer;
  transition: all 150ms;
  white-space: nowrap;
  font-family: inherit;
}

.btn-action:hover {
  background: rgba(99,102,241,0.2);
  color: var(--accent-hover);
  border-color: rgba(99,102,241,0.4);
}

/* ── Filter Bar ────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  align-items: center;
}

.filter-bar select,
.filter-bar input[type="text"] {
  background: var(--bg-surface-2);
  border: 1px solid var(--bg-border);
  color: var(--text-primary);
  padding: 7px 12px;
  border-radius: 5px;
  font-size: 13px;
  outline: none;
  transition: border-color 150ms;
  height: 34px;
}

.filter-bar select:focus,
.filter-bar input[type="text"]:focus {
  border-color: var(--accent);
}

.filter-bar select option { background: var(--bg-surface-2); }

.filter-search {
  flex: 1;
  min-width: 160px;
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 7px 10px;
  border-radius: 5px;
  border: 1px solid var(--bg-border);
  background: var(--bg-surface-2);
  height: 34px;
  transition: all 150ms;
  user-select: none;
}

.filter-toggle:hover { border-color: var(--accent); color: var(--text-primary); }
.filter-toggle.active { border-color: var(--cold-chain); color: var(--cold-chain); background: var(--cold-muted); }

/* ── Batch Expand Row ──────────────────────────────────────────────────────── */
.batch-detail-row td {
  padding: 0 !important;
  background: var(--bg-primary) !important;
}

.batch-detail-inner {
  overflow: hidden;
  max-height: 0;
  transition: max-height 300ms ease;
}

.batch-detail-inner.expanded {
  max-height: 600px;
}

.batch-detail-content {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  border-top: 1px solid var(--bg-border);
  padding: 20px 24px;
  background: var(--bg-primary);
}

.batch-meta {
  padding-right: 24px;
  border-right: 1px solid var(--bg-border);
}

.batch-meta h4 {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 12px;
}

.batch-meta-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(30,45,69,0.4);
  font-size: 12.5px;
}

.batch-meta-label { color: var(--text-muted); }
.batch-meta-value { color: var(--text-primary); font-weight: 500; }

.batch-stockists {
  padding-left: 24px;
}

.batch-stockists h4 {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ask-ai-btn {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-muted);
  border: 1px solid rgba(99,102,241,0.2);
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 150ms;
  font-family: inherit;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.ask-ai-btn:hover {
  background: rgba(99,102,241,0.2);
  border-color: rgba(99,102,241,0.4);
}

.sell-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 3px;
  font-family: 'DM Mono', monospace;
  letter-spacing: 0.04em;
}

.sell-yes { color: var(--healthy); background: var(--healthy-muted); }
.sell-no  { color: var(--critical); background: var(--critical-muted); }

/* ── Stockist Cards ────────────────────────────────────────────────────────── */
.stockists-summary-bar {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius);
  padding: 12px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.stockists-summary-bar .summary-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.summary-stat {
  font-size: 12.5px;
  color: var(--text-secondary);
}

.summary-stat strong {
  color: var(--text-primary);
  font-weight: 600;
}

.stockist-sort-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sort-label {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-right: 2px;
}

.sort-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--bg-border);
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 150ms;
  font-family: inherit;
}

.sort-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.sort-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-muted); }

.stockist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.stockist-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 200ms;
  cursor: pointer;
}

.stockist-card:hover { border-color: rgba(99,102,241,0.3); }

.stockist-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.stockist-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.stockist-location {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.type-badge {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 3px 7px;
  border-radius: 3px;
  font-family: 'DM Mono', monospace;
  white-space: nowrap;
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--bg-border);
  flex-shrink: 0;
}

.risk-score-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.risk-score-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.risk-score-value {
  font-size: 24px;
  font-weight: 500;
  font-family: 'DM Mono', monospace;
  line-height: 1;
}

.risk-high   { color: var(--critical); }
.risk-medium { color: var(--warning);  }
.risk-low    { color: var(--healthy);  }

.risk-bar-track {
  width: 100%;
  height: 4px;
  background: var(--bg-surface-2);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 14px;
}

.risk-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 600ms ease;
}

.stockist-card-footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--bg-border);
  padding-top: 12px;
}

.stockist-stat {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.stockist-stat-label { color: var(--text-muted); }
.stockist-stat-value { color: var(--text-primary); font-weight: 500; font-family: 'DM Mono', monospace; font-size: 11.5px; }

.cold-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--cold-chain);
  background: var(--cold-muted);
  padding: 2px 8px;
  border-radius: 3px;
  letter-spacing: 0.04em;
  font-family: 'DM Mono', monospace;
  width: fit-content;
}

/* ── AI Assistant ──────────────────────────────────────────────────────────── */
.ai-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  height: calc(100vh - var(--topbar-h) - 48px);
  min-height: 500px;
}

.ai-context-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.ai-context-panel::-webkit-scrollbar { width: 4px; }
.ai-context-panel::-webkit-scrollbar-thumb { background: var(--bg-border); border-radius: 2px; }

.context-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius);
  padding: 16px;
}

.context-card-title {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 12px;
}

.context-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 12.5px;
  border-bottom: 1px solid rgba(30,45,69,0.4);
}

.context-stat-row:last-child { border-bottom: none; }
.context-stat-label { color: var(--text-muted); }
.context-stat-value { color: var(--text-primary); font-weight: 500; font-family: 'DM Mono', monospace; font-size: 12px; }

/* Chat Window */
.chat-window {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--bg-border); border-radius: 2px; }

.chat-welcome {
  text-align: center;
  padding: 32px 16px 16px;
}

.chat-welcome-icon {
  font-size: 28px;
  margin-bottom: 10px;
}

.chat-welcome h3 {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.chat-welcome p {
  font-size: 12.5px;
  color: var(--text-secondary);
  max-width: 320px;
  margin: 0 auto;
  line-height: 1.6;
}

.suggested-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
}

.prompt-pill {
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-muted);
  border: 1px solid rgba(99,102,241,0.2);
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 150ms;
  font-family: inherit;
  text-align: center;
}

.prompt-pill:hover {
  background: rgba(99,102,241,0.2);
  border-color: rgba(99,102,241,0.4);
  color: var(--accent-hover);
}

/* Messages */
.message {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  animation: msgFadeIn 200ms ease;
}

@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user-msg { align-self: flex-end; align-items: flex-end; }
.message.ai-msg   { align-self: flex-start; align-items: flex-start; }

.message-bubble {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.6;
}

.user-msg .message-bubble {
  background: var(--accent);
  color: #fff;
  border-radius: 10px 10px 3px 10px;
}

.ai-msg .message-bubble {
  background: var(--bg-surface-2);
  color: var(--text-primary);
  border: 1px solid var(--bg-border);
  border-radius: 10px 10px 10px 3px;
}

.ai-msg .message-bubble strong { color: var(--text-primary); }
.ai-msg .message-bubble ul, .ai-msg .message-bubble ol {
  padding-left: 18px;
  margin: 6px 0;
}
.ai-msg .message-bubble li { margin: 3px 0; }
.ai-msg .message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}
.ai-msg .message-bubble th, .ai-msg .message-bubble td {
  padding: 5px 8px;
  border: 1px solid var(--bg-border);
  text-align: left;
}
.ai-msg .message-bubble th { background: var(--bg-surface); color: var(--text-muted); }

.message-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
  font-family: 'DM Mono', monospace;
}

/* Thinking indicator */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg-surface-2);
  border: 1px solid var(--bg-border);
  border-radius: 10px 10px 10px 3px;
}

.thinking-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: thinkingBounce 1.2s ease-in-out infinite;
}

.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinkingBounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1.0); opacity: 1; }
}

/* Chat Input */
.chat-input-area {
  padding: 14px 16px;
  border-top: 1px solid var(--bg-border);
  background: var(--bg-surface);
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  background: var(--bg-surface-2);
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13.5px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 100px;
  line-height: 1.5;
  transition: border-color 150ms;
  overflow-y: auto;
}

.chat-textarea:focus { border-color: var(--accent); }
.chat-textarea::placeholder { color: var(--text-muted); }

.chat-send-btn {
  width: 42px;
  height: 42px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 150ms;
  flex-shrink: 0;
  border: none;
}

.chat-send-btn:hover { background: var(--accent-hover); }
.chat-send-btn:disabled { background: var(--bg-surface-2); cursor: not-allowed; opacity: 0.5; }

.chat-send-btn svg { color: #fff; }

/* ── Scrollable table wrapper ──────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .ai-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
  .ai-context-panel { flex-direction: row; overflow-x: auto; }
  .context-card { min-width: 240px; }
  .charts-row { grid-template-columns: 1fr; }
  .batch-detail-content { grid-template-columns: 1fr; }
  .batch-meta { border-right: none; border-bottom: 1px solid var(--bg-border); padding-right: 0; padding-bottom: 16px; margin-bottom: 16px; }
  .batch-stockists { padding-left: 0; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 60px; }
  .nav-item span:not(.nav-icon) { display: none; }
  .logo-text { display: none; }
  .sidebar-footer { display: none; }
  .sidebar-logo { justify-content: center; padding: 16px; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-item::before { display: none; }
  .main-content { padding: 16px; }
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.text-right { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-primary { color: var(--text-primary) !important; }
.font-mono { font-family: 'DM Mono', monospace; }
.risk-value-text { font-family: 'DM Mono', monospace; font-size: 12.5px; }

/* Risk value highlights */
.val-danger { color: var(--critical); }
.val-amber  { color: var(--warning);  }
.val-green  { color: var(--healthy);  }

/* ── Geo Inventory View ────────────────────────────────────────────────────── */
.geo-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Role bar */
.geo-role-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bg-border);
  flex-shrink: 0;
}

.geo-role-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.geo-field-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
}

.geo-select {
  background: var(--bg-surface-2);
  border: 1px solid var(--bg-border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  min-width: 180px;
  transition: border-color 150ms;
}
.geo-select:hover, .geo-select:focus { border-color: var(--accent); }
.geo-select option { background: var(--bg-surface-2); }

.geo-role-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  padding: 6px 12px;
  background: var(--accent-muted);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: 6px;
  font-size: 20px;
}

.role-badge-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.role-badge-desc {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* Body layout */
.geo-body {
  display: grid;
  grid-template-columns: 260px 1fr;
  flex: 1;
  overflow: hidden;
  border-top: 1px solid var(--bg-border);
}

/* (old user-selector replaced by geo-role-bar above) */

/* Sidebar */
.geo-sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--bg-border);
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Main content area */
.geo-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.geo-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bg-border);
  flex-shrink: 0;
}

.geo-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-family: 'DM Mono', monospace;
}

.crumb-link {
  color: var(--accent-hover);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 150ms;
}
.crumb-link:hover { background: var(--accent-muted); }

.crumb-current {
  color: var(--text-primary);
  font-weight: 600;
}

.crumb-sep {
  color: var(--text-muted);
  padding: 0 2px;
}

.geo-back-btn {
  font-size: 12px;
  padding: 5px 12px;
  background: var(--bg-surface-2);
  border: 1px solid var(--bg-border);
  border-radius: 5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 150ms;
}
.geo-back-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.geo-content {
  flex: 1;
  overflow: auto;
  padding: 16px 20px;
}

.geo-sidebar::-webkit-scrollbar { width: 4px; }
.geo-sidebar::-webkit-scrollbar-thumb { background: var(--bg-border); border-radius: 2px; }

.geo-section {
  padding: 16px 14px;
  border-bottom: 1px solid var(--bg-border);
}

.geo-section:last-child {
  border-bottom: none;
}

.geo-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 10px;
}

/* Regional Filters */
.geo-filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.geo-filter-btn {
  padding: 6px 10px;
  background: var(--bg-surface-2);
  border: 1px solid var(--bg-border);
  border-radius: 5px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 150ms;
  text-align: left;
}

.geo-filter-btn:hover {
  background: var(--bg-border);
  border-color: var(--accent);
  color: var(--text-primary);
}

.geo-filter-btn.active {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* KPI items */
.geo-kpi {
  background: var(--bg-surface-2);
  padding: 10px 8px;
  border-radius: 6px;
  border: 1px solid var(--bg-border);
  text-align: center;
}

.geo-kpi-value {
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
}

.geo-kpi-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Alerts */
.geo-alerts {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.geo-alert {
  padding: 8px 10px;
  background: var(--critical-bg);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: 5px;
  border-left: 3px solid var(--critical);
}

.geo-alert-success {
  background: transparent;
  border: 1px solid rgba(16,185,129,0.2);
  border-left-color: var(--healthy);
}

.geo-alert-success { color: var(--healthy); }
.geo-alert-critical { color: var(--critical); }

.alert-title {
  font-size: 11.5px;
  font-weight: 600;
  color: inherit;
}

.alert-meta {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 2px;
  font-family: 'DM Mono', monospace;
}

/* Top Stockists */
.geo-top-stockists {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.geo-stockist-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-surface-2);
  border-radius: 5px;
  border: 1px solid var(--bg-border);
  font-size: 11.5px;
}

.stockist-name {
  color: var(--text-primary);
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stockist-risk {
  font-weight: 600;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  flex-shrink: 0;
}

/* KPI grid in sidebar */
.geo-kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.geo-exposure-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-surface-2);
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  margin-top: 2px;
}

.geo-exposure-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.geo-exposure-value {
  font-family: 'DM Mono', monospace;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--warning);
}

/* Alert styles */
.geo-alert {
  padding: 7px 10px;
  border-radius: 5px;
  border-left: 3px solid;
  margin-bottom: 6px;
  font-size: 12px;
}
.geo-alert-ok {
  border-color: var(--healthy);
  color: var(--healthy);
  background: var(--healthy-muted);
}
.geo-alert-critical {
  border-color: var(--critical);
  background: var(--critical-bg);
}
.alert-product {
  font-weight: 600;
  color: var(--critical);
  font-size: 11.5px;
}
.alert-meta {
  font-family: 'DM Mono', monospace;
  font-size: 10.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Top stockists in sidebar */
.geo-stockist-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  background: var(--bg-surface-2);
  border: 1px solid var(--bg-border);
  border-radius: 5px;
  margin-bottom: 5px;
  cursor: pointer;
  transition: border-color 150ms;
}
.geo-stockist-row:hover { border-color: var(--accent); }

.gsr-name {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-primary);
}
.gsr-city {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 1px;
}
.gsr-score {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  margin-left: 8px;
}

/* Table header bar */
.geo-table-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.geo-table-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.geo-table-hint {
  font-size: 11px;
  color: var(--text-muted);
  align-self: center;
}

.geo-detail-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
}

/* Data table */
.geo-table-scroll {
  width: 100%;
  overflow-x: auto;
}

.geo-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.geo-data-table thead {
  position: sticky;
  top: 0;
  z-index: 5;
}

.geo-data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-surface);
  border-bottom: 2px solid var(--bg-border);
  white-space: nowrap;
}

.geo-data-table th.col-num,
.geo-data-table th.col-val,
.geo-data-table th.col-mono { text-align: right; }

.geo-row td {
  padding: 12px 14px;
  color: var(--text-secondary);
  vertical-align: middle;
  border-bottom: 1px solid var(--bg-border);
}

.geo-row.clickable { cursor: pointer; transition: background 150ms; }
.geo-row.clickable:hover { background: var(--bg-surface); }
.geo-row.clickable:hover .col-arrow { color: var(--accent-hover); }

.col-name {
  color: var(--text-primary);
  font-weight: 500;
  min-width: 140px;
}
.col-city { color: var(--text-secondary); font-size: 12px; }
.col-therapy { color: var(--text-secondary); font-size: 12px; }
.col-num {
  font-family: 'DM Mono', monospace;
  text-align: right;
  font-size: 12.5px;
  white-space: nowrap;
}
.col-val {
  font-family: 'DM Mono', monospace;
  text-align: right;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
}
.col-mono {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  text-align: right;
}
.col-arrow {
  color: var(--text-muted);
  font-size: 16px;
  text-align: center;
  width: 30px;
  transition: color 150ms;
}

.text-muted { color: var(--text-muted); }
.val-warn { color: var(--warning); font-weight: 600; }

/* Status badge */
.status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge-healthy { background: var(--healthy-muted);  color: var(--healthy);  border: 1px solid rgba(16,185,129,0.3); }
.badge-warning { background: var(--warning-muted);  color: var(--warning);  border: 1px solid rgba(245,158,11,0.3); }
.badge-critical{ background: var(--critical-muted); color: var(--critical); border: 1px solid rgba(239,68,68,0.3);  }

/* Type pill */
.type-pill {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: 3px;
  color: var(--text-secondary);
}

/* Cold chain tag */
.cold-tag {
  font-size: 10px;
  color: var(--cold-chain);
  margin-left: 4px;
  opacity: 0.85;
}

/* Empty / prompt state */
.geo-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 280px;
  text-align: center;
  gap: 10px;
  padding: 40px;
}

.geo-empty-icon { font-size: 48px; opacity: 0.5; }

.geo-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.geo-empty-desc {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 320px;
  line-height: 1.5;
}

/* Responsive */
@media (max-width: 1024px) {
  .geo-body { grid-template-columns: 220px 1fr; }
}
@media (max-width: 768px) {
  .geo-body { grid-template-columns: 1fr; }
  .geo-sidebar { display: none; }
  .geo-role-bar { flex-wrap: wrap; }
}

/* ── Page Tabs (new modules) ───────────────────────────────────────────────── */
.page-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  padding: 4px;
  width: fit-content;
}

.page-tab {
  padding: 7px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  border-radius: 5px;
  cursor: pointer;
  transition: all 150ms;
  font-family: inherit;
  border: none;
  background: none;
  white-space: nowrap;
}

.page-tab:hover { color: var(--text-primary); }

.page-tab.active {
  background: var(--accent-muted);
  color: var(--accent-hover);
  font-weight: 500;
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-2);
  color: var(--text-muted);
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  border-radius: 10px;
  padding: 1px 6px;
  margin-left: 6px;
  min-width: 18px;
}

.page-tab.active .tab-count {
  background: rgba(99,102,241,0.2);
  color: var(--accent);
}

/* ── Toast Notifications ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transform: translateY(20px);
  opacity: 0;
  transition: all 300ms ease;
  max-width: 360px;
}

.toast.toast-show { transform: translateY(0); opacity: 1; }

.toast-success { background: #0f2a1e; border: 1px solid rgba(16,185,129,0.3); color: var(--healthy); }
.toast-warning { background: #1a1200; border: 1px solid rgba(245,158,11,0.3); color: var(--warning); }
.toast-error   { background: #1a0a0a; border: 1px solid rgba(239,68,68,0.3);  color: var(--critical); }

/* ── Table Scroll Wrapper ─────────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
}

.table-scroll::-webkit-scrollbar { height: 4px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--bg-border); border-radius: 2px; }

/* ── Form Components (modals) ─────────────────────────────────────────────── */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  background: var(--bg-surface-2);
  border: 1px solid var(--bg-border);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 150ms;
  box-sizing: border-box;
}

.form-input:focus { border-color: var(--accent); }
.form-input option { background: var(--bg-surface-2); }
textarea.form-input { resize: vertical; min-height: 80px; }

/* ── Font helpers ─────────────────────────────────────────────────────────── */
.font-mono { font-family: 'DM Mono', monospace; }
.text-muted { color: var(--text-muted); }

/* ── Demo Banner ──────────────────────────────────────────────────────────── */
.demo-banner {
  background: linear-gradient(90deg, rgba(99,102,241,0.1), rgba(6,182,212,0.08));
  border: 1px solid rgba(99,102,241,0.25);
  border-radius: 8px;
  padding: 14px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.demo-banner-text {
  font-size: 13px;
  color: var(--text-secondary);
}

.demo-banner-text strong { color: var(--accent-hover); }

/* ── Recommendation Card Arrow ────────────────────────────────────────────── */
.rec-card { transition: opacity 350ms ease; }

/* ── Replenishment card ───────────────────────────────────────────────────── */
.stockist-repl-card { transition: all 200ms; }
.stockist-repl-card:hover { border-color: rgba(99,102,241,0.3); }

