/* ===== Design tokens ===== */
:root {
  --bg: #F2F2F7;
  --bg-card: rgba(255,255,255,0.72);
  --bg-elevated: #FFFFFF;
  --text: #1C1C1E;
  --text-secondary: #6E6E73;
  --text-tertiary: #AEAEB2;
  --border: rgba(0,0,0,0.07);
  --accent: #0A84FF;
  --gold: #C9A24B;
  --gold-light: #F4E2B8;
  --green: #34C759;
  --red: #FF3B30;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #000000;
  --bg-card: rgba(28,28,30,0.72);
  --bg-elevated: #1C1C1E;
  --text: #F5F5F7;
  --text-secondary: #9A9AA0;
  --text-tertiary: #636366;
  --border: rgba(255,255,255,0.09);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg: #000000;
    --bg-card: rgba(28,28,30,0.72);
    --bg-elevated: #1C1C1E;
    --text: #F5F5F7;
    --text-secondary: #9A9AA0;
    --text-tertiary: #636366;
    --border: rgba(255,255,255,0.09);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  transition: background 0.3s ease, color 0.3s ease;
}

button, input, select, textarea { font-family: inherit; }

#app { display: flex; flex-direction: column; height: 100dvh; }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: var(--safe-top);
  background: var(--bg-card);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
}
.brand-mark { width: 26px; height: 26px; border-radius: 7px; }
.topbar h1 {
  flex: 1;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2.4; fill: none; stroke-linecap: round; }

/* ===== Content ===== */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px calc(100px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}
.view { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; animation: fadein 0.35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== Tabbar ===== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  padding-bottom: var(--safe-bottom);
  background: var(--bg-card);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-tertiary);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px 8px;
  cursor: pointer;
  transition: color 0.2s ease;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab span { font-size: 10.5px; font-weight: 500; letter-spacing: -0.01em; }
.tab.active { color: var(--accent); }

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.card h2, .card h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-row + .card-row { margin-top: 8px; }
.muted { color: var(--text-secondary); }
.small { font-size: 12.5px; }
.tiny { font-size: 11px; }

/* ===== Hero (salary header) ===== */
.hero { text-align: center; padding: 22px 6px 6px; }
.hero-label { color: var(--text-secondary); font-size: 14px; margin-bottom: 4px; }
.hero-value { font-size: 50px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.hero-stats { display: flex; justify-content: center; gap: 22px; margin-top: 14px; flex-wrap: wrap; }
.hero-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hero-stat .v { font-size: 13px; font-weight: 600; }
.hero-stat .l { font-size: 10.5px; color: var(--text-secondary); }
.hero-footnote { margin-top: 12px; font-size: 10.5px; color: var(--text-tertiary); padding: 0 20px; }

/* ===== Progress bar ===== */
.progress-track {
  height: 14px;
  border-radius: 7px;
  background: rgba(127,127,127,0.16);
  overflow: hidden;
  margin: 10px 0;
}
.progress-fill {
  height: 100%;
  border-radius: 7px;
  background: linear-gradient(90deg, #0A84FF, #64D2FF);
  transition: width 0.6s cubic-bezier(.22,1,.36,1);
}
.progress-fill.done { background: linear-gradient(90deg, #34C759, #64D9A6); }

/* ===== Inline icon sizing ===== */
svg { width: 20px; height: 20px; }
.mi-inline { width: 15px; height: 15px; vertical-align: -2px; margin-right: 2px; }
.icon-32 { width: 30px; height: 30px; }

/* ===== Metric grid ===== */
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.metric-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px; }
.metric-card .mi { width: 20px; height: 20px; stroke: var(--accent); fill: none; stroke-width: 2; margin-bottom: 6px; }
.metric-card .mv { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-card .ml { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; }

/* ===== Coach ===== */
.coach-tip { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; font-size: 13.5px; color: var(--text-secondary); }
.coach-tip:not(:last-child) { border-bottom: 1px solid var(--border); }
.coach-tip b { color: var(--text); font-weight: 600; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.02em; }
input[type=text], input[type=number], input[type=date], select, textarea {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s ease;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.amount-input { font-size: 34px; font-weight: 700; text-align: left; padding: 10px 14px; }
.type-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.type-option {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 6px;
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  transition: all 0.15s ease;
  text-align: center;
}
.type-option svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.type-option.selected { border-color: var(--accent); color: var(--accent); background: rgba(10,132,255,0.08); }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-secondary { background: rgba(127,127,127,0.14); color: var(--text); }
.btn-danger { background: rgba(255,59,48,0.12); color: var(--red); }

/* ===== Modal / sheet ===== */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 50; display: flex; align-items: flex-end;
  animation: fadeinbg 0.2s ease;
}
@keyframes fadeinbg { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(24px + var(--safe-bottom));
  max-height: 88vh;
  overflow-y: auto;
  animation: slideup 0.28s cubic-bezier(.22,1,.36,1);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 36px; height: 5px; border-radius: 3px; background: var(--text-tertiary); margin: 8px auto 14px; opacity: 0.5; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-header h2 { margin: 0; font-size: 18px; font-weight: 700; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 15px; cursor: pointer; padding: 4px; font-weight: 500; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  z-index: 80;
  animation: toastin 0.25s ease, toastout 0.25s ease 1.6s forwards;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%,0); } }
@keyframes toastout { to { opacity: 0; transform: translate(-50%, 8px); } }

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 60px 24px; color: var(--text-secondary); }
.empty-state svg { width: 44px; height: 44px; stroke: var(--text-tertiary); fill: none; stroke-width: 1.6; margin-bottom: 14px; }
.empty-state h3 { color: var(--text); margin: 0 0 6px; font-size: 17px; }
.empty-state p { margin: 0 0 18px; font-size: 13.5px; }

/* ===== List rows ===== */
.list-section-title { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.03em; padding: 0 4px; margin-top: 4px; }
.sale-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.sale-row:last-child { border-bottom: none; }
.sale-icon {
  width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,132,255,0.1); color: var(--accent);
  flex-shrink: 0;
}
.sale-icon svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2; }
.sale-info { flex: 1; min-width: 0; }
.sale-info .t { font-size: 14.5px; font-weight: 500; }
.sale-info .d { font-size: 11.5px; color: var(--text-secondary); }
.sale-amount { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sale-delete { background: none; border: none; color: var(--red); padding: 4px; cursor: pointer; opacity: 0.7; }
.sale-delete svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

.month-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 4px; cursor: pointer; }
.month-row .m-name { font-weight: 600; font-size: 15px; }
.month-row .m-sub { font-size: 11.5px; color: var(--text-secondary); }
.month-row .m-value { font-weight: 700; font-size: 15.5px; }

/* ===== Search / filter ===== */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px;
}
.search-bar svg { width: 16px; height: 16px; stroke: var(--text-tertiary); fill: none; stroke-width: 2; flex-shrink: 0; }
.search-bar input { border: none; padding: 0; background: none; font-size: 15px; }
.search-bar input:focus { outline: none; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 13px;
  font-size: 12.5px; font-weight: 500; color: var(--text-secondary);
  background: var(--bg-elevated); cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: white; }

/* ===== Charts ===== */
.chart-wrap { position: relative; height: 190px; }
.chart-wrap.small { height: 170px; }
.chart-wrap.donut { height: 200px; }

/* ===== Settings ===== */
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); gap: 12px; }
.settings-row:last-child { border-bottom: none; }
.settings-row label { font-size: 14.5px; }
.settings-row input[type=number] { width: 100px; text-align: right; }
.segmented { display: flex; background: rgba(127,127,127,0.14); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  flex: 1; border: none; background: none; padding: 7px 4px; border-radius: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--text-secondary); cursor: pointer;
}
.segmented button.active { background: var(--bg-elevated); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

/* Scrollbar tidy */
::-webkit-scrollbar { width: 0; height: 0; }
