:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --text: #1a1a18;
  --text-secondary: #5f5e5a;
  --text-muted: #888780;
  --border: #e1e0d9;
  --accent: #2a78d6;
  --accent-bg: #e6f1fb;
  --warning: #eda100;
  --warning-bg: #faeeda;
  --warning-text: #854f0b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1e1e1c;
    --surface-2: #262624;
    --text: #f1efe8;
    --text-secondary: #b4b2a9;
    --text-muted: #888780;
    --border: #35342f;
    --accent-bg: #0c447c;
    --warning-bg: #412402;
    --warning-text: #fac775;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 20px 0;
}

.hidden { display: none !important; }

h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
p.subtitle { color: var(--text-secondary); font-size: 14px; margin: 0 0 20px; }

label.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

input[type="text"], input[type="email"], input[type="password"], input[type="date"], select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 15px;
  margin-bottom: 16px;
}

button { font-family: inherit; cursor: pointer; }

.btn-primary {
  width: 100%;
  background: var(--text);
  color: var(--bg);
  border: none;
  font-size: 15px;
  font-weight: 600;
  padding: 13px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  padding: 4px 0;
}

.error-text { color: #c0392b; font-size: 13px; margin: -8px 0 12px; }

.card {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
}

.chip-grid, .seg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.chip, .seg {
  padding: 12px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 14px;
  text-align: left;
}

.seg { text-align: center; }

.chip.active, .seg.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.amount-input {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 0 12px;
  margin-bottom: 16px;
}

.amount-input span {
  font-size: 20px;
  color: var(--text-secondary);
  margin-right: 6px;
}

.amount-input input {
  border: none;
  background: transparent;
  font-size: 24px;
  font-weight: 600;
  padding: 12px 0;
  margin: 0;
  width: 100%;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
}

.toggle-row .toggle-label { font-size: 13px; color: var(--text-secondary); margin: 0 0 2px; }
.toggle-row .toggle-value { font-size: 15px; font-weight: 600; margin: 0; }

.switch {
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: var(--border);
  border: none;
  position: relative;
  padding: 0;
  flex-shrink: 0;
}

.switch.on { background: var(--warning); }

.switch .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  transition: transform 0.15s ease;
}

.switch.on .thumb { transform: translateX(20px); }

.metric-label { font-size: 13px; color: var(--text-secondary); margin: 0 0 4px; }
.metric-value { font-size: 26px; font-weight: 600; margin: 0; }

.chart-wrap { position: relative; margin-bottom: 20px; }

.bottom-nav {
  display: flex;
  border-top: 1px solid var(--border);
  margin: auto -20px 0;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  position: sticky;
  bottom: 0;
}

.nav-tab {
  flex: 1;
  background: none;
  border: none;
  text-align: center;
  color: var(--text-muted);
  padding: 6px;
}

.nav-tab.active { color: var(--accent); }
.nav-tab i { font-size: 20px; display: block; margin: 0 auto 2px; }
.nav-tab span { font-size: 11px; }

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.list-row .cat { font-weight: 500; }
.list-row .meta { color: var(--text-muted); font-size: 12px; }

.app-view {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.summary-charts {
  display: block;
}

/* Desktop: sidebar nav instead of bottom tabs, wider forms, charts side by side. */
@media (min-width: 900px) {
  .app-shell { max-width: 1000px; padding: 0; }

  .app-view { flex-direction: row; min-height: 100vh; }

  .bottom-nav {
    order: -1;
    flex-direction: column;
    width: 180px;
    flex-shrink: 0;
    border-top: none;
    border-right: 1px solid var(--border);
    margin: 0;
    padding: 32px 12px;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
  }

  .nav-tab {
    text-align: left;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 4px;
  }

  .nav-tab.active { background: var(--accent-bg); color: var(--accent); }
  .nav-tab span { font-size: 14px; }

  #screen-add, #screen-summary, #screen-export {
    padding: 40px 48px;
    max-width: 640px;
  }

  .chip-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .summary-charts {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
  }

  .summary-charts:has(#trend-wrap.hidden) {
    grid-template-columns: minmax(0, 1fr);
  }

  #trend-wrap, .cat-chart-block { margin-bottom: 0; }
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 10;
}
