:root {
  --bg: #0b1322; --bg2: #0f1a2e; --surface: #131f36; --line: #22304b; --line2: #2b3b5c;
  --ink: #e9eef7; --muted: #8796b0; --faint: #5d6c88;
  --accent: #f2a93b; --accent-ink: #1b1204; --cyan: #3cc8f0;
  --pos: #3dd68c; --neg: #f2647a; --pos-bg: rgba(61, 214, 140, .13); --neg-bg: rgba(242, 100, 122, .13);
  --r-s: 10px; --r-m: 16px;
  --tabs-h: 64px;
  --font: "SF Pro Text", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: "SF Pro Display", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5f8; --bg2: #e9edf3; --surface: #ffffff; --line: #e1e6ee; --line2: #cfd7e3;
    --ink: #0f1a2c; --muted: #5b6880; --faint: #8a96aa;
    --accent: #c9790f; --accent-ink: #ffffff; --cyan: #1689b3;
    --pos: #13915a; --neg: #d23a52; --pos-bg: rgba(19, 145, 90, .1); --neg-bg: rgba(210, 58, 82, .1);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
    --bg: #f3f5f8; --bg2: #e9edf3; --surface: #ffffff; --line: #e1e6ee; --line2: #cfd7e3;
    --ink: #0f1a2c; --muted: #5b6880; --faint: #8a96aa;
    --accent: #c9790f; --accent-ink: #ffffff; --cyan: #1689b3;
    --pos: #13915a; --neg: #d23a52; --pos-bg: rgba(19, 145, 90, .1); --neg-bg: rgba(210, 58, 82, .1);
    color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.pos { color: var(--pos); } .neg { color: var(--neg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

#view { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.note { color: var(--muted); font-size: 13px; margin: 8px 0; }
.dim { opacity: .45; transition: opacity .2s; }

/* intestazione */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(env(safe-area-inset-top) + 14px) 0 10px; position: sticky; top: 0; z-index: 5; background: var(--bg); }
.top h1 { font-size: 22px; display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-r { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.top.back { justify-content: flex-start; }
.top.back h1 { font-size: 18px; flex: 1; }
.back-btn { font-size: 30px; line-height: 1; padding: 0 10px 4px 0; color: var(--accent); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.live-dot.on { background: var(--pos); box-shadow: 0 0 0 4px var(--pos-bg); }
.pf-pick select, .sort select, .field select {
  appearance: none; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238796b0' fill='none' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 28px 6px 12px; font-size: 13px; max-width: 46vw;
}
.sort select { border-color: transparent; background-color: transparent; color: var(--muted); }

/* hero */
.hero { padding: 6px 0 4px; }
.hero-label { color: var(--muted); font-size: 13px; min-height: 19px; }
.hero-value { font: 680 38px/1.1 var(--font-num); letter-spacing: -.025em; margin: 2px 0 8px; word-break: break-all; transition: color .4s; }
.hero-sub { display: flex; align-items: center; gap: 8px; font-size: 13px; min-height: 24px; flex-wrap: wrap; }
.pill { padding: 3px 9px; border-radius: 999px; font-weight: 600; font-size: 13px; background: var(--line); }
.pill.pos { background: var(--pos-bg); } .pill.neg { background: var(--neg-bg); }

/* grafici */
.chart-box { margin: 8px -16px 0; min-height: 140px; position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.card .chart-box { margin: 8px -14px 0; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { stroke: var(--bg); stroke-width: 2; }
.chart .zero { stroke: var(--line2); stroke-width: 1; }
.chart-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 56px 16px; }
.spark { flex-shrink: 0; }
.spark.up polyline { stroke: var(--pos); } .spark.down polyline { stroke: var(--neg); }
.bars .axis { fill: var(--muted); font-size: 10px; }
.donut-wrap { display: flex; align-items: center; gap: 16px; margin-top: 12px; }
.donut { flex-shrink: 0; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.legend .lk { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .lv { font-weight: 600; }
.legend.inline { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; }
.legend.inline li { padding: 0; }
.legend.inline .lk { flex: none; }
.sw { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* controlli a segmenti */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--bg2); border-radius: 12px; margin: 10px 0; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 6px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 0 var(--line2); }

/* indicatori */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-radius: var(--r-m); overflow: hidden; margin: 6px 0 18px; }
.kpis div { background: var(--surface); padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; }
.kpis span { font-size: 12px; color: var(--muted); }
.kpis b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpis small { font-size: 12px; }

/* liste */
.list-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 2px; }
.list-head h2, .sub-h { font-size: 17px; }
.sub-h { margin: 22px 0 6px; }
.mini-h { font-size: 13px; color: var(--muted); font-weight: 600; margin: 12px 0 0; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li { position: relative; border-bottom: 1px solid var(--line); }
.rows > li:last-child { border-bottom: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; width: 100%; background: none; border: 0; text-align: left; cursor: pointer; min-height: 60px; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main b, .row-end b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main small, .row-end small { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; text-align: right; flex-shrink: 0; max-width: 46%; }
.row-end small .pos, .row-end small.pos { color: var(--pos); } .row-end small .neg, .row-end small.neg { color: var(--neg); }
.logo { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; background: var(--bg2); object-fit: cover; }
.logo.sm { width: 24px; height: 24px; }
.logo.ph { display: inline-grid; place-items: center; font-size: 10px; font-weight: 700; color: var(--muted); }
.rank { width: 22px; font-size: 11px; color: var(--faint); text-align: right; flex-shrink: 0; }
.market .row { padding-right: 30px; gap: 9px; }
.market .row-end { min-width: 0; max-width: 40%; }
.market .logo { width: 30px; height: 30px; }
.star { position: absolute; right: -6px; top: 50%; transform: translateY(-50%); width: 40px; height: 44px; border: 0; background: none; color: var(--faint); font-size: 17px; cursor: pointer; }
.star[aria-pressed="true"] { color: var(--accent); }
.empty-row { color: var(--muted); padding: 18px 0; font-size: 14px; }
.tx-ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; background: var(--bg2); }
.tx-ico.buy, .tx-ico.transfer_in { color: var(--pos); } .tx-ico.sell, .tx-ico.transfer_out { color: var(--neg); }
.closed { margin: 16px 0; color: var(--muted); }
.closed summary { cursor: pointer; font-size: 14px; padding: 6px 0; }
.rows.plain .row { min-height: 48px; }

/* prezzi che cambiano */
@keyframes up { from { color: var(--pos); background: var(--pos-bg); } to { background: transparent; } }
@keyframes down { from { color: var(--neg); background: var(--neg-bg); } to { background: transparent; } }
.flash-up { animation: up 1.1s ease-out; border-radius: 4px; }
.flash-down { animation: down 1.1s ease-out; border-radius: 4px; }
.tick { animation: up 1.1s ease-out; }
@media (prefers-reduced-motion: reduce) { .flash-up, .flash-down, .tick { animation: none; } }

/* schede */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 14px; margin: 14px 0; overflow: hidden; }
.card h2 { font-size: 16px; margin-bottom: 8px; }
.grid2, .metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.grid2 div, .metric { display: flex; flex-direction: column; min-width: 0; }
.grid2 > div > span, .metric > span { font-size: 12px; color: var(--muted); }
.grid2 b, .metric b { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.grid2 small, .metric small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.why { margin-top: 12px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; }
.why summary { cursor: pointer; color: var(--accent); font-weight: 600; list-style: none; }
.why summary::-webkit-details-marker { display: none; }
.why summary::before { content: "+ "; }
.why[open] summary::before { content: "\2212  "; }
.why p { margin: 8px 0 0; line-height: 1.55; }
.why b { color: var(--ink); }
.hhi { font-size: 14px; margin: 12px 0 0; }
.big-num { font: 650 26px/1.2 var(--font-num); margin: 0; }

/* pulsanti */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line2); background: var(--surface); padding: 10px 14px; border-radius: 12px; font-weight: 600; font-size: 14px; cursor: pointer; text-align: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--neg); }
.btn.big { width: 100%; padding: 14px; font-size: 15px; margin-top: 10px; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.actions { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin: 14px 0 4px; }
.actions .btn { padding: 11px 8px; font-size: 13.5px; }
.star-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn { border: 0; background: none; font-size: 22px; color: var(--faint); width: 36px; height: 40px; cursor: pointer; flex-shrink: 0; }
.fab { position: fixed; right: max(16px, calc(50vw - 304px)); bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); width: 58px; height: 58px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); font-size: 32px; font-weight: 400; display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); z-index: 6; line-height: 1; }

/* moduli */
.field { display: flex; flex-direction: column; gap: 5px; margin: 10px 0; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field input, .field select, .search-bar input, .picker-in, .add-pf input {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 16px; min-height: 46px;
}
.card .field input, .card .field select, .card .picker-in, .card .add-pf input { background: var(--bg); }
.field select { border-radius: 12px; padding: 12px 30px 12px 12px; max-width: none; }
.field input:focus, .search-bar input:focus, .picker-in:focus { outline: none; border-color: var(--accent); }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field.inline input, .field.inline select { width: auto; flex: 1; max-width: 60%; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.calc { margin: 0; font-size: 14px; color: var(--muted); min-height: 20px; }
.txf { padding-bottom: 20px; }
.coin-chip { display: flex; align-items: center; gap: 12px; width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; cursor: pointer; text-align: left; }
.card .coin-chip { background: var(--bg); }
.coin-chip span { flex: 1; display: flex; flex-direction: column; }
.coin-chip small { color: var(--muted); font-size: 12.5px; }
.coin-chip em { font-style: normal; color: var(--accent); font-weight: 600; font-size: 13px; }
.picker { max-height: 320px; overflow-y: auto; margin-top: 4px; }
.picker .row { min-height: 52px; padding: 8px 2px; }
.search-bar { position: sticky; top: calc(env(safe-area-inset-top) + 58px); z-index: 4; background: var(--bg); padding-bottom: 2px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; font-size: 14px; }
.switch-row input { width: 46px; height: 26px; appearance: none; background: var(--line2); border-radius: 999px; position: relative; flex-shrink: 0; cursor: pointer; transition: background .2s; }
.switch-row input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::after { transform: translateX(20px); }
.add-pf { display: flex; gap: 8px; margin-top: 10px; }
.custom-dates { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.custom-dates[hidden] { display: none; }
.custom-dates .btn { height: 46px; margin: 10px 0; }

/* vuoto */
.empty { text-align: center; padding: 56px 12px; }
.empty h2 { font-size: 20px; margin: 14px 0 6px; }
.empty p { color: var(--muted); max-width: 32ch; margin: 0 auto 20px; }
.empty-mark { display: block; width: 72px; height: 72px; margin: 0 auto 8px; border-radius: 18px; }

/* barra in basso */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; max-width: 128px; height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--faint); font-size: 10.5px; font-weight: 600; }
.tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--accent); }

/* notifiche */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 86px); margin: 0 auto; max-width: 520px; background: var(--ink); color: var(--bg); padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 30; opacity: 0; transform: translateY(10px); transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--neg); color: #fff; }
.toast.alert { background: var(--accent); color: var(--accent-ink); }

/* accesso */
.login-body { padding: 0; display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; }
.login { width: 100%; max-width: 360px; padding: 24px 16px; text-align: center; }
.login-icon { border-radius: 22px; }
.login h1 { font-size: 26px; margin: 14px 0 4px; }
.login form { text-align: left; margin-top: 26px; }
.login .err { color: var(--neg); min-height: 20px; font-size: 14px; }

@media (min-width: 700px) { .chart-box { margin: 8px 0 0; } }
#positions, #closed { margin-bottom: 0; }
#closed { padding-bottom: 76px; }

.hero-value.flash-up, .hero-value.flash-down { background: none; }
.hero-value.flash-up { animation: upc 1.1s ease-out; } .hero-value.flash-down { animation: downc 1.1s ease-out; }
@keyframes upc { from { color: var(--pos); } } @keyframes downc { from { color: var(--neg); } }
.alerts .row-main small { white-space: normal; }
.alerts .row-end { max-width: 38%; }
.login-alt { margin-top: 18px; font-size: 14px; }
.login-alt a, .login-links a, .login .switch-row a { color: var(--accent, #4c8dff); }
.login-links { display: flex; gap: 18px; justify-content: center; margin-top: 22px; font-size: 13px; flex-wrap: wrap; }
.tabs a { position: relative; }
.tabs .badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--neg, #e5484d); color: #fff; font-size: 11px; line-height: 18px; font-weight: 700; }
.admin { max-width: 760px; margin: 0 auto; padding: 16px; }
.admin table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin th, .admin td { text-align: left; padding: 6px 4px; border-bottom: 1px solid rgba(127,127,127,.2); vertical-align: top; }
.admin .tbl { overflow-x: auto; }
.admin .btn.small { margin: 2px 0; }
.admin .pw-out { font-family: ui-monospace, monospace; user-select: all; }
.pw-wrap { display: flex; gap: 8px; align-items: center; }
.pw-wrap input { flex: 1; min-width: 0; }
.note.good { color: var(--pos, #2fa36b); }
.gift-ok { text-align: center; }
.install .steps { text-align: left; margin-top: 22px; display: grid; gap: 12px; }
.big-steps { padding-left: 22px; margin: 6px 0 0; font-size: 17px; line-height: 1.5; display: grid; gap: 10px; }
.install .skip { margin-top: 26px; display: block; }
.guide { position: fixed; inset: 0; z-index: 50; display: grid; place-items: end center; background: rgba(0,0,0,.45); padding: 16px; }
.guide-card { width: 100%; max-width: 420px; background: var(--surface); color: var(--ink); border-radius: 18px; padding: 22px 20px 18px; box-shadow: 0 10px 40px rgba(0,0,0,.3); margin-bottom: calc(var(--tabs-h, 64px) + 8px + env(safe-area-inset-bottom)); }
.guide-card h2 { margin: 6px 0 8px; font-size: 21px; }
.guide-card p { font-size: 16px; line-height: 1.5; margin: 0 0 16px; }
.guide-dots { display: flex; gap: 6px; }
.guide-dots i { width: 8px; height: 8px; border-radius: 4px; background: rgba(127,127,127,.35); }
.guide-dots i.on { background: var(--accent, #4c8dff); width: 20px; }
.guide-nav { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.gift-link { font-family: ui-monospace, monospace; word-break: break-all; user-select: all; font-size: 13px; padding: 8px; border-radius: 8px; background: rgba(127,127,127,.12); }
.gift-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
[hidden] { display: none !important; }
.pending { font-size: .55em; color: var(--muted); font-weight: 600; }

/* honeypot iscrizione: fuori schermo, non display:none (alcuni robot lo saltano) */
.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }

.list-head { gap: 10px; }
.lh-title { display: flex; flex-direction: column; min-width: 0; }
.lh-title h2 { margin: 0; }
.lh-title small { font-size: 12px; line-height: 1.3; }
.list-head .sort { flex: 0 0 auto; }
