:root {
  --bg: #12141c;
  --bg-elev: #1a1d29;
  --bg-elev2: #222738;
  --border: #2b3242;
  --text: #e8eaf0;
  --text-dim: #9aa1b4;
  --accent: #f5c043;
  --accent-ink: #2a2005;
  --accent2: #4cd08a;
  --danger: #f2647c;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(0,0,0,.35);
}
html[data-theme="light"] {
  --bg: #f4f2ec;
  --bg-elev: #ffffff;
  --bg-elev2: #eceadf;
  --border: #ddd8c8;
  --text: #262319;
  --text-dim: #6b6656;
  --accent: #c9821a;
  --accent-ink: #fff7e6;
  --accent2: #1f9d63;
  --danger: #c8324a;
  --shadow: 0 4px 18px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

#shell { display: flex; min-height: 100vh; }

/* --- Gate (auth / create-join family) --- */
#gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; max-width: 380px; width: 100%; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.5rem; }
.auth-card .field { margin-bottom: 10px; }
.auth-card input { width: 100%; }
.auth-card [data-mode][data-active="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* --- Sidebar / nav --- */
#nav {
  width: 220px; flex: 0 0 auto; background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 10px; gap: 4px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 12px;
  border: none; background: transparent; color: var(--text-dim); border-radius: var(--radius);
  font-size: .92rem; font-weight: 600;
}
.nav-btn .ic { font-size: 1.05rem; width: 1.3em; text-align: center; }
.nav-btn:hover { background: var(--bg-elev2); color: var(--text); }
.nav-btn[data-active="true"] { background: var(--accent); color: var(--accent-ink); }

/* --- Header --- */
#main-col { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 22px;
  border-bottom: 1px solid var(--border); background: var(--bg-elev); gap: 12px; flex-wrap: wrap;
}
#topbar .household { font-weight: 700; font-size: 1.05rem; }
#topbar .clock { color: var(--text-dim); font-variant-numeric: tabular-nums; font-size: .9rem; text-align: right; }

#main { flex: 1 1 auto; padding: 22px; overflow-y: auto; }

h2.section-title { margin: 0 0 4px; font-size: 1.3rem; }
p.section-sub { margin: 0 0 18px; color: var(--text-dim); font-size: .88rem; }

.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: .74rem; font-weight: 700; background: var(--bg-elev2); color: var(--text-dim);
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: .74rem; color: var(--text-dim); font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], input[type=email], select, textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: 7px 9px;
}
input[type=color] { width: 40px; height: 32px; padding: 2px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); }
textarea { resize: vertical; min-height: 44px; }

.btn { border: 1px solid var(--border); background: var(--bg-elev2); color: var(--text); border-radius: 7px; padding: 7px 12px; font-weight: 600; font-size: .85rem; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: .78rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.list-clean { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.item-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.item-row.done { opacity: .55; text-decoration: line-through; }
.item-row input[type=checkbox] { width: 18px; height: 18px; }
.item-row .grow { flex: 1; min-width: 0; }
.muted { color: var(--text-dim); }
.empty-note { color: var(--text-dim); font-size: .88rem; padding: 10px 2px; }

form.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }

/* Calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: .72rem; color: var(--text-dim); font-weight: 700; padding-bottom: 4px; }
.cal-day { min-height: 74px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 6px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; text-align: left; }
.cal-day:hover { border-color: var(--accent); }
.cal-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-day.selected { background: var(--bg-elev2); }
.cal-day.other-month { opacity: .35; }
.cal-daynum { font-size: .78rem; font-weight: 700; }
.cal-evt { font-size: .68rem; padding: 1px 4px; border-radius: 4px; background: var(--bg-elev2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Meal grid */
.meal-grid { display: grid; grid-template-columns: 90px repeat(7, 1fr); gap: 6px; }
.meal-grid .hdr { font-size: .74rem; font-weight: 700; color: var(--text-dim); padding: 6px 4px; }
.meal-grid textarea { width: 100%; min-height: 54px; font-size: .82rem; }

table.rewards-tbl { width: 100%; border-collapse: collapse; }
table.rewards-tbl th, table.rewards-tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: .88rem; }

.placeholder-card { border: 1px dashed var(--border); border-radius: var(--radius); padding: 40px 20px; text-align: center; color: var(--text-dim); }
.placeholder-card .big { font-size: 2rem; margin-bottom: 10px; }

@media (max-width: 760px) {
  #shell { flex-direction: column; }
  #nav { width: 100%; flex-direction: row; overflow-x: auto; padding: 8px; border-right: none; border-bottom: 1px solid var(--border); }
  .nav-btn { flex: 0 0 auto; }
  .meal-grid { grid-template-columns: repeat(7, minmax(110px, 1fr)); }
  .meal-grid .hdr:first-child { display: none; }
}
