/* === BONE & SAUCER — KEYWORD TRACKER === */
/* Design System Tokens */
:root {
  /* Brand colors */
  --ember: hsl(24, 90%, 52%);
  --flame: hsl(32, 95%, 55%);
  --gold: hsl(42, 90%, 58%);
  --brick: hsl(8, 65%, 45%);

  /* Surfaces */
  --surface-0: #0A0A0A;
  --surface-1: #121212;
  --surface-2: #1A1A1A;
  --surface-3: #222222;
  --surface-4: #2A2A2A;

  /* Text */
  --text-primary: #e6e3de;
  --text-secondary: #808080;
  --text-muted: #5a5a5a;

  /* Semantic */
  --positive: hsl(145, 55%, 42%);
  --negative: var(--brick);
  --neutral-delta: var(--text-secondary);

  /* Fonts */
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --radius: 8px;
  --radius-sm: 4px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--surface-0);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface-1);
  border-right: 1px solid rgba(255,255,255,0.04);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s var(--ease);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.sidebar-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--ember);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s var(--ease);
  border-left: 3px solid transparent;
}

.nav-link:hover {
  color: var(--text-primary);
  background: rgba(232, 114, 42, 0.06);
}

.nav-link.active {
  color: var(--ember);
  background: rgba(232, 114, 42, 0.08);
  border-left-color: var(--ember);
}

.nav-link svg { flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 18px;
  border-top: 1px solid rgba(255,255,255,0.04);
}

.sidebar-footer-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.sidebar-footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 11px;
  opacity: 0.4;
  transition: opacity 0.2s;
}

.sidebar-footer-links a:hover { opacity: 0.7; }

.sidebar-copyright {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.sidebar-attribution {
  font-size: 10px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.sidebar-attribution:hover { color: var(--text-secondary); }

/* === Hamburger (mobile) === */
.hamburger {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
}

.hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: all 0.3s var(--ease);
}

.hamburger.open span:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

/* === Main Content === */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Top Bar === */
.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  background: var(--surface-1);
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scan-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--positive);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.topbar-timestamp {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

/* === Pages === */
.page {
  display: none;
  padding: 24px 28px;
  flex: 1;
  animation: fadeIn 0.3s var(--ease);
}

.page.active { display: block; }

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

/* === KPI Cards === */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-grid.narrow {
  grid-template-columns: repeat(3, 1fr);
}

.kpi-card {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s var(--ease);
}

.kpi-card:hover {
  border-color: rgba(232, 114, 42, 0.15);
}

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

.kpi-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  margin-bottom: 8px;
}

.kpi-value.score-high { color: var(--ember); }

.kpi-sparkline {
  height: 24px;
  margin-bottom: 6px;
}

.kpi-sparkline svg { display: block; }

.kpi-delta {
  font-family: var(--font-mono);
  font-size: 11px;
}

.kpi-delta.positive { color: var(--positive); }
.kpi-delta.negative { color: var(--brick); }
.kpi-delta.neutral { color: var(--text-secondary); }
.kpi-delta.alert { color: var(--flame); }

/* === Cards === */
.card {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header-row .card-title { margin-bottom: 0; }

/* === Content Grid === */
.content-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}

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

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

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text-primary);
}

.data-table tr:hover td {
  background: rgba(255,255,255,0.02);
}

.mono {
  font-family: var(--font-mono);
}

.trend-up { color: var(--positive); font-family: var(--font-mono); font-size: 11px; }
.trend-down { color: var(--brick); font-family: var(--font-mono); font-size: 11px; }
.trend-neutral { color: var(--text-secondary); font-family: var(--font-mono); font-size: 11px; }

/* === Summary === */
.summary-content p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.summary-content p strong {
  color: var(--flame);
  font-weight: 600;
}

.summary-content p:last-child { margin-bottom: 0; }

/* === Time Selector === */
.time-selector {
  display: flex;
  gap: 4px;
  background: var(--surface-1);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.time-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s var(--ease);
}

.time-btn:hover { color: var(--text-primary); }

.time-btn.active {
  background: var(--ember);
  color: #fff;
}

/* === Chart === */
.chart-container {
  position: relative;
  height: 360px;
}

/* === Heatmap === */
.heatmap-container {
  overflow-x: auto;
}

.heatmap-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 700px;
}

.heatmap-table th,
.heatmap-table td {
  padding: 8px 10px;
  text-align: center;
  font-size: 11px;
}

.heatmap-table th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.heatmap-table th:first-child {
  text-align: left;
  min-width: 120px;
}

.heatmap-cell {
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
  position: relative;
  min-width: 48px;
  padding: 8px 6px;
}

.heatmap-cell:hover {
  transform: scale(1.08);
  box-shadow: 0 0 12px rgba(232,114,42,0.3);
  z-index: 2;
}

.heatmap-source {
  text-align: left;
  color: var(--text-primary);
  font-weight: 500;
  font-size: 12px;
}

/* === Financial Dashboard === */
.financial-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.fin-section.full-width {
  grid-column: 1 / -1;
}

.fin-metrics {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 12px;
}

.fin-metric {
  display: grid;
  grid-template-columns: 120px 1fr auto 80px;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.fin-metric:last-child { border-bottom: none; }

.fin-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.fin-value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.fin-delta {
  font-family: var(--font-mono);
  font-size: 11px;
}

.fin-delta.positive { color: var(--positive); }
.fin-delta.negative { color: var(--brick); }
.fin-delta.neutral { color: var(--text-secondary); }

.fin-sparkline {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.fin-sparkline svg { display: block; }

/* Economic Indicators Grid */
.econ-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.econ-metric {
  background: var(--surface-1);
  border-radius: var(--radius-sm);
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.03);
}

.econ-label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 6px;
}

.econ-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  display: block;
  margin-bottom: 4px;
}

.econ-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  display: block;
}

/* === Narrative Detection === */
.cluster-timeline {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 12px;
}

.cluster-item {
  display: flex;
  gap: 14px;
  padding: 16px;
  background: var(--surface-1);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.03);
  transition: border-color 0.2s var(--ease);
}

.cluster-item:hover {
  border-color: rgba(232,114,42,0.12);
}

.cluster-badge {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 4px 8px;
  border-radius: 3px;
  height: fit-content;
  white-space: nowrap;
}

.cluster-badge.high { background: rgba(232,114,42,0.15); color: var(--ember); }
.cluster-badge.medium { background: rgba(245,166,35,0.15); color: var(--flame); }
.cluster-badge.low { background: rgba(128,128,128,0.15); color: var(--text-secondary); }

.cluster-content { flex: 1; }

.cluster-phrase {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.cluster-meta {
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.cluster-outlets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.outlet-tag {
  font-size: 10px;
  font-weight: 500;
  padding: 3px 8px;
  background: var(--surface-3);
  border-radius: 3px;
  color: var(--text-secondary);
}

.spread-bar {
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}

.spread-fill {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--ember), var(--flame), var(--gold));
  transition: width 0.6s var(--ease);
}

/* Network Diagram */
.network-diagram {
  height: 300px;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface-1);
}

.network-diagram svg {
  width: 100%;
  height: 100%;
}

/* === Settings === */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.settings-grid .full-width {
  grid-column: 1 / -1;
}

.seed-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  margin-top: 12px;
}

.seed-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(232,114,42,0.1);
  border: 1px solid rgba(232,114,42,0.2);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ember);
}

.chip-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
}

.chip-remove:hover { color: var(--brick); }

.add-term {
  display: flex;
  gap: 8px;
}

.input-field {
  flex: 1;
  padding: 8px 12px;
  background: var(--surface-1);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.input-field:focus { border-color: var(--ember); }

.btn-ember {
  padding: 8px 16px;
  background: var(--ember);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-ember:hover { background: hsl(24, 90%, 46%); }

/* Schedule */
.schedule-list {
  margin-top: 12px;
}

.schedule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.schedule-time { font-size: 14px; color: var(--text-primary); }

.schedule-status {
  font-size: 11px;
  font-weight: 600;
}

.active-status { color: var(--positive); }

.schedule-note {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 12px;
}

/* Source grid */
.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.source-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px 10px;
  background: var(--surface-1);
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.source-check:hover { background: var(--surface-3); }

.source-check input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--text-muted);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 0.15s;
}

.source-check input[type="checkbox"]:checked {
  background: var(--ember);
  border-color: var(--ember);
}

.source-check input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

/* Thresholds */
.threshold-list {
  margin-top: 12px;
}

.threshold-item {
  margin-bottom: 16px;
}

.threshold-item label {
  font-size: 12px;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 6px;
}

.threshold-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-input {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface-3);
  border-radius: 2px;
  outline: none;
}

.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--ember);
  border-radius: 50%;
  cursor: pointer;
}

.threshold-val {
  font-size: 13px;
  color: var(--ember);
  min-width: 32px;
  text-align: right;
}

/* Export */
.export-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.btn-export {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface-1);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.btn-export:hover {
  background: var(--surface-3);
  border-color: rgba(232,114,42,0.2);
}

/* === Responsive === */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid.narrow { grid-template-columns: repeat(2, 1fr); }
  .content-grid { grid-template-columns: 1fr; }
  .financial-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .econ-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .hamburger { display: flex; }

  .main-content {
    margin-left: 0;
  }

  .topbar {
    padding-left: 52px;
  }

  .page { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-grid.narrow { grid-template-columns: 1fr; }

  .fin-metric {
    grid-template-columns: 100px 1fr;
    gap: 4px;
  }

  .fin-sparkline { display: none; }

  .econ-grid { grid-template-columns: 1fr; }

  .cluster-meta { flex-direction: column; gap: 4px; }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.sidebar-overlay.visible { display: block; }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
