/* Homeschool Planner — mobile-first, light/dark via CSS custom properties. */

:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #26231d;
  --muted: #6b655a;
  --line: #e3ddcf;
  --brand: #2e6e62;
  --brand-ink: #ffffff;
  --brand-soft: #e3eeeb;
  --accent: #c77d2b;
  --ok: #3e8a4f;
  --warn: #b07c1f;
  --danger: #b3433c;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(40, 32, 16, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181611;
    --card: #232019;
    --ink: #ece7dc;
    --muted: #a39b8b;
    --line: #3a352a;
    --brand: #43a08f;
    --brand-ink: #10231f;
    --brand-soft: #27352f;
    --accent: #d99a4e;
    --ok: #5aa36b;
    --warn: #c99b45;
    --danger: #d06a62;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--brand); }

/* ---------- header / tabs / shell ---------- */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--brand);
  color: var(--brand-ink);
  flex-wrap: wrap;
}
.brand { font-family: Georgia, "Times New Roman", serif; font-size: 20px; font-weight: 700; letter-spacing: 0.3px; }
.context { display: flex; gap: 8px; align-items: center; flex: 1; }
.ctx-select {
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 14px;
}
.ctx-select option { color: #222; background: #fff; }
.ctx-label { font-size: 14px; opacity: 0.9; }
.user { display: flex; align-items: center; gap: 8px; }
.family-name { font-size: 14px; opacity: 0.9; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.15);
  color: inherit; font-weight: 700; cursor: pointer; overflow: hidden; padding: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.tabs {
  display: flex; gap: 2px; overflow-x: auto;
  background: var(--brand);
  padding: 0 max(12px, env(safe-area-inset-left)) 0;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: transparent; color: var(--brand-ink);
  opacity: 0.75; padding: 9px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
  border-radius: 10px 10px 0 0;
}
.tab[aria-selected="true"] { background: var(--bg); color: var(--ink); opacity: 1; font-weight: 600; }

#main { max-width: 1060px; margin: 0 auto; padding: 16px; }
.foot { max-width: 1060px; margin: 0 auto; padding: 4px 16px 20px; min-height: 24px; }

/* ---------- generic ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin: 0 0 14px;
}
.card h3 { margin: 0 0 10px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card h4 { margin: 10px 0 6px; font-size: 14px; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }

.btn {
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--card); color: var(--ink);
  padding: 7px 14px; font-size: 14px; cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.big { padding: 12px 22px; font-size: 16px; }
.btn.small-btn { padding: 3px 9px; font-size: 13px; }
.btn.danger, button.danger { color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: default; }

input, select, textarea {
  font: inherit; color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 9px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--brand); flex-shrink: 0; }
input[type="color"] { padding: 0; width: 26px; height: 26px; border-radius: 6px; cursor: pointer; }

.chip {
  display: inline-block; font-size: 12px; border-radius: 99px;
  padding: 1px 9px; margin-left: 6px; vertical-align: 1px;
  background: var(--brand-soft); color: var(--ink); border: 1px solid var(--line);
}
.chip.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); border-color: transparent; }
.chip.ahead { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); border-color: transparent; }
.chip.behind { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); border-color: transparent; }

.progress { height: 7px; border-radius: 99px; background: var(--line); overflow: hidden; min-width: 60px; }
.progress .bar { height: 100%; background: var(--brand); border-radius: 99px; }

.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; margin-right: 6px; flex-shrink: 0; }

.empty { text-align: center; padding: 34px 16px; }
.empty p { margin: 0 0 12px; color: var(--muted); }

/* ---------- sign-in / onboarding ---------- */

.hero-card { max-width: 420px; margin: 8vh auto 0; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 36px 28px; box-shadow: var(--shadow); }
.hero-mark { font-size: 44px; }
.hero-card h1 { font-family: Georgia, serif; margin: 6px 0 4px; }
.hero-card .btn { margin-top: 16px; }
.dev-login { margin-top: 22px; display: flex; gap: 6px; justify-content: center; }
.onboarding { max-width: 460px; margin: 4vh auto 0; }
.onboarding .card { margin-bottom: 16px; }
.onboarding label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }

/* ---------- week tab ---------- */

.week-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.week-title { display: flex; align-items: center; gap: 8px; }
.bump-all { margin-left: auto; }

.week-scroll { overflow-x: auto; border-radius: var(--radius); }
.week-grid {
  display: grid;
  grid-template-columns: minmax(110px, 140px) repeat(var(--cols), minmax(150px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: calc(110px + var(--cols) * 150px);
}
.wg-corner, .wg-day, .wg-subject, .wg-cell { background: var(--card); padding: 8px; }
.wg-day { text-align: center; }
.wg-day.today .wg-date { color: var(--accent); font-weight: 700; }
.wg-day.off, .wg-cell.off { background: color-mix(in srgb, var(--line) 40%, var(--card)); }
.wg-date { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.off-label { font-size: 12px; color: var(--muted); font-style: italic; }
.att-row { display: flex; gap: 4px; justify-content: center; align-items: center; }
.att-chip {
  font-size: 11px; border: 1px dashed var(--line); background: transparent; color: var(--muted);
  border-radius: 99px; padding: 2px 8px; cursor: pointer;
}
.att-chip.on { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); border: 1px solid transparent; font-weight: 600; }
.att-hours { width: 52px; font-size: 12px; padding: 2px 5px; }

.wg-subject { font-weight: 600; font-size: 14px; display: flex; align-items: center; position: sticky; left: 0; z-index: 1; }
.wg-cell { min-height: 64px; display: flex; flex-direction: column; gap: 4px; }

.item { display: flex; align-items: flex-start; gap: 6px; font-size: 14px; }
.item.done .item-text { text-decoration: line-through; color: var(--muted); }
.item-text { flex: 1; cursor: pointer; overflow-wrap: anywhere; }
.item-link { text-decoration: none; margin-left: 3px; }
.bumped { color: var(--warn); font-size: 12px; margin-left: 3px; cursor: help; }
.has-notes { font-size: 12px; margin-left: 3px; cursor: help; }

.item-menu { position: relative; }
.item-menu summary { list-style: none; cursor: pointer; color: var(--muted); padding: 0 4px; border-radius: 6px; }
.item-menu summary::-webkit-details-marker { display: none; }
.item-menu[open] summary { background: var(--line); }
.item-menu .menu {
  position: absolute; right: 0; top: 100%; z-index: 5;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-width: 170px; padding: 4px; gap: 2px;
}
.item-menu .menu button { border: 0; background: transparent; color: var(--ink); text-align: left; padding: 7px 10px; font-size: 13px; border-radius: 7px; cursor: pointer; }
.item-menu .menu button:hover { background: var(--brand-soft); }

.cell-add {
  border: 1px dashed transparent; background: transparent; font-size: 13px;
  padding: 3px 6px; margin-top: auto; width: 100%;
}
.cell-add::placeholder { color: var(--line); }
.wg-cell:hover .cell-add { border-color: var(--line); }
.cell-add:focus { border-color: var(--brand); background: var(--bg); }

.item-edit { display: flex; flex-direction: column; gap: 5px; background: var(--bg); border: 1px solid var(--brand); border-radius: 9px; padding: 7px; }
.item-edit input, .item-edit textarea { font-size: 13px; }

.weekly-checklist { margin-top: 16px; }
.checklist-cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.checklist-col h4 { margin: 0 0 6px; }
.check-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; cursor: pointer; }
.check-row.done { color: var(--muted); text-decoration: line-through; }
.check-row.inactive { opacity: 0.6; font-style: italic; }
.check-row.manage { cursor: default; text-decoration: none; }
.check-row.manage .item-text { text-decoration: none; }

/* ---------- attendance tab ---------- */

.totals .total-big { font-size: 18px; margin-bottom: 8px; }
.totals .total-big strong { font-size: 26px; color: var(--brand); }
.totals .progress { margin-bottom: 8px; }
.day-detail .row { align-items: end; }
.day-detail label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 3px; }

.calendar { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.month h4 { margin: 0 0 8px; color: var(--ink); }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.month-grid .dow { text-align: center; font-size: 11px; color: var(--muted); }
.month-grid .day {
  aspect-ratio: 1; border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; padding: 0;
}
.month-grid .day.school { border-color: var(--line); color: var(--ink); background: var(--bg); }
.month-grid .day.off { background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); }
.month-grid .day.logged { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 700; }
.month-grid .day.today { outline: 2px solid var(--accent); }
.month-grid .day.selected { box-shadow: 0 0 0 2px var(--accent); }
.month-grid .day.outside { visibility: hidden; }
.month-grid .day:disabled { cursor: default; }

/* ---------- curriculum tab ---------- */

.pace-note { margin: 0 0 10px; }
.curr-row { border-top: 1px solid var(--line); padding: 10px 0; }
.curr-row:first-of-type { border-top: 0; }
.curr-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.curr-head .item-menu { margin-left: auto; }
.curr-progress { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.curr-count { font-size: 14px; color: var(--muted); white-space: nowrap; }
.curr-add { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.curr-add input[name="title_"], .curr-add input[name="text"], .curr-add input[name="name"] { flex: 2 1 180px; }
.curr-add input[type="number"] { width: 76px; }
.curr-add input[name="unit"] { width: 90px; }
.curr-edit { position: sticky; top: 8px; z-index: 6; display: flex; flex-direction: column; gap: 7px; border-color: var(--brand); }

/* ---------- checklist tab ---------- */

.checklist-cat .cat-name { cursor: pointer; }
.cat-name:hover { color: var(--brand); }
.checklist-cat h3 { justify-content: space-between; }

/* ---------- records tab ---------- */

.records-add { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.records-add input[name="title_"] { flex: 2 1 160px; }
.score-input { width: 80px; }
.records-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.records-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.records-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.records-table tr.standardized td { background: color-mix(in srgb, var(--brand) 7%, transparent); }
.book-list { display: flex; flex-direction: column; }
.book-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.book-row:first-child { border-top: 0; }
.stars { color: var(--accent); white-space: nowrap; }

/* ---------- requirements tab ---------- */

.req-title { font-family: Georgia, serif; font-size: 20px; margin: 0 0 12px; }
.req.done { opacity: 0.75; }
.req.overdue { border-color: var(--danger); }
.req-head { display: flex; align-items: flex-start; gap: 10px; }
.req-head input[type="checkbox"] { margin-top: 3px; }
.req-detail { margin: 7px 0 0 27px; }
.req-note { width: calc(100% - 27px); margin: 8px 0 0 27px; font-size: 13px; background: transparent; border-style: dashed; }
.req-note:focus { background: var(--bg); border-style: solid; }
.disclaimer { text-align: center; margin-top: 18px; }

/* ---------- setup tab ---------- */

.member-list { display: flex; flex-direction: column; }
.member-row { display: flex; align-items: center; gap: 9px; padding: 6px 0; border-top: 1px solid var(--line); }
.member-row:first-child { border-top: 0; }
.member-row.archived { opacity: 0.55; }
.member-pic { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.member-pic.initial { background: var(--brand-soft); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.invite-box { margin-top: 8px; }
.invite-code { display: block; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0; font-size: 13px; overflow-wrap: anywhere; }
.year-row { border-top: 1px solid var(--line); padding: 8px 0; }
.year-row summary { cursor: pointer; }
.year-form { margin: 10px 0; }
.dow-row { font-size: 14px; color: var(--muted); }
.dow-label { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; margin-right: 2px; }
.days-off { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.add-year summary { list-style: none; display: inline-block; cursor: pointer; margin-top: 6px; }
.add-year summary::-webkit-details-marker { display: none; }
.color-swatch { border: 1px solid var(--line); }

/* ---------- quick print of the current tab ---------- */

@media print {
  .top, .tabs, .foot, .week-nav button, .bump-all, .cell-add, .item-menu, .curr-add, .records-add, .dev-login { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .week-grid { box-shadow: none; }
  #main { max-width: none; padding: 0; }
}

@media (max-width: 640px) {
  .top { gap: 8px; }
  .family-name { display: none; }
  #main { padding: 10px; }
  .week-grid { grid-template-columns: minmax(92px, 110px) repeat(var(--cols), minmax(140px, 1fr)); min-width: calc(92px + var(--cols) * 140px); }
}
