:root {
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f7f9;
  --card: #ffffff;
  --accent: #1e3a8a;
  --accent-2: #1d4ed8;
  --accent-soft: #e8eefc;
  --side: #0f1a33;
  --side-2: #1a2848;
  --side-ink: #d7deee;
  --side-muted: #8e9bbd;
  --side-line: #25355c;
  --side-link: #b8c7f0;
  --side-btn: #2f55c4;
  --side-btn-hover: #2848a8;
  --auth-a: #0f1a33;
  --auth-b: #1e3a8a;
  --brand-gold: #f5b942;
  --ok: #166534;      --ok-bg: #e8f6ec;
  --warn: #92400e;    --warn-bg: #fdf3dc;
  --bad: #b42318;     --bad-bg: #fdecea;
  --info: #1e3a8a;    --info-bg: #e8eefc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--accent-2); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.muted { color: var(--ink-3); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.sub { color: var(--ink-2); font-size: .93rem; margin-top: 4px; }
.boot { display: grid; place-items: center; height: 100%; color: var(--ink-3); }
.loading { padding: 28px; text-align: center; color: var(--ink-3); }
.stack { display: grid; gap: 16px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid #cfd4dc; background: #fff; color: var(--ink);
  font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 38px;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(.88); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { background: #8f1b12; }
.btn.danger-text { color: var(--bad); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .86rem; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; border-radius: 6px; padding: 6px 8px; line-height: 1; color: inherit; }
.icon-btn:hover { background: rgba(127, 127, 127, .18); }
.icon-btn.small { padding: 4px 5px; font-size: .8rem; }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent-2); cursor: pointer; text-decoration: underline; font-size: inherit; }

/* forms */
.field { display: grid; gap: 5px; margin-bottom: 14px; min-width: 0; align-content: start; }
.field label { font-weight: 600; font-size: .9rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=date], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #cfd4dc; border-radius: 8px; background: #fff; min-height: 40px;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: 0; border-color: var(--accent-2); }
.hint { color: var(--ink-3); font-size: .84rem; }
.form-error { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 9px 12px; margin-bottom: 12px; font-size: .92rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin: 12px 0 4px; }
.filters .field { margin-bottom: 0; min-width: 150px; }
.filters .grow { flex: 1 1 220px; }

/* notices, badges, toasts */
.notice { padding: 11px 14px; border-radius: 8px; margin-bottom: 12px; font-size: .93rem; background: var(--info-bg); color: var(--info); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef0f3; color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); font-size: .92rem; }
.toast.ok { background: #14532d; }
.toast.error { background: #991b1b; }

/* login / signup */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, var(--auth-a) 0%, var(--auth-b) 100%); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.auth-card h1 { margin: 18px 0 4px; }
.auth-card form { margin-top: 18px; }
.auth-switch, .auth-note { margin-top: 14px; text-align: center; color: var(--ink-2); font-size: .92rem; }
.auth-note { font-size: .84rem; color: var(--ink-3); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.05rem; letter-spacing: .01em; }
.brand-mark { color: var(--brand-gold); }
.brand.big { font-size: 1.15rem; color: var(--accent); }

/* frame */
.shell { display: grid; grid-template-columns: 290px 1fr; height: 100%; }
.sidebar { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; min-height: 0; padding: 16px 12px 12px; gap: 10px; }
.sidebar .brand { color: #fff; padding: 2px 6px 6px; }
.sidebar .btn.primary { background: var(--side-btn); border-color: var(--side-btn); }
.sidebar .btn.primary:hover { background: var(--side-btn-hover); filter: none; }
.side-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); padding: 6px 8px 0; }
.chat-list { flex: 1 1 auto; overflow-y: auto; min-height: 60px; display: grid; gap: 2px; align-content: start; }
.chat-list-empty { color: var(--side-muted); font-size: .88rem; padding: 8px; }
.chat-item { display: flex; align-items: center; border-radius: 8px; padding-right: 4px; }
.chat-item:hover, .chat-item.active { background: var(--side-2); }
.chat-item.active { box-shadow: inset 3px 0 0 var(--brand-gold); }
.chat-link { flex: 1; min-width: 0; display: grid; padding: 7px 8px; color: inherit; text-decoration: none; }
.chat-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; font-size: .92rem; }
.chat-time { font-size: .74rem; color: var(--side-muted); }
.chat-item .icon-btn { visibility: hidden; color: var(--side-link); }
.chat-item:hover .icon-btn, .chat-item:focus-within .icon-btn { visibility: visible; }
.side-foot { border-top: 1px solid var(--side-line); padding-top: 10px; display: grid; gap: 8px; }
.admin-nav { display: grid; gap: 2px; }
.nav-link { display: flex; justify-content: space-between; align-items: center; padding: 7px 8px; border-radius: 8px; color: var(--side-ink); text-decoration: none; font-size: .93rem; }
.nav-link:hover, .nav-link.active { background: var(--side-2); color: #fff; }
.count { background: var(--brand-gold); color: #1f1300; border-radius: 999px; padding: 0 8px; font-size: .76rem; font-weight: 700; }
.me { padding: 4px 8px 0; min-width: 0; }
.me-name { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-email { font-size: .8rem; color: var(--side-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-actions { display: flex; gap: 14px; padding: 0 8px 4px; font-size: .85rem; }
.me-actions .link-btn { color: var(--side-link); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: #fff; min-height: 50px; }
.page-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; font-size: 1.2rem; }
.main-content { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.scrim { display: none; }

/* chat */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.messages { max-width: 820px; margin: 0 auto; padding: 22px 20px 8px; display: grid; gap: 16px; }
.welcome { text-align: center; padding: 12vh 0 0; color: var(--ink-2); }
.welcome h2 { font-size: 1.5rem; color: var(--ink); margin-bottom: 8px; }
.msg-who { font-size: .76rem; font-weight: 700; color: var(--ink-3); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .05em; }
.msg.user { justify-self: end; max-width: 85%; }
.msg.user .msg-who { text-align: right; }
.msg.user .msg-body { background: var(--accent); color: #fff; padding: 10px 14px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .msg-body { background: var(--card); border: 1px solid var(--line); padding: 12px 16px; border-radius: 4px 14px 14px 14px; box-shadow: var(--shadow); overflow-wrap: anywhere; min-height: 44px; }
.msg.assistant.typing .msg-body:empty::after { content: "Thinking…"; color: var(--ink-3); }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body p, .msg-body ul, .msg-body ol, .msg-body blockquote, .msg-body pre, .msg-body .table-scroll { margin: 0 0 10px; }
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 { font-size: 1.02rem; margin: 14px 0 6px; }
.msg-body ul, .msg-body ol { padding-left: 22px; }
.msg-body code { background: #f1f3f5; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.msg-body pre { background: #111827; color: #e5e7eb; padding: 12px; border-radius: 8px; overflow-x: auto; }
.msg-body pre code { background: none; padding: 0; color: inherit; }
.msg-body blockquote { border-left: 3px solid #cfd4dc; padding-left: 12px; color: var(--ink-2); }
.msg-body table { border-collapse: collapse; font-size: .92rem; }
.msg-body th, .msg-body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.msg-body th { background: #f6f7f9; }
.msg-tools { margin-top: 4px; font-size: .8rem; }
.msg-tools .link-btn { color: var(--ink-3); text-decoration: none; }
.msg-tools .link-btn:hover { text-decoration: underline; }
.composer { max-width: 820px; width: 100%; margin: 0 auto; padding: 8px 20px 14px; }
.composer-box { display: flex; align-items: flex-end; gap: 8px; background: #fff; border: 1px solid #cfd4dc; border-radius: 14px; padding: 8px; box-shadow: var(--shadow); }
.composer-box:focus-within { border-color: var(--accent-2); }
.composer-box textarea { border: 0; outline: 0 !important; resize: none; padding: 7px 8px; min-height: 38px; max-height: 220px; background: transparent; }
.composer-note { font-size: .78rem; color: var(--ink-3); text-align: center; margin-top: 7px; }
.btn.stop { border-color: var(--bad); color: var(--bad); }

/* admin pages */
.page { padding: 22px 24px 40px; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head, .card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card > h2 { margin-bottom: 4px; }
.card .sub { margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; background: #fff; font-size: .92rem; }
table.data th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfc; }
table.data td { padding: 9px 10px; border-bottom: 1px solid #f0f1f3; vertical-align: top; overflow-wrap: break-word; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.actions { white-space: nowrap; }
table.data td.actions .btn { margin: 0 4px 4px 0; }
table.data td.empty, .empty { text-align: center; color: var(--ink-3); padding: 26px; }
table.data tr.group td { background: #f3f5fa; border-top: 1px solid var(--line); color: var(--ink-2); }
.page > .table-scroll, .page > div > .table-scroll { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.preview { color: var(--ink-3); font-size: .84rem; margin-top: 2px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { font-size: .8rem; color: var(--ink-3); font-weight: 600; }
.tile-value { font-size: 1.7rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile-note { font-size: .8rem; color: var(--ink-3); }

/* dialogs */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 460px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal-text { margin-bottom: 14px; color: var(--ink-2); }
.transcript { padding: 12px 0 0; max-width: none; }

/* phones and small tablets */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-100%); transition: transform .18s ease; z-index: 40; }
  .nav-open .sidebar { transform: none; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 30; }
  .menu-btn { display: inline-block; }
  .chat-item .icon-btn { visibility: visible; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .page { padding: 16px 14px 32px; }
  .topbar { padding: 8px 12px; }
  .messages { padding: 16px 12px 8px; }
  .composer { padding: 8px 12px 12px; }
  .msg.user { max-width: 94%; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* data analysis */
.mono { font-family: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace; font-size: .92em; }
.link-btn.mono { text-decoration: none; }
.link-btn.mono:hover { text-decoration: underline; }
.back-link { display: inline-block; margin-bottom: 6px; font-size: .9rem; text-decoration: none; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 16px; }
.preview-table { border: 1px solid var(--line); border-radius: 8px; max-height: 190px; }
.preview-table td, .preview-table th { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.pager .sub { margin: 0; }
.file-banner { margin: 0; }
.badge.muted { background: #eef0f3; color: var(--ink-3); }

/* charts: one series, bars from a zero baseline, quiet grid, values in text colours */
.viz-root { --series-1: #2a78d6; --grid: #e7e9ed; --axis-text: var(--ink-3); margin: 0; }
.chart figcaption { margin-bottom: 12px; }
.chart-note { color: var(--ink-3); font-size: .9rem; }
.chart-frame { display: grid; grid-template-columns: auto 1fr; gap: 8px; height: 190px; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; text-align: right; font-size: .74rem; color: var(--axis-text); font-variant-numeric: tabular-nums; min-width: 28px; transform: translateY(-.5em); height: calc(100% + 1em); }
.chart-area { position: relative; min-width: 0; }
.chart-grid { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.chart-grid i { display: block; height: 1px; background: var(--grid); }
.chart-plot { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.chart-col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; cursor: default; outline-offset: -2px; }
.chart-bar { width: calc(100% - 2px); max-width: 24px; min-height: 0; background: var(--series-1); border-radius: 4px 4px 0 0; }
.chart-plot.dense .chart-bar { border-radius: 1px 1px 0 0; width: max(1px, calc(100% - 1px)); }
.chart-col:hover .chart-bar, .chart-col:focus .chart-bar { filter: brightness(1.18); }
.chart-x { display: flex; margin: 6px 0 0 36px; font-size: .74rem; color: var(--axis-text); }
.chart-x span { flex: 1 1 0; min-width: 0; text-align: center; white-space: nowrap; overflow: visible; }
.chart-tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: #1f2937; color: #fff; padding: 6px 10px; border-radius: 6px; font-size: .84rem; white-space: nowrap; pointer-events: none; z-index: 3; }
.chart-tip-label { color: #cbd5e1; font-size: .78rem; }
.chart-table { margin-top: 10px; font-size: .9rem; }
.chart-table summary { cursor: pointer; color: var(--ink-2); }
.chart-table .table-scroll { max-height: 260px; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* printing an analysis (Print / save as PDF) */
@media print {
  html, body { height: auto; background: #fff; }
  .sidebar, .topbar, .scrim, .no-print, #toasts, .tabs { display: none !important; }
  .shell { display: block; height: auto; }
  .main, .main-content { display: block; overflow: visible; height: auto; }
  .page { padding: 0; max-width: none; }
  .card, .tile { box-shadow: none; break-inside: avoid; }
  .table-scroll { overflow: visible; }
  .chart-table { display: none; }
}

/* data files inside a chat */
.chat-files { border-bottom: 1px solid var(--line); background: #fff; padding: 8px 20px; }
.file-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; max-width: 820px; margin: 0 auto; }
.file-chips-label { font-size: .8rem; color: var(--ink-3); font-weight: 600; }
.file-chip { display: inline-flex; align-items: center; gap: 2px; background: var(--accent-soft); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: .86rem; max-width: 100%; }
.file-chip a { text-decoration: none; color: var(--accent); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.file-chip-meta { color: var(--ink-3); white-space: nowrap; }
.file-chips-note { max-width: 820px; margin: 5px auto 0; font-size: .78rem; color: var(--ink-3); }
.icon-btn.attach { font-size: 1.15rem; min-height: 38px; }
.attach-head { margin: 18px 0 8px; font-size: .95rem; }
.welcome-tip { margin-top: 10px; font-size: .9rem; }
@media print { .chat-files, .composer { display: none !important; } }

/* general report */
.sheet-picker { display: flex; flex-wrap: wrap; gap: 2px 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.sheet-picker .tab { padding: 7px 10px; font-size: .86rem; }
.file-heading { font-size: .9rem; color: var(--ink-2); display: grid; gap: 2px; }

/* branding: emblem, organisation name, colour themes chosen by the administrator */
.brand { min-width: 0; }
.brand-text { display: grid; min-width: 0; line-height: 1.2; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-sub { font-size: .74rem; font-weight: 500; color: var(--side-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-logo { width: 38px; height: 38px; object-fit: contain; flex: none; }
.brand.big { flex-direction: column; text-align: center; gap: 10px; }
.brand.big .brand-logo { width: 84px; height: 84px; }
.brand.big .brand-name { font-size: 1.2rem; white-space: normal; }
.brand.big .brand-sub { color: var(--ink-2); font-size: .9rem; white-space: normal; }
.auth-notice { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); text-align: center; font-size: .8rem; color: var(--ink-3); }
.logo-preview { display: grid; place-items: center; width: 120px; height: 120px; border: 1px dashed #cfd4dc; border-radius: 10px; background: #fafbfc; margin-bottom: 8px; text-align: center; font-size: .82rem; padding: 6px; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
:root[data-theme="blue"]     { --accent: #1447b8; --accent-2: #1d5fe0; --accent-soft: #e6eefc; --info: #1447b8; --info-bg: #e6eefc; --side: #0b2559; --side-2: #143676; --side-line: #1f4690; --side-muted: #93a9d6; --side-link: #bcd0f7; --side-btn: #2a6cf0; --side-btn-hover: #1f58cc; --auth-a: #0b2559; --auth-b: #1447b8; }
:root[data-theme="maroon"]   { --accent: #7a1f2b; --accent-2: #a12a3a; --accent-soft: #f8e9eb; --info: #7a1f2b; --info-bg: #f8e9eb; --side: #2a0f14; --side-2: #43171f; --side-line: #5a222c; --side-muted: #c7a0a7; --side-link: #f0c6cd; --side-btn: #a12a3a; --side-btn-hover: #8a2331; --auth-a: #2a0f14; --auth-b: #7a1f2b; }
:root[data-theme="green"]    { --accent: #14532d; --accent-2: #1a7a40; --accent-soft: #e6f3ea; --info: #14532d; --info-bg: #e6f3ea; --side: #0c2416; --side-2: #143a23; --side-line: #1d4d30; --side-muted: #9bbfa8; --side-link: #c3e6cf; --side-btn: #1a7a40; --side-btn-hover: #156535; --auth-a: #0c2416; --auth-b: #14532d; }
:root[data-theme="brown"]    { --accent: #5c4520; --accent-2: #7d5f2c; --accent-soft: #f4eee1; --info: #5c4520; --info-bg: #f4eee1; --side: #2b2314; --side-2: #40341e; --side-line: #56472b; --side-muted: #c2b393; --side-link: #e8dab8; --side-btn: #7d5f2c; --side-btn-hover: #694f24; --auth-a: #2b2314; --auth-b: #5c4520; }
:root[data-theme="charcoal"] { --accent: #1f2937; --accent-2: #374151; --accent-soft: #eceef1; --info: #1f2937; --info-bg: #eceef1; --side: #111418; --side-2: #1f242b; --side-line: #2c333c; --side-muted: #9aa3ae; --side-link: #cfd6de; --side-btn: #374151; --side-btn-hover: #2b3340; --auth-a: #111418; --auth-b: #374151; }

/* ---------------------------------- splash -------------------------------- */
#splash { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: linear-gradient(160deg, var(--auth-a) 0%, var(--auth-b) 100%); color: #fff; opacity: 1; transition: opacity .42s ease; }
#splash.hide { opacity: 0; pointer-events: none; }
.splash-inner { display: grid; justify-items: center; gap: 10px; padding: 24px; text-align: center; animation: splash-in .6s ease both; }
.splash-emblem { width: 132px; height: 132px; display: grid; place-items: center; margin-bottom: 6px; }
.splash-emblem img { max-width: 100%; max-height: 100%; object-fit: contain; filter: drop-shadow(0 8px 24px rgba(0, 0, 0, .35)); animation: splash-in .5s ease both; }
.splash-mark { font-size: 64px; color: var(--brand-gold); line-height: 1; }
.splash-name { font-size: 1.7rem; font-weight: 700; letter-spacing: .01em; min-height: 1.3em; }
.splash-sub { font-size: 1rem; color: rgba(255, 255, 255, .78); min-height: 1.3em; }
.splash-bar { width: 180px; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, .18); overflow: hidden; margin-top: 18px; }
.splash-bar i { display: block; width: 40%; height: 100%; border-radius: 3px; background: var(--brand-gold); animation: splash-bar 1.1s ease-in-out infinite; }
.splash-foot { margin-top: 14px; font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; color: rgba(255, 255, 255, .55); }
@keyframes splash-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes splash-bar { 0% { transform: translateX(-110%); } 100% { transform: translateX(280%); } }
@media (prefers-reduced-motion: reduce) { #splash, .splash-inner, .splash-emblem img, .splash-bar i { animation: none; transition: none; } }
@media print { #splash { display: none; } }

/* ------------------------------ login, two panels -------------------------- */
.auth { padding: 24px 16px; }
.auth-wrap { width: 100%; max-width: 940px; display: grid; grid-template-columns: 1fr 1fr; border-radius: 18px; overflow: hidden; box-shadow: 0 30px 70px rgba(0, 0, 0, .38); background: #fff; }
.auth-wrap .auth-card { max-width: none; border-radius: 0; box-shadow: none; padding: 40px 38px; align-self: center; }
.auth-wrap .auth-card h1 { margin-top: 0; }
.auth-side { background: linear-gradient(170deg, var(--side-2) 0%, var(--side) 100%); color: #fff; padding: 40px 34px; display: flex; flex-direction: column; justify-content: center; gap: 30px; }
.auth-side .brand.big { color: #fff; }
.auth-side .brand.big .brand-logo { width: 112px; height: 112px; }
.auth-side .brand.big .brand-mark { font-size: 46px; }
.auth-side .brand.big .brand-name { font-size: 1.45rem; }
.auth-side .brand.big .brand-sub { color: rgba(255, 255, 255, .75); }
.auth-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.auth-points li { display: flex; gap: 12px; align-items: flex-start; }
.auth-points strong { display: block; font-size: .95rem; }
.auth-points span { font-size: .84rem; color: rgba(255, 255, 255, .72); }
.auth-point-mark { flex: none; width: 22px; height: 22px; border-radius: 50%; background: rgba(255, 255, 255, .14); color: var(--brand-gold) !important; display: grid; place-items: center; font-size: .78rem !important; font-weight: 700; margin-top: 2px; }
@media (max-width: 760px) {
  .auth-wrap { grid-template-columns: 1fr; max-width: 440px; }
  .auth-side { padding: 26px 24px; gap: 0; }
  .auth-points { display: none; }
  .auth-side .brand.big .brand-logo { width: 76px; height: 76px; }
  .auth-wrap .auth-card { padding: 28px 24px; }
}

/* ------------------------------- recovery key ------------------------------ */
.recovery { display: grid; gap: 12px; justify-items: start; }
.recovery .notice { margin: 0; }
.recovery-key { width: 100%; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 1.02rem; font-weight: 700; letter-spacing: .04em; line-height: 1.7; padding: 14px 16px; border: 2px dashed var(--accent); border-radius: 10px; background: var(--accent-soft); color: var(--ink); overflow-wrap: anywhere; text-align: center; user-select: all; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .92rem; cursor: pointer; }
.check input { margin-top: 3px; width: 16px; height: 16px; }

/* ------------------------------- finishing touches ------------------------- */
body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
.btn { transition: background .12s ease, filter .12s ease, box-shadow .12s ease; }
.btn.primary { box-shadow: 0 1px 2px rgba(16, 24, 40, .18); }
.card, .tile { border-radius: 12px; }
.topbar { box-shadow: 0 1px 0 rgba(16, 24, 40, .03); }
.topbar .page-title { flex: 1; min-width: 0; }
.secure-pill { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); font-size: .78rem; font-weight: 600; cursor: help; white-space: nowrap; }
.me { display: flex; align-items: center; gap: 10px; }
.me-text { min-width: 0; }
.avatar { flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--side-btn); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .86rem; letter-spacing: .02em; }
.tile-value.small { font-size: 1.15rem; margin-top: 4px; }
.key-box { display: grid; gap: 6px; font-size: .93rem; }
.nav-link { transition: background .12s ease; }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: #c5cad3 transparent; }
.sidebar * { scrollbar-color: rgba(255, 255, 255, .25) transparent; }
@media (max-width: 860px) { .secure-pill { padding: 4px 8px; } }

/* ---- hardware keys and registration keys ---- */
.hw-steps { margin: 0 0 14px; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-2); font-size: .95rem; }
.hw-make { display: grid; gap: 12px; }
.hw-make .notice, .hw-make .modal-text { margin: 0; }
.hw-make-steps { display: grid; gap: 8px; }
.plain-list { margin: 4px 0 0; padding-left: 18px; display: grid; gap: 8px; color: var(--ink-2); font-size: .93rem; }
.reg-key { font-size: .9rem; letter-spacing: .02em; text-align: left; line-height: 1.6; }
.field-extra { margin-top: 4px; }
.cell-note { color: var(--ink-3); font-size: .8rem; font-weight: 400; margin-top: 2px; }
.field textarea.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .86rem; overflow-wrap: anywhere; }
.card-head h2 .badge { vertical-align: middle; margin-left: 4px; }

/* ---- layout fixes: the app is pinned to the window, and only its own areas scroll ---- */
/* The page behind the app can no longer scroll, so the menu and the top bar always stay in place. */
.shell { position: fixed; inset: 0; height: auto; overflow: hidden; }
/* On a short window the menu scrolls inside itself, so "Change password" and "Log out" can always be reached. */
.sidebar { overflow-y: auto; overscroll-behavior: contain; }
.sidebar > * { flex-shrink: 0; }
.sidebar > .chat-list { flex: 1 1 auto; min-height: 96px; }
.main-content { position: relative; overscroll-behavior: contain; }
.messages-scroll { overscroll-behavior: contain; }
.modal-body { position: relative; overscroll-behavior: contain; }
.modal { max-height: calc(100dvh - 32px); }
/* A wide table scrolls sideways inside its own box instead of pushing the whole page wider than the window. */
.page, .stack > *, .two-col > *, .card, .tiles > *, .page-head > *, .card-head > * { min-width: 0; }
.card-head > div:first-child, .page-head > div:first-child { flex: 1 1 260px; }
.cell-note { max-width: 240px; }
/* The first column (a name) keeps a readable width; on a narrow screen the table scrolls sideways instead. */
table.data td:first-child { min-width: 132px; }
/* Tabs that do not fit can be swiped sideways; a soft fade shows there is more. */
.tabs { scrollbar-width: none; -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); padding-right: 24px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; white-space: nowrap; }
@media print {
  .shell { position: static; overflow: visible; }
  .main-content, .modal-body { position: static; }
}
/* Action buttons wrap onto a second line instead of being pushed out of sight to the right. */
table.data td.actions { white-space: normal; min-width: 190px; }
.cell-note { max-width: 280px; overflow-wrap: anywhere; }

/* ---- home screen: the tools a person may use ---- */
.welcome { padding: 5vh 0 12px; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 22px auto 0; max-width: 820px; text-align: left; }
.tool-card { display: flex; gap: 12px; align-items: flex-start; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); color: inherit; text-decoration: none; min-width: 0; }
a.tool-card:hover, a.tool-card:focus-visible { border-color: var(--accent-2); }
.tool-card.off { opacity: .6; box-shadow: none; }
.tool-mark { flex: none; width: 42px; height: 42px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: .74rem; font-weight: 700; letter-spacing: .03em; }
.tool-text { display: grid; gap: 2px; min-width: 0; }
.tool-text strong { color: var(--ink); font-size: .98rem; }
.tool-text span { color: var(--ink-2); font-size: .86rem; line-height: 1.4; }
tr.group .btn.small { margin-left: 8px; }
.messages { grid-template-columns: minmax(0, 1fr); }
.welcome { min-width: 0; }
