:root {
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11,11,11,0.10);
  --gridline: #e1e0d9;
  --blue: #2a78d6;
  --good: #0ca30c;
  --bad: #d03b3b;
  --danger-bg: #fbeceb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
}
.brand {
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}
.brand:hover { text-decoration: none; }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a {
  color: var(--text-secondary);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
}
nav a:hover { background: var(--surface-2); text-decoration: none; }
nav a.active { color: var(--text-primary); background: var(--surface-2); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 16px; }
.ccy-toggle { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.ccy-toggle a { padding: 5px 10px; font-size: 13px; color: var(--text-secondary); }
.ccy-toggle a.on { background: var(--blue); color: #fff; }
.ccy-toggle a:hover { text-decoration: none; }
.logout { font-size: 14px; color: var(--text-secondary); }

.page { max-width: 1080px; margin: 0 auto; padding: 28px 20px 60px; }

h1 { font-size: 26px; margin: 0 0 20px; }
h1 .muted { font-size: 16px; font-weight: 400; }
h2 { font-size: 16px; margin: 0; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h1 { margin: 0; }

.muted { color: var(--text-muted); }
.pos { color: var(--good); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }

.notice {
  background: #fff6e0;
  border: 1px solid #ecd48f;
  color: #6b4e00;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
}
.card-header { margin-bottom: 14px; }

.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th {
  text-align: left;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--gridline); font-size: 14px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table td.comment { color: var(--text-secondary); max-width: 280px; }

form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
form input, form select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface-1);
  color: var(--text-primary);
}
.hint { font-size: 12px; color: var(--text-muted); }

button {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
button:hover { opacity: 0.9; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { background: var(--bad); }
.btn-secondary { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:disabled { opacity: 0.35; cursor: default; }

.reorder-cell { display: flex; gap: 4px; }
.reorder-cell form { margin: 0; }
.reorder-cell button { padding: 4px 8px; line-height: 1; }

.no-spinner::-webkit-inner-spin-button,
.no-spinner::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.no-spinner { -moz-appearance: textfield; appearance: textfield; }

.btn {
  display: inline-block;
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
}
.btn:hover { text-decoration: none; background: var(--gridline); }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; max-width: 220px; }
.inline-form label { margin-bottom: 0; }

.purchase-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.purchase-form label { min-width: 130px; }
.purchase-form label.qty-label { min-width: 170px; }
.purchase-form label.grow { flex: 1; min-width: 200px; }
.purchase-form button { height: 38px; }

.chart-header { display: flex; align-items: center; justify-content: space-between; }
.range-toggle { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.range-toggle a { padding: 5px 10px; font-size: 13px; color: var(--text-secondary); }
.range-toggle a:hover { text-decoration: none; background: var(--surface-2); }
.range-toggle a.on { background: var(--blue); color: #fff; }
.chart-wrap { position: relative; }
.chart-loading { position: absolute; top: 8px; right: 4px; font-size: 12px; }

.price-card .price-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.price-value { font-size: 24px; font-weight: 700; }
.price-source { font-size: 12px; color: var(--text-muted); font-weight: 400; margin-left: 8px; text-transform: uppercase; }

.goal-progress-row { display: flex; align-items: center; gap: 12px; }
.goal-progress-track {
  flex: 1;
  height: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.goal-progress-fill {
  height: 100%;
  background: var(--good);
  border-radius: 999px 0 0 999px;
  transition: width 0.3s ease;
}
.goal-progress-label { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }

.goal-complete-box {
  margin-top: 16px;
  background: linear-gradient(135deg, var(--good), var(--blue));
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
  padding: 16px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}
.goal-complete-box:hover { opacity: 0.92; }

#fireworks-canvas {
  display: none;
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

.auth-card {
  max-width: 380px;
  margin: 60px auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
}
.auth-card h1 { text-align: center; letter-spacing: 0.05em; }
.auth-card > p.muted { text-align: center; margin-top: 0; }
.auth-card button { width: 100%; margin-top: 4px; }

.flashes { margin-bottom: 20px; }
.flash { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 8px; }
.flash-error { background: var(--danger-bg); color: var(--bad); }
.flash-success { background: #e7f7e7; color: var(--good); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255,255,255,0.10);
    --gridline: #2c2c2a;
    --blue: #3987e5;
    --good: #0ca30c;
    --bad: #e66767;
    --danger-bg: #3a1f1e;
  }
}
