/* ===== Aeizch — Fluid aesthetic ============================================
   Drop-in replacement for frontend/styles.css. Keeps every selector
   the React app uses; rebuilds the token system around a warm-near-black
   ground, bone-white text, and a single luminous mint accent.
   ==========================================================================*/

:root, [data-theme="indigo"], [data-theme="cream"] {
  /* Surfaces */
  --bg:          oklch(0.18 0.012 60);
  --bg-elev:     oklch(0.22 0.012 60);
  --bg-soft:     oklch(0.24 0.012 60);
  --surface:     oklch(0.22 0.012 60);

  /* Ink */
  --ink:         oklch(0.96 0.008 80);
  --ink-2:       oklch(0.86 0.008 80);
  --ink-3:       oklch(0.62 0.010 60);
  --ink-4:       oklch(0.45 0.010 60);

  /* Lines */
  --line:        oklch(0.30 0.012 60);
  --line-2:      oklch(0.26 0.012 60);

  /* Accents */
  --accent:      oklch(0.86 0.13 165);
  --accent-ink:  oklch(0.18 0.012 60);
  --accent-soft: oklch(0.32 0.06 165);
  --accent-2:    oklch(0.80 0.13 80);

  /* Sentiment */
  --pos:         oklch(0.86 0.13 165);
  --pos-soft:    oklch(0.32 0.06 165);
  --neg:         oklch(0.72 0.13 25);
  --neg-soft:    oklch(0.30 0.06 25);
  --warn:        oklch(0.80 0.13 80);
  --warn-soft:   oklch(0.30 0.06 80);

  /* Geometry */
  --radius-sm:   12px;
  --radius-md:   16px;
  --radius-lg:   20px;
  --radius-full: 999px;

  /* Shadows — restrained, only used by floating elements */
  --shadow-1: 0 1px 0 rgba(0,0,0,0.20);
  --shadow-2: 0 12px 32px rgba(0,0,0,0.40);
  --shadow-3: 0 24px 60px rgba(0,0,0,0.55);

  /* Type */
  --font-sans: "Inter Tight", "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-num:  "IBM Plex Mono", ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.005em;
}
button { font-family: inherit; }
.num {
  font-family: var(--font-num);
  font-feature-settings: "tnum" 1, "zero" 1;
  letter-spacing: -0.02em;
}

/* ── App shell ─────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.app.no-shell { grid-template-columns: 1fr; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  padding: 22px 14px;
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; letter-spacing: -0.04em; font-size: 15px;
}
.brand-name {
  font-weight: 500; letter-spacing: -0.02em; font-size: 16px; color: var(--ink);
}
.brand-sub {
  font-family: var(--font-num); font-size: 9.5px;
  color: var(--ink-3); margin-top: 2px;
  letter-spacing: 0.16em; text-transform: uppercase;
}

.nav-label {
  font-family: var(--font-num);
  font-size: 9.5px; font-weight: 500; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-4);
  padding: 18px 12px 8px;
}

.nav-item {
  appearance: none; border: 0; background: transparent;
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 10px;
  color: var(--ink-3); cursor: pointer; text-align: left;
  font-size: 13.5px; font-weight: 400;
  letter-spacing: -0.005em;
  position: relative;
  transition: color .18s, background .18s;
}
.nav-item:hover { color: var(--ink); background: var(--bg-elev); }
.nav-item.active {
  background: var(--bg-elev);
  color: var(--ink);
}
.nav-item.active::before {
  content: ''; position: absolute; left: -14px; top: 12px; bottom: 12px;
  width: 2px; background: var(--accent); border-radius: 0 2px 2px 0;
}
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { width: 17px; height: 17px; color: var(--ink-4); flex: none; }

.nav-badge {
  margin-left: auto;
  font-family: var(--font-num); font-size: 10px;
  padding: 2px 7px; background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; font-weight: 600;
}

.sidebar-foot {
  margin-top: auto; padding: 14px 8px 6px;
  display: flex; align-items: center; gap: 10px;
  border-top: 1px solid var(--line);
}
.avatar {
  width: 32px; height: 32px; border-radius: 16px;
  background: var(--bg-elev); color: var(--ink-3);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-family: var(--font-num); font-weight: 500; font-size: 11px;
  letter-spacing: 0.04em;
  flex: none;
}

/* ── Main ──────────────────────────────────────────────────────────────── */
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 32px 36px 14px; gap: 16px;
  border-bottom: 1px solid var(--line);
}
.crumb {
  font-family: var(--font-num);
  font-size: 10px; color: var(--ink-3); font-weight: 500;
  letter-spacing: 0.18em; text-transform: uppercase;
}
.h1 {
  font-size: 30px; font-weight: 400; letter-spacing: -0.03em;
  margin: 6px 0 0; color: var(--ink);
}
.h2 {
  font-size: 18px; font-weight: 500; letter-spacing: -0.015em;
  margin: 0; color: var(--ink);
}
.h3 {
  font-size: 14px; font-weight: 500; letter-spacing: -0.005em;
  margin: 0; color: var(--ink);
}
.muted { color: var(--ink-3); }
.tiny  { font-size: 11.5px; }

.content {
  padding: 24px 36px 80px;
  display: flex; flex-direction: column; gap: 18px;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card.flat {
  background: transparent;
  border: 1px solid var(--line);
}
.card.dark {
  background: oklch(0.14 0.012 60);
  border-color: var(--line);
  color: var(--ink);
}
.card.dark .muted { color: var(--ink-3); }
.card.lift { box-shadow: var(--shadow-1); }

/* ── KPI ──────────────────────────────────────────────────────────────── */
.kpi { display: flex; flex-direction: column; gap: 8px; }
.kpi-label {
  font-family: var(--font-num);
  font-size: 10px; color: var(--ink-3); font-weight: 500;
  letter-spacing: 0.16em; text-transform: uppercase;
}
.kpi-value {
  font-size: 26px; font-weight: 400; letter-spacing: -0.028em;
  color: var(--ink);
}
.kpi-delta {
  font-family: var(--font-num); font-size: 12px;
  font-weight: 500; display: inline-flex; align-items: center; gap: 5px;
  letter-spacing: -0.01em;
}
.kpi-delta.pos { color: var(--pos); }
.kpi-delta.neg { color: var(--neg); }

/* ── Layout helpers ───────────────────────────────────────────────────── */
.row { display: flex; align-items: center; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-10 { gap: 10px; }
.gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-20 { gap: 20px; } .gap-24 { gap: 24px; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }

/* ── Pills ────────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-family: var(--font-num);
  font-size: 10px; font-weight: 500;
  letter-spacing: 0.10em; text-transform: uppercase;
  background: var(--bg-soft); color: var(--ink-2);
  border: 1px solid var(--line);
}
.pill.pos  { background: var(--pos-soft);  color: var(--pos);  border-color: transparent; }
.pill.neg  { background: var(--neg-soft);  color: var(--neg);  border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill .dot {
  width: 5px; height: 5px; border-radius: 999px; background: currentColor;
  animation: dotpulse 2.4s ease-in-out infinite;
}
@keyframes dotpulse {
  0%,100% { opacity: 0.5; transform: scale(1); }
  50%     { opacity: 1;   transform: scale(1.15); }
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 14px;
  font-size: 13.5px; font-weight: 500; font-family: inherit;
  letter-spacing: -0.01em;
  transition: background .16s, color .16s, transform .12s, opacity .16s, border-color .16s;
}
.btn:active { transform: translateY(0.5px) scale(0.985); }

.btn.primary {
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); }

.btn.accent { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.accent:hover { filter: brightness(1.06); }

.btn.ghost {
  background: transparent; color: var(--ink); border: 1px solid var(--line);
}
.btn.ghost:hover { background: var(--bg-elev); border-color: var(--ink-4); }

.btn.soft { background: var(--bg-elev); color: var(--ink); border: 1px solid var(--line); }
.btn.soft:hover { border-color: var(--ink-4); }

.btn.danger {
  background: var(--neg); color: oklch(0.18 0.012 60); font-weight: 600;
}

.btn.sm { padding: 7px 12px; font-size: 12px; border-radius: 10px; }
.btn.lg { padding: 14px 22px; font-size: 14px; border-radius: 16px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ── Inputs ───────────────────────────────────────────────────────────── */
.input, .select, .textarea {
  appearance: none; width: 100%;
  padding: 12px 14px; border-radius: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit; font-size: 14px;
  letter-spacing: -0.005em;
  transition: border .16s, box-shadow .16s, background .16s;
}
.input::placeholder { color: var(--ink-4); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px oklch(0.86 0.13 165 / 0.18);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-family: var(--font-num);
  font-size: 10px; font-weight: 500; color: var(--ink-3);
  letter-spacing: 0.14em; text-transform: uppercase;
}
.field-hint { font-size: 11.5px; color: var(--ink-3); }

/* ── Table ────────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td {
  text-align: left; padding: 14px 18px;
  border-bottom: 1px solid var(--line-2);
  font-size: 13px;
}
.tbl th {
  font-family: var(--font-num);
  font-size: 9.5px; font-weight: 500;
  color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.14em;
  border-bottom: 1px solid var(--line);
  padding-top: 16px; padding-bottom: 12px;
}
.tbl tbody tr { transition: background .14s; }
.tbl tbody tr:hover { background: var(--bg-soft); }
.tbl tbody tr:last-child td { border-bottom: 0; }

/* ── Bot card ─────────────────────────────────────────────────────────── */
.bot-card {
  position: relative; padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color .16s, transform .16s;
  display: flex; flex-direction: column; gap: 14px;
}
.bot-card:hover { border-color: var(--ink-4); transform: translateY(-1px); }

.bot-emblem {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--bg-soft); border: 1px solid var(--line);
  display: grid; place-items: center;
  font-family: var(--font-num);
  font-weight: 500; font-size: 13px;
  color: var(--ink);
  letter-spacing: -0.02em;
}

/* Risk pip — three dots indicating risk level */
.risk-pip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line);
  font-family: var(--font-num);
  font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3);
}
.risk-pip .dots { display: inline-flex; gap: 3px; }
.risk-pip .dots i {
  width: 4px; height: 4px; border-radius: 2px;
  background: var(--ink-4); display: inline-block;
}
.risk-pip.lvl-1 .dots i:nth-child(1) { background: var(--ink); }
.risk-pip.lvl-2 .dots i:nth-child(-n+2) { background: var(--ink); }
.risk-pip.lvl-3 .dots i { background: var(--ink); }

/* ── Sparkline ────────────────────────────────────────────────────────── */
.spark { width: 100%; height: 64px; }
.chart-wrap { position: relative; width: 100%; }

/* ── Modal — used on desktop. On mobile, becomes a sheet. ─────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: oklch(0.10 0.008 60 / 0.65);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: grid; place-items: center;
  animation: fadeIn .22s ease;
}
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow: auto;
  box-shadow: var(--shadow-3);
  animation: popIn .28s cubic-bezier(.2,.85,.3,1.05);
}
.modal-hd {
  padding: 22px 24px 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.modal-bd {
  padding: 8px 24px 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-x {
  background: var(--bg-soft); border: 1px solid var(--line);
  width: 32px; height: 32px; border-radius: 16px; cursor: pointer;
  color: var(--ink-3);
  display: grid; place-items: center;
}
.modal-x:hover { color: var(--ink); border-color: var(--ink-4); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn  {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Auth ─────────────────────────────────────────────────────────────── */
.auth-shell {
  min-height: 100vh; display: grid;
  grid-template-columns: 1.05fr 1fr;
  background: var(--bg);
}
.auth-side {
  background: oklch(0.14 0.012 60);
  color: var(--ink);
  padding: 44px;
  border-right: 1px solid var(--line);
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
}
.auth-side .brand-name { color: var(--ink); }
.auth-side .brand-mark { background: var(--accent); color: var(--accent-ink); }
.auth-pane {
  display: flex; align-items: center; justify-content: center; padding: 32px;
}
.auth-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 18px; }

.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px 18px; border-radius: 12px;
  background: var(--bg-elev); color: var(--ink);
  border: 1px solid var(--line);
  font: inherit; font-weight: 500; font-size: 14px;
  cursor: pointer; width: 100%;
  transition: border-color .15s;
}
.google-btn:hover { border-color: var(--ink-4); }
.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink-3);
  font-family: var(--font-num); font-size: 10px; font-weight: 500;
  letter-spacing: 0.18em; text-transform: uppercase;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

/* ── Steps ────────────────────────────────────────────────────────────── */
.steps { display: flex; align-items: center; gap: 6px; }
.step {
  flex: 1; height: 3px; border-radius: 2px;
  background: var(--bg-soft);
  transition: background .25s;
}
.step.done   { background: var(--accent); }
.step.active { background: var(--ink); }

/* ── Dropzone ─────────────────────────────────────────────────────────── */
.dropzone {
  border: 1.25px dashed var(--line); border-radius: 16px;
  padding: 28px 20px; text-align: center;
  background: transparent;
  cursor: pointer; transition: border-color .16s, background .16s;
}
.dropzone:hover { border-color: var(--accent); background: var(--bg-elev); }

/* ── Scrollbar (Webkit) ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-4); }

/* ── Selection ────────────────────────────────────────────────────────── */
::selection { background: var(--accent-soft); color: var(--ink); }

/* ── Mobile ───────────────────────────────────────────────────────────── */
/* Default: mobile floating logout hidden on desktop. Mobile media query
   below overrides this with display: inline-flex. */
.mobile-logout { display: none; }

@media (max-width: 860px) {
  html, body { overflow-x: hidden; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 14px; top: auto; left: 14px; right: 14px;
    height: auto;
    flex-direction: row; gap: 2px;
    padding: 6px; border: 1px solid var(--line); border-radius: 28px;
    background: oklch(0.22 0.012 60 / 0.88);
    -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
    box-shadow: var(--shadow-2);
    z-index: 50; overflow: hidden;
    justify-content: space-around;
  }
  .brand, .nav-label, .sidebar-foot { display: none; }
  .sidebar .nav-item.mobile-hide { display: none; }
  .nav-item {
    flex-direction: column; gap: 3px; padding: 8px 6px;
    font-size: 9.5px; flex: 1; min-width: 0;
    border-radius: 22px; text-align: center; line-height: 1.1;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    color: var(--ink-3);
  }
  .nav-item::before { display: none; }
  .nav-item.active { background: var(--bg-soft); color: var(--ink); }
  .nav-item .nav-badge { display: none; }

  .topbar {
    padding: 18px 18px 12px;
    flex-direction: column; align-items: flex-start; gap: 12px;
  }
  .topbar > div:last-child { width: 100%; }
  .topbar .btn { flex: 1; }
  .content { padding: 14px 18px 110px; gap: 12px; }
  .h1 { font-size: 22px; }
  .h2 { font-size: 16px; }
  .card { padding: 16px; border-radius: 18px; }

  .grid { gap: 10px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  .kpi-value { font-size: 22px; }
  .kpi-label { font-size: 9.5px; }

  .range-row { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .range-row::-webkit-scrollbar { display: none; }
  .range-row .btn { flex: none; }

  .auth-shell { grid-template-columns: 1fr; min-height: auto; }
  .auth-side  { padding: 28px; }
  .auth-side h1 { font-size: 30px !important; }
  .auth-pane  { padding: 24px; }

  .card .tbl { display: block; }
  .card .tbl thead { display: none; }
  .card .tbl tbody { display: block; }
  .card .tbl tr {
    display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
    padding: 14px 16px; border-bottom: 1px solid var(--line-2); align-items: center;
  }
  .card .tbl tr:last-child { border-bottom: 0; }
  .card .tbl td { padding: 0; border: 0; font-size: 13px; }
  .card .tbl td:first-child { grid-column: 1 / 2; }
  .card .tbl td:nth-child(n+2) { grid-column: 2 / 3; text-align: right; }
  .card .tbl td:nth-child(n+3):not(:last-child) { font-size: 11px; color: var(--ink-3); }
  .card .tbl td:last-child { grid-row: 1; grid-column: 2; justify-self: end; }

  /* Modal becomes a bottom sheet on mobile */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    width: 100%; max-width: 100%;
    border-radius: 24px 24px 0 0;
    max-height: 92vh;
    animation: sheetUp .35s cubic-bezier(.2,.85,.3,1.05);
  }
  @keyframes sheetUp { from { transform: translateY(40%); } to { transform: translateY(0); } }

  /* Mobile-only floating logout — sidebar-foot is hidden on mobile so the
     desktop sign-out button is unreachable; float a small one top-right.
     The desktop hide rule lives ABOVE the media query so this override wins. */
  .mobile-logout {
    display: inline-flex; align-items: center; justify-content: center;
    position: fixed; top: 14px; right: 14px; z-index: 60;
    width: 38px; height: 38px; border-radius: 50%;
    background: oklch(0.22 0.012 60 / 0.88);
    -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
    border: 1px solid var(--line); color: var(--ink-2);
    box-shadow: var(--shadow-2); cursor: pointer;
    transition: transform .15s, background .15s;
  }
  .mobile-logout:active { transform: scale(0.94); }
  .mobile-logout:hover { background: var(--bg-soft); color: var(--ink); }
}

@media (max-width: 420px) {
  .h1 { font-size: 20px; }
  .h2 { font-size: 15px; }
  .kpi-value { font-size: 20px; letter-spacing: -0.03em; }
  .nav-item { font-size: 9px; padding: 8px 4px; }
  .nav-icon { width: 16px; height: 16px; }
}
