:root {
  --bg: #0d1117;
  --card: #151b23;
  --line: #262e39;
  --text: #e6edf3;
  --muted: #8b96a5;
  --accent: #4f8cff;
  --pos: #2fbf71;
  --neg: #f0524f;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* so display:grid/flex rules can't override the hidden attribute */

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px max(16px, calc((100% - 1100px) / 2));
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; display: grid; gap: 16px; }

h2 { margin: 0 0 12px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.error { color: var(--neg); margin: 8px 0 0; }

.badge { color: var(--pos); font-size: 13px; font-weight: 600; }

.btn {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.active { border-color: var(--accent); color: var(--accent); }
.btn.danger:hover { border-color: var(--neg); color: var(--neg); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
.detail-stats .label .link { font-size: 12px; margin-left: 4px; }
.link:disabled { color: var(--muted); cursor: default; }

.banner {
  background: #3a1f1f;
  border: 1px solid #6b2b2b;
  color: #ffb4b0;
  padding: 10px 14px;
  border-radius: 8px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

/* Summary tiles */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 13px; font-variant-numeric: tabular-nums; }

/* Allocation bar */
.allocation { display: none; }
.allocation.on { display: block; }
.alloc-bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--line); }
.alloc-bar span { display: block; height: 100%; }
.alloc-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.alloc-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; border-bottom: 1px solid var(--line); }
td { border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
#holdings tbody tr { cursor: pointer; }
#holdings tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
#holdings tbody tr.selected { background: rgba(79, 140, 255, 0.1); }
.coin { display: flex; align-items: center; gap: 10px; }
.coin img { width: 24px; height: 24px; border-radius: 50%; background: var(--line); }
.coin small { color: var(--muted); display: block; line-height: 1.1; }
.pl small { display: block; font-size: 12px; }
.empty { text-align: center; padding: 24px 0 8px; }

/* Detail */
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.detail-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.detail-stats .label { color: var(--muted); font-size: 12px; }
.detail-stats .value { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ranges { display: flex; gap: 6px; }
.chart-box { position: relative; height: 320px; margin-bottom: 20px; }
.chart-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* Dialog */
dialog {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  width: min(480px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  width: 100%;
  min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.preview { margin: 0; min-height: 22px; font-size: 14px; }
.preview strong { color: var(--text); }
details summary { cursor: pointer; color: var(--accent); font-size: 13px; margin-bottom: 8px; }
details .hint { margin: 6px 0 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.coin-picker { position: relative; }
.results {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  max-height: 260px; overflow-y: auto;
}
.results li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 6px; cursor: pointer; color: var(--text); font-size: 14px; }
.results li:hover, .results li.hl { background: rgba(79, 140, 255, 0.15); }
.results li img { width: 20px; height: 20px; border-radius: 50%; }
.results li small { color: var(--muted); margin-left: auto; }
.results .none { color: var(--muted); cursor: default; }
.chosen { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.chosen img { width: 20px; height: 20px; border-radius: 50%; }

@media (max-width: 560px) {
  .grid2 { grid-template-columns: 1fr; }
  .tile .value { font-size: 20px; }
  th, td { padding: 10px 8px; }
  .chart-box { height: 240px; }
}

/* ---------- Finance: navigation and layout ---------- */
.tabs { display: flex; gap: 4px; margin-left: auto; } /* pinned to the right of the header */
.tabs a {
  color: var(--muted); text-decoration: none; padding: 8px 14px; border-radius: 8px; font-weight: 500;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); background: rgba(79, 140, 255, 0.15); }

.view { display: grid; gap: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.month-nav { display: flex; align-items: center; gap: 10px; min-width: 190px; justify-content: space-between; }
.month-nav .btn:disabled { opacity: 0.4; cursor: default; }

select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 10px; font: inherit; min-width: 0;
}
select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
dialog select { width: 100%; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.seg button { background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 7px; font: inherit; cursor: pointer; }
.seg button.active { background: var(--accent); color: #fff; }

/* Spending by category */
.cat { margin-bottom: 12px; }
.cat-top { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* Recent transactions */
.rec { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.rec:last-child { border-bottom: 0; }
.rec small { display: block; color: var(--muted); font-size: 12px; }
.rec .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sub-note { display: block; color: var(--muted); font-size: 12px; }
tr.total td { border-top: 1px solid var(--line); border-bottom: 0; }

@media (max-width: 700px) {
  .two-col { grid-template-columns: 1fr; }
  /* Tabs stay in the top-right corner; just a little tighter so four fit on a phone. */
  .topbar { padding-top: 12px; padding-bottom: 12px; }
  .tabs a { padding: 8px 10px; font-size: 14px; }
  .toolbar .btn.primary { flex: 1; }
  .month-nav { min-width: 0; flex: 1; }
}

/* ---------- Expenses: bills and budgets ---------- */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.paid { background: rgba(47, 191, 113, 0.15); color: var(--pos); }
.pill.overdue { background: rgba(240, 82, 79, 0.15); color: var(--neg); }
.pill.due { background: rgba(245, 166, 35, 0.15); color: #f5a623; }
.rec .amt .pill { margin-left: 8px; }
.cat-sub { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 4px; min-height: 26px; }
.bar.warn span { background: #f5a623; }
.bar.over span { background: var(--neg); }
.bar.plain span { background: var(--muted); opacity: 0.5; }
#x-bills td small.sub-note { margin-top: 0; }

/* ---------- Calculator pop-up ---------- */
body { padding-bottom: 88px; } /* room so the round button never covers the last row */
.calc-fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--accent); color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s ease, filter 0.15s ease;
}
.calc-fab:hover { filter: brightness(1.1); }
.calc-fab:active { transform: scale(0.94); }
.calc-fab.open { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.calc-fab:focus-visible, .calc-key:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.calc {
  position: fixed; right: 16px; bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 30;
  width: min(300px, calc(100vw - 32px)); padding: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  transform-origin: bottom right; animation: calc-pop 0.16s ease-out;
}
@keyframes calc-pop { from { opacity: 0; transform: scale(0.92) translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .calc { animation: none; } .calc-fab { transition: none; } }

.calc-screen { background: var(--bg); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; text-align: right; overflow: hidden; }
.calc-expr { min-height: 20px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.calc-value { font-size: 32px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-x: auto; white-space: nowrap; }
.calc-value.long { font-size: 22px; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.calc-key {
  height: 50px; border: 0; border-radius: 12px; font: inherit; font-size: 18px; cursor: pointer;
  background: #202833; color: var(--text); transition: filter 0.1s ease, transform 0.1s ease;
}
.calc-key:hover { filter: brightness(1.25); }
.calc-key:active { transform: scale(0.95); }
.calc-key.fn { background: #2a3340; color: var(--muted); }
.calc-key.op { background: rgba(79, 140, 255, 0.2); color: var(--accent); font-size: 22px; }
.calc-key.eq { background: var(--accent); color: #fff; font-size: 22px; }

/* ---------- Spending vs budget: periods, draggable limit ---------- */
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.period-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.period-bar select { flex: 0 1 260px; min-width: 0; }
.period-note { margin: 4px 0 14px; }
.badge-pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-pill.current { background: rgba(47, 191, 113, 0.15); color: var(--pos); }
.badge-pill.archived { background: rgba(139, 150, 165, 0.18); color: var(--muted); }
#b-tiles { margin-bottom: 18px; }
.b-cats .cat { margin-bottom: 18px; }

.slider { position: relative; height: 24px; display: flex; align-items: center; }
.slider-track { position: absolute; left: 8px; right: 8px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; pointer-events: none; }
.slider-track .fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.15s ease; }
.fill.warn { background: #f5a623; }
.fill.over { background: var(--neg); }
.limit-range {
  position: relative; width: 100%; height: 24px; margin: 0; padding: 0; background: transparent;
  -webkit-appearance: none; appearance: none; cursor: pointer; touch-action: pan-y;
}
.limit-range::-webkit-slider-runnable-track { height: 24px; background: transparent; }
.limit-range::-moz-range-track { height: 24px; background: transparent; }
.limit-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 24px; border-radius: 7px; cursor: grab;
  background: var(--text); border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--muted);
}
.limit-range::-moz-range-thumb {
  width: 10px; height: 18px; border-radius: 7px; cursor: grab;
  background: var(--text); border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--muted);
}
.limit-range:active::-webkit-slider-thumb { cursor: grabbing; }
.limit-range:focus-visible { outline: none; }
.limit-range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--accent); }
.limit-range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px var(--accent); }

.num-edit {
  background: none; border: 0; border-bottom: 1px dashed var(--muted); color: var(--text);
  font: inherit; padding: 0 1px; cursor: text; font-variant-numeric: tabular-nums;
}
.num-edit:hover { border-bottom-color: var(--accent); color: var(--accent); }
.num-input { width: 110px; padding: 2px 6px; font-size: 14px; text-align: right; }
details.period-list { margin-top: 6px; }
details.period-list summary { margin-bottom: 10px; }

/* Confirmation message, e.g. "€45.00 taken from Main bank" */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 40;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5); max-width: calc(100vw - 32px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast, .slider-track .fill { transition: none; } }
@media (max-width: 560px) { .head-actions { width: 100%; } .head-actions .btn { flex: 1; } }

/* Overview quick view of spending vs budget */
.link-btn { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }
.ov-total { margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.ov-total .cat-top { font-size: 15px; }
#ov-budget .cat { margin-bottom: 12px; }
#ov-budget .cat-sub { min-height: 0; margin-top: 2px; }
#ov-budget .period-note { margin: 0 0 12px; }

/* ---------- Accounts: login page, account menu, settings ---------- */
.banner.info { background: rgba(79, 140, 255, 0.12); border-color: rgba(79, 140, 255, 0.4); color: var(--text); }
.banner.info .link { margin-left: 4px; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: min(420px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 24px; display: grid; gap: 14px; margin: 0;
}
.auth-card h1 { margin: 0; font-size: 26px; text-align: center; }
.auth-tagline { text-align: center; margin: -6px 0 4px; }
.auth-card form { display: grid; gap: 12px; }
.auth-submit { width: 100%; padding: 11px; font-size: 15px; }
.auth-info { margin: 0; padding: 10px 12px; border-radius: 8px; background: rgba(47, 191, 113, 0.12); color: var(--pos); }
.auth-foot { text-align: center; margin: 4px 0 0; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 62px; }
.pw-toggle { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 13px; }

.user-menu { position: relative; }
.user-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; display: grid; place-items: center;
}
.user-btn:hover, .user-btn[aria-expanded="true"] { border-color: var(--accent); }
.user-pop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 25; min-width: 200px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.user-email { padding: 8px 10px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); margin-bottom: 4px; word-break: break-all; }
.user-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); font: inherit; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.user-pop button:hover { background: rgba(255, 255, 255, 0.06); }

#dlg-settings { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
.settings { display: grid; gap: 4px; }
.settings-head { display: flex; justify-content: space-between; align-items: center; }
.settings-head h2 { margin: 0; }
.settings-sec { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.settings-sec h3 { margin: 0 0 8px; font-size: 15px; }
.settings-sec form { display: grid; gap: 10px; }
.settings-msg { margin: 0; color: var(--neg); }
.settings-msg.ok { color: var(--pos); }
.inline-check { display: flex; align-items: center; gap: 8px; }
.inline-check input { width: auto; }
@media (max-width: 700px) { .topbar { gap: 8px; } .tabs { order: 3; width: 100%; margin-left: 0; justify-content: space-between; } .user-menu { margin-left: auto; } }
