:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0077b6;
  --brand-dark: #005f8e;
  --brand-soft: #e0f2fe;
  --good: #16a34a;
  --bad: #dc2626;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #131c2e;
    --text: #e5edf8;
    --muted: #8da0b9;
    --line: #243148;
    --brand: #38bdf8;
    --brand-dark: #7dd3fc;
    --brand-soft: #0c2a40;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  line-height: 1.4;
}
.wrap { max-width: 1000px; margin: 0 auto; padding: 16px; }
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1rem; margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: .8rem; color: var(--muted); }
.up { color: var(--good); } .down { color: var(--bad); }

/* form */
form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 12px; align-items: end; }
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select {
  width: 100%; padding: 10px 12px; font-size: 1rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus { outline: 2px solid var(--brand); border-color: transparent; }
.btn {
  background: var(--brand); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 16px; font-size: .95rem; font-weight: 600; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .btn { color: #04202f; } }
.btn:hover { background: var(--brand-dark); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.small { padding: 6px 10px; font-size: .8rem; }
.btn.danger { color: var(--bad); }
.form-actions { display: flex; gap: 8px; }
.editing { border-color: var(--brand); }

/* segmented controls */
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 8px; font-size: .85rem; font-weight: 600; cursor: pointer; }
.seg button.active { background: var(--card); color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* chart: always fits width */
.chart-box { position: relative; height: 320px; }

/* table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); }
tbody tr:hover { background: var(--brand-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pb { background: #facc15; color: #422006; font-size: .65rem; font-weight: 700; padding: 2px 6px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.more { text-align: center; margin-top: 12px; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; transition: .25s; pointer-events: none; font-size: .9rem; z-index: 10;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  form { grid-template-columns: 1fr 1fr; }
  form .form-actions { grid-column: 1 / -1; }
  form .form-actions .btn { flex: 1; }
  .chart-box { height: 260px; }
  .hide-sm { display: none; }
}
