@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,600&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #F1F2ED;
  --surface: #FFFFFF;
  --ink: #1C2321;
  --muted: #6B7268;
  --border: #DCDED4;
  --done: #3C6E52;
  --pending-accent: #B5652A;
  --danger: #B5432A;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: inherit; }

html { scroll-padding-top: env(safe-area-inset-top, 0px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.page { min-height: 100%; display: flex; flex-direction: column; }

/* ---- Top bar ---- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 20px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.eyebrow-date {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  flex-basis: 100%;
}
.user-tabs { display: flex; gap: 4px; margin-top: 10px; }
.user-tab {
  padding: 10px 4px;
  text-decoration: none;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-right: 18px;
}
.user-tab.active { color: var(--ink); border-bottom-color: var(--done); }
.topbar-actions { display: flex; gap: 16px; margin-top: 10px; margin-left: auto; }
.ghost-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.ghost-link:hover { color: var(--ink); }

/* ---- Ledger / main content ---- */
.ledger { max-width: 640px; margin: 0 auto; padding: 28px 20px 60px; width: 100%; }
.ledger-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 600;
  font-size: 32px;
  margin: 0 0 22px;
}

/* ---- Add form ---- */
.add-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 28px;
}
.add-form input[type="text"] {
  width: 100%;
  border: none;
  font-size: 17px;
  font-family: inherit;
  padding: 6px 4px 12px;
  background: transparent;
  color: var(--ink);
}
.add-form input[type="text"]:focus { outline: none; }
.add-form-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.add-form select {
  font-family: inherit;
  font-size: 14px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}
.recurrence-sub { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.day-chip { position: relative; cursor: pointer; }
.day-chip input { position: absolute; opacity: 0; }
.day-chip span {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.day-chip input:checked + span {
  background: var(--done);
  border-color: var(--done);
  color: #fff;
}
.inline-label {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.inline-label input {
  width: 56px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-family: inherit;
}
.add-form-row button {
  margin-left: auto;
  background: var(--done);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

/* ---- Item list ---- */
.item-list { list-style: none; margin: 0; padding: 0; }
.item-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
  transition: opacity 0.25s ease;
}
.item-row.completed { opacity: 0.5; }
.item-check-wrap { position: relative; width: 24px; height: 24px; flex-shrink: 0; cursor: pointer; }
.item-check { position: absolute; opacity: 0; width: 24px; height: 24px; cursor: pointer; }
.checkmark {
  position: absolute; inset: 0;
  border: 2px solid var(--muted);
  border-radius: 50%;
  transition: all 0.15s ease;
}
.item-check:checked + .checkmark {
  background: var(--done);
  border-color: var(--done);
}
.item-check:checked + .checkmark::after {
  content: '';
  position: absolute;
  left: 7px; top: 3px;
  width: 6px; height: 11px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.item-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.item-title { font-size: 16px; }
.item-row.completed .item-title { text-decoration: line-through; }
.item-recurrence { font-size: 12px; color: var(--muted); }
.item-delete {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
}
.item-delete:hover { color: var(--danger); }
.empty-state { padding: 30px 4px; color: var(--muted); font-size: 15px; text-align: center; }

/* ---- Auth pages ---- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
}
.auth-card h1 {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 26px;
  margin: 0 0 8px;
}
.auth-sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input {
  font-family: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--ink);
}
.auth-card button, .stacked-form button {
  background: var(--done);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
}
.error { color: var(--danger); font-size: 14px; }
.success { color: var(--done); font-size: 14px; }
.notice { background: var(--surface); border: 1px solid var(--border); padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 20px; }

/* ---- Admin ---- */
.admin-section { margin-bottom: 40px; }
.admin-section h2 { font-family: 'Source Serif 4', Georgia, serif; font-size: 22px; margin-bottom: 10px; }
.section-hint { color: var(--muted); font-size: 13px; margin-top: 0; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 16px; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
.link-button { background: none; border: none; color: var(--pending-accent); cursor: pointer; font-size: 13px; padding: 0; }
.admin-add summary { cursor: pointer; font-size: 14px; color: var(--muted); padding: 8px 0; }
.stacked-form { display: flex; flex-direction: column; gap: 12px; max-width: 320px; margin-top: 12px; }
.stacked-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.stacked-form input, .stacked-form select {
  font-family: inherit; font-size: 15px; padding: 8px 10px;
  border-radius: 6px; border: 1px solid var(--border);
}
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.checkbox-label input { width: auto; }
.inline-form { display: inline; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14170F;
    --surface: #1E2219;
    --ink: #ECEDE5;
    --muted: #A2A897;
    --border: #34392C;
    --done: #5FA37E;
    --pending-accent: #DB9257;
    --danger: #DE7A57;
  }
}
:root[data-theme="dark"] {
  --bg: #14170F;
  --surface: #1E2219;
  --ink: #ECEDE5;
  --muted: #A2A897;
  --border: #34392C;
  --done: #5FA37E;
  --pending-accent: #DB9257;
  --danger: #DE7A57;
}
