@import url("tokens.css");

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
/* light that bends: the kit's glass sits on a photograph; on pure black these soft monochrome glows are
   what the 45px blur and the rims have to refract. Nothing coloured. */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(900px 560px at 18% -10%, rgba(255,255,255,0.16), transparent 62%),
    radial-gradient(760px 520px at 92% 112%, rgba(255,255,255,0.10), transparent 62%),
    radial-gradient(520px 360px at 70% 38%, rgba(255,255,255,0.05), transparent 65%);
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted-foreground); }
.eyebrow { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted-foreground); }
h1, h2, h3 { margin: 0; font-weight: 500; letter-spacing: -0.01em; }
h1 { font-size: 28px; line-height: 1.1; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--muted-foreground); font-weight: 500; }
.hidden { display: none !important; }

/* ---------- glass material — the kit's layer stack, in order (see tokens.css for the node map) ---------- */
.glass {
  position: relative;
  background: var(--glass-fill);                       /* 1:9 fill  */
  border: 1px solid var(--glass-stroke);               /* 1:4 outer stroke */
  border-radius: var(--r-card);
  box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: blur(var(--glass-blur));    /* 1:9 blur  */
  backdrop-filter: blur(var(--glass-blur));
  overflow: hidden;
  isolation: isolate;                                  /* rims blend with this glass, not with the page */
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
/* 1:14 + 1:15 — two specular rims, 1px each, blurred 1.5px, additive */
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 1;
  border: 1px solid var(--glass-rim-light);
  box-shadow: inset 0 0 0 1px var(--glass-rim-soft);
  filter: blur(var(--glass-rim-blur));
  mix-blend-mode: plus-lighter;
}
/* 1:13 — the dark rim, 1px, blurred 4px, multiply */
.glass::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 1;
  border: 1px solid var(--glass-rim-dark);
  filter: blur(var(--glass-rim-dark-blur));
  mix-blend-mode: multiply;
}
.glass > * { position: relative; z-index: 2; }
.glass.raised { box-shadow: var(--glass-shadow-raised); background: var(--glass-fill-strong); }
.glass.interactive:hover { background: var(--glass-fill-hover); border-color: var(--glass-stroke-strong); }
.glass.interactive:active { transform: scale(0.992); }
/* 1:10 + 1:16 — the lens: the inner shape, inset 6px, radius outer − 6, darkened 10% with its own 4px blur */
.lens {
  background: var(--glass-lens);
  -webkit-backdrop-filter: blur(var(--glass-lens-blur)); backdrop-filter: blur(var(--glass-lens-blur));
  box-shadow: inset 0 0 0 1px var(--glass-rim-soft);
}

/* ---------- shell ---------- */
.shell { position: relative; z-index: 1; display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; padding: 18px 16px; display: flex; flex-direction: column; gap: 14px;
  border-right: 1px solid var(--sidebar-border);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)); backdrop-filter: blur(var(--glass-blur));
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px; min-height: var(--touch); }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.brand .word { font-weight: 600; letter-spacing: -0.02em; font-size: 15px; }
.brand .word span { color: var(--muted-foreground); font-weight: 500; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; min-height: var(--touch); padding: 0 12px; border-radius: var(--r-control);
  font: var(--tab-label); color: var(--muted-foreground); transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav a svg { width: 16px; height: 16px; flex: none; }
.nav a:hover { background: var(--glass-fill-hover); color: var(--foreground); }
/* selected = the kit's segment: darker lens, not a lighter tint */
.nav a.active { color: var(--foreground); background: var(--glass-lens); -webkit-backdrop-filter: blur(var(--glass-lens-blur)); backdrop-filter: blur(var(--glass-lens-blur)); box-shadow: inset 0 0 0 1px var(--glass-rim-soft); }
.nav .section { margin: 10px 12px 2px; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; }
.main { min-width: 0; }
.header {
  position: sticky; top: 0; z-index: 5; height: var(--header-h); display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 28px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(0,0,0,0.75), rgba(0,0,0,0.35));
  -webkit-backdrop-filter: blur(var(--glass-blur)); backdrop-filter: blur(var(--glass-blur));
}
.header .title { display: flex; align-items: baseline; gap: 12px; }
.header .header-mark { display: none; width: 24px; height: 24px; border-radius: 7px; align-self: center; }
.tabbar { display: none; }
.header .clock { color: var(--muted-foreground); }
.content { max-width: var(--content-max); padding: 24px 28px 64px; display: grid; gap: 20px; }

/* ---------- bento grid ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
.card { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.card .head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card .head h2 { display: flex; align-items: center; gap: 8px; }
.card .head h2 svg { width: 16px; height: 16px; color: var(--muted-foreground); }
.card .foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted-foreground); font-size: 12px; }

/* KDS language: big tabular figures, labels in mono eyebrow */
.figure { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 34px; line-height: 1; font-weight: 500; letter-spacing: -0.02em; }
.figure.small { font-size: 22px; }
.figure .unit { font-size: 14px; color: var(--muted-foreground); margin-left: 6px; font-weight: 500; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted-foreground); } .kv dd { margin: 0; font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.rows { display: grid; gap: 8px; }
.row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-control); background: rgba(255,255,255,0.035); border: 1px solid var(--border); min-height: var(--touch); }
.row .name { display: flex; align-items: center; gap: 8px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--foreground); flex: none; }
.dot.dim { opacity: 0.4; }

/* status pill: brightness + a word, no colour */
.pill { display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px; border-radius: var(--r-chip); border: 1px solid var(--glass-stroke); background: var(--glass-fill); font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.pill .led { width: 8px; height: 8px; border-radius: 50%; background: var(--status-watch); box-shadow: 0 0 0 3px rgba(255,255,255,0.06); }
.pill.ok .led { background: var(--status-ok); } .pill.ok { color: var(--status-ok); }
.pill.watch .led { background: var(--status-watch); } .pill.watch { color: var(--status-watch); }
.pill.fail { color: var(--status-fail); border-color: var(--glass-stroke-strong); background: var(--glass-fill-strong); }
.pill.fail .led { background: var(--status-fail); box-shadow: 0 0 0 3px rgba(255,255,255,0.18), 0 0 18px rgba(255,255,255,0.35); animation: hq-breathe 2.4s var(--ease) infinite; }
.chip { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: var(--r-chip); border: 1px solid var(--border); background: rgba(255,255,255,0.03); font-family: var(--font-mono); font-size: 11px; color: var(--muted-foreground); }
.chip.on { color: var(--foreground); border-color: var(--glass-stroke-strong); }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--touch); padding: 0 16px; border-radius: var(--r-chip); border: 1px solid var(--glass-stroke); background: var(--glass-fill-strong); color: var(--foreground); transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.btn:hover { background: var(--glass-fill-hover); border-color: var(--glass-stroke-strong); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }
.btn.primary:hover { background: oklch(0.92 0 0); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted-foreground); }
.btn.ghost:hover { background: var(--glass-fill); color: var(--foreground); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.input, textarea.input { width: 100%; min-height: var(--touch); padding: 10px 14px; border-radius: var(--r-control); border: 1px solid var(--input); background: rgba(255,255,255,0.04); color: var(--foreground); transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); }
.input:focus { outline: none; border-color: var(--glass-stroke-strong); background: rgba(255,255,255,0.06); }
.input::placeholder { color: oklch(0.5 0 0); }
textarea.input { resize: vertical; min-height: 72px; line-height: 1.45; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted-foreground); }

/* ---------- chat ---------- */
.chat { display: grid; grid-template-rows: 1fr auto; min-height: 420px; }
.thread { display: grid; gap: 10px; align-content: start; padding: 4px 0 12px; overflow: auto; max-height: 56vh; }
.bubble { max-width: 88%; padding: 12px 16px; border-radius: 20px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; animation: hq-msg-in var(--dur) var(--ease); }
.bubble.owner { justify-self: end; background: var(--foreground); color: var(--background); border-bottom-right-radius: 8px; }
.bubble.assistant { justify-self: start; background: var(--glass-fill); border: 1px solid var(--border); border-bottom-left-radius: 8px; }
.bubble .meta { display: flex; gap: 10px; align-items: center; margin-top: 8px; font-family: var(--font-mono); font-size: 11px; color: var(--muted-foreground); }
.bubble .meta { flex-wrap: wrap; }
.bubble .meta button { background: none; border: 1px solid var(--border); color: inherit; border-radius: var(--r-chip); padding: 2px 8px; white-space: nowrap; }
/* Classes replacing inline style attributes (CSP: style-src 'self'). */
.sub { margin: 6px 0 0; }
.nav a svg.out { margin-left: auto; opacity: 0.5; }
.header-right { display: flex; gap: 10px; align-items: center; }
.stack { display: grid; gap: 8px; }
.composer.bare { border: 0; padding: 0; }
/* sales intelligence */
.seg-switch { display: flex; gap: 6px; margin-top: 6px; }
.seg-switch .chip { cursor: pointer; }
.seg-switch .chip.on { background: var(--glass-lens); color: var(--foreground); border-color: var(--glass-stroke); }
.pbars { display: grid; gap: 10px; }
.pbar { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 10px; font-size: 12px; }
.pbar .name { color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pbar .track { height: 8px; border-radius: 4px; background: rgba(255,255,255,0.06); overflow: hidden; }
.pbar .fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, rgba(255,255,255,0.85), rgba(255,255,255,0.45)); animation: hq-bar-wide var(--dur-slow) var(--ease) both; transform-origin: left; }
@keyframes hq-bar-wide { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.row.origin .tick.on { background: var(--foreground); border-color: var(--foreground); }
.row.origin { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.row.origin > .mono { white-space: normal; text-align: right; overflow-wrap: anywhere; }
td.num, th.num { white-space: nowrap; }
/* to-do */
.task-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
select.input { appearance: none; -webkit-appearance: none; }
.row.task .name { align-items: flex-start; }
.row.task .task-text { white-space: normal; overflow-wrap: anywhere; }
.row.task.high .task-text { color: var(--foreground); }
.tick { flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%; border: 1px solid var(--glass-stroke); background: none; padding: 0; transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
.tick:hover { background: var(--glass-fill-hover); border-color: var(--glass-stroke-strong); }
.tick[disabled] { opacity: 0.4; }
.bubble .meta button:hover { color: var(--foreground); border-color: var(--glass-stroke-strong); }
.reasoning { font-family: var(--font-mono); font-size: 11px; color: var(--muted-foreground); white-space: pre-wrap; max-height: 120px; overflow: auto; margin-bottom: 6px; border-left: 2px solid var(--border); padding-left: 8px; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; padding-top: 12px; border-top: 1px solid var(--border); }
/* sources line: when the figures were generated, and any control resource that did not answer */
.sources { font-size: 11px; max-width: 46vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sources.bad { color: var(--foreground); }
/* chosen verdict on an answer */
.bubble .meta button.on { color: var(--foreground); border-color: var(--glass-stroke-strong); background: var(--glass-lens); }
.bubble .meta button[disabled] { opacity: 0.55; cursor: default; }
/* dictation: the mic breathes while listening; status line underneath the composer */
.btn.listening { color: var(--foreground); border-color: var(--glass-stroke-strong); background: var(--glass-lens); animation: hq-breathe 1.6s var(--ease) infinite; }
.mic-status { font-size: 11px; margin-top: 6px; }
/* briefing narration: the model's words, kept visually apart from the numbers */
.narration { padding: 12px 16px; border-radius: 20px; border-bottom-left-radius: 8px; background: var(--glass-fill); border: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; line-height: 1.5; animation: hq-msg-in var(--dur) var(--ease); }
.narration .meta { display: flex; gap: 10px; margin-top: 8px; font-family: var(--font-mono); font-size: 11px; color: var(--muted-foreground); }
/* minted key: message, the key once, a copy button */
.mint-result { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.mint-result code { overflow-wrap: anywhere; font-size: 12px; }
/* phone sheet backdrop (only rendered when the sheet is open) */
.backdrop { display: none; }
.thinking { display: inline-flex; align-items: center; gap: 8px; color: var(--muted-foreground); font-family: var(--font-mono); font-size: 12px; }
.thinking .mark { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--glass-stroke-strong); animation: hq-breathe 1.6s var(--ease) infinite; }
.disclosure { font-size: 12px; color: var(--muted-foreground); }

/* ---------- sign-in ---------- */
.signin { min-height: 100dvh; display: grid; place-items: center; padding: 24px; position: relative; z-index: 1; }
.signin .panel { width: min(420px, 100%); padding: 28px; border-radius: var(--r-container); display: grid; gap: 16px; animation: hq-rise var(--dur-slow) var(--ease); }
.signin .panel .brand { padding: 0; }
.signin form { display: grid; gap: 12px; }
.error { color: var(--foreground); background: var(--glass-fill-strong); border: 1px solid var(--glass-stroke-strong); border-radius: var(--r-control); padding: 10px 12px; font-size: 13px; }

/* sparkline bars (sales) */
.bars { display: grid; grid-auto-flow: column; align-items: end; gap: 6px; height: 64px; }
.bars .bar { background: linear-gradient(180deg, rgba(255,255,255,0.85), rgba(255,255,255,0.35)); border-radius: 4px 4px 2px 2px; min-height: 3px; transform-origin: bottom; animation: hq-bar-grow var(--dur-slow) var(--ease) both; }
.bars .bar.dim { opacity: 0.35; }
.legend { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 10px; color: var(--muted-foreground); }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted-foreground); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid rgba(255,255,255,0.05); font-variant-numeric: tabular-nums; }
td.num { font-family: var(--font-mono); text-align: right; }

/* skeleton */
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, rgba(255,255,255,0.05), rgba(255,255,255,0.12), rgba(255,255,255,0.05)); background-size: 200% 100%; animation: hq-shimmer 1.4s linear infinite; }

/* ---------- motion ---------- */
@keyframes hq-rise { from { opacity: 0; transform: translateY(12px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes hq-msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes hq-breathe { 0%, 100% { transform: scale(1); opacity: 0.85; } 50% { transform: scale(1.18); opacity: 1; } }
@keyframes hq-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes hq-bar-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.rise { animation: hq-rise var(--dur-slow) var(--ease) both; }
.rise:nth-child(2) { animation-delay: 40ms; } .rise:nth-child(3) { animation-delay: 80ms; } .rise:nth-child(4) { animation-delay: 120ms; }
.rise:nth-child(5) { animation-delay: 160ms; } .rise:nth-child(6) { animation-delay: 200ms; } .rise:nth-child(7) { animation-delay: 240ms; } .rise:nth-child(8) { animation-delay: 280ms; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .span-3, .span-4, .span-5 { grid-column: span 6; } .span-7, .span-8 { grid-column: span 12; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  /* the sidebar becomes a glass sheet behind the tab bar's "More" */
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: auto; max-height: 82dvh; overflow: auto; z-index: 40;
    border-right: 0; border-top: 1px solid var(--glass-stroke); border-radius: var(--r-container) var(--r-container) 0 0;
    padding: 14px 14px calc(var(--tab-h) + 36px + env(safe-area-inset-bottom));
    transform: translateY(100%); visibility: hidden;
    transition: transform var(--dur) var(--ease), visibility 0s linear var(--dur);
  }
  .sidebar.open { transform: none; visibility: visible; transition: transform var(--dur) var(--ease), visibility 0s; }
  .backdrop { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(0,0,0,0.45); }
  .sources { display: none; } .sources.bad { display: inline-block; max-width: 38vw; } /* on the phone the line shows only when a source is missing */
  .header { padding: 0 16px; } .header .header-mark { display: block; }
  .header h1 { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .header .clock { display: none; }
  .header .title { min-width: 0; align-items: center; }
  .pill { white-space: nowrap; }
  .content { padding: 16px 16px calc(var(--tab-h) + 44px + env(safe-area-inset-bottom)); }
  .grid > * { grid-column: span 12 !important; }
  .figure { font-size: 28px; }
  /* the kit's control: 84px pill, 6px inset, 72px segments at radius 42 − 6 */
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0;
    position: fixed; left: 16px; right: 16px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 50;
    height: var(--tab-h); padding: var(--glass-inset); border-radius: var(--r-chip);
  }
  .tabbar .seg {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    height: var(--tab-seg-h); border-radius: calc(var(--tab-h) / 2 - var(--glass-inset)); padding: 0; border: 0; background: none;
    font: var(--tab-label); color: var(--muted-foreground); transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  }
  .tabbar .seg svg { width: 24px; height: 24px; } /* kit: 32px for two segments; 24px keeps five legible on 390px */
  .tabbar .seg.active { color: var(--foreground); background: var(--glass-lens); -webkit-backdrop-filter: blur(var(--glass-lens-blur)); backdrop-filter: blur(var(--glass-lens-blur)); box-shadow: inset 0 0 0 1px var(--glass-rim-soft); }
}
