:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #15171c;
  --muted: #6b7280;
  --line: #e3e5ea;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --pos: #12804a;
  --neg: #c62f2f;
  --warn: #9a6200;
  --warn-bg: #fdf1d6;
  --ok-bg: #dff5e8;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --card: #191c22;
    --text: #eceef2;
    --muted: #98a0ad;
    --line: #2a2e37;
    --accent: #6d8dff;
    --accent-text: #0b0d12;
    --pos: #4fd08a;
    --neg: #ff7b7b;
    --warn: #f0b84a;
    --warn-bg: #3a2e12;
    --ok-bg: #153524;
  }
}

* { box-sizing: border-box; }

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

main { max-width: 980px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
[hidden] { display: none !important; }

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

button, .btn, input, select {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  padding: 8px 12px;
  min-height: 38px;
}
button, .btn { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.small { min-height: 30px; padding: 3px 9px; font-size: 13px; }
button.danger { color: var(--neg); }
input { width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label input, label select { color: var(--text); font-size: 15px; }

.login { max-width: 340px; margin: 18vh auto 0; display: grid; gap: 14px; }
.error { color: var(--neg); margin: 0; min-height: 1.4em; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.top nav { display: flex; gap: 8px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.new .grid { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 560px) {
  .stats, .new .grid { grid-template-columns: repeat(2, 1fr); }
}
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat.main .v { font-size: 26px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.grid.one { grid-template-columns: 1fr; }

.toolbar { display: flex; gap: 10px; margin: 16px 0 10px; }
.seg { display: flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; border-left: 0; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.acc { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.acc-head {
  width: 100%; border: 0; border-radius: 0; background: none; padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left; white-space: normal;
}
.acc-name { font-weight: 650; font-size: 16px; overflow-wrap: anywhere; }
.acc-meta { font-size: 12px; color: var(--muted); }
.acc-bal { text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.acc-bal .v { font-size: 18px; font-weight: 650; }
.acc-body { border-top: 1px solid var(--line); padding: 12px 16px 16px; display: grid; gap: 12px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .spacer { flex: 1; }
.pw { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border-radius: 6px; padding: 4px 8px; overflow-wrap: anywhere; }
.note { color: var(--muted); font-size: 13px; margin: 0; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-size: 12px; font-weight: 500; color: var(--muted); }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) { text-align: left; }
tr.pending .gain { opacity: 0.5; }
tfoot td { border-bottom: 0; font-weight: 650; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }

.badge { border-radius: 999px; padding: 2px 10px; font-size: 12px; min-height: 26px; border-color: transparent; }
.badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.validated { background: var(--ok-bg); color: var(--pos); }

.add { display: grid; grid-template-columns: auto 1fr 1fr auto; gap: 8px; align-items: end; }
@media (max-width: 560px) {
  .add { grid-template-columns: 1fr 1fr; }
  .toolbar { flex-direction: column; }
}

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }
