/* HCC Insights. Every colour, size, radius and type style comes from tokens.css, which is
   generated from design/tokens.json. Layout-only values (grid, safe areas) live here. */
:root {
  --ease-ios: cubic-bezier(.32,.72,0,1);
  --ease-emph: cubic-bezier(.2,0,0,1);
  --tabbar-h: 64px;
  color-scheme: light dark;
}
[data-platform=ios] { font: -apple-system-body; }
[data-platform=android] { --font-ui: Roboto, "Google Sans Text", system-ui, sans-serif; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  background: var(--bg); color: var(--ink); font: var(--type-body);
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--brand-text); }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.view {
  max-width: 560px; margin: 0 auto; min-height: 100%;
  padding: calc(env(safe-area-inset-top) + var(--space-3)) var(--space-4) calc(env(safe-area-inset-bottom) + 170px);
  outline: none;
}
.view.enter { animation: fade 150ms ease-out; }
[data-platform=ios] .view.push { animation: ios-push 350ms var(--ease-ios); }
[data-platform=android] .view.push { animation: shared-axis 300ms var(--ease-emph); }
@keyframes fade { from { opacity: 0; } }
@keyframes ios-push { from { transform: translateX(30%); opacity: .4; } }
@keyframes shared-axis { from { transform: translateX(30px); opacity: 0; } }

/* Headers */
.large-header { display: flex; align-items: flex-start; gap: var(--space-3); margin: var(--space-6) 0 var(--space-4); }
.large-header h1 { font: var(--type-title-large); margin: 0; }
.large-header .sub { font: var(--type-callout); color: var(--ink-2); margin-top: 2px; }
.large-header > div:first-child { flex: 1; min-width: 0; }
.compact-header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: var(--space-2);
  margin: calc(-1 * (env(safe-area-inset-top) + var(--space-3))) calc(-1 * var(--space-4)) var(--space-4);
  padding: calc(env(safe-area-inset-top) + var(--space-2)) var(--space-4) var(--space-2) var(--space-2);
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.compact-header .titles { flex: 1; min-width: 0; }
.compact-header .t { font: var(--type-body-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compact-header .s { font: var(--type-caption); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
[data-platform=ios] .compact-header .titles { text-align: center; }
.spacer48 { width: var(--touch-min); flex: none; }
.icon-btn {
  min-width: var(--touch-min); min-height: var(--touch-min); display: inline-grid; place-items: center;
  border: 0; background: none; border-radius: 50%; cursor: pointer; color: var(--ink);
}
.icon-btn:active { background: var(--surface-sunken); }
.icon-btn.busy svg { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards and rows */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.briefing { padding: var(--space-4) var(--space-4) var(--space-1); margin-bottom: var(--space-3); }
.briefing .kicker { display: flex; justify-content: space-between; font: var(--type-callout); font-weight: 600; color: var(--brand-text); }
.kicker-cost { color: var(--ink-2); font-weight: 400; }
.briefing .lead { font: var(--type-headline); margin: var(--space-2) 0; }
.row {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 64px;
  padding: var(--space-3) 0; border: 0; border-top: 1px solid var(--border); background: none;
  text-align: left; text-decoration: none; color: inherit; cursor: pointer;
}
.row:active { background: var(--surface-sunken); }
.row[data-static] { cursor: default; }
.row[data-static]:active { background: none; }
.row[data-static] .detail { display: block; -webkit-line-clamp: unset; }
.row .txt { flex: 1; min-width: 0; }
.row .title { display: block; font: var(--type-body-strong); }
.row .detail { font: var(--type-callout); color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .chev { color: var(--ink-2); width: 20px; height: 20px; }
.row .end { font: var(--type-callout); color: var(--ink-2); }
.row .end.warn { color: var(--warn); }
.row.more { min-height: var(--touch-min); color: var(--brand-text); font: var(--type-body-strong); justify-content: center; }
.quiet-note { font: var(--type-callout); color: var(--ink-2); border-top: 1px solid var(--border); padding: var(--space-3) 0; }
.danger-text { color: var(--danger); }
.tile-icon { width: var(--icon-tile); height: var(--icon-tile); border-radius: var(--radius-md); display: grid; place-items: center; background: var(--brand-tint); color: var(--brand-text); flex: none; }
.tile-icon.warn { background: var(--warn-tint); color: var(--warn); }
.tile-icon.danger { background: var(--danger-tint); color: var(--danger); }
.tile-icon.muted { background: var(--surface-sunken); color: var(--ink-2); }
.tile-icon svg { width: 20px; height: 20px; }

.list-card { padding: 0 var(--space-4); margin-bottom: var(--space-3); }
.list-card > .row:first-child { border-top: 0; }
.section-label { font: var(--type-callout); font-weight: 600; color: var(--ink-2); margin: var(--space-6) var(--space-1) var(--space-2); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin-bottom: var(--space-3); }
.tile { padding: var(--space-3) var(--space-4); text-align: left; cursor: pointer; text-decoration: none; color: inherit; display: block; }
.tile:active { background: var(--surface-sunken); }
.tile .k { font: var(--type-callout); color: var(--ink-2); }
.tile .v { font: var(--type-title); font-variant-numeric: tabular-nums; margin: 6px 0 2px; }
.tile .s { font: var(--type-callout); color: var(--ink-2); }
.tile .s.good { color: var(--brand-text); }
.tile .s.warn { color: var(--warn); }
.tile.muted .v { font: var(--type-body-strong); color: var(--ink-2); }
.tile.err .v { font: var(--type-body-strong); color: var(--danger); }

/* Loading placeholders: static, no looping motion (design/motion.md) */
.skel { background: var(--surface-sunken); border-radius: 6px; height: 14px; margin: 8px 0; }
.skel[data-h=l] { height: 22px; } .skel[data-h=xl] { height: 26px; }
.skel[data-w="40"] { width: 40%; } .skel[data-w="60"] { width: 60%; } .skel[data-w="70"] { width: 70%; }

/* Credit pill (docs/handoff/05: height 34, ring 18, remaining USD) */
.credit-pill { display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch-min); padding: 0 12px 0 8px; margin: -7px 0; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface); color: var(--ink); font: var(--type-callout); font-weight: 600; font-variant-numeric: tabular-nums; text-decoration: none; flex: none; }
.credit-pill svg { width: 18px; height: 18px; }
.credit-pill .track { fill: none; stroke: var(--border); stroke-width: 2.5; }
.credit-pill .val { fill: none; stroke: var(--brand-text); stroke-width: 2.5; stroke-linecap: round; transition: stroke-dasharray 600ms ease-out; }
.credit-pill.low .val { stroke: var(--warn); }
.compact-header .credit-pill { margin: 0; }
.large-header .credit-pill { align-self: center; }

/* Chat thread */
.turn + .turn { margin-top: var(--space-6); border-top: 1px solid var(--border); padding-top: var(--space-4); }
.steps { list-style: none; margin: 0 0 var(--space-3); padding: 0; display: grid; gap: var(--space-2); }
.steps li { display: flex; align-items: center; gap: var(--space-2); font: var(--type-callout); color: var(--ink-2); }
.steps li svg { width: 16px; height: 16px; color: var(--brand-text); }
.steps li.current { color: var(--ink); }
.steps .ring { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--brand-text); flex: none; margin: 0 1px; }
.answer h2.bottom-line { font: var(--type-headline); margin: 0 0 var(--space-3); }
.answer .md-h { font: var(--type-body-strong); margin: var(--space-3) 0 var(--space-2); }
.answer p { margin: 0 0 var(--space-3); }
.answer ol { margin: 0 0 var(--space-3); padding-left: 22px; }
.answer code { font-size: 0.875em; background: var(--surface-sunken); padding: 1px 4px; border-radius: 4px; }
.search { margin-bottom: var(--space-2); }
.new-btn { background: var(--brand-fill); color: var(--on-brand-fill); }
.new-btn:active { background: var(--brand-fill-pressed); }

/* Connect ERPNext */
.connect-card { padding: var(--space-4); margin-bottom: var(--space-3); display: grid; gap: var(--space-2); justify-items: start; }
.connect-card h2 { font: var(--type-headline); margin: 0; }
.connect-card p, .err-box p { margin: 0 0 var(--space-2); color: var(--ink-2); font: var(--type-callout); }
a.btn-link { display: inline-flex; align-items: center; text-decoration: none; }

/* Answer */
.q-bubble { margin: var(--space-2) 0 var(--space-4) auto; max-width: 82%; width: fit-content; background: var(--surface-sunken); border-radius: 18px 18px 6px 18px; padding: 10px 14px; }
.answer .bottom-line { font: var(--type-headline); margin: 0 0 var(--space-3); }
.answer .status { font: var(--type-caption); color: var(--ink-2); margin-bottom: var(--space-2); display: flex; gap: 6px; align-items: center; }
.answer .status svg { width: 14px; height: 14px; color: var(--brand-text); }
.thinking { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.table-card { overflow-x: auto; padding: 0 var(--space-4); margin-bottom: var(--space-3); -webkit-overflow-scrolling: touch; }
.table-card[data-pad] { padding: var(--space-3) var(--space-4); }
table { border-collapse: collapse; width: 100%; font: var(--type-body); }
th { font: var(--type-caption); color: var(--ink-2); text-align: left; padding: var(--space-3) var(--space-2) var(--space-2) 0; white-space: nowrap; }
td { padding: var(--space-2) var(--space-2) var(--space-2) 0; border-top: 1px solid var(--border); vertical-align: middle; min-height: var(--touch-min); }
td:first-child { min-width: 9em; }
table.nohead tr:first-child td { border-top: 0; }
th:last-child, td:last-child { padding-right: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap, th.nowrap { white-space: nowrap; }
td a.cell-link { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--touch-min); color: inherit; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
td a.cell-link svg { width: 14px; height: 14px; color: var(--ink-2); }
.cell-sub { display: block; font: var(--type-caption); color: var(--ink-2); white-space: nowrap; }
.answer ul { margin: 0 0 var(--space-3); padding-left: 20px; }
.answer li { margin: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch-min); padding: 4px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); font: var(--type-caption); color: var(--ink-2); text-decoration: none; }
.chip svg { width: 14px; height: 14px; }
.next { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--touch-min); padding: 6px 16px; border-radius: var(--radius-pill); border: 0; background: var(--brand-tint); color: var(--brand-on-tint); font: var(--type-body-strong); cursor: pointer; text-decoration: none; }
.next.plain { background: none; color: var(--brand-text); }
.next svg { width: 16px; height: 16px; }
.meta { display: flex; align-items: center; gap: var(--space-2); font: var(--type-caption); color: var(--ink-2); margin-top: var(--space-2); flex-wrap: wrap; }
.meta[data-center] { justify-content: center; }
.i18 { width: 18px; height: 18px; }
.err-box { padding: var(--space-4); border-color: var(--danger); background: var(--danger-tint); margin-bottom: var(--space-3); }
.err-box strong { color: var(--danger); }
.err-box.muted { border-color: var(--border); background: var(--surface); }
.err-box.muted strong { color: var(--ink); }
.btn-link { border: 0; background: none; color: var(--brand-text); font: var(--type-body-strong); min-height: var(--touch-min); padding: 0 var(--space-2); cursor: pointer; }

/* Composer */
.composer {
  position: fixed; left: 0; right: 0; z-index: 9; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px);
  max-width: 560px; margin: 0 auto; padding: 0 var(--space-4);
}
.composer.no-tabs { bottom: calc(env(safe-area-inset-bottom) + var(--space-3)); }
.composer form {
  display: flex; align-items: flex-end; gap: 6px; min-height: 52px; padding: 4px 4px 4px 18px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-pill); box-shadow: var(--shadow-field);
}
.composer textarea { flex: 1; border: 0; background: none; resize: none; outline: none; padding: var(--space-3) 0; max-height: 7.5em; line-height: 1.4; font: var(--type-body); }
.composer textarea::placeholder { color: var(--ink-2); }
.composer form:focus-within { outline: 2px solid var(--brand-text); outline-offset: 1px; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--brand-fill); color: var(--on-brand-fill); display: grid; place-items: center; cursor: pointer; flex: none; }
.send:active { background: var(--brand-fill-pressed); }
.send:disabled { background: var(--surface-sunken); color: var(--ink-2); cursor: default; }
.bold-stroke { stroke-width: 2.2; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom); background: var(--glass); border-top: 1px solid var(--border);
  -webkit-backdrop-filter: blur(22px) saturate(170%); backdrop-filter: blur(22px) saturate(170%); box-shadow: var(--shadow-glass);
}
.tabbar a { flex: 1; max-width: 140px; min-height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink-2); text-decoration: none; font: var(--type-tab-label); }
.tabbar a[aria-current=page] { color: var(--brand-text); }
.tabbar a[aria-current=page] svg { stroke-width: 2; }

/* Sign in */
.signin { min-height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: var(--space-4); padding-top: 10vh; }
.signin .logo { width: 200px; max-width: 70%; height: auto; }
.signin .dark-logo { display: none; width: 96px; }
.signin-title { font: var(--type-title); margin: var(--space-2) 0 0; }
.signin p { color: var(--ink-2); max-width: 30ch; margin: 0; }
.btn-primary { min-height: 52px; padding: 0 22px; border-radius: var(--radius-pill); border: 0; background: var(--brand-fill); color: var(--on-brand-fill); font: var(--type-body-strong); display: inline-flex; align-items: center; gap: 10px; text-decoration: none; cursor: pointer; }
.btn-primary:active { background: var(--brand-fill-pressed); }
.btn-secondary { min-height: var(--touch-min); padding: 0 18px; border-radius: var(--radius-pill); border: 1px solid var(--border-strong); background: var(--surface); font: var(--type-body-strong); cursor: pointer; }
.field { min-height: var(--touch-min); padding: 0 14px; border-radius: var(--radius-md); border: 1px solid var(--border-strong); background: var(--surface); width: 100%; }
.no-stroke { stroke: none; }
.dev { border-top: 1px dashed var(--border); padding-top: var(--space-4); width: 100%; max-width: 320px; display: grid; gap: var(--space-2); }
.dev small { color: var(--warn); }
.notice { font: var(--type-callout); color: var(--danger); }

.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand-text); flex: none; }
.status-dot.off { background: var(--border-strong); }
.offline { position: sticky; top: 0; z-index: 20; background: var(--ink); color: var(--surface); text-align: center; padding: calc(env(safe-area-inset-top) + 6px) var(--space-3) 6px; font: var(--type-callout); }
.snack { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 76px); z-index: 30; background: var(--ink); color: var(--surface); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font: var(--type-callout); max-width: calc(100% - 32px); }

@media (prefers-color-scheme: dark) { .signin .light-logo { display: none; } .signin .dark-logo { display: block; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 150ms !important; animation-name: fade !important; animation-iteration-count: 1 !important; transition-duration: 0ms !important; }
}
