:root {
  --red: #c62828;
  --blue: #1565c0;
  --grey: #616161;
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1c1c1e;
  --text-muted: #6b6f76;
  --border: #e6e7eb;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --card-bg: #232427;
    --text: #f0f0f2;
    --text-muted: #a0a3a8;
    --border: #34363a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

.topbar {
  background: linear-gradient(135deg, var(--red), #8e0000);
  color: white;
  padding: 1.1rem 1.2rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { margin: 0; font-size: 1.2rem; font-weight: 600; }

.tabs {
  display: flex;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 9;
}
.tab-btn {
  flex: 1;
  padding: 0.85rem 0.5rem;
  border: none;
  background: none;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab-btn.active {
  color: var(--red);
  border-bottom-color: var(--red);
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
}
.card h2 {
  margin: 0 0 0.8rem 0;
  font-size: 1.02rem;
  font-weight: 600;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}
.card-header h2 { margin: 0; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.7rem;
}

input, select {
  font-size: 1rem;
  padding: 0.55rem 0.6rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}
input:focus, select:focus { outline: 2px solid var(--red); outline-offset: 1px; }

.form-row { display: flex; gap: 0.7rem; }
.form-row label { flex: 1; min-width: 0; }
.form-row.three label { flex: 1; min-width: 0; }

.form-actions { display: flex; gap: 0.6rem; margin-top: 0.3rem; }

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--red); color: white; flex: 1; }
.btn-primary:active { opacity: 0.85; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

.form-error {
  color: var(--red);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.latest-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.latest-label { font-size: 0.85rem; color: var(--text-muted); }
.latest-values { display: flex; gap: 1.2rem; font-size: 1.3rem; font-weight: 600; }
.latest-values small { display: block; font-size: 0.65rem; font-weight: 400; color: var(--text-muted); }

.badge {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: white;
}

.chart-wrap { position: relative; height: 260px; }
.empty-hint { color: var(--text-muted); font-size: 0.85rem; text-align: center; padding: 1rem 0; }

.entry-list { display: flex; flex-direction: column; gap: 0.5rem; }
.entry-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.2rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.entry-row:last-child { border-bottom: none; }
.entry-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.entry-main { flex: 1; min-width: 0; }
.entry-values { font-weight: 600; }
.entry-meta { color: var(--text-muted); font-size: 0.78rem; }
.entry-note { color: var(--text-muted); font-size: 0.78rem; font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-actions { display: flex; gap: 0.3rem; }
.icon-btn {
  border: none;
  background: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  color: var(--text-muted);
}

.range-quick { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.8rem; }
.range-quick button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.range-quick button.active { background: var(--red); color: white; border-color: var(--red); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.7rem;
}
.stat-tile {
  background: var(--bg);
  border-radius: 10px;
  padding: 0.7rem;
  text-align: center;
}
.stat-tile .val { font-size: 1.3rem; font-weight: 700; }
.stat-tile .lbl { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.15rem; }

.cat-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.cat-table td { padding: 0.4rem 0.3rem; border-bottom: 1px solid var(--border); }
.cat-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; margin-right: 0.5rem; vertical-align: middle; }

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1.2rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 100;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}
.toast.error { background: var(--red); color: white; }

@media (max-width: 420px) {
  .form-row.three { flex-wrap: wrap; }
  .form-row.three label { min-width: 30%; }
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  background: linear-gradient(135deg, var(--red), #8e0000);
}
.login-screen[hidden] { display: none; }
.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.6rem 1.4rem;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  text-align: center;
}
.login-logo { font-size: 2.4rem; margin-bottom: 0.2rem; }
.login-card h1 { font-size: 1.15rem; margin: 0 0 1.2rem 0; }
.login-card label { text-align: left; }
.login-card .btn-primary { width: 100%; margin-top: 0.4rem; }

.account-info { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.8rem; }
