*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f5;
  --surface: #fff;
  --border: #ddd;
  --text: #222;
  --muted: #666;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* ── Auth ── */
.screen { width: 100%; }

#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1rem;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  text-align: center;
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
}

.toggle-auth {
  text-align: center;
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

.toggle-auth a { color: var(--accent); text-decoration: none; }

/* ── Layout ── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

header h1 { font-size: 1.25rem; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
}

nav {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  flex: 1;
  padding: 0.6rem 0.5rem;
  border: none;
  background: none;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-content { display: none; padding: 1rem; max-width: 720px; margin: 0 auto; }
.tab-content.active { display: block; }

/* ── Forms ── */
label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.75rem;
  color: var(--muted);
}

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

button, .btn {
  display: inline-block;
  padding: 0.55rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  width: 100%;
  margin-top: 0.5rem;
}

button:hover { background: var(--accent-hover); }

.btn-sm {
  width: auto;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
  margin: 0;
}

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }

.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }
.status { color: var(--success); font-size: 0.85rem; margin-top: 0.5rem; }

/* ── History ── */
.history-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.history-row .row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.history-row .row-date { font-weight: 600; }

.history-row .row-actions {
  display: flex;
  gap: 0.4rem;
}

.history-row .row-details {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

/* ── Edit modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal h3 { margin-bottom: 1rem; }

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.modal-actions button { flex: 1; }

/* ── Metrics ── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}

.summary-card .card-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.summary-card .card-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

/* ── Responsive ── */
@media (min-width: 600px) {
  .chart-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 400px) {
  header h1 { font-size: 1.1rem; }
  .tab { font-size: 0.82rem; padding: 0.5rem 0.3rem; }
}
