/* ============================================================
   LAYOUT + COMPONENTS
   ============================================================ */

#app { min-height: 100vh; position: relative; z-index: 1; }

/* ---- background FX layers ---- */
.fx { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.fx-grid {
  position: absolute; inset: -2px;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
}

/* ============================================================
   SHELL GRID
   ============================================================ */
.shell { display: grid; grid-template-columns: 76px 1fr; height: 100vh; overflow: hidden; }

/* ---- SIDEBAR ---- */
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 18px 0; z-index: 40;
  background: linear-gradient(180deg, rgba(16,14,28,0.6), rgba(8,7,15,0.4));
  border-right: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
}
.sidebar-logo {
  width: 42px; height: 42px; border-radius: 12px; margin-bottom: 14px;
  display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--violet-deep));
  box-shadow: 0 8px 22px -6px var(--accent);
  position: relative;
}
.sidebar-logo::after { content:''; position:absolute; inset:0; border-radius:inherit; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25); }
.nav-items { display: flex; flex-direction: column; gap: 3px; width: 100%; align-items: center; flex: 1; }
.nav-item {
  position: relative; width: 46px; height: 46px; border-radius: 13px;
  display: grid; place-items: center; color: var(--text-lo);
  transition: all 0.2s ease;
}
.nav-item svg { width: 21px; height: 21px; }
.nav-item:hover { color: var(--text-hi); background: rgba(255,255,255,0.05); }
.nav-item:hover::before { transform: scaleY(1); }
.nav-item::before {
  content: ''; position: absolute; left: -18px; top: 50%; translate: 0 -50%;
  width: 3px; height: 22px; border-radius: 3px; background: var(--accent);
  transform: scaleY(0); transition: transform 0.22s ease;
}
.nav-item.active { color: var(--accent-bright); background: rgba(139,92,246,0.12); box-shadow: inset 0 0 0 1px var(--glass-border-hi); }
.nav-item.active::before { transform: scaleY(1); box-shadow: 0 0 12px var(--accent); }
.nav-item .tip {
  position: absolute; left: 56px; white-space: nowrap;
  font-family: var(--font-mono); font-size: 11px; padding: 6px 10px;
  background: var(--bg-panel-solid); border: 1px solid var(--glass-border);
  border-radius: 8px; opacity: 0; transform: translateX(-6px); pointer-events: none;
  transition: all 0.16s ease; z-index: 50; box-shadow: var(--shadow-panel);
}
.nav-item:hover .tip { opacity: 1; transform: none; }

/* Only the content area scrolls; the sidebar + header stay frozen on the side. */
.main { min-width: 0; display: flex; flex-direction: column; height: 100vh; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }

/* ---- HEADER ---- */
.header {
  position: sticky; top: 0; z-index: 35;
  display: flex; align-items: center; gap: 18px;
  padding: 14px 26px;
  background: linear-gradient(180deg, rgba(8,7,15,0.85), rgba(8,7,15,0.45));
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
}
.workspace-pill {
  display: flex; align-items: center; gap: 10px; padding: 7px 14px 7px 9px;
  border-radius: 100px; border: 1px solid var(--glass-border-hi);
  background: rgba(139,92,246,0.08);
}
.ws-badge { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 13px; color: #fff; }
.search {
  flex: 1; max-width: 540px; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 12px;
  background: rgba(255,255,255,0.035); border: 1px solid var(--glass-border);
  transition: all 0.2s ease;
}
.search:focus-within { border-color: var(--glass-border-hi); box-shadow: 0 0 0 4px rgba(139,92,246,0.08); }
.search input { flex: 1; background: none; border: none; color: var(--text-hi); font-size: 13.5px; outline: none; }
.search input::placeholder { color: var(--text-lo); }
.header-spacer { flex: 1; }
.hstat { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-mid); }
.hicon {
  position: relative; width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  color: var(--text-mid); border: 1px solid var(--glass-border); background: rgba(255,255,255,0.025);
  transition: all 0.18s ease;
}
.hicon:hover { color: var(--text-hi); border-color: var(--glass-border-hi); }
.hicon .badge { position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--red); color: #fff; font-family: var(--font-mono); font-size: 9.5px; font-weight: 700; display: grid; place-items: center; }
.avatar { width: 40px; height: 40px; border-radius: 11px; background: linear-gradient(135deg, var(--cyan), var(--violet)); display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; color: #fff; font-size: 13px; }

/* ---- BRAND TABS ---- */
.brandbar { display: flex; align-items: center; gap: 10px; padding: 16px 26px 4px; flex-wrap: wrap; }
.brand-tab {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 9px 16px 9px 11px; border-radius: 100px;
  border: 1px solid var(--glass-border); background: rgba(255,255,255,0.025);
  transition: all 0.2s ease; overflow: hidden;
}
.brand-tab:hover { border-color: var(--glass-border-hi); transform: translateY(-1px); }
.brand-tab.active { border-color: transparent; background: rgba(139,92,246,0.14); box-shadow: inset 0 0 0 1px var(--glass-border-hi), 0 8px 24px -10px var(--accent); }
.brand-tab.active::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; padding: 1px;
  background: linear-gradient(120deg, var(--accent), var(--cyan), var(--emerald));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
  opacity: 0.7; animation: sweep-glow 3s ease-in-out infinite;
}
.brand-mark { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 12px; color: #fff; flex: none; }
.brand-meta { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 13px; letter-spacing: 0.02em; }
.brand-sub { font-family: var(--font-mono); font-size: 9.5px; color: var(--text-lo); display: flex; align-items: center; gap: 5px; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; animation: pulse-dot 1.6s ease-in-out infinite; }

/* ---- content scroll region ---- */
.content { padding: 8px 26px 120px; display: flex; flex-direction: column; gap: 26px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 2px; }
.section-title { font-family: var(--font-display); font-size: 19px; font-weight: 600; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.section-title .ico { color: var(--accent-bright); display: grid; place-items: center; }

/* Dashboard time filter (Daily/Weekly/Monthly/All) */
.period-toggle { display: inline-flex; gap: 2px; padding: 3px; border-radius: 100px; background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border); flex: none; }
.period-btn { font-family: var(--font-mono); font-size: 11px; font-weight: 600; padding: 6px 13px; border-radius: 100px; color: var(--text-mid); transition: all 0.15s ease; white-space: nowrap; }
.period-btn:hover { color: var(--text-hi); }
.period-btn.active { background: linear-gradient(135deg, var(--accent), var(--violet-deep)); color: #fff; box-shadow: 0 4px 12px -4px var(--accent); }
.period-date { margin-left: 6px; padding: 5px 9px; border-radius: 100px; font-family: var(--font-mono); font-size: 11px; border: 1px solid var(--glass-border); background: rgba(255,255,255,0.04); color: var(--text-hi); color-scheme: dark; }
.period-range { display: inline-flex; align-items: center; gap: 4px; }
.period-range .period-date { margin-left: 0; }
.period-arrow { font-family: var(--font-mono); font-size: 11px; color: var(--text-lo); }

/* ---- HERO ---- */
.hero { position: relative; padding: 40px 38px 36px; overflow: hidden; }
.hero-bg-glow { position: absolute; inset: 0; background: radial-gradient(120% 100% at 18% 0%, var(--hero-glow-a), transparent 55%), radial-gradient(90% 90% at 88% 30%, var(--hero-glow-b), transparent 60%); opacity: 0.5; pointer-events: none; }
.hero-inner { position: relative; display: grid; grid-template-columns: 1.35fr 1fr; gap: 40px; align-items: center; }
.hero h1 { font-family: var(--font-display); font-size: clamp(30px, 4vw, 50px); font-weight: 700; line-height: 1.02; letter-spacing: -0.02em; margin: 14px 0 14px; }
.hero h1 .grad { background: linear-gradient(110deg, var(--violet-bright), var(--cyan-bright) 55%, var(--emerald-bright)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--text-mid); font-size: 15px; line-height: 1.6; max-width: 52ch; }
.hero-cta { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.hero-orb { position: relative; aspect-ratio: 1; max-width: 320px; margin-left: auto; }

/* ---- KPI GRID ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi { position: relative; padding: 18px; overflow: hidden; transition: transform 0.22s ease, box-shadow 0.22s ease; }
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-glow); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.kpi-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; }
.kpi-label { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-lo); }
.kpi-value { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.kpi-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.kpi-delta { font-family: var(--font-mono); font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.spark { height: 28px; display: flex; align-items: flex-end; gap: 2px; }
.spark span { width: 3px; border-radius: 2px; background: var(--accent); opacity: 0.55; }

/* ---- generic panel ---- */
.panel { padding: 22px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.panel-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 9px; }

/* two-col layout for charts/upload.
   NB: minmax(0, …) instead of 1fr so grid tracks can shrink below their content
   width — without it, wide children (long file names, gateway labels) force the
   whole grid past the viewport and get clipped on mobile. */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 26px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

/* responsive grids — defined as classes so the media queries below can
   override them (inline React styles can't be targeted by CSS breakpoints) */
.provider-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.channel-grid  { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
.summary-grid  { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.insight-grid  { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

/* ---- UPLOAD ---- */
.dropzone {
  position: relative; border: 1.5px dashed var(--glass-border-hi); border-radius: var(--radius);
  padding: 34px; text-align: center; transition: all 0.22s ease; overflow: hidden;
  /* fill the grid row height and center content so a short dropzone next to a
     tall ingest list doesn't leave a hollow gap */
  align-self: stretch;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(120% 120% at 50% 0%, rgba(139,92,246,0.06), transparent 60%);
}
.dropzone.drag { border-color: var(--accent-bright); background: radial-gradient(120% 120% at 50% 0%, rgba(139,92,246,0.18), transparent 65%); transform: scale(1.005); }
.dz-ico { width: 60px; height: 60px; margin: 0 auto 14px; border-radius: 16px; display: grid; place-items: center; background: rgba(139,92,246,0.12); border: 1px solid var(--glass-border-hi); color: var(--accent-bright); }
.dz-formats { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.file-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.file-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.file-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none; font-family: var(--font-mono); font-size: 9px; font-weight: 700; }
.file-name { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; }
.file-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-lo); }
.progress { height: 5px; border-radius: 4px; background: rgba(255,255,255,0.06); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--cyan)); transition: width 0.3s ease; }
.parse-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.pstat { text-align: center; padding: 8px 4px; border-radius: var(--radius-xs); background: rgba(255,255,255,0.03); min-width: 0; }
.pstat b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pstat b { font-family: var(--font-mono); font-size: 15px; display: block; }
.pstat span { font-family: var(--font-mono); font-size: 9px; color: var(--text-lo); text-transform: uppercase; letter-spacing: 0.08em; }

/* ---- EXPENSES ---- */
.exp-input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border);
  color: var(--text-hi); font-size: 13px; outline: none; min-width: 0;
}
.exp-input:focus { border-color: var(--glass-border-hi); box-shadow: 0 0 0 3px rgba(139,92,246,0.08); }
.exp-input::placeholder { color: var(--text-lo); }
.exp-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  border-radius: var(--radius-xs); background: rgba(255,255,255,0.025);
  border: 1px solid var(--glass-border);
}
.exp-total {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--glass-border);
}

/* ---- CHARTS ---- */
.chart-wrap { width: 100%; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 150px; padding: 9px 11px; border-radius: 10px;
  background: var(--bg-panel-solid); border: 1px solid var(--glass-border-hi);
  box-shadow: var(--shadow-panel); transform: translateX(-50%);
}
.chart-tip-day { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-lo); margin-bottom: 7px; }
.chart-tip-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; font-size: 12px; margin-top: 4px; }
.chart-tip-row span { display: flex; align-items: center; gap: 6px; color: var(--text-mid); }
.chart-tip-row i { width: 8px; height: 8px; border-radius: 2px; }
.chart-tip-row b { font-family: var(--font-mono); font-weight: 600; color: var(--text-hi); }
.chart-tip-row.gap { margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--glass-border); }
.chart-tip-row.gap b { color: var(--amber); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--text-mid); }
.legend i { width: 9px; height: 9px; border-radius: 3px; }
.heat { display: grid; grid-template-columns: auto repeat(7, 1fr); gap: 4px; }
.heat .cell { aspect-ratio: 1.6; border-radius: 5px; transition: transform .1s; }
.heat .cell:hover { transform: scale(1.12); outline: 1px solid rgba(255,255,255,.4); }
.heat .lbl { font-family: var(--font-mono); font-size: 10px; color: var(--text-lo); display: grid; place-items: center; }
/* smaller variant with bigger hover target */
.heat-sm { gap: 3px; max-width: 360px; }
.heat-sm .cell { aspect-ratio: 1.9; border-radius: 4px; }
.heat-sm .lbl { font-size: 9px; }

/* ---- TABLE ---- */
.table-wrap { overflow: auto; border-radius: var(--radius); }
table.audit { width: 100%; border-collapse: collapse; font-size: 13px; }
table.audit thead th {
  position: sticky; top: 0; z-index: 2; text-align: left;
  font-family: var(--font-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-lo); padding: 12px 14px; background: var(--bg-panel-solid);
  border-bottom: 1px solid var(--glass-border); white-space: nowrap;
}
table.audit tbody td { padding: 13px 14px; border-bottom: 1px solid rgba(255,255,255,0.04); }
table.audit tbody tr { transition: background 0.14s ease; cursor: pointer; }
table.audit tbody tr:hover { background: rgba(139,92,246,0.05); }
table.audit tbody tr.crit { box-shadow: inset 3px 0 0 var(--red); }
table.audit tbody tr.warn-row { box-shadow: inset 3px 0 0 var(--amber); }
table.audit tbody tr.ok-row { box-shadow: inset 3px 0 0 var(--emerald); }
.tx-id { font-family: var(--font-mono); font-size: 12px; color: var(--text-mid); }
.expand-row td { background: rgba(0,0,0,0.25); padding: 0 !important; }
.expand-inner { padding: 16px 18px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; animation: rise-in 0.3s ease; }
.exp-field span { font-family: var(--font-mono); font-size: 9.5px; color: var(--text-lo); text-transform: uppercase; letter-spacing: 0.08em; display: block; margin-bottom: 4px; }
.exp-field b { font-family: var(--font-mono); font-size: 13px; }

/* ---- INSIGHTS ---- */
.insight { padding: 16px; display: flex; gap: 14px; transition: transform 0.2s ease; }
.insight:hover { transform: translateX(3px); }
.insight-ico { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.insight h4 { font-family: var(--font-display); font-size: 14px; font-weight: 600; margin-bottom: 5px; display: flex; align-items: center; gap: 8px; }
.insight p { font-size: 12.5px; color: var(--text-mid); line-height: 1.55; }
.insight-actions { display: flex; gap: 8px; margin-top: 10px; }
.mini-btn { font-family: var(--font-mono); font-size: 10.5px; padding: 5px 10px; border-radius: 7px; border: 1px solid var(--glass-border); color: var(--text-mid); transition: all 0.15s; }
.mini-btn:hover { border-color: var(--glass-border-hi); color: var(--text-hi); }

/* ============================================================
   AI CHAT DOCK
   ============================================================ */
.ai-fab {
  position: fixed; bottom: 26px; right: 26px; z-index: 60;
  width: 60px; height: 60px; border-radius: 18px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--violet-deep));
  box-shadow: 0 14px 40px -10px var(--accent), inset 0 0 0 1px rgba(255,255,255,0.2);
  color: #fff; transition: transform 0.2s ease;
}
.ai-fab:hover { transform: scale(1.06) rotate(-4deg); }
.ai-fab .ping { position: absolute; inset: 0; border-radius: inherit; border: 2px solid var(--accent-bright); animation: ring-pulse 2.4s ease-out infinite; --ring: rgba(139,92,246,0.5); }

.ai-dock {
  position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 92vw; z-index: 70;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, rgba(16,14,28,0.92), rgba(8,7,15,0.92));
  -webkit-backdrop-filter: blur(28px); backdrop-filter: blur(28px);
  border-left: 1px solid var(--glass-border-hi);
  box-shadow: -30px 0 80px -30px rgba(0,0,0,0.8);
  transform: translateX(100%); transition: transform 0.34s cubic-bezier(.2,.8,.2,1), visibility 0.34s;
  /* hidden while closed so the off-screen panel can't be panned to on mobile */
  visibility: hidden;
}
.ai-dock.open { transform: none; visibility: visible; }
.ai-head { padding: 16px 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--glass-border); }
.ai-orb-sm { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: linear-gradient(135deg, var(--cyan), var(--violet)); position: relative; }
.ai-msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 10px; animation: rise-in 0.35s ease; }
.msg.user { flex-direction: row-reverse; }
.msg-av { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; font-family: var(--font-mono); font-size: 11px; font-weight: 700; }
.msg-bubble { max-width: 80%; padding: 12px 14px; border-radius: 14px; font-size: 13px; line-height: 1.55; }
.msg.ai .msg-bubble { background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border); border-top-left-radius: 4px; }
.msg.user .msg-bubble { background: linear-gradient(135deg, var(--accent), var(--violet-deep)); color: #fff; border-top-right-radius: 4px; }
.msg-bubble .reason-card { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: rgba(34,211,238,0.06); border: 1px solid rgba(34,211,238,0.18); }
.msg-link { display: inline-flex; align-items: center; gap: 5px; margin-top: 4px; padding: 5px 11px; border-radius: 9px; text-decoration: none; font-weight: 600; background: rgba(139,92,246,0.18); border: 1px solid var(--glass-border-hi); color: var(--accent-bright); }
.msg.user .msg-link { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.3); color: #fff; }
.msg-link:hover { background: rgba(139,92,246,0.30); }
.msg-link { display: inline-flex; align-items: center; gap: 5px; margin-top: 4px; padding: 5px 11px; border-radius: 9px; text-decoration: none; font-weight: 600; background: rgba(139,92,246,0.18); border: 1px solid var(--glass-border-hi); color: var(--accent-bright); }
.msg.user .msg-link { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.3); color: #fff; }
.msg-link:hover { background: rgba(139,92,246,0.30); }
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-mid); animation: pulse-dot 1.2s ease-in-out infinite; }
.typing i:nth-child(2){ animation-delay: 0.2s; } .typing i:nth-child(3){ animation-delay: 0.4s; }
.quick-prompts { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 18px 12px; }
.qp { font-family: var(--font-mono); font-size: 10.5px; padding: 7px 11px; border-radius: 100px; border: 1px solid var(--glass-border); color: var(--text-mid); transition: all 0.15s; text-align: left; }
.qp:hover { border-color: var(--glass-border-hi); color: var(--text-hi); background: rgba(139,92,246,0.08); }
.ai-input-wrap { padding: 14px 16px 16px; border-top: 1px solid var(--glass-border); }
.ai-input { display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 14px; border-radius: 14px; background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border); }
.ai-input:focus-within { border-color: var(--glass-border-hi); }
.ai-input textarea { flex: 1; background: none; border: none; color: var(--text-hi); font-size: 13px; resize: none; outline: none; max-height: 120px; line-height: 1.5; padding: 5px 0; }
.ai-input textarea::placeholder { color: var(--text-lo); }
.ai-send { width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--violet-deep)); color: #fff; transition: all 0.15s; }
.ai-send:hover { filter: brightness(1.1); }
.ai-send:disabled { opacity: 0.4; cursor: default; }
.io-btn { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--text-mid); }
.io-btn:hover { color: var(--text-hi); background: rgba(255,255,255,0.05); }

.scrim { position: fixed; inset: 0; z-index: 65; background: rgba(4,3,10,0.5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.scrim.show { opacity: 1; pointer-events: auto; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* tablet / small laptop */
@media (max-width: 1180px) {
  .hero-inner { grid-template-columns: 1fr; }
  .hero-orb { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .provider-grid { grid-template-columns: repeat(3, 1fr); }
}

/* large phone / small tablet */
@media (max-width: 860px) {
  .channel-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .insight-grid { grid-template-columns: 1fr; }
  .provider-grid { grid-template-columns: repeat(2, 1fr); }
}

/* phone — sidebar becomes a bottom tab bar */
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: 58px;
    flex-direction: row; width: 100%; padding: 0 6px; gap: 0;
    overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
    border-right: none; border-top: 1px solid var(--glass-border); z-index: 50;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar-logo { display: none; }
  .nav-items { flex-direction: row; flex: 1; gap: 0; justify-content: space-around; }
  .nav-item { width: 44px; height: 44px; flex: none; }
  .nav-item::before { display: none; }
  .nav-item .tip { display: none; }

  /* header collapses to two rows: identity + actions, then full-width search */
  .header { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .workspace-pill { padding: 6px 12px 6px 8px; }
  .header-spacer { display: none; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .hstat { display: none; }
  .hicon { width: 38px; height: 38px; }

  .brandbar { padding: 12px 14px 2px; gap: 8px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .brandbar::-webkit-scrollbar { display: none; }
  .brand-tab { flex: none; }

  /* content: leave room for the bottom tab bar + the FAB */
  .content { padding: 8px 14px 96px; gap: 20px; }
  .grid-3 { grid-template-columns: 1fr; }
  .provider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 25px; }

  .hero { padding: 28px 22px 26px; }
  .panel { padding: 16px; }
  .section-head { flex-wrap: wrap; gap: 8px; }

  /* Global overflow guard: never let a child force the page wider than the
     screen. Combined with minmax(0,…) on the grids, this keeps every card,
     table, and text block inside the viewport on phones. */
  .content, .panel, .glass, .file-card, .insight, .kpi { min-width: 0; max-width: 100%; }

  /* Upload Center: the dropzone text was being clipped, and the 4-up parse
     stats can't shrink (gateway names blow out the row), so drop to 2-up and
     let long values wrap/ellipsize instead of forcing width. */
  .grid-2 { grid-template-columns: 1fr; }
  .dropzone { padding: 24px 16px; }
  .dropzone, .dropzone * { overflow-wrap: anywhere; }
  .dz-formats { gap: 6px; }
  .parse-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pstat { min-width: 0; }
  .pstat b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .file-card { min-width: 0; }

  /* keep the AI button clear of the bottom tab bar */
  .ai-fab { bottom: 74px; right: 16px; width: 54px; height: 54px; }

  /* full-screen chat dock on phones */
  .ai-dock { width: 100%; max-width: 100%; border-left: none; }
}

/* very small phones */
@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .provider-grid { grid-template-columns: 1fr; }
  .parse-stats { grid-template-columns: repeat(2, 1fr); }
  .hero h1 { font-size: clamp(26px, 8vw, 34px); }
}
