:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #121820;
  --panel-2: #18202b;
  --line: #243040;
  --text: #e8edf3;
  --muted: #8a97a8;
  --down: #ff4d5e;
  --down-soft: rgba(255, 77, 94, 0.14);
  --up: #2bd67b;
  --gold: #ffc542;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
body > .wrap { flex: 1; }
a { color: var(--text); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; width: 100%; }

/* Ticker tape (matches the landing page) */
.tape {
  border-bottom: 1px solid var(--line); background: #080b0f; overflow: hidden; white-space: nowrap;
  font-family: var(--mono); font-size: 13px;
}
.tape-track { display: inline-block; padding: 8px 0; animation: tape-scroll 40s linear infinite; }
.tape span { margin: 0 22px; color: var(--muted); }
.tape b { color: var(--text); font-weight: 600; margin-right: 6px; }
.tape i { font-style: italic; }
.tape .tape-you b { color: var(--down); }
.tape .tape-you { background: var(--down-soft); padding: 2px 8px; border-radius: 4px; }
@keyframes tape-scroll { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .tape-track { animation: none; } }

/* Nav */
.topnav { display: flex; align-items: center; justify-content: space-between; padding: 20px 0; gap: 12px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -0.02em; text-decoration: none; }
.logo em { font-style: normal; color: var(--down); }
.navlinks { display: flex; align-items: center; gap: 16px; font-size: 14px; font-weight: 600; }
.navlinks a, .navlinks .linkbtn { text-decoration: none; white-space: nowrap; }
.nav-cta { padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; }
.nav-cta:hover { border-color: var(--down); }
.ticker-chip { font-family: var(--mono); color: var(--down) !important; background: var(--down-soft); padding: 5px 10px; border-radius: 6px; }
.inline { display: inline; margin: 0; }
.linkbtn { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }
.linkbtn:hover { color: var(--text); }

/* Layout */
main { padding: 24px 0 64px; margin: 0 auto; }
.main-narrow { max-width: 460px; }
.main-wide { max-width: 860px; }
.main-full { max-width: 1120px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 20px;
}
h1 { font-size: 28px; letter-spacing: -0.03em; margin: 0 0 6px; line-height: 1.15; }
h2 { font-size: 20px; letter-spacing: -0.02em; margin: 0 0 12px; }
.muted { color: var(--muted); margin: 0 0 20px; }
.page-title { margin-top: 4px; }

/* Forms */
label { display: block; font-size: 14px; font-weight: 600; margin: 16px 0 6px; }
.label-link { float: right; font-weight: 500; color: var(--muted); }
input[type=email], input[type=password], input[type=text] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 10px;
}
input:focus { outline: none; border-color: var(--down); box-shadow: 0 0 0 3px var(--down-soft); }
.prefix-input { display: flex; align-items: stretch; }
.prefix-input span {
  display: flex; align-items: center; padding: 0 12px;
  font-family: var(--mono); font-weight: 600; color: var(--down);
  background: var(--panel-2); border: 1px solid var(--line); border-right: 0; border-radius: 10px 0 0 10px;
}
.prefix-input input { border-radius: 0 10px 10px 0; font-family: var(--mono); text-transform: uppercase; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--muted); }
.check input { width: 16px; height: 16px; accent-color: var(--down); }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.field-error { font-size: 13px; color: var(--gold); margin: 6px 0 0; }

.btn {
  display: inline-block;
  width: 100%;
  margin-top: 22px;
  background: var(--down);
  color: #fff;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 13px 20px;
  border-radius: 10px;
  text-align: center;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn-danger { background: transparent; border: 1px solid var(--down); color: var(--down); }
.below { text-align: center; color: var(--muted); font-size: 14px; margin: 20px 0 0; }

.alert, .flash {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 18px;
}
.alert { background: rgba(255, 197, 66, 0.1); border: 1px solid rgba(255, 197, 66, 0.35); color: var(--gold); }
.flash-ok { background: rgba(43, 214, 123, 0.1); border: 1px solid rgba(43, 214, 123, 0.35); color: var(--up); }
.flash-error { background: rgba(255, 197, 66, 0.1); border: 1px solid rgba(255, 197, 66, 0.35); color: var(--gold); }
.flash-info { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }

/* Account */
.ticker-card .sym { font-family: var(--mono); font-weight: 600; font-size: 40px; color: var(--down); letter-spacing: -0.02em; }
.ticker-card .muted { margin-bottom: 16px; }
.coming-soon { background: var(--panel-2); border-radius: 10px; padding: 14px 16px; color: var(--muted); font-size: 14px; }
.coming-soon strong { display: block; color: var(--text); }
details.danger summary { cursor: pointer; font-weight: 700; color: var(--down); }
details.danger[open] summary { margin-bottom: 12px; }

footer { border-top: 1px solid var(--line); padding: 24px 0 32px; color: var(--muted); font-size: 13px; }

/* Shared app pieces ------------------------------------------------------- */
h3 { font-size: 15px; margin: 24px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
select, input[type=date], input[type=time] {
  width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 15px; padding: 11px 12px; border-radius: 10px;
}
select:focus, input[type=date]:focus, input[type=time]:focus { outline: none; border-color: var(--down); box-shadow: 0 0 0 3px var(--down-soft); }
textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  font-family: var(--mono); font-size: 13px; padding: 12px; border-radius: 10px; resize: vertical;
}
.optional { font-weight: 400; color: var(--muted); font-size: 12px; }
.muted-sm { color: var(--muted); font-size: 13px; }
.dn { color: var(--down); }
.up { color: var(--up); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.btn-small {
  display: inline-block; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none;
}
.btn-small:hover { border-color: var(--muted); }
.btn-small.btn-danger { color: var(--down); border-color: rgba(255, 77, 94, 0.5); background: transparent; }
.btn-secondary { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.btn-inline { width: auto; margin-top: 0; }

.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .muted { margin: 0; }
.head-link { margin-left: auto; font-size: 14px; color: var(--muted); }
.card-editing { border-color: rgba(255, 197, 66, 0.5); }

/* Weigh-in form */
.when { position: relative; margin-top: 14px; }
.when-now {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-size: 14px;
}
.when-icon { color: var(--muted); flex: none; }
#now-text { font-family: var(--mono); font-weight: 600; }
.when-tz { color: var(--muted); font-size: 13px; }
.override-link {
  display: inline; margin: 0 0 0 auto; font-size: 13px; font-weight: 600; color: var(--muted);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.override-link:hover { color: var(--text); }
.override-toggle { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.override-toggle:focus-visible ~ .when-now .override-link { outline: 2px solid var(--down); outline-offset: 2px; border-radius: 3px; }
.override-panel { display: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px 14px 14px; }
.override-toggle:checked ~ .when-now { display: none; }
.override-toggle:checked ~ .override-panel, .when-editing .override-panel { display: block; }
.when-editing .override-panel { background: none; border: 0; padding: 0; }
.override-fields { display: grid; grid-template-columns: 1fr 0.8fr 1.4fr; gap: 0 14px; }
.override-panel .override-link { display: inline-block; margin: 12px 0 0; }
.field-weight { max-width: 260px; }
.field-weight input { font-family: var(--mono); font-size: 22px; font-weight: 600; padding: 8px 14px; }
.form-actions { display: flex; align-items: center; gap: 18px; }
.form-actions .btn { width: auto; padding-left: 28px; padding-right: 28px; }
.cancel { margin-top: 22px; color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; }
table.history, table.preview { width: 100%; border-collapse: collapse; font-size: 14px; }
.history th, .preview th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
  font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.history td, .preview td { padding: 9px 10px; border-bottom: 1px solid rgba(36, 48, 64, 0.6); vertical-align: middle; }
.history tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.history .num, .history th.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.nowrap { white-space: nowrap; }
.muted-cell { color: var(--muted); }
.col-check { width: 32px; }
.col-check input { width: 16px; height: 16px; accent-color: var(--down); }
.col-note { color: var(--muted); max-width: 280px; overflow-wrap: anywhere; }
.actions { white-space: nowrap; text-align: right; }
.actions a, .actions .linkbtn { font-size: 13px; margin-left: 12px; }
.actions a { color: var(--muted); }
.actions a:hover { color: var(--text); }
.danger-link:hover { color: var(--down); }
.row-editing td { background: rgba(255, 197, 66, 0.07); }
.tag {
  display: inline-block; font-size: 11px; font-family: var(--mono); color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-left: 4px; vertical-align: 1px;
}
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.pager { display: flex; gap: 16px; align-items: center; font-size: 14px; color: var(--muted); }

/* Import */
.step-num {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--down-soft); color: var(--down); font-family: var(--mono); font-size: 13px; margin-right: 6px; vertical-align: 2px;
}
.dropzone {
  position: relative; display: block; text-align: center; margin: 0; padding: 34px 20px;
  border: 2px dashed var(--line); border-radius: 14px; cursor: pointer; font-weight: 500; color: var(--muted);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--down); background: var(--down-soft); }
.dropzone:focus-within { border-color: var(--down); }
.dropzone strong { color: var(--text); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dz-icon { display: block; font-size: 26px; color: var(--down); margin-bottom: 6px; }
.dz-link { color: var(--down); text-decoration: underline; }
.dz-file { display: block; margin-top: 8px; font-family: var(--mono); font-size: 13px; color: var(--text); }
.paste { margin-top: 16px; }
.paste summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.paste textarea { margin: 10px 0; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 18px; margin-bottom: 14px; }
.preview { font-family: var(--mono); font-size: 12px; }
.preview td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.preview .hl { color: var(--text); background: rgba(255, 77, 94, 0.07); }
.tag-map { color: var(--down); border-color: rgba(255, 77, 94, 0.5); text-transform: none; letter-spacing: 0; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.summary .stat, .stats-grid .stat { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.unit-warning { background: rgba(255, 197, 66, 0.1); border: 1px solid rgba(255, 197, 66, 0.35); color: var(--gold); border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.bad-rows { margin-top: 14px; }
.bad-rows summary { cursor: pointer; color: var(--gold); font-size: 14px; }
.gap { text-align: center; color: var(--muted); font-size: 12px; }

/* Dashboard */
.quote-bar { display: flex; align-items: center; gap: 14px 28px; margin: 4px 0 18px; flex-wrap: wrap; }
.quote-id .sym { font-family: var(--mono); font-weight: 600; font-size: 34px; color: var(--down); letter-spacing: -0.02em; line-height: 1.1; }
.quote-px { font-family: var(--mono); }
.quote-px .last { font-size: 30px; font-weight: 600; line-height: 1.1; }
.quote-px .chg { font-size: 14px; }
.quote-bar .btn { margin-left: auto; }
.rating { font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; padding: 4px 10px; border-radius: 5px; }
.r-strong-sell { background: var(--down); color: #fff; }
.r-sell { background: var(--down-soft); color: var(--down); }
.r-hold { background: var(--panel-2); color: var(--muted); }
.r-buy { background: rgba(43, 214, 123, 0.12); color: var(--up); }
.r-strong-buy { background: var(--up); color: #062312; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .v { font-family: var(--mono); font-size: 17px; font-weight: 600; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chart-card { padding: 16px; }
.chart-toolbar { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button {
  background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--text); }
.toolbar-right { display: flex; gap: 8px; align-items: center; }
.fs-btn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.fs-btn:hover { color: var(--text); border-color: #3a4a60; }
.fs-icon-exit { display: none; }
.is-fullscreen .fs-icon-enter { display: none; }
.is-fullscreen .fs-icon-exit { display: inline; }
.chart-card.is-fullscreen {
  position: fixed; inset: 0; z-index: 1000; margin: 0; border: 0; border-radius: 0;
  width: 100%; height: 100%; overflow: hidden; background: var(--panel);
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.chart-card:fullscreen { background: var(--panel); }
.chart-card::backdrop { background: var(--panel); }
html.chart-fs-open, html.chart-fs-open body { overflow: hidden; }
.indicator-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--line); color: var(--muted);
  font: inherit; font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px; cursor: pointer;
}
.chip[aria-pressed="true"] { color: var(--text); border-color: #3a4a60; background: var(--panel-2); }
.chip .sw { width: 10px; height: 3px; border-radius: 2px; opacity: 0.4; }
.chip[aria-pressed="true"] .sw { opacity: 1; }
.chip-pane::before { content: "\25A4"; font-size: 11px; }
.chart-wrap { position: relative; }
.chart { width: 100%; height: 420px; }
.chart-legend {
  position: absolute; top: 6px; left: 8px; z-index: 3; pointer-events: none;
  display: flex; flex-wrap: wrap; gap: 4px 12px; font-family: var(--mono); font-size: 12px; color: var(--text);
  background: rgba(18, 24, 32, 0.85); padding: 3px 6px; border-radius: 6px; max-width: calc(100% - 80px);
}
.chart-legend b { color: var(--muted); font-weight: 400; }
.chart-help { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.credit { float: right; }
.credit a { color: var(--muted); }
.guide summary { cursor: pointer; font-weight: 700; }
.guide dl { margin: 14px 0 0; }
.guide dt { font-weight: 700; margin-top: 12px; }
.guide dd { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.empty-state { text-align: center; padding: 40px 28px; }
.empty-state .muted { max-width: 520px; margin: 0 auto 22px; }
.empty-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }

@media (max-width: 700px) {
  .override-fields { grid-template-columns: 1fr 1fr; }
  .override-fields .field-tz { grid-column: 1 / -1; }
  .field-weight { max-width: none; }
  .col-note { display: none; }
  .hide-sm { display: none; }
}
@media (max-width: 480px) {
  .logo span { display: none; }
  .card { padding: 22px 16px; }
  .navlinks { gap: 12px; }
  .quote-bar .btn { margin-left: 0; width: 100%; }
  .chart { height: 360px; }
  .chart-card { padding: 12px 8px; }
  .col-time, .weekday { display: none; }
  .history .actions a, .history .actions .linkbtn { display: block; margin: 2px 0; text-align: right; }
  .history td, .history th { padding-left: 6px; padding-right: 6px; }
  .fs-label { display: none; }
  .actions a, .actions .linkbtn { margin-left: 8px; }
}
