/* finance.meshydra.com — theme-aware styles (dark default) */
:root {
  --radius: 14px;
  --maxw: 1080px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

:root[data-theme="dark"] {
  --bg: #0b0e14;
  --bg-2: #121722;
  --card: #161c28;
  --card-2: #1c2433;
  --border: #232c3d;
  --text: #e8edf5;
  --muted: #8a97ad;
  --accent: #4f8cff;
  --accent-2: #6f5cff;
  --ok: #33c98a;
  --warn: #f2b83c;
  --danger: #f2545b;
  --up: #33c98a;
  --down: #f2545b;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}
:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-2: #eef1f7;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --border: #e2e7f0;
  --text: #16202e;
  --muted: #66748c;
  --accent: #2f6bff;
  --accent-2: #6f5cff;
  --ok: #12a06a;
  --warn: #c98a12;
  --danger: #d63a41;
  --up: #12a06a;
  --down: #d63a41;
  --shadow: 0 8px 24px rgba(20,30,50,.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 80% -10%, var(--bg-2), var(--bg)) fixed;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
.container { flex: 1 0 auto; }   /* pushes footer to the very bottom */
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--card-2); padding: 1px 6px; border-radius: 6px; font-size: .85em; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 24px; background: color-mix(in srgb, var(--card) 85%, transparent);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo { width: 26px; height: 26px; border-radius: 7px; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { color: var(--muted); padding: 7px 12px; border-radius: 9px; font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--card-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--card-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: .9rem; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.avatar.sm { width: 22px; height: 22px; }
.icon-btn {
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: .85rem; font-family: var(--font);
}
.icon-btn:hover { border-color: var(--accent); text-decoration: none; }
.icon-btn.sm { padding: 4px 9px; font-size: .8rem; }
.icon-btn.danger:hover, .icon-btn.danger { color: var(--danger); }
.icon-btn.ok { color: var(--ok); }

/* Layout */
.container { max-width: var(--maxw); margin: 0 auto; padding: 28px 24px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 2px; font-size: 1.6rem; }
.head-actions { display: flex; gap: 10px; align-items: center; }
h1, h2 { letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.strong { font-weight: 700; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }

/* Cards & grids */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.card-title { font-weight: 600; margin-bottom: 14px; font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.grid { display: grid; gap: 20px; margin-bottom: 20px; }
/* minmax(0,1fr) stops grid tracks from growing to fit oversized children (canvas). */
.grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 800px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* Fixed-size chart container: Chart.js sizes to this, preventing runaway growth. */
.chart-box { position: relative; width: 100%; height: 220px; min-width: 0; }
.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

/* Hero net worth */
.hero { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  border-radius: var(--radius); padding: 28px; margin-bottom: 20px; box-shadow: var(--shadow); }
.hero-total { display: flex; align-items: baseline; gap: 10px; }
.hero-total .currency { font-size: 1.1rem; opacity: .8; }
.hero-total .amount { font-size: 2.8rem; font-weight: 800; letter-spacing: -0.03em; }
.hero-change { margin-top: 8px; font-weight: 600; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hero-change .pct { opacity: .9; }
.hero-change .muted { color: rgba(255,255,255,.75); }

/* Period toggle */
.period-toggle { display: inline-flex; background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.period-toggle a { padding: 8px 16px; color: var(--muted); font-weight: 600; font-size: .88rem; }
.period-toggle a:hover { color: var(--text); text-decoration: none; }
.period-toggle a.active { background: var(--accent); color: #fff; }

/* Allocation */
.alloc-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: center; }
@media (max-width: 500px){ .alloc-wrap { grid-template-columns: 1fr; } }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.legend .muted { margin-left: auto; }
.dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; background: var(--accent); flex: 0 0 auto; }
.legend-scroll { max-height: 240px; overflow-y: auto; padding-right: 6px; }

/* Portfolio share cell (read-only dashboard holdings) */
.share { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.share-pct { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; min-width: 42px; }
.share-bar { width: 70px; height: 6px; background: var(--card-2); border-radius: 4px; overflow: hidden; }
.share-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* Metrics row (Today / Gain-Loss / Goal) */
.metrics { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.metric { flex: 1; min-width: 220px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); display: flex;
  align-items: center; gap: 14px; }
.metric-label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.metric-value { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; margin-top: 2px; }
.metric-value.small-v { font-size: 1.05rem; }
.metric-sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.metric.pos .metric-value { color: var(--up); }
.metric.neg .metric-value { color: var(--down); }
.metric.pos { border-color: color-mix(in srgb, var(--up) 30%, var(--border)); }
.metric.neg { border-color: color-mix(in srgb, var(--down) 30%, var(--border)); }

/* Goal progress ring */
.ring { flex: 0 0 auto; }
.ring-bg { fill: none; stroke: var(--card-2); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round;
  transition: stroke-dasharray .8s cubic-bezier(.2,.7,.2,1); }

/* Coloured deltas (day change / gain) */
.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.pos { color: var(--up); }
.delta.neg { color: var(--down); }
.delta-pct { font-weight: 600; font-size: .82rem; opacity: .85; margin-left: 2px; }

/* Stats */
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-label { color: var(--muted); font-size: .82rem; }
.stat-value { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }
.stat-bar { height: 6px; background: var(--card-2); border-radius: 4px; margin-top: 10px; overflow: hidden; }
.stat-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.interest-summary { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.interest-summary .stat { flex: 1; min-width: 180px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table th.r, .table td.r { text-align: right; }
.table-scroll { overflow-x: auto; }
.hname { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.sym { color: var(--muted); font-weight: 500; font-size: .82rem; }

/* Per-holding logo with monogram fallback */
.logo { width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; background: transparent; }
.logo img { width: 100%; height: 100%; object-fit: contain; }
.logo .mono-letter { display: none; font-weight: 800; font-size: .95rem; color: #fff; }
.logo.mono { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }
.logo.mono img { display: none; }
.logo.mono .mono-letter { display: block; }

/* Tags */
.tag { display: inline-block; background: var(--card-2); border: 1px solid var(--border); color: var(--muted);
  padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.tag-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.tag-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.tag-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.tag-binance { color: #f0b90b; border-color: rgba(240,185,11,.4); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 11px;
  font-weight: 600; cursor: pointer; border: 1px solid var(--border); background: var(--card-2);
  color: var(--text); font-family: var(--font); font-size: .9rem; }
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn.danger, .btn .danger { color: var(--danger); }
.btn-google { background: #fff; color: #1f2937; border-color: #dfe3ea; width: 100%; justify-content: center; padding: 12px; }
.btn-google .g { font-weight: 800; color: #4285F4; }

/* Forms */
label { display: block; margin: 12px 0 0; font-size: .85rem; color: var(--muted); font-weight: 600; }
input, select, textarea { width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text); font-family: var(--font); font-size: .95rem; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
select option { background: var(--card); color: var(--text); }
.ccy-switch select option { background: var(--card); color: var(--text); }
.row { display: flex; gap: 12px; }
.row label { flex: 1; }
.inline-form { display: flex; align-items: flex-end; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.stacked-form { max-width: 460px; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.bullets { padding-left: 18px; line-height: 1.9; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 460px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Flash */
.flashes { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 11px 14px; border-radius: 10px; font-size: .9rem; border: 1px solid var(--border); background: var(--card); }
.flash-success { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); color: var(--ok); }
.flash-error { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); color: var(--danger); }

/* Auth pages */
.auth-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 40px; max-width: 380px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.auth-logo { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 8px; }
.auth-card h1 { margin: 6px 0; }
.auth-card .btn { margin: 16px 0 8px; }

.empty { padding: 12px 0; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 30px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.binance-status { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

/* ── Icons ──────────────────────────────────────────────────────────────────── */
.ico { width: 18px; height: 18px; flex: 0 0 auto; vertical-align: -3px; }
.nav a { display: inline-flex; align-items: center; gap: 7px; }
.nav .ico { width: 16px; height: 16px; }
.card-title { display: flex; align-items: center; gap: 8px; }
.card-title .ct-ico { width: 16px; height: 16px; color: var(--accent); }
.btn .ico { width: 16px; height: 16px; }
.icon-btn.iconic { display: inline-flex; align-items: center; justify-content: center; padding: 7px; }
.icon-btn.iconic.sm { padding: 5px; }
.foot-ico { width: 13px; height: 13px; opacity: .7; }
.tico { width: 12px; height: 12px; }
.flip { transform: scaleY(-1); }

/* Currency switcher */
.ccy-switch { display: inline-flex; align-items: center; gap: 6px; background: var(--card-2);
  border: 1px solid var(--border); border-radius: 9px; padding: 3px 8px 3px 10px; }
.ccy-switch .ccy-ico { width: 15px; height: 15px; color: var(--muted); }
.ccy-switch select { width: auto; margin: 0; padding: 4px 4px; border: none; background: transparent;
  color: var(--text); font-weight: 700; font-size: .85rem; cursor: pointer; }
.ccy-switch select:focus { outline: none; }

/* ── Animations ─────────────────────────────────────────────────────────────── */
@keyframes revealUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes barGrow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.reveal { animation: revealUp .55s cubic-bezier(.2,.7,.2,1) both; animation-delay: var(--d, 0s); }
.reveal-row { animation: revealUp .4s ease both; }
.table-holdings tbody tr:nth-child(1) { animation-delay: .02s; }
.table-holdings tbody tr:nth-child(2) { animation-delay: .06s; }
.table-holdings tbody tr:nth-child(3) { animation-delay: .10s; }
.table-holdings tbody tr:nth-child(4) { animation-delay: .14s; }
.table-holdings tbody tr:nth-child(n+5) { animation-delay: .18s; }
.stat-bar span { transform-origin: left; animation: barGrow .8s cubic-bezier(.2,.7,.2,1) both; animation-delay: .2s; }
.flash { animation: slideDown .4s ease both; }
.hero { position: relative; overflow: hidden; }
.hero::after { content: ''; position: absolute; top: -50%; right: -20%; width: 60%; height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,.18), transparent 60%); pointer-events: none; }

/* Transitions & hover polish */
.card, .stat, .btn, .icon-btn, .nav a, .tag, .period-toggle a { transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease, color .18s ease, filter .18s ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 16px 40px rgba(0,0,0,.28); }
.stat:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.btn:hover { transform: translateY(-1px); }
.btn:active, .icon-btn:active { transform: translateY(0) scale(.97); }
.icon-btn.iconic:hover { color: var(--accent); transform: translateY(-1px); }
#theme-toggle .ico { transition: transform .4s ease; }
#theme-toggle:hover .ico { transform: rotate(-25deg); }
.table-holdings tbody tr { transition: background .15s ease; }
.table-holdings tbody tr:hover { background: var(--card-2); }
@media (prefers-reduced-motion: reduce) {
  .reveal, .reveal-row, .flash, .stat-bar span, .hero-total .amount { animation: none !important; }
  .card:hover, .stat:hover, .btn:hover { transform: none; }
}

/* Modal pop-in */
.modal { animation: popIn .22s cubic-bezier(.2,.8,.2,1) both; }
.modal-backdrop { animation: slideDown .2s ease both; }

/* Hero change pill */
.chg-pill { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.16);
  padding: 4px 12px; border-radius: 999px; font-weight: 700; }
.chg-pill .ico { width: 15px; height: 15px; }
.hero-change .pct { opacity: .95; }

/* Holding extras */
.tag-row { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.tag-ccy { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.symbol-field { display: flex; gap: 8px; }
.symbol-field input { flex: 1; }
.symbol-field .btn.sm { padding: 8px 12px; white-space: nowrap; margin-top: 6px; }
.btn.sm { font-size: .82rem; }
.fetch-msg { font-size: .82rem; margin-top: 6px; min-height: 1.1em; color: var(--muted); }
.fetch-msg.ok { color: var(--ok); }
.fetch-msg.err { color: var(--danger); }
