/* ============================================================
   FUN & SUN · Revenue Desk
   Editorial newspaper aesthetic — cream paper, serif display,
   red accent, numbered sidebar, masthead chrome.
   ============================================================ */

:root {
  /* Paper / ink */
  --paper: #F7F4EE;
  --paper-soft: #FFFCF5;
  --paper-edge: #EBE5D6;
  --ink: #0A0A0A;
  --ink-2: #1F1C18;
  --ink-3: #3A3631;

  /* Text */
  --text: #0A0A0A;
  --text-dim: #5C5852;
  --text-muted: #84807A;
  --text-faint: #B0AB9F;
  --text-on-ink: #F7F4EE;
  --text-on-ink-dim: #A8A39A;
  --text-on-ink-faint: #6B6862;

  /* Hairlines */
  --rule: #1A1714;          /* on paper, near-black thin rules */
  --rule-soft: #C9C2B0;     /* dividers */
  --rule-dim: #E5DFCF;
  --rule-on-ink: #2A2622;

  /* Accents */
  --red: #E11D2C;           /* primary accent */
  --red-deep: #B81522;
  --red-soft: #FCE4E5;
  --gold: #C9A14A;          /* secondary brand */
  --green: #2D6A3E;
  --green-soft: #E1ECDF;
  --amber: #B5832C;
  --amber-soft: #F4E8CE;
  --neg: #C13530;

  /* Type stacks */
  --serif: 'Cormorant Garamond', 'EB Garamond', 'Source Serif 4', Georgia, serif;
  --sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Layout */
  --sidebar-w: 240px;
  --copilot-w: 380px;
  --topbar-h: 64px;
  --statusbar-h: 28px;

  /* Legacy aliases — map old dark-theme tokens to editorial palette
     so older components/pages render correctly without rewrites. */
  --brand: var(--red);
  --brand-soft: var(--red-soft);
  --info: var(--ink);
  --pos: var(--green);
  --warn: var(--amber);
  --bg-0: var(--paper);
  --bg-1: var(--paper-soft);
  --bg-2: var(--paper-soft);
  --bg-3: var(--paper-edge);
  --bg-4: var(--paper-edge);
  --line: var(--rule-soft);
  --line-strong: var(--rule);
  --font-mono: var(--mono);
  --font-sans: var(--sans);
  --accent: var(--red);
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1, 'tnum' 0;
  overflow: hidden;
}
::selection { background: var(--ink); color: var(--paper); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule-soft); border: 2px solid var(--paper); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ---------- Type primitives ---------- */
.serif { font-family: var(--serif); font-weight: 500; letter-spacing: -0.005em; }
.serif-it { font-family: var(--serif); font-style: italic; font-weight: 400; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.smallcaps {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.label {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--red);
}
.dropcap::first-letter {
  font-family: var(--serif);
  font-weight: 500;
  float: left;
  font-size: 4.6em;
  line-height: 0.9;
  padding: 0.06em 0.08em 0 0;
  color: var(--ink);
}

/* ---------- Page headline ---------- */
.headline {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 56px;
  line-height: 1.04;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 14px;
}
.headline em { font-style: italic; font-weight: 400; }
.subhead {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 19px;
  line-height: 1.5;
  color: var(--text-dim);
  letter-spacing: 0;
  max-width: 62ch;
}
.section-h {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

/* ---------- App shell ---------- */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  min-width: 1440px;
  background: var(--paper);
}
body { overflow: auto; }
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}
.content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--paper);
}

/* Copilot — full-screen overlay (fills the entire viewport, desktop + mobile).
   The conversation/composer use an inner max-width so text stays readable on
   wide monitors; the bar chrome spans full width. */
.copilot-panel {
  position: fixed !important;
  inset: 0;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  z-index: 200;
  border-left: none !important;
  box-shadow: 0 -1px 0 var(--rule-soft);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--ink);
  color: var(--text-on-ink);
  display: flex;
  flex-direction: column;
  height: 100%;
}
.sidebar-brand {
  padding: 24px 22px 22px;
  border-bottom: 1px solid var(--rule-on-ink);
}
.sidebar-wordmark {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 30px;
  letter-spacing: -0.015em;
  color: var(--text-on-ink);
  line-height: 1;
}
.sidebar-tag {
  margin-top: 6px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--red);
}
.sidebar-edition {
  padding: 18px 22px 10px;
  border-bottom: 1px solid var(--rule-on-ink);
}
.sidebar-edition-label {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-on-ink-faint);
}
.sidebar-edition-value {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 500;
  margin-top: 2px;
  color: var(--text-on-ink);
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0 18px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 22px;
  font-size: 12.5px;
  color: var(--text-on-ink-dim);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: color 0.12s ease, background 0.12s ease;
  position: relative;
}
.nav-item:hover { color: var(--text-on-ink); background: rgba(255,255,255,0.03); }
.nav-item.active {
  color: var(--text-on-ink);
  border-left-color: var(--red);
  background: linear-gradient(90deg, rgba(225,29,44,0.08), transparent 80%);
}
.nav-num {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-on-ink-faint);
  letter-spacing: 0.04em;
  min-width: 16px;
}
.nav-item.active .nav-num { color: var(--red); }
.nav-label { flex: 1; font-weight: 500; }
.nav-shortcut {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--text-on-ink-faint);
  letter-spacing: 0.05em;
}
.sidebar-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--rule-on-ink);
  font-size: 10px;
  color: var(--text-on-ink-faint);
}
.sidebar-footer-label {
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-on-ink-dim);
}

/* ---------- Top masthead ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
  position: relative;
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
}
.topbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  bottom: -5px;
  height: 1px;
  background: var(--ink);
}
.masthead {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 18px;
  white-space: nowrap;
}
.masthead > * { flex-shrink: 0; }
.masthead .masthead-divider { flex-shrink: 1; }
.masthead-issue {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.masthead-divider {
  flex: 1;
  height: 1px;
  background: var(--rule-soft);
}
.masthead-live {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.masthead-live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 0 rgba(225,29,44,0.5);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(225,29,44,0.45); }
  50% { box-shadow: 0 0 0 6px rgba(225,29,44,0); }
}
.masthead-live em { font-family: var(--serif); font-style: italic; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 13px; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 22px;
  border-left: 1px solid var(--rule-soft);
}
.topbar-search {
  width: 240px;
  height: 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--paper-soft);
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  font-size: 11.5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.1s ease;
}
.topbar-search:hover { border-color: var(--ink); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn-sm { height: 24px; padding: 0 9px; font-size: 11px; }
.btn-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.btn-primary:hover { background: var(--red); border-color: var(--red); }
.btn-accent {
  background: var(--red);
  color: white;
  border-color: var(--red);
}
.btn-accent:hover { background: var(--red-deep); border-color: var(--red-deep); }
.btn-buy { color: var(--green); border-color: var(--green); background: transparent; }
.btn-buy:hover { background: var(--green); color: white; }
.btn-sell { color: var(--red); border-color: var(--red); }
.btn-sell:hover { background: var(--red); color: white; }
.btn-ghost { border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--ink); border-color: var(--rule-soft); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--rule-soft); }

/* ---------- Status bar ---------- */
.statusbar {
  height: var(--statusbar-h);
  border-top: 1px solid var(--rule-soft);
  background: var(--paper-soft);
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 24px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.statusbar-section { display: flex; align-items: center; gap: 7px; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-pos { background: var(--green); }
.dot-warn { background: var(--amber); }
.dot-neg { background: var(--red); }
.dot-info { background: var(--ink); }

/* ---------- Panels & cards ---------- */
.panel {
  background: var(--paper-soft);
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
}
.panel-flat {
  background: transparent;
  border: none;
  border-top: 1px solid var(--ink);
  padding-top: 16px;
}
.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--rule-soft);
  gap: 14px;
}
.panel-head-title {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.005em;
  line-height: 1.2;
  color: var(--ink);
}
.panel-head-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  font-style: italic;
}
.panel-body { padding: 16px 18px; }
.panel-body-flush { padding: 0; }

/* ---------- KPI tiles (editorial) ---------- */
.kpi {
  padding: 16px 18px 18px;
  background: var(--paper-soft);
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 32px;
  height: 1px;
  background: var(--red);
}
.kpi-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.kpi-value {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin-top: 2px;
  font-variant-numeric: lining-nums;
}
.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.kpi-delta.pos { color: var(--green); }
.kpi-delta.neg { color: var(--red); }

/* ---------- Pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  height: 18px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-radius: 2px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill-pos { background: var(--green-soft); color: var(--green); border-color: transparent; }
.pill-neg { background: var(--red-soft); color: var(--red); border-color: transparent; }
.pill-warn { background: var(--amber-soft); color: var(--amber); }
.pill-info { background: var(--paper-edge); color: var(--ink-3); }
.pill-brand { background: var(--ink); color: var(--paper); }
.pill-outline { border-color: var(--rule-soft); color: var(--text-dim); background: transparent; }
.pill-red-out { border: 1px solid var(--red); color: var(--red); background: transparent; }

/* ---------- Tables (editorial financial register) ---------- */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.tbl th {
  text-align: left;
  padding: 10px 12px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--ink);
  background: var(--paper-soft);
  position: sticky;
  top: 0;
  z-index: 1;
}
.tbl td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule-dim);
  color: var(--ink-2);
  vertical-align: middle;
}
.tbl tbody tr:hover { background: var(--paper-edge); }
.tbl tr.selected { background: var(--paper-edge); box-shadow: inset 3px 0 0 var(--red); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .num.mono { font-family: var(--mono); }
.tbl tr.clickable { cursor: pointer; }
.tbl input[type="checkbox"] { accent-color: var(--ink); }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-faint { color: var(--text-faint); }

/* ---------- Layout helpers ---------- */
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.gap-2 { gap: 10px; }
.gap-3 { gap: 16px; }
.row { display: flex; align-items: center; }
.gap-1 { gap: 6px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--ink);
  padding: 0 18px;
}
.tab {
  padding: 12px 16px 11px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.1s ease, border-color 0.1s ease;
  font-family: var(--sans);
  letter-spacing: 0.01em;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--red);
}

/* ---------- Filter chip ---------- */
.filter-chip {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.filter-chip:hover { color: var(--ink); border-color: var(--ink); }
.filter-chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- Inputs ---------- */
.input {
  height: 28px;
  padding: 0 10px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink);
  background: var(--paper-soft);
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  outline: none;
}
.input:focus { border-color: var(--ink); }

/* ---------- Heatmap cells ---------- */
.heat-cell {
  text-align: center;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 7px 6px;
  border-radius: 2px;
}

/* ---------- Charts (SVG) ---------- */
.axis-text {
  font-family: var(--mono);
  font-size: 9.5px;
  fill: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.axis-line { stroke: var(--ink); stroke-width: 1; }
.grid-line { stroke: var(--rule-dim); stroke-width: 1; stroke-dasharray: 2 3; }
.bar { transition: opacity 0.15s ease; }
.bar:hover { opacity: 0.85; }

/* ---------- Stars ---------- */
.stars {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  font-weight: 500;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6vh;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--paper);
  border: 1px solid var(--ink);
  width: min(1080px, 92vw);
  max-height: 86vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------- Login ---------- */
.login-bg {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100vh;
  width: 100vw;
  background: var(--paper);
  padding: 56px 32px 56px;
  overflow-y: auto;
}

/* ---------- Smallcaps box ---------- */
.boxed {
  border: 1px solid var(--rule-soft);
  background: var(--paper-soft);
  padding: 14px 16px;
}

/* Helper utility */
.kbd {
  font-family: var(--mono);
  font-size: 9.5px;
  padding: 1px 5px;
  color: var(--text-on-ink-faint);
  letter-spacing: 0.05em;
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

/* Newspaper section divider */
.section-rule {
  height: 1px;
  background: var(--ink);
  margin: 24px 0 18px;
  position: relative;
}
.section-rule::before {
  content: '';
  position: absolute;
  top: -2px;
  left: 0;
  width: 60px;
  height: 5px;
  background: var(--red);
}

/* Page wrapper */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 36px 48px 60px;
}
.page-head {
  margin-bottom: 28px;
}

/* ============================================================
   Utility shims (text colors, layout, tooltips)
   ============================================================ */
.text-pos { color: var(--green); }
.text-neg { color: var(--red); }
.text-warn { color: var(--amber); }
.text-info { color: var(--ink); }
.between { justify-content: space-between; }
.flex-1 { flex: 1; }
.grid-6 { grid-template-columns: repeat(6, 1fr); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; }
.upper { text-transform: uppercase; letter-spacing: 0.08em; }

.kpi-spark {
  margin-top: 6px;
  opacity: 0.85;
}
.kpi-spark svg { display: block; }

.tbl-zebra tbody tr:nth-child(even) td { background: rgba(0,0,0,0.015); }

.tip {
  position: absolute;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 2px;
  padding: 6px 9px;
  font-size: 10.5px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
  pointer-events: none;
  white-space: nowrap;
  z-index: 50;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

/* Reading column / drop cap article block */
.article-col {
  max-width: 64ch;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink-2);
}
.article-col p { margin: 0 0 14px; }
.article-col p + p { text-indent: 1.4em; }

/* Sparkline cleanup */
.spark { display: block; }

/* Pull-quote */
.pullquote {
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1.25;
  font-style: italic;
  color: var(--ink);
  border-left: 3px solid var(--red);
  padding: 4px 0 4px 18px;
  margin: 8px 0;
}

/* Byline strip */
.byline {
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-size: 11.5px;
  color: var(--text-dim);
  font-style: italic;
  border-top: 1px solid var(--rule-soft);
  border-bottom: 1px solid var(--rule-soft);
  padding: 8px 0;
  margin-bottom: 16px;
}
.byline strong {
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--ink);
}
.byline .sep { color: var(--rule-soft); }

/* ============================================================
   MOBILE — phone-native shell (≤768px)  v2 (8pt grid · 4-size scale)
   ──────────────────────────────────────────────────────────
   Applies the ceorkm/mobile-app-ui-design ruleset:
   - 4 font sizes max (12 / 14 / 18 / 28)
   - 8-point grid spacing (8 / 12 / 16 / 24 / 32)
   - 44×44 minimum touch targets
   - 60/30/10 color (cream paper / ink / red accent)
   - Hierarchy via opacity (100% headings, 80% body, 60% secondary)
   - Cards: rounded-2xl, 20px padding, soft tinted shadows
   - Mobile baseline width: 375px (iPhone SE)
   ============================================================ */
/* Mobile shell applies on narrow viewports OR short ones (phone landscape, #7) */
@media (max-width: 768px), (max-height: 480px) {
  :root {
    --copilot-w: 100vw;
    --topbar-h: auto;
    --m-tabbar-h: 64px;
    --m-header-h: 60px;

    /* 4-size scale (only these allowed in mobile contexts) */
    --m-size-xs: 12px;   /* secondary / metadata */
    --m-size-sm: 14px;   /* body */
    --m-size-md: 18px;   /* section titles, card headlines */
    --m-size-lg: 28px;   /* KPI values, large numbers */

    /* 8pt spacing scale */
    --m-s1: 8px;
    --m-s2: 12px;
    --m-s3: 16px;
    --m-s4: 24px;
    --m-s5: 32px;

    /* Opacity hierarchy (color = ink, modulated via opacity) */
    --m-opa-strong: 1;
    --m-opa-body:   0.78;
    --m-opa-second: 0.58;
  }
  html, body { overflow-x: hidden; }
  body {
    font-size: var(--m-size-sm);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
  }

  .app, .app-mobile {
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    width: 100%;
  }
  .main { width: 100%; }
  .workspace {
    flex-direction: column;
    overflow: visible;
  }
  .content {
    padding-bottom: calc(var(--m-tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--m-s3));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Desktop chrome — gone. */
  .app-mobile .sidebar,
  .app-mobile .topbar,
  .app-mobile .statusbar { display: none !important; }

  /* Workspace content padding — 8pt grid. */
  .content > div {
    padding: var(--m-s3) !important;
    gap: var(--m-s3) !important;
  }
  .panel {
    border-radius: 14px;                   /* rounded-2xl */
    border-color: var(--rule-dim);
    box-shadow: 0 1px 2px rgba(10, 10, 10, 0.04);
  }
  .panel-head {
    padding: var(--m-s4) var(--m-s4) var(--m-s2);
    flex-wrap: wrap;
    gap: var(--m-s1);
    border-bottom: 1px solid var(--rule-dim);
  }
  .panel-head-title {
    font-size: var(--m-size-md);
    line-height: 1.3;
    opacity: var(--m-opa-strong);
  }
  .panel-head-sub {
    font-size: var(--m-size-xs);
    opacity: var(--m-opa-second);
  }
  .panel-body { padding: var(--m-s3); }

  /* KPI tiles: 2-up at 768, 1-up at 480. Big headline values. */
  .grid-2, .grid-3, .grid-4, .grid-5, .grid-6 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--m-s2) !important;
  }
  .grid[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  .kpi {
    padding: var(--m-s3);
    border-radius: 12px;
    min-height: 96px;
    background: var(--paper-soft);
  }
  .kpi-label {
    font-size: var(--m-size-xs);
    letter-spacing: 0.14em;
    opacity: var(--m-opa-second);
  }
  .kpi-value {
    font-size: var(--m-size-lg);
    line-height: 1.05;
  }
  .kpi-sub {
    font-size: var(--m-size-xs);
    opacity: var(--m-opa-second);
  }

  /* ───────── Tables → cards (8pt grid, 4-size scale).
     <tr> becomes a stacked card; rank cells hidden; first visible td promoted
     to headline. Numeric cells render as mono lines below. */
  .tbl, .tbl thead, .tbl tbody, .tbl tr, .tbl th, .tbl td {
    display: block;
    width: auto;
  }
  .tbl { border-collapse: separate; }
  .tbl thead { display: none; }
  .tbl tr {
    background: var(--paper-soft);
    border: 1px solid var(--rule-dim);
    border-radius: 12px;
    padding: var(--m-s3);
    margin-bottom: var(--m-s2);
    box-shadow: 0 1px 2px rgba(10, 10, 10, 0.04);
  }
  .tbl tr:hover { background: var(--paper-soft); }
  .tbl tr.selected { box-shadow: inset 4px 0 0 var(--red); background: var(--paper-edge); }
  .tbl tr.clickable:active { background: var(--paper-edge); }
  .tbl td {
    padding: 4px 0 !important;
    border: none !important;
    font-size: var(--m-size-sm);
    text-align: left !important;
    white-space: normal;
    color: var(--ink);
    opacity: var(--m-opa-body);
  }

  /* Hide rank-style first cells (.text-faint.mono in position 1). */
  .tbl td:first-child.text-faint.mono:not(.num) { display: none; }

  /* Promote real headline cell. Uses :has() (iOS Safari 15.4+). */
  .tbl tr:has(> td:first-child.text-faint.mono:not(.num)) > td:nth-child(2),
  .tbl tr:not(:has(> td:first-child.text-faint.mono:not(.num))) > td:first-child {
    font-size: var(--m-size-md);
    font-weight: 600;
    opacity: var(--m-opa-strong);
    padding: 0 0 var(--m-s1) !important;
    margin-bottom: var(--m-s1);
    border-bottom: 1px solid var(--rule-dim) !important;
  }

  /* Numeric cells */
  .tbl td.num {
    font-family: var(--mono);
    font-size: var(--m-size-sm);
    opacity: var(--m-opa-body);
  }
  .tbl td.num.text-muted,
  .tbl td.text-muted {
    opacity: var(--m-opa-second);
    font-size: var(--m-size-xs);
  }

  /* Restore the column label that the hidden <thead> would have provided, as a
     small eyebrow above each value (#5 source markets, #6 hotel pricing recs,
     #10 pricing suggestions). data-label is set at runtime by
     enhanceTableLabels(); the headline + rank cells deliberately have none. */
  .tbl td[data-label] { padding-top: var(--m-s1) !important; }
  .tbl td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-family: var(--sans);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    opacity: var(--m-opa-second);
    margin-bottom: 1px;
  }

  /* Hide tail columns to keep cards skimmable */
  .tbl td:nth-child(n+9) { display: none; }

  /* Tabs row: horizontal scroll, 44pt touch */
  .tabs {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px 12px 0 0;
  }
  .tab {
    flex: 0 0 auto;
    padding: var(--m-s2) var(--m-s3);
    font-size: var(--m-size-sm);
    min-height: 44px;
  }

  /* Filter chips — 44pt minimum */
  .filterbar {
    flex-wrap: wrap;
    gap: var(--m-s1);
    padding: var(--m-s2) var(--m-s3);
  }
  .filter-chip {
    font-size: var(--m-size-xs);
    padding: var(--m-s2) var(--m-s3);
    min-height: 44px;
    border-radius: 22px;
    display: inline-flex;
    align-items: center;
  }

  /* Buttons — 44pt minimum */
  .btn {
    padding: var(--m-s2) var(--m-s3);
    font-size: var(--m-size-sm);
    min-height: 44px;
    border-radius: 10px;
  }
  .btn.btn-sm {
    padding: 10px var(--m-s2);
    min-height: 44px;
    font-size: var(--m-size-xs);
    border-radius: 10px;
  }

  /* Inputs — 16px font-size avoids iOS auto-zoom on focus */
  .input {
    font-size: 16px !important;
    padding: var(--m-s2) var(--m-s3) !important;
    min-height: 44px;
    border-radius: 10px;
  }

  /* Pills (small status tags) */
  .pill {
    font-size: var(--m-size-xs);
    height: auto;
    padding: 4px var(--m-s1);
    border-radius: 6px;
  }

  /* SVG charts: full width, auto height */
  svg { max-width: 100%; height: auto; }
  /* …except a horizontally-scrolled chart, which must keep its full width (#8) */
  .chart-scroll-x { -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
  .chart-scroll-x svg { max-width: none; }

  /* Login front page: less edge padding so the masthead fits (#3) */
  .login-bg { padding: 28px 16px calc(28px + env(safe-area-inset-bottom, 0px)); }

  /* Copilot — full-screen overlay; safe-area aware.
     Fill the dynamic viewport from top:0 and inset the CONTENT via padding, so
     the input row sits above the home indicator instead of below the screen.
     (Previously used height:100% with top:safe-top, which pushed the bottom
     input ~44px off-screen on notched iPhones.) */
  aside[style*="--copilot-w"] {
    position: fixed !important;
    inset: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 200;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* Modal/login full screen */
  .modal-backdrop > div {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 14px;
  }

  /* Headlines & text inside body */
  h1, .headline { font-size: var(--m-size-lg); line-height: 1.15; }
  h2 { font-size: var(--m-size-md); }
  p, .text { font-size: var(--m-size-sm); opacity: var(--m-opa-body); }
  .text-muted, .text-dim { opacity: var(--m-opa-second); }
  .text-faint { opacity: 0.4; }
}

/* ≤480px: collapse KPI grid to 1 column for legibility */
@media (max-width: 480px) {
  .grid-2, .grid-3, .grid-4, .grid-5, .grid-6 {
    grid-template-columns: 1fr !important;
  }
  .panel-head { padding: var(--m-s3) var(--m-s3) var(--m-s2); }
  .panel-body { padding: var(--m-s3); }
}

/* ============================================================
   Mobile-only chrome (rendered by mobile-shell.jsx).
   Visible regardless of CSS media query — controlled by JS isMobile.
   We still wrap most rules in @media so they don't leak on desktop
   if mobile-shell.jsx misfires.
   ============================================================ */

/* MobileHeader — slim cream bar with brand + page title + action icons */
.m-header {
  position: sticky; top: 0; z-index: 30;
  /* min-height so safe-area padding adds to (not eats into) the bar */
  min-height: var(--m-header-h, 60px);
  background: var(--paper);
  border-bottom: 1px solid var(--rule-soft);
  /* 3 zones that can never overlap: brand | title | actions */
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  padding: 6px 14px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
  flex-shrink: 0;
}
.m-header-brand {
  display: flex; flex-direction: column; align-items: flex-start;
  justify-content: center;
  line-height: 1.05; min-width: 0;
}
/* Brand is demoted to a secondary wordmark so the page title is the one focal
   element — fixes the two 18px serifs colliding at the top (#4, #9). */
.m-header-brand-name {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
}
.m-header-brand-name em {
  font-style: italic;
  font-weight: 400;
}
.m-header-brand-tag {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--red);
  margin-top: 2px;
  white-space: nowrap;
}
.m-header-title {
  grid-column: 2;
  font-family: var(--serif);
  font-size: var(--m-size-md, 18px);
  font-weight: 500;
  color: var(--ink);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
  min-width: 0;
}
.m-header-actions { display: flex; align-items: center; gap: 6px; }
.m-icon-btn {
  width: 40px; height: 40px;
  background: transparent;
  border: 1px solid var(--rule-soft);
  border-radius: 50%;
  font-size: 18px;
  color: var(--ink);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.m-icon-btn:active { background: var(--paper-edge); }
.m-header-alert-pill {
  background: var(--red); color: var(--paper);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  min-width: 22px; height: 22px;
  border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 7px;
}

/* MobileBottomNav */
.m-tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  /* Trim most of the home-indicator safe-area so the labels sit lower / closer
     to the bottom edge instead of floating high above a big cream gap. Keep a
     small clearance (down to 0 on devices without a safe area). */
  height: calc(var(--m-tabbar-h, 64px) + 0px);
  padding-bottom: 0px;
  background: var(--paper);
  border-top: 1px solid var(--ink);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
}
.m-tab {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  background: transparent;
  border: none;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink);
  opacity: 0.5;
  cursor: pointer;
  position: relative;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  padding: 7px 4px 3px;
  transition: opacity 0.15s ease;
}
.m-tab:active { background: var(--paper-edge); opacity: 1; }
.m-tab.active { color: var(--ink); opacity: 1; }
.m-tab.active::before {
  content: '';
  position: absolute;
  top: 0; left: 30%; right: 30%;
  height: 2px;
  background: var(--red);
}
.m-tab-icon {
  font-size: 20px;
  line-height: 1;
  font-family: var(--serif);
}
.m-tab-label {
  font-size: 10.5px;
  letter-spacing: 0.02em;
}
.m-tab-badge {
  position: absolute;
  top: 6px; right: calc(50% - 22px);
  background: var(--red); color: var(--paper);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

/* "Daha" bottom sheet */
.m-sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 55;
  display: flex; align-items: flex-end;
}
.m-sheet {
  width: 100%;
  background: var(--paper);
  border-top-left-radius: 14px;
  border-top-right-radius: 14px;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -2px 20px rgba(0,0,0,0.15);
}
.m-sheet-handle {
  width: 40px; height: 4px;
  background: var(--rule-soft);
  border-radius: 2px;
  margin: 0 auto 14px;
}
.m-sheet-title {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 12px;
}
.m-sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.m-sheet-item {
  background: var(--paper-soft);
  border: 1px solid var(--rule-soft);
  border-radius: 8px;
  padding: 16px 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.m-sheet-item.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* Floating Copilot button */
.m-fab {
  position: fixed;
  right: 14px;
  bottom: calc(var(--m-tabbar-h, 64px) + 0px + 14px);
  z-index: 45;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 28px;
  padding: 12px 18px;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.m-fab:active { background: var(--ink-2); }
.m-fab-glyph {
  font-size: 16px;
  color: var(--red);
}
.m-fab-label {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
}

/* PWA install hint */
.m-install-hint {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--m-tabbar-h, 64px) + 0px + 80px);
  z-index: 45;
  background: var(--ink);
  color: var(--paper);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.25);
  font-family: var(--sans);
}
.m-install-text { flex: 1; }
.m-install-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.m-install-body {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-on-ink-dim);
}
.m-install-body strong { color: var(--paper); font-weight: 600; }
.m-install-dismiss {
  background: transparent;
  border: none;
  color: var(--text-on-ink-dim);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

/* Hide mobile-only chrome on true desktop only. Must exclude short viewports
   (phone landscape) so the mobile shell isn't hidden there — mirrors the JS
   isMobileViewport() rule and the mobile @media above. */
@media (min-width: 769px) and (min-height: 481px) {
  .m-tabbar, .m-fab, .m-install-hint, .m-header, .m-sheet-backdrop {
    display: none !important;
  }
}

/* ── AI Özet (InsightBox) ─────────────────────────────────────────────────
   Editorial callout that renders a live Claude summary under a chart. */
.insight-box {
  margin: 12px 0 2px;
  padding: 12px 16px 13px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 5%, var(--paper-soft)) 0%, var(--paper-soft) 100%);
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--rule-soft));
  border-left: 3px solid var(--brand);
  border-radius: 3px;
}
.insight-compact { margin-top: 8px; padding: 10px 14px; }
.insight-eyebrow {
  display: flex; align-items: center; gap: 7px;
  font-size: 9.5px; letter-spacing: 0.2em; text-transform: uppercase;
  font-weight: 700; color: var(--brand); margin-bottom: 7px;
}
.insight-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.insight-by {
  margin-left: auto; font-size: 9px; letter-spacing: 0.12em;
  font-weight: 600; color: var(--text-faint);
}
.insight-text {
  font-family: var(--sans); font-size: 13.5px; line-height: 1.55; color: var(--ink);
}
.insight-text strong { font-weight: 700; color: #000; }
.insight-li {
  position: relative; padding-left: 14px; margin-bottom: 3px;
}
.insight-li::before {
  content: '–'; position: absolute; left: 0; color: var(--brand); font-weight: 600;
}
.insight-loading, .insight-demo {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--serif); font-style: italic; font-size: 14.5px; color: var(--text-muted);
}
.insight-demo { font-style: normal; font-family: inherit; font-size: 11.5px; }
.insight-shimmer {
  width: 38px; height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, var(--rule-soft) 0%, var(--brand) 50%, var(--rule-soft) 100%);
  background-size: 200% 100%; animation: insight-pan 1.1s ease-in-out infinite;
}
@keyframes insight-pan { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Daily Briefing page ──────────────────────────────────────────────────── */
.brf-h {
  font-family: var(--serif); font-weight: 600; font-size: 21px; color: var(--brand);
  margin: 18px 0 8px; padding-bottom: 5px; border-bottom: 1px solid color-mix(in srgb, var(--brand) 25%, var(--rule-soft));
  letter-spacing: -0.01em;
}
.brf-h:first-child { margin-top: 2px; }
.brf-p { font-family: var(--sans); font-size: 14.5px; line-height: 1.62; color: var(--ink); margin: 4px 0 9px; }
.brf-li {
  position: relative; padding-left: 24px; margin-bottom: 9px;
  font-family: var(--sans); font-size: 14.5px; line-height: 1.56; color: var(--ink);
}
.brf-li .brf-num {
  position: absolute; left: 0; top: 0; font-family: var(--mono); font-size: 11px;
  font-weight: 700; color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent);
  width: 17px; height: 17px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
}
.brf-li.brf-dash::before { content: '–'; position: absolute; left: 7px; top: -1px; color: var(--brand); font-weight: 700; }
.brf-li strong, .brf-p strong { font-weight: 700; color: #000; }
.brf-stat {
  padding: 9px 12px; background: var(--paper-soft); border: 1px solid var(--rule-soft); border-radius: 3px;
}
.brf-stat .brf-stat-l { font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase; font-weight: 700; color: var(--text-muted); margin-bottom: 3px; }
.brf-stat .brf-stat-v { font-family: var(--mono); font-size: 15px; font-weight: 600; color: var(--ink); }
.brf-paper {
  background: var(--paper-soft); border: 1px solid var(--rule-soft); border-radius: 4px;
  padding: 4px 20px 16px; position: relative;
}
