/* Mirrorline – design system. Ink + lime, solid surfaces, Instrument Serif/Sans + JetBrains Mono. No framework, no build step.
   Sections: 1 tokens · 2 base · 3 layout · 4 components · 5 motion · 6 utilities */

/* 1 ─ Tokens ─────────────────────────────────────────────────────────────────────────────── */
@font-face {
  font-family: "Instrument Sans";
  src: url("/static/fonts/InstrumentSans-Variable.woff2") format("woff2");
  font-weight: 400 700; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("/static/fonts/InstrumentSans-Variable-ext.woff2") format("woff2");
  font-weight: 400 700; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("/static/fonts/InstrumentSerif-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("/static/fonts/InstrumentSerif-Regular-ext.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("/static/fonts/InstrumentSerif-Italic.woff2") format("woff2");
  font-weight: 400; font-style: italic; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Variable.woff2") format("woff2");
  font-weight: 100 800; font-style: normal; font-display: swap;
}

/* dark is the default theme */
:root {
  color-scheme: dark;
  --font: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Instrument Serif", ui-serif, Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --bg: #0b0d12;
  --sidebar: #0e1016;
  --surface: #12151c;
  --surface-2: #171b23;
  --raised: #1c212b;
  --hover: rgba(255, 255, 255, .035);
  --line: #232835;
  --line-strong: #2f3542;
  --overlay: rgba(4, 5, 8, .72);

  --text-1: #eceef2;
  --text-2: #a3aab8;
  --text-3: #6b7385;

  --accent: #c6f432;
  --accent-hover: #d6fb63;
  --on-accent: #0b0d12;
  --accent-text: #c6f432;
  --accent-soft: rgba(198, 244, 50, .10);
  --accent-line: rgba(198, 244, 50, .35);

  --success: #22c55e; --success-soft: rgba(34, 197, 94, .12);
  --warning: #f5a524; --warning-soft: rgba(245, 165, 36, .13);
  --danger: #ef4444;  --danger-soft: rgba(239, 68, 68, .12);
  --info: #38bdf8;    --info-soft: rgba(56, 189, 248, .12);
  --neutral: #8b93a3; --neutral-soft: rgba(139, 147, 163, .12);
  --gain: #22c55e;
  --loss: #ef4444;

  --r-sm: 6px; --r-md: 8px; --r-lg: 10px; --r-xl: 12px; --r-full: 999px;
  --shadow-1: none;
  --shadow-pop: 0 0 0 1px var(--line-strong), 0 16px 40px -12px rgba(0, 0, 0, .7);

  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px;

  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in: cubic-bezier(.4, 0, 1, 1);
  --dur-1: 140ms; --dur-2: 200ms; --dur-3: 260ms;

  --sidebar-w: 248px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f6f1;
  --sidebar: #efefe8;
  --surface: #ffffff;
  --surface-2: #f9f9f5;
  --raised: #ffffff;
  --hover: rgba(20, 22, 27, .035);
  --line: #e4e4dc;
  --line-strong: #d3d3c9;
  --overlay: rgba(20, 22, 27, .38);

  --text-1: #14161b;
  --text-2: #555b66;
  --text-3: #8a8f98;

  --accent-text: #4f6b00;
  --accent-soft: rgba(124, 163, 0, .12);
  --accent-line: rgba(79, 107, 0, .35);

  --success: #15803d; --success-soft: rgba(21, 128, 61, .10);
  --warning: #b45309; --warning-soft: rgba(217, 119, 6, .12);
  --danger: #dc2626;  --danger-soft: rgba(220, 38, 38, .09);
  --info: #0369a1;    --info-soft: rgba(3, 105, 161, .09);
  --neutral: #6b7280; --neutral-soft: rgba(107, 114, 128, .11);
  --gain: #15803d;
  --loss: #dc2626;

  --shadow-1: 0 1px 2px rgba(20, 22, 27, .05);
  --shadow-pop: 0 0 0 1px var(--line), 0 16px 40px -12px rgba(20, 22, 27, .22);
}

/* 2 ─ Base ───────────────────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; font-family: var(--font); font-size: 14px; line-height: 1.5;
  color: var(--text-1); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4, h5, p, dl, dd, ul, ol, figure { margin: 0; }
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -.02em; line-height: 1.25; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--accent-text); text-decoration: none; transition: color var(--dur-1) var(--ease-out), opacity var(--dur-1); }
@media (hover: hover) and (pointer: fine) { a:hover { color: var(--text-1); } }
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
code, kbd, .mono { font-family: var(--mono); font-size: .92em; }
code { padding: .1em .38em; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line); color: var(--text-1); }
kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 5px; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text-3);
  font-size: 11px; font-family: var(--mono); line-height: 1;
}
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-4) 0; }
::selection { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.num, .mono, .table, .kpi-value, .entity-figure, .entity-stats, .ticker, .dl dd, .status-chip { font-variant-numeric: tabular-nums; }

.icon { width: 18px; height: 18px; flex: none; fill: currentColor; }
.icon-sm { width: 15px; height: 15px; }

/* small labels */
.eyebrow, .kpi-label, .table th, .entity-figure-label, .entity-stats dt, .nav-label, .palette-group, .ticker .th {
  font-size: 12px; font-weight: 500; letter-spacing: .005em; color: var(--text-3);
}
/* serif for titles and headline figures – the typographic signature of the UI */
.page-title, .kpi-value, .entity-figure, .auth-card h1, .modal-head h3, .error-code, .section-title h2, .empty b {
  font-family: var(--serif); font-weight: 400; letter-spacing: -.005em;
}

/* 3 ─ Layout ─────────────────────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }
html[data-sidebar="collapsed"] { --sidebar-w: 68px; }

.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: var(--s-2);
  padding: 16px 12px; z-index: 30; overflow: hidden; background: var(--sidebar); border-right: 1px solid var(--line);
}

/* brand */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; color: var(--text-1); white-space: nowrap; }
@media (hover: hover) and (pointer: fine) { .brand:hover { color: var(--text-1); } }
.brand-mark { width: 30px; height: 30px; flex: none; border-radius: 8px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.brand-mark svg { width: 20px; height: 20px; }
.brand-name { font-family: var(--serif); font-style: italic; font-size: 22px; line-height: 1; letter-spacing: 0; }
.signet { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.signet .node { fill: currentColor; stroke: none; }

/* navigation */
.nav { position: relative; display: flex; flex-direction: column; gap: 2px; }
.nav-label { padding: 18px 10px 6px; white-space: nowrap; }
.nav-link {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 11px; height: 36px; padding: 0 10px;
  border-radius: var(--r-md); color: var(--text-2); font-weight: 500; white-space: nowrap;
  transition: color var(--dur-2) var(--ease-out), background var(--dur-1) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) { .nav-link:hover { color: var(--text-1); background: var(--hover); } }
.nav-link .icon { width: 19px; height: 19px; color: var(--text-2); transition: color var(--dur-2) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .nav-link:hover .icon { color: var(--text-1); } }
.nav-link.active { color: var(--text-1); background: transparent; }
.nav-link.active .icon { color: var(--accent-text); }
.nav-indicator {
  position: absolute; z-index: 0; left: 0; right: 0; top: 0; height: 36px; border-radius: var(--r-md);
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); pointer-events: none; opacity: 0;
  transform: translateY(var(--y, 0)); transition: transform var(--dur-3) var(--ease-out), opacity var(--dur-2);
}
.nav-indicator::before { content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav-indicator.ready { opacity: 1; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: var(--s-3); border-top: 1px solid var(--line); }
.search-trigger {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; width: 100%;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--text-3); white-space: nowrap;
  transition: border-color var(--dur-1) var(--ease-out), color var(--dur-1);
}
@media (hover: hover) and (pointer: fine) { .search-trigger:hover { border-color: var(--line-strong); color: var(--text-2); } }
.search-trigger kbd { margin-left: auto; }
.status-chip {
  display: flex; align-items: center; gap: 9px; min-height: 34px; padding: 6px 10px; border-radius: var(--r-md);
  font-size: 12px; color: var(--text-2); white-space: nowrap; transition: background var(--dur-1);
}
@media (hover: hover) and (pointer: fine) { .status-chip:hover { color: var(--text-1); background: var(--hover); } }
.status-chip b { color: var(--text-1); font-weight: 600; }
.status-chip .chip-dot { height: auto; padding: 0; background: none; }
.status-errors { display: flex; align-items: center; gap: 2px; }
.status-errors .status-chip { flex: 1; min-width: 0; }
.status-errors .status-chip, .status-errors b { color: var(--danger); }
.status-errors .status-chip svg { width: 14px; height: 14px; flex: none; }
html[data-sidebar="collapsed"] .sidebar .status-errors .btn { display: none; }
#nav-status { min-height: 34px; }
.user-btn {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 6px; border: 0; border-radius: var(--r-md);
  background: transparent; text-align: left; white-space: nowrap; transition: background var(--dur-1) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) { .user-btn:hover { background: var(--hover); } }
.avatar {
  width: 28px; height: 28px; flex: none; border-radius: 7px; display: grid; place-items: center;
  font-family: var(--font); font-size: 11.5px; font-weight: 600; letter-spacing: 0; color: var(--on-accent); background: var(--accent);
}
.avatar.has-img { background: var(--raised); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: inherit; }
.avatar-xs { width: 20px; height: 20px; border-radius: 5px; font-size: 8.5px; }
.avatar-lg { width: 40px; height: 40px; border-radius: 10px; font-size: 15px; }
.avatar-xl { width: 72px; height: 72px; border-radius: 16px; font-size: 24px; }
.avatar-row { display: flex; align-items: center; gap: var(--s-5); flex-wrap: wrap; }
.avatar-row .card-title { margin-bottom: 4px; }
.avatar-actions { gap: 8px; }
.file-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip-path: inset(50%); }
.avatar-row label.btn:has(+ .file-hidden:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.user-meta { min-width: 0; line-height: 1.25; }
.user-meta b { display: block; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { font-size: 11px; color: var(--text-3); }
.sidebar-tools { display: flex; gap: 4px; align-items: center; }
.collapse-btn .icon { transition: transform var(--dur-3) var(--ease-out); }

/* collapsed sidebar */
html[data-sidebar="collapsed"] .sidebar :is(.brand-name, .nav-link span, .search-trigger span,
  .search-trigger kbd, .status-chip .chip-text, .user-meta) { display: none; }
html[data-sidebar="collapsed"] .sidebar :is(.nav-link, .search-trigger, .status-chip) { justify-content: center; padding: 0; }
html[data-sidebar="collapsed"] .sidebar .nav-label { height: 18px; padding: 0; font-size: 0; }
html[data-sidebar="collapsed"] .user-btn { justify-content: center; flex: none; }
html[data-sidebar="collapsed"] .brand { justify-content: center; padding-inline: 0; }
html[data-sidebar="collapsed"] .collapse-btn .icon { transform: rotate(180deg); }
html[data-sidebar="collapsed"] .sidebar-tools { flex-direction: column; }

.topbar { display: none; }
.content-wrap { min-width: 0; }
.content { width: 100%; padding: 32px 40px 72px; }
@media (min-width: 1600px) { .content { padding: 40px 56px 80px; } }

.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); }
.page-title { font-size: 38px; line-height: 1.05; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.page-sub { margin-top: 6px; color: var(--text-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.page-sub .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-3); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.crumb { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px; font-size: 13px; color: var(--text-3); font-weight: 500; }
@media (hover: hover) and (pointer: fine) { .crumb:hover { color: var(--text-1); } }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin: var(--s-8) 0 var(--s-3); }
.section-title h2 { font-size: 22px; display: flex; align-items: center; gap: 8px; }
.section-title h2 .icon { color: var(--text-3); }

.sidebar-scrim { display: none; }

@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 272px; transform: translateX(-104%);
    transition: transform var(--dur-3) var(--ease-out);
  }
  html[data-sidebar] .sidebar :is(.brand-name, .nav-link span, .search-trigger span, .search-trigger kbd, .status-chip .chip-text, .user-meta) { display: revert; }
  html[data-sidebar] .sidebar .nav-label { height: auto; padding: 18px 10px 6px; font-size: 11px; }
  html[data-sidebar] .sidebar .status-errors .btn { display: inline-flex; }
  html[data-sidebar] .sidebar :is(.nav-link, .search-trigger, .status-chip) { justify-content: flex-start; padding: 0 10px; }
  html[data-sidebar] .sidebar .status-chip { padding: 6px 10px; }
  html[data-sidebar] .sidebar .user-btn { justify-content: flex-start; flex: 1; }
  html[data-sidebar] .sidebar .brand { justify-content: flex-start; padding: 4px 6px 16px; }
  html[data-sidebar] .sidebar-tools { flex-direction: row; }
  .collapse-btn { display: none !important; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  .sidebar-scrim {
    display: block; position: fixed; inset: 0; z-index: 25; background: var(--overlay); opacity: 0; pointer-events: none;
    transition: opacity var(--dur-3) var(--ease-out);
  }
  body.nav-open .sidebar-scrim { opacity: 1; pointer-events: auto; }
  .topbar {
    display: flex; align-items: center; gap: var(--s-2); position: sticky; top: 0; z-index: 20; height: 56px; padding: 0 12px;
    background: var(--sidebar); border-bottom: 1px solid var(--line);
  }
  .topbar .brand { padding: 0; }
  .topbar .brand-mark { width: 28px; height: 28px; }
  .topbar-actions { margin-left: auto; display: flex; gap: 4px; }
  .content { padding: 20px 16px 56px; }
  .page-title { font-size: 31px; }
}

/* 4 ─ Components ─────────────────────────────────────────────────────────────────────────── */
/* card */
.card { position: relative; border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line); min-height: 52px; }
.card-title { font-family: var(--serif); font-size: 20px; font-weight: 400; line-height: 1.15; display: flex; align-items: center; gap: 10px; }
.card-title > .icon { display: none; }
.card-title .live-label, .card-title .tag, .card-title .pill { font-family: var(--font); }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }
/* hover only changes colour – no movement, so the pointer never "falls off" the edge and causes a jitter loop */
a.card, .card.interactive { color: inherit; transition: border-color var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { a.card:hover, .card.interactive:hover { border-color: var(--line-strong); background: var(--surface-2); color: inherit; } }

/* KPI strip */
.kpis {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1px; overflow: hidden;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-1);
}
@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { padding: 18px 20px 16px; background: var(--surface); min-width: 0; }
.kpi-value { font-size: 44px; line-height: 1; white-space: nowrap; }
.kpi-value small { font-family: var(--font); font-size: 15px; color: var(--text-3); margin-left: 6px; }
.kpi-label { display: block; margin-top: 8px; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi.tone-danger .kpi-value, .kpi.tone-warning .kpi-value { color: var(--tone); }
@media (max-width: 640px) { .kpi { padding: 14px 14px 12px; } .kpi-value { font-size: 34px; } }

.tone-success { --tone: var(--success); --tone-soft: var(--success-soft); }
.tone-warning { --tone: var(--warning); --tone-soft: var(--warning-soft); }
.tone-danger  { --tone: var(--danger);  --tone-soft: var(--danger-soft); }
.tone-info    { --tone: var(--info);    --tone-soft: var(--info-soft); }
.tone-neutral { --tone: var(--neutral); --tone-soft: var(--neutral-soft); }
.tone-accent  { --tone: var(--accent-text); --tone-soft: var(--accent-soft); }

/* buttons */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text-1); --btn-bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: var(--r-md); border: 1px solid var(--btn-bd); background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 500; font-size: 13.5px; white-space: nowrap; user-select: none; text-decoration: none;
  transition: background var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out), color var(--dur-1), transform var(--dur-1) var(--ease-out), opacity var(--dur-1);
}
@media (hover: hover) and (pointer: fine) { .btn:hover { --btn-bg: var(--surface-2); color: var(--btn-fg); border-color: var(--text-3); } }
.btn:active { transform: scale(.98); }
.btn .icon { width: 16px; height: 16px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-primary { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-bd: var(--accent); font-weight: 600; }
@media (hover: hover) and (pointer: fine) { .btn-primary:hover { --btn-bg: var(--accent-hover); --btn-bd: var(--accent-hover); border-color: var(--accent-hover); } }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-2); }
@media (hover: hover) and (pointer: fine) { .btn-ghost:hover { --btn-bg: var(--hover); --btn-fg: var(--text-1); border-color: transparent; } }
.btn-success { --btn-bg: var(--success); --btn-fg: #04130a; --btn-bd: var(--success); font-weight: 600; }
.btn-warning { --btn-bg: var(--warning); --btn-fg: #1a1000; --btn-bd: var(--warning); font-weight: 600; }
.btn-danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); font-weight: 600; }
[data-theme="light"] .btn-success { --btn-fg: #fff; }
[data-theme="light"] .btn-warning { --btn-fg: #fff; }
@media (hover: hover) and (pointer: fine) { :is(.btn-success, .btn-warning, .btn-danger):hover { --btn-bg: var(--btn-bd); border-color: var(--btn-bd); filter: brightness(1.08); } }
.btn-soft-danger { --btn-fg: var(--danger); --btn-bg: transparent; --btn-bd: var(--line-strong); }
@media (hover: hover) and (pointer: fine) { .btn-soft-danger:hover { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); border-color: var(--danger); } }
.btn-soft { --btn-fg: var(--text-1); --btn-bg: var(--surface-2); --btn-bd: var(--line-strong); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: var(--r-sm); gap: 6px; }
.btn-sm .icon { width: 14px; height: 14px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14.5px; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; flex-wrap: wrap; gap: var(--s-2); }
.htmx-request.btn, .btn.htmx-request { opacity: .65; pointer-events: none; }

.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* status pill & tags */
.pill {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500; white-space: nowrap; vertical-align: middle;
  color: var(--text-2);
}
.pill .dot { width: 7px; height: 7px; border-radius: 1.5px; background: var(--tone, var(--neutral)); flex: none; }
.pill.live .dot { animation: square-pulse 2.6s ease-in-out infinite; }
@keyframes square-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes ping { 0% { transform: scale(.6); opacity: .8; } 80%, 100% { transform: scale(1.8); opacity: 0; } }
.page-title .pill { font-family: var(--font); font-size: 13px; letter-spacing: 0; margin-top: 6px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 5px;
  font-size: 11.5px; font-weight: 500; color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line); white-space: nowrap; vertical-align: middle;
}
.tag-accent { color: var(--accent-text); border-color: var(--accent-line); background: var(--accent-soft); }
.tag-xs { height: 16px; padding: 0 4px; font-size: 10px; border-radius: 4px; vertical-align: 1px; }
.tag .icon { width: 12px; height: 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }

/* forms */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--s-4); }
.form-grid > * { grid-column: span 12; }
.col-3 { grid-column: span 3 !important; } .col-4 { grid-column: span 4 !important; } .col-5 { grid-column: span 5 !important; }
.col-6 { grid-column: span 6 !important; } .col-7 { grid-column: span 7 !important; } .col-8 { grid-column: span 8 !important; }
@media (max-width: 720px) { .form-grid > [class*="col-"] { grid-column: span 12 !important; } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 13px; font-weight: 500; color: var(--text-1); display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.label .opt { font-size: 12px; font-weight: 400; color: var(--text-3); }
.help { font-size: 12.5px; color: var(--text-3); line-height: 1.45; }
.help code { font-size: 11.5px; }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px; border-radius: var(--r-md); border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--text-1); outline: none;
  transition: border-color var(--dur-1) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}
[data-theme="light"] :is(.input, .select, .textarea) { background: var(--surface); }
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
@media (hover: hover) and (pointer: fine) { .input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); } }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent-text); box-shadow: 0 0 0 3px var(--accent-soft); }
.input:disabled, .select:disabled { opacity: .55; cursor: not-allowed; }
.select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a8f98' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.input-sm, .select-sm { height: 32px; font-size: 13px; border-radius: var(--r-sm); padding-left: 10px; }
.select-sm { padding-right: 30px; background-position: right 8px center; }
.input-lg { height: 44px; font-size: 15px; }
.input.mono, .textarea.mono { font-size: 13px; }
.input-otp { height: 54px; font-size: 24px; letter-spacing: .5em; text-align: center; font-family: var(--mono); padding-left: .5em; }
input[type="date"].input { padding-right: 8px; }

.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; user-select: none; }
.switch input {
  appearance: none; flex: none; width: 36px; height: 20px; margin: 0; border-radius: 99px; position: relative; cursor: pointer;
  background: var(--raised); box-shadow: inset 0 0 0 1px var(--line-strong);
  transition: background var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}
[data-theme="light"] .switch input { background: var(--line); }
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2);
  transition: transform var(--dur-2) var(--ease-out), background var(--dur-2);
}
[data-theme="light"] .switch input::after { background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked { background: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.switch input:checked::after { transform: translateX(16px); background: var(--on-accent); }
.switch-text { display: flex; flex-direction: column; gap: 2px; }
.switch-text b { font-weight: 500; }
.check { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.check input {
  appearance: none; width: 17px; height: 17px; margin: 0; flex: none; border-radius: 5px; cursor: pointer; position: relative;
  border: 1px solid var(--line-strong); background: var(--bg); transition: background var(--dur-1), border-color var(--dur-1);
}
[data-theme="light"] .check input { background: var(--surface); }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ""; position: absolute; left: 5px; top: 1.5px; width: 5px; height: 9px; border: solid var(--on-accent); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.check input[type="radio"] { border-radius: 50%; }
.check input[type="radio"]:checked::after { left: 4px; top: 4px; width: 7px; height: 7px; border: 0; border-radius: 50%; background: var(--on-accent); transform: none; }

.radio-cards { display: grid; gap: 8px; }
.radio-card {
  display: flex; gap: 12px; padding: 13px 14px; border-radius: var(--r-lg); border: 1px solid var(--line-strong); cursor: pointer;
  background: var(--surface); transition: border-color var(--dur-1) var(--ease-out), background var(--dur-1);
}
@media (hover: hover) and (pointer: fine) { .radio-card:hover { border-color: var(--text-3); } }
.radio-card:has(input:checked) { border-color: var(--accent-text); background: var(--accent-soft); }
.radio-card.danger:has(input:checked) { border-color: var(--danger); background: var(--danger-soft); }
.radio-card.danger input:checked { background: var(--danger); border-color: var(--danger); }
.radio-card.danger input[type="radio"]:checked::after { background: #fff; }
.radio-card input { margin-top: 2px; }
.radio-card b { display: block; font-weight: 600; margin-bottom: 2px; }
.radio-card span { color: var(--text-2); font-size: 13px; }

.callout {
  display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--r-lg); font-size: 13px; line-height: 1.5;
  color: var(--text-2); background: var(--surface-2); border: 1px solid var(--line); border-left: 2px solid var(--tone, var(--accent-text));
}
.callout > .icon { color: var(--tone, var(--accent-text)); margin-top: 1px; width: 16px; height: 16px; }
.callout b { color: var(--text-1); font-weight: 600; }
.notify-table .group-row td { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); background: var(--surface-2); padding-top: 10px; }
.notify-table input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; color: var(--text-2); cursor: pointer; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; margin: 0; }
.form-actions { display: flex; gap: var(--s-2); align-items: center; margin-top: var(--s-6); flex-wrap: wrap; }

/* segmented control */
.segmented { position: relative; display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--line); }
[data-theme="light"] .segmented { background: var(--surface-2); }
.segmented > a, .segmented > button {
  position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px; border: 0;
  border-radius: 6px; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: color var(--dur-2) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) { .segmented > a:hover, .segmented > button:hover { color: var(--text-1); } }
.segmented > .active { color: var(--text-1); }
.segmented-thumb {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; border-radius: 6px; background: var(--raised);
  box-shadow: inset 0 0 0 1px var(--line-strong); transform: translateX(var(--x, 0)); width: var(--w, 0);
  transition: transform var(--dur-3) var(--ease-out), width var(--dur-3) var(--ease-out);
}
.segmented:not([data-ready]) > .active { background: var(--raised); }
.segmented-sm > a, .segmented-sm > button { height: 24px; padding: 0 9px; font-size: 12px; }
.segmented .icon { width: 15px; height: 15px; }

/* tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th { height: 38px; padding: 0 14px; text-align: left; white-space: nowrap; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.table td { height: 48px; padding: 8px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--dur-1) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .table tbody tr:hover { background: var(--hover); } }
.table th:first-child, .table td:first-child { padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.table .num { text-align: right; font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.table th.num { font-family: var(--font); font-size: 12px; }
.table .nowrap, .table td.strong, .table td:first-child { white-space: nowrap; }
.table .sub { display: block; font-size: 12px; color: var(--text-3); margin-top: 1px; }
.table a.strong { font-weight: 600; color: var(--text-1); }
@media (hover: hover) and (pointer: fine) { .table a.strong:hover { color: var(--accent-text); } }
.table-sm td { height: 42px; padding-top: 6px; padding-bottom: 6px; font-size: 13px; }
.table tr.is-error td:first-child, .table tr.is-skip td:first-child, .table tr.is-pending td:first-child { position: relative; }
.table tr.is-error td:first-child::before, .table tr.is-skip td:first-child::before, .table tr.is-pending td:first-child::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px; border-radius: 0 2px 2px 0;
}
.table tr.is-error td:first-child::before { background: var(--danger); }
.table tr.is-error { background: var(--danger-soft); }
.table tr.is-skip td:first-child::before { background: var(--warning); }
.table tr.is-pending { color: var(--text-2); }
.table tr.is-pending td:first-child::before { background: var(--info); }
.table .inline-form { display: flex; gap: 6px; align-items: center; }
.table .inline-form .input { width: 92px; height: 30px; font-size: 12.5px; padding: 0 8px; border-radius: var(--r-sm); }
.action-cell { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.action-ico { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; background: var(--tone-soft, var(--surface-2)); color: var(--tone, var(--text-2)); flex: none; }
.action-ico .icon { width: 13px; height: 13px; }
.side { display: inline-flex; align-items: center; height: 19px; padding: 0 6px; border-radius: 4px; font-size: 11.5px; font-weight: 600; }
.side-buy { color: var(--gain); background: var(--success-soft); }
.side-sell { color: var(--loss); background: var(--danger-soft); }

/* definition list */
.dl { display: grid; grid-template-columns: auto 1fr; }
.dl dt, .dl dd { padding: 10px 0; border-bottom: 1px solid var(--line); }
.dl dt { color: var(--text-2); font-size: 13px; padding-right: var(--s-4); }
.dl dd { text-align: right; font-weight: 500; }
.dl dt:last-of-type, .dl dd:last-of-type { border-bottom: 0; }

/* empty state */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 44px 20px; color: var(--text-2); }
.empty-icon { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; margin-bottom: 8px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--line); }
.empty-icon .icon { width: 20px; height: 20px; }
.empty b { color: var(--text-1); font-size: 21px; }
.empty p { max-width: 420px; font-size: 13.5px; }
.empty .btn { margin-top: 12px; }
.empty-sm { padding: 28px 16px; }
.empty-sm .empty-icon { width: 36px; height: 36px; }
.empty-sm .empty-icon .icon { width: 17px; height: 17px; }

/* entity cards (accounts, sessions) */
.entity-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: var(--s-3); }
.entity { display: flex; flex-direction: column; padding: 16px; gap: 14px; min-width: 0; }
.entity-head { display: flex; align-items: flex-start; gap: 12px; }
.entity-avatar {
  width: 36px; height: 36px; flex: none; border-radius: 9px; display: grid; place-items: center;
  font-weight: 600; font-size: 12.5px; color: var(--text-1); background: var(--raised); border: 1px solid var(--line-strong);
}
.entity-avatar .icon { width: 17px; height: 17px; }
.entity-avatar.tone-success, .entity-avatar.tone-warning, .entity-avatar.tone-danger, .entity-avatar.tone-info { color: var(--tone); background: var(--tone-soft); border-color: transparent; }
.entity-title { min-width: 0; flex: 1; }
.entity-title b { display: block; font-size: 15px; font-weight: 600; letter-spacing: -.015em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-title > span { display: block; font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.entity-figure { font-size: 28px; line-height: 1; white-space: nowrap; }
.entity-figure small { font-family: var(--font); font-size: 12px; font-weight: 500; color: var(--text-3); margin-left: 5px; }
.entity-figure-label { margin-bottom: 4px; }
.entity-stats { display: flex; border-top: 1px solid var(--line); margin: 0 -16px -16px; }
.entity-stats > div { flex: 1; padding: 10px 14px; min-width: 0; }
.entity-stats > div:first-child { padding-left: 16px; }
.entity-stats > div + div { border-left: 1px solid var(--line); }
.entity-stats dt { font-size: 11.5px; }
.entity-stats dd { font-weight: 500; font-size: 12.5px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.entity-error { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--danger); background: var(--danger-soft); padding: 8px 10px; border-radius: var(--r-md); }
.entity-error .icon { width: 15px; height: 15px; margin-top: 1px; }
.entity-error span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.entity-error-full span { display: block; -webkit-line-clamp: none; }
.entity-phase { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text-2); }
.entity-phase .spinner { width: 12px; height: 12px; color: var(--accent-text); }

/* start-up steps of a terminal */
.start-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.start-steps li { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--text-3); }
.start-steps .step-mark { width: 18px; height: 18px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line-strong); }
.start-steps .step-mark .icon { width: 11px; height: 11px; }
.start-steps .step-done { color: var(--text-2); }
.start-steps .step-done .step-mark { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.start-steps .step-current { color: var(--text-1); font-weight: 500; }
.start-steps .step-current .step-mark { border-color: var(--accent); color: var(--accent-text); }
.start-steps .step-current .spinner { width: 10px; height: 10px; border-width: 1.5px; }
.start-steps .step-label { display: flex; flex-wrap: wrap; gap: 4px 8px; padding-top: 1px; }
.step-time { color: var(--text-3); font-weight: 400; font-size: 12px; }

/* health page */
.health-checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--s-4); }
.health-check.tone-danger { border-color: var(--danger); }
.health-check.tone-warning { border-color: var(--warning); }
.log-view { max-height: 65vh; }
.log-line { display: block; }
.log-warning { color: var(--warning); }
.log-error { color: var(--danger); }

/* MT5 journal on the account page */
.journal-card > summary { cursor: pointer; list-style: none; }
.journal-card > summary::-webkit-details-marker { display: none; }
.journal-card > summary .chevron { margin-left: auto; transition: transform .15s ease; color: var(--text-3); }
.journal-card[open] > summary .chevron { transform: rotate(90deg); }
.journal { margin: 0; max-height: 360px; overflow: auto; font-family: var(--mono); font-size: 11.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; }
.journal .j-time { color: var(--text-3); }
.journal .j-src { color: var(--accent-text); }
@media (prefers-reduced-motion: reduce) { .journal-card > summary .chevron { transition: none; } }
.entity-note { font-size: 12.5px; color: var(--warning); display: flex; gap: 6px; align-items: flex-start; }
.entity-note .icon { width: 14px; height: 14px; margin-top: 2px; }
.entity-actions { display: flex; align-items: center; gap: 4px; margin: auto -16px -16px; padding: 8px 10px; border-top: 1px solid var(--line); }
.flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.flow > .icon { color: var(--text-3); width: 15px; height: 15px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px 0 4px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; font-weight: 500; white-space: nowrap; max-width: 100%; color: var(--text-1); }
@media (hover: hover) and (pointer: fine) { a.chip:hover { border-color: var(--line-strong); color: var(--text-1); } }
.ap-suggest { margin-top: var(--s-2); display: grid; gap: var(--s-2); }
.ap-options { display: flex; flex-wrap: wrap; gap: 6px; }
.chip.ap-option { padding: 0 10px; font-family: var(--mono); font-size: 12px; cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .chip.ap-option:hover { border-color: var(--line-strong); } }
.chip.ap-option.selected { border-color: var(--accent); color: var(--accent-text); }
.chip.ap-option .ap-ms { margin-left: 8px; font-family: var(--font); font-size: 11px; color: var(--text-3); }
.chip.ap-option.selected .ap-ms { color: var(--accent-text); }
.chip.ap-option.ap-down { opacity: .55; }
.chip .mini-avatar { width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center; font-size: 9.5px; font-weight: 600; color: var(--text-2); background: var(--raised); }
.chip .mini-avatar.master { color: var(--on-accent); background: var(--accent); }
.chip .mini-avatar .icon { width: 11px; height: 11px; }
.chip.muted { color: var(--text-3); }
.chip .dot { width: 6px; height: 6px; border-radius: 1.5px; background: var(--tone, var(--neutral)); }

/* list view of the same entity markup: fixed columns so every row lines up; notes get their own row */
.entity-grid[data-view="list"] { grid-template-columns: 1fr; gap: var(--s-2); }
.entity-grid[data-view="list"] .entity {
  display: grid; grid-template-columns: minmax(260px, 1.25fr) minmax(300px, 1.4fr) minmax(300px, 1.5fr);
  align-items: center; column-gap: 28px; row-gap: 10px; padding: 12px 16px;
}
.entity-grid[data-view="list"] .entity-head { grid-column: 1; align-items: center; min-width: 0; }
.entity-grid[data-view="list"] .entity-main { grid-column: 2; align-items: center; min-width: 0; }
.entity-grid[data-view="list"] .entity-stats { grid-column: 3; grid-row: 1; margin: 0; border: 0; }
.entity-grid[data-view="list"] .flow { grid-column: 2 / -1; grid-row: 1; }
.entity-grid[data-view="list"] :is(.entity-error, .entity-note) { grid-column: 1 / -1; }
.entity-grid[data-view="list"] .entity-figure { font-size: 24px; }
.entity-grid[data-view="list"] .entity-figure-label { display: none; }
.entity-grid[data-view="list"] .entity-stats > div { padding: 0 16px; }
.entity-grid[data-view="list"] .entity-main :is(.spark, .spark-empty) { flex: none; width: 48%; max-width: none; height: 30px; }
.entity-grid[data-view="list"] .entity-avatar { width: 32px; height: 32px; }
@media (max-width: 1100px) {
  .entity-grid[data-view="list"] .entity { grid-template-columns: 1fr; }
  .entity-grid[data-view="list"] :is(.entity-head, .entity-main, .entity-stats, .flow) { grid-column: 1; grid-row: auto; }
  .entity-grid[data-view="list"] .entity-stats { margin: 0 -16px -12px; border-top: 1px solid var(--line); }
  .entity-grid[data-view="list"] .entity-stats > div { padding: 8px 16px; }
}

/* sparkline */
.spark { width: 128px; height: 38px; overflow: visible; flex: none; color: var(--text-3); }
.entity-main .spark, .entity-main .spark-empty { flex: 1 1 128px; min-width: 96px; max-width: 320px; width: auto; }
.spark.up { color: var(--gain); }
.spark.down { color: var(--loss); }
.spark polyline { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.spark polygon { fill: currentColor; opacity: .07; stroke: none; }
.spark-empty { width: 128px; height: 38px; min-height: 38px; display: flex; align-items: flex-end; justify-content: flex-end; padding-bottom: 2px; font-size: 11px; line-height: 1; color: var(--text-3);
  background: linear-gradient(90deg, var(--line-strong) 50%, transparent 50%) left 9px / 6px 1px repeat-x; }

/* grids */
.grid { display: grid; gap: var(--s-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-side-main { grid-template-columns: 360px minmax(0, 1fr); }
.grid-7-5 { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
.grid-5-7 { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
.grid-dash { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
@media (min-width: 1800px) { .grid-dash { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); } }
@media (max-width: 1180px) { .grid-side-main, .grid-7-5, .grid-5-7, .grid-3, .grid-dash { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s-2); }
.row { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); flex-wrap: wrap; }

/* toolbar (filters) */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 12px 14px; }
.toolbar .field { min-width: 150px; flex: 1; }
.toolbar .field .label { font-size: 12px; font-weight: 500; color: var(--text-3); }
.toolbar .check { height: 32px; font-size: 13px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-4); color: var(--text-3); font-size: 12.5px; }

/* popover menu */
.menu {
  margin: 0; padding: 6px; min-width: 220px; border-radius: var(--r-xl); border: 0; color: var(--text-1);
  background: var(--raised); box-shadow: var(--shadow-pop); position: fixed; inset: auto;
}
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-1); font-size: 13.5px; text-align: left; font-weight: 500; }
@media (hover: hover) and (pointer: fine) { .menu-item:hover { background: var(--hover); color: var(--text-1); } }
.menu-item .icon { width: 16px; height: 16px; color: var(--text-3); }
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-head { padding: 8px 10px 6px; font-size: 12px; line-height: 1.45; color: var(--text-3); max-width: 280px; overflow-wrap: anywhere; }
.theme-switch { display: flex; gap: 2px; padding: 3px; margin: 4px; border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--line); }
.theme-switch button { flex: 1; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--text-3); display: grid; place-items: center; transition: background var(--dur-2), color var(--dur-2); }
.theme-switch button .icon { width: 15px; height: 15px; }
@media (hover: hover) and (pointer: fine) { .theme-switch button:hover { color: var(--text-1); } }
.theme-switch button[aria-pressed="true"] { background: var(--surface-2); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--line-strong); }

/* dialogs */
dialog.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 0; border: 0; border-radius: 14px;
  color: var(--text-1); background: var(--raised); box-shadow: var(--shadow-pop); overflow: auto;
}
dialog.modal::backdrop { background: var(--overlay); }
.modal-head { display: flex; align-items: flex-start; gap: 14px; padding: 20px 20px 0; }
.modal-icon { width: 36px; height: 36px; flex: none; border-radius: 9px; display: grid; place-items: center; color: var(--tone, var(--accent-text)); background: var(--tone-soft, var(--accent-soft)); }
.modal-icon .icon { width: 18px; height: 18px; }
.modal-head h3 { font-size: 22px; line-height: 1.15; }
.modal-head p { color: var(--text-2); margin-top: 4px; font-size: 13.5px; }
.modal-body { padding: 16px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: 0 20px 20px; }
.modal-close { margin-left: auto; margin-top: -4px; margin-right: -6px; }

/* command palette */
dialog.palette { width: min(620px, calc(100vw - 24px)); margin-top: 12vh; margin-bottom: auto; }
.palette-search { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.palette-search .icon { color: var(--text-3); }
.palette-search input { flex: 1; height: 54px; border: 0; outline: none; background: transparent; font-size: 15px; }
.palette-search input::placeholder { color: var(--text-3); }
.palette-list { max-height: min(420px, 56dvh); overflow-y: auto; padding: 6px; scroll-padding: 6px; }
.palette-group { padding: 10px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 10px; border-radius: var(--r-md); cursor: pointer; color: var(--text-1); }
.palette-item .icon { color: var(--text-3); width: 16px; height: 16px; }
.palette-item .p-sub { margin-left: auto; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48%; }
.palette-item[aria-selected="true"] { background: var(--surface-2); box-shadow: inset 2px 0 0 var(--accent); }
.palette-item[aria-selected="true"] .icon { color: var(--accent-text); }
.palette-item mark { background: none; color: var(--accent-text); font-weight: 600; }
.palette-foot { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-3); }
.palette-foot span { display: inline-flex; align-items: center; gap: 6px; }
.palette-empty { padding: 32px; text-align: center; color: var(--text-3); }

/* toasts */
.toast-stack { position: fixed; z-index: 1000; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; padding: 12px 12px 12px 14px; border-radius: var(--r-lg);
  background: var(--raised); box-shadow: var(--shadow-pop); font-size: 13.5px; border-left: 2px solid var(--tone, var(--accent));
  animation: toast-in var(--dur-3) var(--ease-out) both;
}
.toast.toast-update { animation: fade var(--dur-2) var(--ease-out) both; }
.toast.leaving { animation: toast-out var(--dur-2) var(--ease-in) both; }
.toast-icon { flex: none; display: grid; place-items: center; color: var(--tone, var(--accent-text)); padding-top: 1px; }
.toast-icon .icon { width: 17px; height: 17px; }
.toast-body { flex: 1; min-width: 0; word-break: break-word; }
.toast-body b { display: block; font-weight: 600; margin-bottom: 1px; }
.toast-body a { font-weight: 600; }
.toast-close { margin: -4px -4px 0 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@media (max-width: 640px) { .toast-stack { right: 16px; left: 16px; bottom: 16px; width: auto; } }

/* navigation progress line (shown only for slow navigations) */
.progress { position: fixed; z-index: 2000; top: 0; left: 0; height: 2px; width: 100%; pointer-events: none; background: var(--accent); transform-origin: left; transform: scaleX(0); opacity: 0; }
.progress.run { opacity: 1; animation: progress-run 8s cubic-bezier(.1, .7, .2, 1) forwards; }
.progress.done { opacity: 0; transform: scaleX(1); transition: transform var(--dur-2) var(--ease-out), opacity 260ms 140ms; }
@keyframes progress-run { from { transform: scaleX(0); } 30% { transform: scaleX(.55); } to { transform: scaleX(.92); } }

/* live */
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 1.5px; background: var(--success); animation: square-pulse 2.6s ease-in-out infinite; }
.live-label { display: inline-flex; align-items: center; gap: 7px; margin-left: 4px; font-size: 12px; font-weight: 500; color: var(--success); }

/* skeleton (only for the slow live positions) */
.skeleton { border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-2), var(--raised), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.skeleton-rows { display: flex; flex-direction: column; gap: 14px; padding: 20px 18px; }
.skeleton-rows .skeleton { height: 12px; }
.skeleton-rows .skeleton:nth-child(2) { width: 82%; }
.skeleton-rows .skeleton:nth-child(3) { width: 64%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* auth pages */
.auth { position: relative; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; overflow: hidden; }
.auth-motif { position: absolute; left: 50%; top: 50%; width: min(1200px, 160vw); transform: translate(-50%, -50%); color: var(--line); pointer-events: none; }
.auth-motif path { stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.auth-motif .node { fill: none; stroke: currentColor; stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.auth-inner { position: relative; width: min(400px, 100%); }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 22px; color: var(--text-1); }
.auth-brand .brand-mark { width: 34px; height: 34px; border-radius: 9px; }
.auth-brand .brand-mark svg { width: 22px; height: 22px; }
.auth-brand .brand-name { font-size: 27px; }
.auth-card { padding: 28px 28px 24px; }
.auth-card h1 { font-size: 32px; line-height: 1.05; }
.auth-card .auth-sub { color: var(--text-2); font-size: 13.5px; margin: 4px 0 22px; }
.alert-inline { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-md); font-size: 13px; color: var(--tone, var(--danger)); background: var(--tone-soft, var(--danger-soft)); margin-bottom: 16px; }
.alert-inline .icon { width: 16px; height: 16px; margin-top: 1px; }
.alert-inline ul { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.error-code { font-size: 88px; line-height: 1; color: var(--accent-text); }

/* misc */
.qr { padding: 12px; border-radius: var(--r-lg); background: #fff; width: max-content; max-width: 100%; border: 1px solid var(--line); }
.qr svg { max-width: 100%; height: auto; shape-rendering: crispEdges; }
/* groups of four are visual only (inline spans + <wbr>), so copying yields the exact key */
.secret span { margin-right: .6em; }
.secret { font-family: var(--mono); font-size: 13.5px; letter-spacing: .04em; padding: 10px 12px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); user-select: all; }
.ticker { display: grid; grid-template-columns: 1fr auto auto; }
.ticker > div { padding: 10px 18px; border-bottom: 1px solid var(--line); }
.ticker > div:nth-child(3n+2), .ticker > div:nth-child(3n) { text-align: right; font-family: var(--mono); font-size: 12.5px; }
.ticker .th { background: var(--surface-2); padding-top: 9px; padding-bottom: 9px; }
.ticker > div:nth-last-child(-n+3) { border-bottom: 0; }
.side-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 3px; border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--line); }
.side-toggle label { position: relative; }
.side-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.side-toggle span { display: grid; place-items: center; height: 30px; border-radius: 6px; font-weight: 600; font-size: 13px; color: var(--text-2); cursor: pointer; transition: background var(--dur-2), color var(--dur-2); }
.side-toggle .buy input:checked + span { background: var(--success); color: #fff; }
.side-toggle .sell input:checked + span { background: var(--danger); color: #fff; }
.side-toggle input:focus-visible + span { outline: 2px solid var(--accent-text); outline-offset: 1px; }
.chart-box { position: relative; height: 340px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-3); }
.legend i { display: inline-block; width: 14px; height: 2px; border-radius: 2px; margin-right: 6px; vertical-align: middle; background: var(--accent-text); }
.legend i.dashed { background: repeating-linear-gradient(90deg, var(--text-3) 0 4px, transparent 4px 7px); }
.json { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); word-break: break-all; max-width: 520px; }
.role-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--text-3); margin-top: var(--s-4); }
.role-legend b { color: var(--text-2); }

/* 5 ─ Motion ─────────────────────────────────────────────────────────────────────────────── */
@keyframes fade { from { opacity: 0; } }

/* page navigation: only #main is swapped – one fade out, one fade in */
.content { transition: opacity var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-out); }
.content.htmx-swapping { opacity: 0; transform: translateY(-4px); transition-duration: var(--dur-1); transition-timing-function: var(--ease-in); }
.content.htmx-added { opacity: 0; transform: translateY(6px); }

/* slow partials (live positions) fade in once */
.swap-in { animation: fade var(--dur-3) var(--ease-out) both; }

/* live updates */
@keyframes row-flash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }
@keyframes row-flash-error { 0% { background: rgba(239, 68, 68, .24); } 100% { background: var(--danger-soft); } }
@keyframes row-in { from { opacity: 0; transform: translateY(-4px); } }
.table tr.is-new { animation: row-in 320ms var(--ease-out) both, row-flash 1.8s var(--ease-out) both; }
.table tr.is-new.is-error { animation: row-in 320ms var(--ease-out) both, row-flash-error 1.8s var(--ease-out) both; }
@keyframes bump { 40% { color: var(--accent-text); } }
.bump { animation: bump 700ms var(--ease-out); }

/* dialogs + popovers open/close (allow-discrete keeps them rendered while fading out) */
dialog.modal, .menu {
  opacity: 0; transform: translateY(6px) scale(.985);
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out), overlay var(--dur-2) allow-discrete, display var(--dur-2) allow-discrete;
}
dialog.modal[open], .menu:popover-open { opacity: 1; transform: none; }
@starting-style { dialog.modal[open], .menu:popover-open { opacity: 0; transform: translateY(6px) scale(.985); } }
dialog.modal::backdrop { opacity: 0; transition: opacity var(--dur-2) var(--ease-out), overlay var(--dur-2) allow-discrete, display var(--dur-2) allow-discrete; }
dialog.modal[open]::backdrop { opacity: 1; }
@starting-style { dialog.modal[open]::backdrop { opacity: 0; } }

/* drawer: details slide in from the right (a bottom sheet on phones, see below) */
@media (min-width: 641px) {
  dialog.drawer {
    margin: 0 0 0 auto; width: min(640px, 100vw); height: 100dvh; max-height: 100dvh;
    border-radius: 16px 0 0 16px; transform: translateX(32px);
  }
  dialog.drawer[open] { transform: none; }
  @starting-style { dialog.drawer[open] { opacity: 0; transform: translateX(32px); } }
}
.drawer-head { position: sticky; top: 0; z-index: 1; background: var(--raised); padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.drawer-loading { padding: 24px 20px; display: grid; gap: 12px; }
.drawer-loading span { height: 14px; border-radius: 6px; background: var(--surface-2); }
.drawer-loading span:first-child { width: 45%; height: 22px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; color: var(--text-1); overflow-wrap: anywhere; }
.kv-wide { grid-template-columns: minmax(120px, max-content) 1fr; }
.kv-table td { overflow-wrap: anywhere; }
/* master actions: summary, timeline, one card per target account, comparison */
.group-summary, .group-sum { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); }
.group-summary .dot, .group-sum .dot { width: 8px; height: 8px; border-radius: 2px; flex: none; background: var(--tone, var(--neutral)); }
.group-summary { padding: 8px 12px; border-radius: var(--r-md); background: var(--tone-soft, var(--surface-2)); color: var(--text-1); }
.tl-total { font-size: 14px; }
.tl-total b { font-size: 20px; color: var(--text-1); margin-right: 4px; }
.tl-account { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.tl-head { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.tl-stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.tl-stack .seg { min-width: 4px; flex-basis: 0; }
.tl-stack .seg-rest { flex-basis: 0; }
.seg-detect { background: var(--info); }
.seg-prep { background: var(--text-3); }
.seg-prep.tone-warning, .seg-prep.tone-danger { background: var(--tone); }
.seg-exec { background: var(--accent); }
.tl-parts { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); }
.tl-parts i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.tl-moments summary { cursor: pointer; font-size: 13px; color: var(--text-2); }
.tl-moments ol { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; font-size: 12.5px; }
.tl-moments li { display: grid; grid-template-columns: auto 64px 1fr; gap: 10px; }
.cmp-list { display: grid; gap: 8px; }
.cmp-card { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 10px 14px; display: grid; gap: 8px; }
.cmp-card.is-master { background: var(--surface-2); }
.cmp-head { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.cmp-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; }
.cmp-grid dt { font-size: 11.5px; color: var(--text-3); }
.cmp-grid dd { margin: 2px 0 0; font-size: 13px; white-space: nowrap; }
.cmp-split { margin: 0; font-size: 12px; color: var(--text-2); }
.cmp-prices { display: flex; flex-wrap: wrap; gap: 4px 24px; margin: 0; font-size: 13px; }
.cmp-prices > div { display: flex; gap: 8px; align-items: baseline; }
.cmp-prices dt { font-size: 11.5px; color: var(--text-3); }
.cmp-prices dd { margin: 0; }
@media (max-width: 480px) { .cmp-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.copy-card { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px 14px; display: grid; gap: 10px; }
.copy-card.is-error { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.copy-card.is-skip { border-color: color-mix(in srgb, var(--warning) 45%, var(--line)); }
.copy-card-head { display: flex; align-items: center; gap: 8px; }
.compare-table tr.is-master td, .table tr.is-master td { background: var(--surface-2); }
.card-foot-help { padding: 10px 20px 14px; margin: 0; }
@media (max-width: 640px) {
  .tl-moments li { grid-template-columns: 1fr auto; }
  .tl-moments li > span:first-child { grid-column: 1 / -1; }
}
.row-link { cursor: pointer; }
.row-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (hover: hover) and (pointer: fine) { .row-link:hover td { background: var(--hover); } }
/* the details column takes only the space left and cuts its single line */
.audit-details { width: 100%; max-width: 0; }
.audit-table .row { flex-wrap: nowrap; }
.audit-summary { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; animation-delay: 0ms !important; transition-duration: 1ms !important; }
  .pill.live .dot, .live-dot { animation: none; }
}

/* 6 ─ Utilities ──────────────────────────────────────────────────────────────────────────── */
.muted { color: var(--text-3); }
.soft { color: var(--text-2); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.num { font-family: var(--mono); font-size: .93em; white-space: nowrap; }
.gain { color: var(--gain) !important; }
.loss { color: var(--loss) !important; }
.warn-text { color: var(--warning); }
.danger-text { color: var(--danger); }
.success-text { color: var(--success); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); } .mt-6 { margin-top: var(--s-6); }
.w-auto { width: auto; }
.ml-auto { margin-left: auto; }
@media (max-width: 640px) { .hide-sm { display: none !important; } }

/* legal pages and consent */
.legal-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; margin-top: 18px; font-size: 13px; }
.legal-links a { color: var(--text-3); }
.auth.auth-wide { place-items: start center; }
.auth.auth-wide .auth-inner { width: min(820px, 100%); padding-block: 24px; }
.legal-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.legal-tabs a { padding: 6px 12px; border-radius: var(--r-full); border: 1px solid var(--line); color: var(--text-2); font-size: 13px; }
.legal-tabs a.active { border-color: var(--accent); color: var(--accent-text); }
.prose { font-size: 15px; line-height: 1.65; color: var(--text-1); max-width: 70ch; display: grid; gap: 12px; }
.prose h2 { font-family: var(--serif); font-weight: 400; font-size: 26px; margin-top: 18px; }
.prose h3 { font-size: 17px; margin-top: 12px; }
.prose h4 { font-size: 15px; margin-top: 8px; }
.prose ul, .prose ol { padding-left: 20px; display: grid; gap: 6px; }
.prose ul { list-style: disc; } .prose ol { list-style: decimal; }
.prose blockquote { margin: 0; padding: 12px 16px; border-left: 3px solid var(--warning); background: var(--surface-2); border-radius: var(--r-md); }
.prose a { text-decoration: underline; text-underline-offset: 2px; }
.prose .table-wrap { border: 1px solid var(--line); border-radius: var(--r-md); }
mark.placeholder { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--text-1); padding: 0 3px; border-radius: 3px; }
.legal-operator { margin-top: 24px; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-lg); font-size: 14px; color: var(--text-2); display: grid; gap: 6px; }
.legal-operator b { color: var(--text-1); }
.risk-notice { border-left-color: var(--danger) !important; --tone: var(--danger); }
.risk-notice ul { padding-left: 18px; list-style: disc; display: grid; gap: 4px; margin-top: 6px; }

/* 7 ─ Touch and phone ────────────────────────────────────────────────────────────────────── */
/* No double-tap zoom delay on controls; controls are not text to select or long-press. */
button, a, summary, label, [role="button"], .tab { touch-action: manipulation; }
:is(button, .btn, .tab, .chip, .nav-link, .menu-item, .segmented > *, .user-btn) {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
/* Pull-to-refresh is ours (see .ptr); inner scrollers keep their bounce without moving the page. */
html { overscroll-behavior-y: none; }
/* Overlays keep their scroll. Wide tables only keep the sideways swipe (no back gesture, no side bar):
   "contain" on both axes would also swallow the vertical wheel, although a table never scrolls vertically. */
.sidebar, dialog.modal, .palette-list { overscroll-behavior: contain; }
.table-wrap { overscroll-behavior-x: contain; }
.tabbar, .ptr, .sheet-handle { display: none; }

@media (pointer: coarse) {
  /* iOS zooms into anything smaller than 16px */
  input:not([type="checkbox"]):not([type="radio"]), select, textarea, .input, .select, .textarea,
  .input.mono, .textarea.mono { font-size: 16px; }
  .input, .select, .input-sm, .select-sm { min-height: 44px; }
  /* tap targets of at least 44px */
  .btn, .btn-sm { min-height: 44px; }
  .btn-sm { padding: 0 14px; font-size: 13.5px; }
  .btn-icon, .btn-icon.btn-sm { min-width: 44px; }
  .nav-link, .menu-item, .search-trigger, .palette-item { min-height: 44px; }
  .nav-indicator { height: 44px; }
  .check, .switch { min-height: 44px; align-items: center; }
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
  .segmented > * { min-height: 44px; min-width: 44px; }
  .chip.ap-option { height: 40px; padding: 0 14px; }
  .notify-table input[type="checkbox"] { width: 24px; height: 24px; }
  .cell-check { display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; cursor: pointer; }
  .theme-switch button { height: 40px; }
  /* press feedback on touch, right when the finger lands */
  .btn, .tab, .nav-link, .menu-item, a.card { transition: transform 120ms var(--ease-out), background var(--dur-1); }
  .btn:active, .menu-item:active { transform: scale(.97); }
  a.card:active, .tab:active { transform: scale(.985); }
}

@media (max-width: 960px) {
  /* nothing below 12px on small screens */
  .tag, .user-meta span, kbd, .entity-figure-label, .table th, .entity-stats dt, .json, .spark-empty,
  .notify-table .group-row td, .entity-title .mono, html[data-sidebar] .sidebar .nav-label { font-size: 12px; }
  .help { font-size: 13px; }
  .page-title { font-size: 32px; }

  /* notch, Dynamic Island and home indicator */
  .topbar {
    height: calc(56px + env(safe-area-inset-top, 0px)); padding-top: env(safe-area-inset-top, 0px);
    padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .sidebar {
    padding-top: max(16px, env(safe-area-inset-top, 0px)); padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    padding-left: max(12px, env(safe-area-inset-left, 0px)); touch-action: pan-y;
  }
  .content {
    padding: 20px max(16px, env(safe-area-inset-right, 0px)) calc(88px + env(safe-area-inset-bottom, 0px))
      max(16px, env(safe-area-inset-left, 0px));
  }

  /* bottom tab bar: Dashboard, Konten, Sessions, Historie, Mehr */
  .tabbar {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; z-index: 22; left: 0; right: 0; bottom: 0;
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: color-mix(in srgb, var(--sidebar) 92%, transparent); border-top: 1px solid var(--line);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 56px; padding: 6px 2px 4px;
    border: 0; background: none; color: var(--text-3); font: inherit; font-size: 12px; font-weight: 500; text-decoration: none;
  }
  .tab .icon { width: 22px; height: 22px; }
  .tab.active { color: var(--accent-text); }
  body.nav-open .tabbar { visibility: hidden; }
  .toast-stack { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }

  /* sticky main action in forms */
  form .form-actions {
    position: sticky; bottom: calc(56px + env(safe-area-inset-bottom, 0px)); z-index: 5; margin-inline: -16px; padding: 12px 16px;
    background: color-mix(in srgb, var(--bg) 88%, transparent); border-top: 1px solid var(--line);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  }
  .form-actions .btn-primary { flex: 1; }

  /* pull to refresh */
  .ptr {
    display: grid; place-items: center; position: fixed; z-index: 21; left: 50%; top: calc(64px + env(safe-area-inset-top, 0px));
    width: 36px; height: 36px; margin-left: -18px; border-radius: 50%; background: var(--raised); box-shadow: var(--shadow-pop);
    color: var(--accent-text); opacity: 0; transform: translateY(var(--pull, -48px)); pointer-events: none;
  }
  .ptr .spinner { animation-play-state: paused; }
  .ptr.armed .spinner, .ptr.loading .spinner { animation-play-state: running; }

  /* entity action rows wrap instead of pushing the page sideways */
  .entity-actions { flex-wrap: wrap; row-gap: 2px; }
}

/* dialogs become bottom sheets on phones: anchored at the bottom, swipe down to close */
@media (max-width: 640px) {
  dialog.modal:not(.palette) {
    width: 100%; max-width: none; margin: auto 0 0; max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px));
    border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  dialog.modal:not(.palette)[open] { transform: translateY(var(--drag, 0px)); }
  @starting-style { dialog.modal:not(.palette)[open] { transform: translateY(40%); opacity: 1; } }
  dialog.modal:not(.palette) .sheet-handle {
    display: block; width: 40px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--line-strong);
  }
  .modal-foot { flex-direction: column-reverse; align-items: stretch; }
  .modal-foot .btn { width: 100%; }
  .menu:popover-open { position: fixed; inset: auto 0 0 0; width: 100%; margin: 0; border-radius: 18px 18px 0 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }

  /* tables as cards: main facts at a glance, the rest on tap */
  .table-cards, .table-cards tbody { display: block; }
  .table-cards thead { display: none; }
  .table-cards tr {
    display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 10px; row-gap: 4px; padding: 12px 16px;
    border-bottom: 1px solid var(--line);
  }
  .table-cards td { display: block; padding: 0; border: 0; white-space: normal; text-align: left; }
  .table-cards .c-main { flex: 1 1 auto; order: 1; font-weight: 600; min-width: 0; }
  .table-cards .c-aside { order: 2; margin-left: auto; text-align: right; }
  .table-cards .c-break { display: block; order: 3; flex-basis: 100%; height: 0; }
  .table-cards .c-meta { order: 4; color: var(--text-2); }
  .table-cards .c-actions { order: 6; flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px; }
  .table-cards .c-more { order: 5; display: none; flex-basis: 100%; }
  .table-cards tr.open .c-more { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
  .table-cards .c-more[data-label]::before, .table-cards .c-meta[data-label]::before {
    content: attr(data-label); color: var(--text-3); font-weight: 400;
  }
  .table-cards .c-meta[data-label]::before { content: attr(data-label) " "; }
  .table-cards tr[data-expand] { cursor: pointer; }
  /* the status marker moves from the first cell to the card edge */
  .table-cards tr.is-error, .table-cards tr.is-skip, .table-cards tr.is-pending { box-shadow: inset 3px 0 0 var(--tone-bar, transparent); }
  .table-cards tr.is-error { --tone-bar: var(--danger); }
  .table-cards tr.is-skip { --tone-bar: var(--warning); }
  .table-cards tr.is-pending { --tone-bar: var(--info, var(--accent)); }
  .table-cards tr td:first-child::before { display: none; }
  .table-cards tr[data-expand] .c-aside::after {
    content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 8px; border: solid var(--text-3);
    border-width: 0 1.5px 1.5px 0; transform: translateY(-2px) rotate(45deg); transition: transform var(--dur-2) var(--ease-out);
  }
  .table-cards tr.open .c-aside::after { transform: translateY(1px) rotate(-135deg); }
  .table-cards .c-hide-sm { display: none; }
  .card-body.flush .table-wrap:has(.table-cards) { overflow: visible; }
}
.table .c-break { display: none; }

/* filters and actions that move into a sheet on phones */
.action-list { display: grid; gap: 6px; }
.action-list .btn { width: 100%; justify-content: flex-start; min-height: 48px; font-size: 15px; }
.sheet-only { display: none; }
@media (max-width: 640px) {
  .sheet-only { display: revert; }
  .inline-only { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar-scrim, dialog.modal, .ptr { transition: none !important; }
}
