/* ===============================
   Design tokens
   =============================== */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #ffffff;
  --ring: rgba(37, 99, 235, 0.35);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 10px;
}

.dark-mode {
  --bg: #0b1220;
  --surface: #151e30;
  --surface-2: #101828;
  --border: #263248;
  --text: #e6eaf2;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-text: #ffffff;
  --ring: rgba(96, 165, 250, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ===============================
   Base
   =============================== */
* {
  box-sizing: border-box;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  min-height: 100vh;
  padding: 1.5rem 1rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s, color 0.25s;
}

.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

/* ===============================
   Header
   =============================== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ===============================
   Buttons
   =============================== */
.btn,
.theme-toggle {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s,
    box-shadow 0.15s, transform 0.05s;
}

.btn:active,
.theme-toggle:active {
  transform: translateY(1px);
}

.btn:focus-visible,
.theme-toggle:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.theme-toggle {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
  font-size: 0.85rem;
  min-height: 36px;
  padding: 0.35rem 0.8rem;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* ===============================
   Auth row
   =============================== */
.auth-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

/* ===============================
   Controls card
   =============================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
  transition: background-color 0.25s, border-color 0.25s;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field > label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

input[type="date"],
select {
  font: inherit;
  font-size: 1rem; /* ≥16px prevents iOS zoom-on-focus */
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 0.15s, background-color 0.25s, color 0.25s;
}

input[type="date"]:hover,
select:hover {
  border-color: var(--text-muted);
}

.dark-mode input[type="date"] {
  color-scheme: dark; /* native picker + calendar icon follow the theme */
}

.month-buttons {
  display: flex;
  gap: 0.75rem;
}

.month-buttons .btn {
  flex: 1;
}

/* Calendar picker */
.calendar-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 10rem;
  overflow-y: auto;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.calendar-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  cursor: pointer;
  min-height: 28px;
}

.calendar-item input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===============================
   Output & chart
   =============================== */
#output {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin: 0 0 1.25rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-x: auto;
  transition: background-color 0.25s, border-color 0.25s, color 0.25s;
}

#output:empty {
  display: none;
}

/* Chart cards */
.chart-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  transition: background-color 0.25s, border-color 0.25s;
}

.chart-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.chart-title + .hint {
  margin-top: -0.5rem;
}

.chart-subtitle {
  margin: 1rem 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hint {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.chart-wrap {
  position: relative;
  height: 220px;
}

.chart-wrap + .chart-title {
  margin-top: 1.25rem;
}

.donut-wrap {
  position: relative;
  height: 320px;
}

/* ===============================
   Mobile
   =============================== */
@media (max-width: 520px) {
  body {
    padding: 1rem 0.75rem;
  }

  h1 {
    font-size: 1.25rem;
  }

  .auth-row {
    flex-direction: column;
  }

  .auth-row .btn {
    width: 100%;
  }

  .card {
    padding: 1rem;
  }

  .date-grid {
    grid-template-columns: 1fr;
  }

  .month-buttons .btn {
    font-size: 0.9rem;
    padding: 0.55rem 0.5rem;
  }
}
