:root {
  --color-bg: #0f1117;
  --color-surface: #1a1d27;
  --color-border: #2d3044;
  --color-text: #e8eaf0;
  --color-muted: #7880a0;
  --color-forelder1: #4caf50;
  --color-forelder2: #9c27b0;
  --color-barn1: #f44336;
  --color-barn2: #00bcd4;
  --sidebar-w: 80px;
  --topbar-h: 72px;
  --radius: 12px;
}

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

html, body {
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template:
    "topbar topbar" var(--topbar-h)
    "sidebar content" 1fr
    / var(--sidebar-w) 1fr;
  height: 100dvh;
}

/* ── Topbar ── */
#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  gap: .75rem;
  min-width: 0;
}

#clock-weather {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

#clock-display {
  display: flex;
  align-items: baseline;
  gap: .5rem;
}

#clock-time {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -1px;
}

#clock-date {
  font-size: .9rem;
  color: var(--color-muted);
  text-transform: capitalize;
}

#weather-display {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: 1.3rem;
  font-weight: 600;
  padding-left: .75rem;
  border-left: 1px solid var(--color-border);
}

#weather-icon { width: 30px; height: 30px; }

#weather-credit {
  font-size: .6rem;
  color: var(--color-muted);
  text-align: right;
  line-height: 1.3;
  flex-shrink: 0;
}
#weather-credit a { color: var(--color-muted); }

/* ── Forecast bar (inside topbar) ── */
#forecast-bar {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .15rem;
  overflow-x: auto;
  scrollbar-width: none;
  height: 100%;
}
#forecast-bar::-webkit-scrollbar { display: none; }

.fc-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 46px;
  padding: .2rem .2rem;
  border-radius: 6px;
  flex-shrink: 0;
}
.fc-item.fc-now { background: var(--color-border); }
.fc-time { color: var(--color-muted); font-size: .6rem; }
.fc-icon { width: 20px; height: 20px; }
.fc-temp { font-weight: 700; font-size: .75rem; }
.fc-precip { color: #64b5f6; font-size: .6rem; min-height: .6rem; }

/* ── Sidebar ── */
#sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .75rem .5rem;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: .75rem .25rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  font-size: .65rem;
  line-height: 1;
  width: 100%;
}

.nav-btn svg { width: 28px; height: 28px; fill: currentColor; }

.nav-btn:hover { background: var(--color-border); color: var(--color-text); }
.nav-btn.active { background: var(--color-border); color: var(--color-text); }

/* ── Main content ── */
#content {
  grid-area: content;
  overflow-y: auto;
  padding: 1rem;
}

.tab { display: none; }
.tab.active { display: block; }

/* ── Calendar ── */
#person-bar {
  display: flex;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.person-chip {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .75rem;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 600;
}

.person-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .8rem;
  color: #fff;
}

#calendar-grid {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.cal-day {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.cal-day-header {
  padding: .5rem 1rem;
  font-weight: 700;
  font-size: .9rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: baseline;
  gap: .5rem;
}

.cal-day-header .day-name { color: var(--color-text); }
.cal-day-header .day-date { color: var(--color-muted); font-size: .8rem; }
.cal-day.today .cal-day-header { background: #1e2940; }

.cal-allday-row {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  padding: .4rem 1rem;
  border-bottom: 1px solid var(--color-border);
  min-height: 0;
}
.cal-allday-row:empty { display: none; }

.cal-events { padding: .4rem .5rem; display: flex; flex-direction: column; gap: .25rem; }
.cal-empty { color: var(--color-muted); font-size: .85rem; padding: .4rem 1rem; }

.cal-event {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem .5rem;
  border-radius: 6px;
  font-size: .875rem;
}

.cal-event .evt-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}

.cal-event .evt-time { color: var(--color-muted); font-size: .8rem; min-width: 40px; }
.cal-event .evt-title { flex: 1; }

.cal-chip {
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .8rem;
  color: #fff;
  font-weight: 600;
}

/* ── Chores ── */
#chores-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.chores-col {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.chores-col-header {
  padding: .75rem 1rem;
  font-weight: 700;
  font-size: 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.week-sum { font-size: 1.1rem; font-weight: 700; }

.chore-list { padding: .5rem; }

.chore-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background .1s;
}
.chore-item:hover { background: var(--color-border); }
.chore-item .chore-name { flex: 1; font-size: .9rem; }
.chore-item .chore-kr { color: var(--color-muted); font-size: .85rem; }

.chore-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  flex-shrink: 0;
}
.chore-check.pending { border-color: #ff9800; background: #ff980022; }
.chore-check.approved { border-color: #4caf50; background: #4caf50; }
.chore-check.approved::after { content: '✓'; color: #fff; font-size: .65rem;
  display: flex; align-items: center; justify-content: center; height: 100%; }

.chore-count {
  font-size: .7rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  flex-shrink: 0;
}
.chore-count.empty { min-width: 18px; }
.chore-count.pending { background: #ff980033; color: #ff9800; }
.chore-count.approved { background: #4caf5033; color: #4caf50; }

/* ── Chore log modal ── */
.clog-list { display: flex; flex-direction: column; gap: .5rem; max-height: 55vh; overflow-y: auto; }
.clog-empty { color: var(--color-muted); font-size: .9rem; margin-bottom: .5rem; }
.clog-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .5rem .6rem;
  background: var(--color-bg);
  border-radius: 8px;
}
.clog-row > div { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.clog-time { font-size: .8rem; color: var(--color-muted); }
.clog-pending { font-size: .8rem; color: #ff9800; }
.clog-approved { font-size: .8rem; color: #4caf50; }
.clog-rejected { font-size: .8rem; color: #ef5350; }
.clog-approve-btn, .clog-reject-btn {
  flex-shrink: 0;
  padding: .3rem .7rem;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: .8rem;
  cursor: pointer;
}
.clog-approve-btn { background: #283593; }
.clog-reject-btn { background: #6d2020; }

#savings-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.savings-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.savings-header {
  padding: .75rem 1rem;
  font-weight: 700;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.savings-balance { font-size: 1.4rem; font-weight: 700; }
.savings-txn-list { padding: .5rem; max-height: 200px; overflow-y: auto; }
.savings-txn {
  display: flex;
  justify-content: space-between;
  padding: .4rem .5rem;
  font-size: .8rem;
  border-radius: 4px;
}
.savings-txn.deposit { color: #4caf50; }
.savings-txn.withdrawal { color: #f44336; }
.savings-withdraw-btn {
  margin: .5rem;
  width: calc(100% - 1rem);
  padding: .6rem;
  background: #c62828;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  cursor: pointer;
}

/* ── Tasks ── */
#tasks-grid {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.task-list-card {
  flex: 1;
  min-width: 240px;
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.task-list-header {
  padding: .75rem 1rem;
  font-weight: 700;
  border-bottom: 1px solid var(--color-border);
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: .9rem;
}
.task-item:last-child { border-bottom: none; }
.task-item .task-bullet { color: var(--color-muted); margin-top: 3px; }

/* ── Dinner calendar ── */
.dcal-title {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: capitalize;
  margin-bottom: .6rem;
}

.dcal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.dcal-hdr {
  text-align: center;
  font-size: .7rem;
  font-weight: 600;
  color: var(--color-muted);
  padding: .2rem 0 .4rem;
}

.dcal-day {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: .35rem .4rem;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.dcal-day.today {
  border-color: #4caf50;
  background: #0d1f14;
}

.dcal-num {
  font-size: .65rem;
  font-weight: 700;
  color: var(--color-muted);
}

.dcal-day.today .dcal-num { color: #4caf50; }

.dcal-meal {
  font-size: .72rem;
  color: var(--color-text);
  line-height: 1.2;
  flex: 1;
}

.dcal-day.has-dinner { cursor: pointer; }
.dcal-day.has-dinner:hover { background: #222638; border-color: #4a5080; }
.dcal-day.today.has-dinner:hover { background: #122818; }

.dcal-recipe-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #64b5f6;
  align-self: flex-end;
  flex-shrink: 0;
}

/* ── Recipe modal content ── */
.recipe-meta {
  font-size: .8rem;
  color: var(--color-muted);
  margin-bottom: .75rem;
}
.recipe-h {
  font-size: .85rem;
  font-weight: 700;
  margin: .75rem 0 .3rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.recipe-list {
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .9rem;
}
.recipe-steps { list-style: none; padding-left: 0; }
.recipe-steps li { display: flex; gap: .5rem; }
.recipe-notat {
  margin-top: .75rem;
  font-size: .85rem;
  color: var(--color-muted);
  font-style: italic;
}

/* ── Modal ── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
#modal-overlay.hidden { display: none; }

#modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  padding: 1.5rem;
  min-width: 300px;
  max-width: 90vw;
}
#modal h2 { margin-bottom: 1rem; }
#modal-close {
  margin-top: 1rem;
  width: 100%;
  padding: .7rem;
  background: var(--color-border);
  color: var(--color-text);
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}

.modal-btn {
  display: block;
  width: 100%;
  padding: .8rem;
  margin-bottom: .5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}
.modal-btn.parent { background: #283593; color: #fff; }
.modal-btn.danger { background: #c62828; color: #fff; }

.pin-input {
  width: 100%;
  padding: .75rem;
  margin: .5rem 0;
  font-size: 1.2rem;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  text-align: center;
  letter-spacing: .2em;
}

/* ── Responsive portrait ── */
@media (orientation: portrait), (max-width: 600px) {
  :root { --sidebar-w: 0px; }
  #app {
    grid-template:
      "topbar" var(--topbar-h)
      "content" 1fr
      "sidebar" calc(70px + env(safe-area-inset-bottom, 0px))
      / 1fr;
  }
  #sidebar {
    flex-direction: row;
    justify-content: space-around;
    border-right: none;
    border-top: 1px solid var(--color-border);
    padding: .25rem;
    padding-bottom: calc(.25rem + env(safe-area-inset-bottom, 0px));
    overflow-x: auto;
  }
  #content {
    padding-bottom: calc(1rem + 70px + env(safe-area-inset-bottom, 0px));
  }
  .nav-btn { flex-direction: column; width: auto; padding: .5rem .75rem; }
  #chores-grid { grid-template-columns: 1fr; }
  #savings-section { grid-template-columns: 1fr; }
  #tasks-grid { flex-direction: column; }
}
