@font-face { font-family: Atkinson; src: url('/assets/fonts/AtkinsonHyperlegible-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: Atkinson; src: url('/assets/fonts/AtkinsonHyperlegible-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }
:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #eef3f5;
  --border: #dde5e8;
  --text: #172b43;
  --muted: #53647a;
  --primary: #164e87;
  --primary-ink: #ffffff;
  --primary-soft: #e7eff9;
  --brand-red: #c80018;
  --gain: #167348;
  --loss: #b43535;
  --danger: #b3261e;
  --radius: 20px;
  --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1417;
    --surface: #172024;
    --surface-2: #1e2a2f;
    --border: #2a383e;
    --text: #e3ecee;
    --muted: #93a4a9;
    --primary: #8db4ec;
    --primary-ink: #061a38;
    --primary-soft: #1c3150;
    --brand-red: #ff6b7a;
    --gain: #4cc38a;
    --loss: #f07373;
    --danger: #f2b8b5;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 18px/1.5 Atkinson, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.5rem; font-weight: 600; }
h3 { font-size: 1.18rem; font-weight: 600; }
a { color: var(--primary); }

/* Layout */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: #fff; object-fit: contain; }
.auth-logo { display: block; width: 200px; height: auto; margin: 0 auto 4px; border-radius: 16px; background: #fff; padding: 8px; }
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tab {
  border: 0; background: none; padding: 8px 14px; border-radius: 12px; cursor: pointer; color: var(--muted); font-weight: 500;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-current="page"] { background: var(--primary-soft); color: var(--text); }
.topbar .spacer { flex: 1; }
main { width: 100%; max-width: 1200px; margin: 0 auto; padding: 24px 20px 96px; display: grid; gap: 24px; }
.bottom-nav { display: none; }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .topbar .tabs { display: none; }
  main { padding: 16px 16px 96px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav .tab { flex: 1; padding: 8px 2px; font-size: 0.78rem; border-radius: 12px; }
}

/* Surfaces */
.card { background: var(--surface); border: 1px solid transparent; border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.card > h2, .card > h3 { margin-bottom: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.hero-value { font-size: clamp(2rem, 4vw, 2.7rem); font-weight: 650; letter-spacing: -0.01em; margin: 4px 0 14px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; border-top: 1px solid var(--border); padding-top: 14px; }
.metric .label { font-size: 1rem; color: var(--muted); }
.metric .value { font-weight: 600; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; height: 72px; }
th { font-size: 1rem; font-weight: 700; color: var(--muted); }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
.sym { font-weight: 600; }

/* Forms */
form.stack, .stack { display: grid; gap: 12px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
label.field { display: grid; gap: 4px; font-size: 1rem; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); min-height: 52px;
}
textarea { min-height: 110px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px; padding: 8px 16px; border-radius: 12px; border: 1px solid transparent; cursor: pointer; font-weight: 600;
  background: var(--primary); color: var(--primary-ink);
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.tonal { background: var(--primary-soft); color: var(--text); }
.btn.outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn.danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn.small { min-height: 48px; padding: 4px 12px; font-size: 0.85rem; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 8px; font-size: 1rem; }
.icon-btn:hover { background: var(--surface-2); color: var(--danger); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.segmented button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: 0.85rem; }
.segmented button[aria-pressed="true"] { background: var(--primary-soft); font-weight: 600; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 0.78rem; background: var(--surface-2); color: var(--muted); }
.pill.ok { background: color-mix(in srgb, var(--gain) 16%, transparent); color: var(--gain); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand { flex-direction: column; justify-content: center; gap: 10px; margin-bottom: 6px; font-size: 1.7rem; }
.auth .brand-mark { width: 72px; height: 72px; border-radius: 16px; }

/* Agent */
.chat { display: grid; gap: 10px; max-height: 60vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; }
.msg.user { justify-self: end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 4px; }
.msg.assistant { justify-self: start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg .actions { display: flex; gap: 8px; margin-top: 10px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: min(92vw, 480px); box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
}
.empty { padding: 20px; text-align: center; color: var(--muted); }
.spinner { padding: 40px; text-align: center; color: var(--muted); }
details summary { cursor: pointer; font-weight: 600; }
hr { width: 100%; border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
p:empty { display: none; }
.coin-link { border: 0; padding: 0; background: transparent; color: var(--primary); cursor: pointer; font-weight: 700; text-decoration: underline; }
.coin-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.coin-dialog canvas { width: 100%; height: 220px; }
[hidden] { display: none !important; }

/* Dialog headers and actions remain visible while the content scrolls. */
body.modal-open { overflow: hidden; }
.modal[open] { display: flex; flex-direction: column; gap: 0; }
.modal { width: min(680px, calc(100vw - 32px)); max-width: none;
  max-height: calc(var(--dialog-viewport, 100dvh) - 32px); padding: 0;
  overflow: hidden; border: 1px solid var(--border); border-radius: 24px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 18px 60px rgb(13 34 60 / 22%); }
.modal::backdrop { background: rgb(16 30 48 / 52%); }
.modal-header { flex: 0 0 auto; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { min-width: 0; overflow-wrap: anywhere; }
.modal-header .btn { flex-shrink: 0; }
.modal-body { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 20px; }
.modal-body > p { margin-top: 0; }
.modal-actions { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 12px;
  justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface); }
.modal-actions .btn { white-space: normal; }
.modal input, .modal select { min-width: 0; }
.modal .hero-value { font-size: clamp(1.4rem, 5vw, 2rem); overflow-wrap: anywhere; }
.modal.coin-picker-dialog { width: min(520px, calc(100vw - 32px)); padding: 0; }
.coin-picker-dialog .modal-body { display: flex; overflow: hidden; }
.picker-content { min-height: 0; width: 100%; display: flex; flex-direction: column; gap: 12px; }
.picker-content > input { flex: 0 0 auto; }
.picker-content > p { margin: 0; }
.modal .coin-picker-results { min-height: 0; max-height: none; overflow: auto; overscroll-behavior: contain; }
.coin-option .copy { min-width: 0; overflow-wrap: anywhere; }
.dialog-error { margin: 0; color: var(--danger); padding: 12px; background: var(--surface-2); border-radius: 10px; }
.bot-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.msg { overflow-wrap: anywhere; min-width: 0; }
.msg .actions { flex-wrap: wrap; }
@media (max-width: 520px) {
  .modal, .modal.coin-picker-dialog { width: calc(100vw - 16px); max-height: calc(var(--dialog-viewport, 100dvh) - 16px); border-radius: 20px; }
  .modal-header, .modal-body, .modal-actions { padding: 16px; }
  .modal-actions { flex-direction: column; }
  .modal-actions .btn { width: 100%; }
  .modal-header .coin-name { gap: 8px; }
  .modal-header .coin-avatar { width: 34px; height: 34px; }
}
@media (min-width: 761px) and (max-width: 1050px) { .topbar { flex-wrap: wrap; } .topbar .tabs { order: 3; flex-basis: 100%; margin-left: 0; } }

/* Accessible shared product language: space, clear actions, readable data. */
button { touch-action: manipulation; }
button, a { transition: background 160ms ease, color 160ms ease, transform 160ms ease; }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible, a:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.topbar { min-height: 82px; padding-inline: max(20px, calc((100vw - 1200px)/2)); gap: 16px; }
.topbar .brand { font-size: 1.25rem; }
.topbar .tabs { margin-left: 8px; gap: 2px; }
.tab { min-height: 48px; padding: 10px 12px; color: var(--text); }
.tab[aria-current="page"] { color: var(--primary); font-weight: 700; }
.nav-icon { width: 24px; height: 24px; }
.coin-avatar { display: inline-flex; flex: 0 0 auto; width: 44px; height: 44px; padding: 5px; align-items: center; justify-content: center; background: var(--surface-2); border-radius: 14px; }
.coin-avatar img { width: 100%; height: 100%; object-fit: contain; }
.coin-avatar span { font-weight: 700; font-size: 15px; }
.coin-name { display: inline-flex; gap: 14px; align-items: center; text-align: left; }
.coin-name strong { display: block; font-weight: 700; }
.coin-link { text-decoration: none; color: var(--text); }
.coin-link:hover { color: var(--primary); }
.page-heading { margin: 0 0 6px; }
.page-heading p { margin: 8px 0 0; color: var(--muted); }
.home-grid { display: grid; grid-template-columns: 0.9fr 1.1fr; gap: 24px; align-items: start; }
.home-overview { display: grid; gap: 16px; }
.action-link { display: flex; align-items: center; text-align: left; gap: 16px; padding: 20px; width: 100%; background: var(--surface); border: 1px solid transparent; border-radius: 20px; cursor: pointer; }
.action-link strong { display: block; font-size: 1.1rem; }
.action-link span { color: var(--muted); }
.action-link .nav-icon { width: 30px; height: 30px; }
.action-link .copy { flex: 1; }
.bot-link { background: var(--primary-soft); }
.bot-image { object-fit: contain; width: 72px; height: 72px; border-radius: 22px; }
.chart-panel { display: grid; gap: 16px; min-width: 0; }
.chart-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.chart-controls button { min-height: 48px; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 8px 12px; cursor: pointer; }
.chart-controls button[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.chart-canvas { width: 100%; height: 230px; touch-action: pan-y; display: block; }
.chart-price { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-time { color: var(--muted); font-size: 1rem; }
.chart-range { padding: 0; min-height: 44px; accent-color: var(--primary); }
.chart-ends { display: flex; justify-content: space-between; gap: 12px; font-size: .9rem; color: var(--muted); }
.chart-info { font-size: .95rem; color: var(--muted); margin: 0; }
.coin-picker-button { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 56px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; cursor: pointer; text-align: left; }
.coin-picker-dialog::backdrop { background: rgb(16 30 48 / 45%); }
.coin-picker-results { max-height: 48dvh; overflow: auto; display: grid; gap: 6px; }
.coin-option { background: transparent; border: 0; width: 100%; padding: 12px; border-radius: 14px; text-align: left; cursor: pointer; display: flex; align-items: center; gap: 14px; }
.coin-option:hover { background: var(--primary-soft); }
.coin-option .copy { flex: 1; }
.allocation { display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: center; }
.allocation-ring { width: 180px; height: 180px; border-radius: 50%; position: relative; margin: auto; }
.allocation-ring::after { content: ''; position: absolute; inset: 32px; background: var(--surface); border-radius: 50%; }
.allocation-rows { display: grid; gap: 10px; }
.allocation-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.bot-welcome { display: grid; justify-items: center; text-align: center; gap: 14px; padding: 16px 0; }
.bot-welcome .bot-image { width: 160px; height: 160px; }
.bot-welcome p { margin: 0; max-width: 40ch; }
.suggestions { display: grid; gap: 10px; width: min(100%, 450px); padding-top: 12px; }
.suggestions .btn { justify-content: flex-start; text-align: left; }
.chat-shell { width: min(100%, 900px); margin: auto; }
.chat-header { display: flex; gap: 16px; align-items: center; }
.chat-header p { margin: 6px 0 0; }
.chat { min-height: 340px; max-height: 62dvh; padding: 12px 0; gap: 16px; }
.msg { padding: 18px 20px; line-height: 1.55; }
.msg.assistant { background: var(--surface-2); }
.msg.bot-thinking { border: 1px solid var(--primary); }
.msg .actions { flex-wrap: wrap; gap: 12px; }
.chat-input { display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.chat-input input { min-width: 0; }
.market-table td { padding-block: 16px; }
.market-table .coin-link { white-space: normal; }
@media (prefers-color-scheme: dark) { .nav-icon { filter: invert(.9); } }
@media (max-width: 900px) { .home-grid { grid-template-columns: 1fr; } .topbar .tabs { display: none; } .bottom-nav { display: flex; } .topbar { padding-inline: 16px; } }
@media (max-width: 760px) {
  body { font-size: 17px; } main { padding: 20px 16px 112px; gap: 20px; }
  .card { padding: 20px; } .topbar .brand { font-size: 1.1rem; } .brand-mark { width: 32px; height: 32px; }
  .topbar { gap: 6px; min-height: 76px; flex-wrap: nowrap; }
  .segmented button { padding: 10px 8px; min-height: 44px; }
  .bottom-nav .tab { display: grid; justify-items: center; gap: 4px; min-height: 64px; font-size: .9rem; color: var(--text); }
  .allocation { grid-template-columns: 1fr; }
  .market-table th:nth-child(4), .market-table td:nth-child(4) { display: none; }
  .market-table td { white-space: normal; min-width: 100px; }
  .market-table .row { gap: 6px; }
  .chat-shell { padding: 18px; }
  .chat-header .bot-image { width: 56px; height: 56px; }
  .chat-input { gap: 8px; } .chat-input .btn { padding-inline: 14px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

.bot-greeting { background: transparent; border: 0; border-radius: 24px; padding: 0; cursor: pointer; }

@media (min-width: 901px) { .topbar > .icon-btn { display: none; } }
@media (max-width: 760px) {
  .market-table, .market-table tbody { display: block; width: 100%; }
  .market-table thead { display: none; }
  .market-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; padding: 18px 0; border-bottom: 1px solid var(--border); }
  .market-table td { padding: 0; border: 0; height: auto; min-width: 0; }
  .market-table td:first-child { grid-row: 1 / 3; }
  .market-table td:nth-child(2) { grid-column: 2; grid-row: 1; font-weight: 700; }
  .market-table td:nth-child(3) { grid-column: 2; grid-row: 2; }
  .market-table td:nth-child(5) { grid-column: 1 / 3; margin-top: 12px; }
  .market-table td:nth-child(5) .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .market-table .coin-avatar { width: 36px; height: 36px; border-radius: 12px; }
  .market-table .coin-name { gap: 10px; }
  .coin-dialog canvas { height: 230px; }
}

@media (max-width: 900px) {
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav .tab { flex: 1; display: grid; justify-items: center; gap: 4px; min-height: 64px; padding: 8px 2px; font-size: .9rem; color: var(--text); }
}
@media (max-width: 760px) {
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; }
  .topbar .brand { grid-column: 1; grid-row: 1; }
  .topbar .spacer { display: none; }
  .topbar > .segmented { grid-row: 2; grid-column: 1 / -1; display: flex; }
  .topbar > .segmented button { flex: 1; }
  .topbar > .icon-btn:nth-last-child(2) { grid-column: 2; grid-row: 1; }
  .topbar > .icon-btn:last-child { grid-column: 3; grid-row: 1; }
  .coin-name strong, .coin-name .small { overflow-wrap: anywhere; }
}
