:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f0efe8;
  --text: #1f2421;
  --muted: #66706a;
  --border: #dedcd2;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e1efe9;
  --done: #2e7d4f;
  --done-soft: #e2f3e8;
  --skip: #6b7280;
  --skip-soft: #eceef1;
  --overdue: #b42318;
  --overdue-soft: #fde8e6;
  --deferred: #a15c07;
  --deferred-soft: #fdf0dc;
  --due: #1d5fbf;
  --due-soft: #e3edfc;
  --prov: #7a4fb5;
  --prov-soft: #efe7fa;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816; --surface: #1c211f; --surface-2: #242a27; --text: #e7ebe8; --muted: #9aa49e; --border: #323a36;
    --accent: #5fb89c; --accent-ink: #0d1512; --accent-soft: #1f3530;
    --done: #63c28a; --done-soft: #1d3326; --skip: #9ca3af; --skip-soft: #2a2e33;
    --overdue: #ff8a7f; --overdue-soft: #3a1f1c; --deferred: #f0b35a; --deferred-soft: #3a2c16;
    --due: #7fb0ff; --due-soft: #1c2a40; --prov: #c4a3f0; --prov-soft: #2d2340;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141816; --surface: #1c211f; --surface-2: #242a27; --text: #e7ebe8; --muted: #9aa49e; --border: #323a36;
  --accent: #5fb89c; --accent-ink: #0d1512; --accent-soft: #1f3530;
  --done: #63c28a; --done-soft: #1d3326; --skip: #9ca3af; --skip-soft: #2a2e33;
  --overdue: #ff8a7f; --overdue-soft: #3a1f1c; --deferred: #f0b35a; --deferred-soft: #3a2c16;
  --due: #7fb0ff; --due-soft: #1c2a40; --prov: #c4a3f0; --prov-soft: #2d2340;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: .95rem; margin: 0; }
h4 { font-size: .85rem; margin: .9rem 0 .3rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
ul { margin: .2rem 0; padding-left: 1.2rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 1.2rem; }
.empty { color: var(--muted); font-style: italic; margin: .4rem 0; }
.error { color: var(--overdue); font-weight: 600; min-height: 1em; margin: 0; }

/* Header & tabs */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.brand-mark { font-size: 1.3rem; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; flex: 1; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: .45rem .75rem; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }

.main { max-width: 1180px; margin: 0 auto; padding: 1rem 16px 4rem; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-weight: 600; font-size: .9rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: .45rem .8rem; cursor: pointer; min-height: 36px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.accent { border-color: var(--accent); color: var(--accent); }
.btn.danger { color: var(--overdue); border-color: color-mix(in srgb, var(--overdue) 40%, var(--border)); }
.btn.tiny { padding: .25rem .55rem; font-size: .8rem; min-height: 30px; }
.btn.icon { width: 36px; padding: 0; font-size: 1.2rem; }
.btn.ghost-btn { background: transparent; border-color: transparent; color: var(--accent); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; min-height: 36px; width: 100%;
}
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* View header */
.view-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; margin-bottom: 1rem;
}
.view-head > div:nth-child(2) { flex: 1; min-width: 200px; }
.view-head h1 { flex: 1; }
.nav-group { display: flex; gap: .35rem; align-items: center; }
.date-input { width: auto; }
.holiday { color: var(--deferred); font-size: .85rem; font-weight: 600; margin-top: .15rem; }

/* Progress */
.progress { display: flex; align-items: center; gap: .5rem; min-width: 140px; }
.progress-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 60px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .25s; }
.progress-fill.full { background: var(--done); }
.progress-text { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Slots & routines */
.slot {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem; margin-bottom: .9rem; box-shadow: var(--shadow);
}
.slot.callout { border-color: color-mix(in srgb, var(--due) 35%, var(--border)); }
.slot.callout.warn { border-color: color-mix(in srgb, var(--overdue) 35%, var(--border)); }
.slot-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }
.slot-head .progress { max-width: 200px; }
.routine { border: 1px dashed var(--border); border-radius: 10px; padding: .4rem; margin: .4rem 0; background: var(--surface-2); }
.routine .task-row { background: var(--surface); }
.routine-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .15rem .3rem .35rem; }
.routine-name { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Task row */
.task-row {
  display: flex; align-items: center; gap: .65rem; padding: .5rem .5rem; border-radius: 8px; margin: .2rem 0;
  border: 1px solid transparent;
}
.task-row:hover { background: var(--surface-2); }
.task-main { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.tid { font-size: .72rem; color: var(--muted); font-weight: 700; margin-right: .35rem; font-variant-numeric: tabular-nums; }
.check {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface);
  color: #fff; font-weight: 800; cursor: pointer; display: grid; place-items: center; font-size: .95rem; padding: 0;
}
.check:hover { border-color: var(--done); }
.check.on { background: var(--done); border-color: var(--done); }
.check.skip { background: var(--skip-soft); border-color: var(--skip); color: var(--skip); }
.check-ghost { flex: none; width: 30px; text-align: center; color: var(--muted); }
.st-done .task-title, .st-skipped .task-title { color: var(--muted); }
.st-done .task-title { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.st-overdue { border-color: color-mix(in srgb, var(--overdue) 30%, transparent); }
.task-row.ghost { opacity: .6; }

.badges { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .2rem; }
.badges.spaced { margin: .6rem 0; }
.badge {
  font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); white-space: nowrap;
}
.badge.warn { color: var(--overdue); background: var(--overdue-soft); border-color: transparent; }
.badge.info { color: var(--due); background: var(--due-soft); border-color: transparent; }
.badge.prov { color: var(--prov); background: var(--prov-soft); border-color: transparent; }
.badge.moved { color: var(--deferred); background: var(--deferred-soft); border-color: transparent; }
.badge.time { color: var(--accent); background: var(--accent-soft); border-color: transparent; font-weight: 600; }
.badge.note { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

.pill {
  flex: none; font-size: .72rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill.done { background: var(--done-soft); color: var(--done); }
.pill.skipped { background: var(--skip-soft); color: var(--skip); }
.pill.overdue { background: var(--overdue-soft); color: var(--overdue); }
.pill.deferred, .pill.moved { background: var(--deferred-soft); color: var(--deferred); }
.pill.due { background: var(--due-soft); color: var(--due); }

/* Week */
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; }
.week-col {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem;
  display: flex; flex-direction: column; gap: .35rem; min-width: 0;
}
.week-col.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.week-day-head {
  display: flex; align-items: baseline; gap: .4rem; border: 0; background: none; padding: 0; color: var(--text);
  cursor: pointer; font: inherit; text-align: left;
}
.week-day-head .wd { font-size: .78rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.week-day-head .dn { font-size: 1.2rem; font-weight: 700; }
.week-col .progress { min-width: 0; }
.daily-sum {
  font: inherit; font-size: .78rem; font-weight: 600; border: 1px dashed var(--border); background: var(--surface-2);
  border-radius: 8px; padding: .3rem .4rem; color: var(--muted); cursor: pointer; text-align: left;
}
.daily-sum.full { color: var(--done); border-color: var(--done); background: var(--done-soft); }
.week-col .task-row { padding: .3rem .2rem; gap: .4rem; }
.week-col .check { width: 24px; height: 24px; font-size: .75rem; }
.week-col .task-title { font-size: .84rem; font-weight: 600; }
.week-col .tid { display: none; }
.empty.small { font-size: .8rem; }
.week-col .badge { white-space: normal; }

/* Month */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow { text-align: center; font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; padding: .25rem 0; }
.cal-cell {
  font: inherit; color: var(--text); text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  min-height: 110px; padding: .3rem; display: flex; flex-direction: column; gap: .2rem; min-width: 0;
}
.cal-cell:hover { border-color: var(--accent); }
.cal-cell.out { opacity: .45; }
.cal-cell.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cal-top { display: flex; justify-content: space-between; align-items: center; }
.cal-num { font-weight: 700; font-size: .9rem; }
.cal-hol { font-size: .66rem; color: var(--deferred); font-weight: 600; line-height: 1.15; }
.chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chip {
  font-size: .68rem; line-height: 1.3; padding: 0 .3rem; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.chip.done { background: var(--done-soft); color: var(--done); text-decoration: line-through; }
.chip.skipped { background: var(--skip-soft); color: var(--skip); }
.chip.overdue { background: var(--overdue-soft); color: var(--overdue); }
.chip.deferred { background: var(--deferred-soft); color: var(--deferred); }
.chip.due { background: var(--due-soft); color: var(--due); }
.chip.more { background: transparent; color: var(--muted); }
.daily-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--border); vertical-align: middle; }
.daily-dot.full { background: var(--done); }
.daily-dot.part { background: var(--deferred); }
.daily-dot.miss { background: var(--overdue); }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .8rem; font-size: .8rem; color: var(--muted); align-items: center; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .75rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem;
  display: flex; flex-direction: column; gap: .3rem; box-shadow: var(--shadow);
}
.card-title { font-weight: 700; }
.trigger { font-size: .84rem; }
.card-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; align-items: center; }

/* Tasks list */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .8rem; }
.filters input[type="search"] { max-width: 280px; }
.filters select { width: auto; }
.check-label { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; cursor: pointer; }
.task-table { display: flex; flex-direction: column; gap: .4rem; }
.task-line {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .75rem;
}
.task-line.inactive { opacity: .6; }
.tl-main { flex: 1; min-width: 220px; cursor: pointer; }
.tl-actions { display: flex; gap: .35rem; flex-wrap: wrap; }

/* History */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; margin-bottom: .5rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem; }
.tile-num { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile-lbl { font-size: .78rem; color: var(--muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.stats { width: 100%; border-collapse: collapse; font-size: .86rem; }
.stats th, .stats td { padding: .4rem .6rem; text-align: right; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats th { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.stats td.bad { color: var(--overdue); font-weight: 700; }
.stats tr:last-child td { border-bottom: 0; }
.feed { display: flex; flex-direction: column; gap: .3rem; }
.feed-row { display: flex; gap: .6rem; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem; }
.feed-row .pill { min-width: 120px; text-align: center; }

/* Settings */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.panel h2 { margin-top: 0; }
details { border-top: 1px solid var(--border); padding: .5rem 0; }
summary { cursor: pointer; font-weight: 600; }
details li { margin: .2rem 0; font-size: .9rem; }

/* Modal */
.modal {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(680px, calc(100vw - 24px));
  max-height: calc(100vh - 40px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal::backdrop { background: rgba(10, 14, 12, .5); }
#modal-body { padding: 1rem 1.1rem 1.2rem; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .3rem; }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.status-line { display: flex; gap: .5rem; align-items: center; margin: .4rem 0 .7rem; flex-wrap: wrap; }
.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin: .7rem 0; }
.resched { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; margin-top: .5rem; }
.resched label { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; font-weight: 600; }
.resched input { width: auto; }
label.block { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; font-weight: 600; }
.details { border-top: 1px solid var(--border); margin-top: .8rem; padding-top: .3rem; font-size: .9rem; }
.details dl { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .9rem; margin: .5rem 0; }
.details dt { color: var(--muted); font-weight: 600; font-size: .82rem; }
.details dd { margin: 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.form-grid > label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; font-weight: 600; }
.form-grid > label.check-label { flex-direction: row; font-weight: 500; }
.span2 { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: .6rem .75rem .75rem; margin: 0; display: flex; flex-direction: column; gap: .6rem; }
fieldset label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; font-weight: 600; }
fieldset.flags { flex-direction: row; flex-wrap: wrap; gap: .5rem 1.2rem; }
fieldset.flags label { flex-direction: row; font-weight: 500; }
legend { font-weight: 700; font-size: .85rem; padding: 0 .3rem; }
.rec-field.row { display: flex; gap: .6rem; flex-wrap: wrap; }
.rec-field.row label { flex: 1; min-width: 120px; }
.rec-field[hidden], #time-wrap[hidden] { display: none !important; }
.lbl { font-size: .85rem; font-weight: 600; display: block; margin-bottom: .25rem; }
.day-boxes { display: flex; flex-wrap: wrap; gap: .3rem; }
.day-box {
  display: inline-flex !important; flex-direction: row !important; align-items: center; gap: .3rem !important;
  border: 1px solid var(--border); border-radius: 8px; padding: .3rem .5rem; font-weight: 600; cursor: pointer;
}
.day-box:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 40px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 999px; font-weight: 600; font-size: .9rem;
  transition: transform .2s, opacity .2s; z-index: 100; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Responsive */
@media (max-width: 900px) {
  .week-grid { grid-template-columns: 1fr; }
  .week-col { flex-direction: column; }
  .week-col .tid { display: inline; }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .app-header { padding: .5rem 16px; gap: .4rem; }
  .brand-name { font-size: .95rem; }
  .tabs { flex-basis: 100%; }
  .cal { gap: 2px; }
  .cal-cell { min-height: 64px; padding: .2rem; }
  .chip { font-size: 0; height: 5px; padding: 0; border-radius: 2px; }
  .chip.more { font-size: .6rem; height: auto; }
  .cal-hol { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .action-grid { grid-template-columns: 1fr 1fr; }
  .pill { display: none; }
  .slot-head .progress { max-width: 120px; min-width: 100px; }
  .feed-row .pill { display: inline-block; min-width: 0; }
  .view-head h1 { font-size: 1.15rem; }
  .date-input { max-width: 150px; }
}
