:root {
  --bg: #f6f1ea;
  --surface: #ffffff;
  --ink: #2a1d18;
  --muted: #6b736e;
  --line: #e8dfd4;
  --accent: #b4532f;
  --accent-ink: #ffffff;
  --accent-soft: #f7e6de;
  --warn: #9a5b13;
  --warn-soft: #fbf0e0;
  --danger: #a33a2b;
  --danger-soft: #fbe9e6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 42, 36, .06), 0 4px 16px rgba(31, 42, 36, .05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
small, .muted { color: var(--muted); }
code { background: #f1ede4; padding: 1px 6px; border-radius: 6px; font-size: .9em; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: #2a1d18; color: #e9e6df; padding: 22px 16px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { font-weight: 800; font-size: 1.2rem; padding: 4px 10px 18px; color: #fff; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.brand svg { width: 34px; height: 34px; flex: none; }
.topbar .mark { width: 26px; height: 26px; }
.brand span { color: #e9a184; }
.side a.nav {
  color: #cfd6d1; text-decoration: none; padding: 9px 12px; border-radius: 10px; display: block; font-size: .95rem;
}
.side a.nav:hover { background: rgba(255,255,255,.06); color: #fff; }
.side a.nav.active { background: rgba(233,161,132,.18); color: #fff; font-weight: 600; }
.side .spacer { flex: 1; }
.side form button { width: 100%; text-align: left; background: none; border: 0; color: #cfd6d1; padding: 9px 12px; font: inherit; cursor: pointer; border-radius: 10px; }
.side form button:hover { background: rgba(255,255,255,.06); color: #fff; }
.main { padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1100px; width: 100%; }
.topbar { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; padding-top: calc(22px + env(safe-area-inset-top)); z-index: 30; transform: translateX(-105%); transition: transform .2s; height: 100%; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: #2a1d18; color: #fff; position: sticky; top: 0; z-index: 20; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; padding: 0 4px; }
  .main { padding-top: 20px; }
}

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat .num { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; }
.stat .lbl { color: var(--muted); font-size: .9rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin: 0; }

label { display: block; font-weight: 600; font-size: .92rem; margin: 0 0 6px; }
.field { margin-bottom: 16px; }
.hint { font-size: .85rem; color: var(--muted); margin-top: 4px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; padding: 11px 13px; border: 1px solid #d4cec2; border-radius: 10px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; }
input[type=color] { width: 56px; height: 42px; border: 1px solid #d4cec2; border-radius: 10px; padding: 3px; background: #fff; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 4px; width: 18px; height: 18px; flex: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px; border-radius: 999px;
  border: 2px solid var(--accent); background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 6px 14px; font-size: .88rem; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.link { background: none; border: 0; color: var(--danger); padding: 4px 6px; font-weight: 500; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; background: var(--accent-soft); color: #7a3518; border: 1px solid #efcdbd; }
.flash.err { background: var(--danger-soft); color: var(--danger); border-color: #efc9c2; }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: #f0dbbd; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button, .tabs a { border: 1px solid var(--line); background: #faf8f3; padding: 7px 14px; border-radius: 999px; font: inherit; font-size: .92rem; cursor: pointer; color: var(--ink); text-decoration: none; }
.tabs button.active, .tabs a.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabpane { display: none; }
.tabpane.active { display: block; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #eee; color: #444; }
.badge.active { background: #e3efe7; color: #1d4a35; }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.unsubscribed { background: var(--danger-soft); color: var(--danger); }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; position: relative; padding: 0 0 14px 42px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: -2px; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; }
.steps li.done::before { content: "✓"; background: var(--accent); color: #fff; }

.copy { display: flex; gap: 8px; }
.copy input { flex: 1; }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 420px; }
.auth .brand { color: var(--ink); justify-content: center; padding: 0 0 18px; font-size: 1.6rem; }
.auth .brand svg { width: 44px; height: 44px; }
.auth .brand span { color: var(--accent); }
.langsw { text-align: center; margin-top: 12px; font-size: .9rem; }
.langsw a { margin: 0 6px; }

/* ---------- Installable app ---------- */
.install { display: none; align-items: center; gap: 16px; }
.install.show { display: flex; }
.install img { width: 52px; height: 52px; border-radius: 14px; flex: none; }
.install .txt { flex: 1; }
.install .txt p { margin: 0; color: var(--muted); font-size: .92rem; }
.install .ios { display: none; font-size: .92rem; color: var(--muted); margin-top: 6px; }
.install.ios-mode .ios { display: block; }
.install.ios-mode .btn { display: none; }
@media (display-mode: standalone) { .install { display: none !important; } }
@media (max-width: 520px) { .install { flex-wrap: wrap; } .install .btn { width: 100%; } }
.badge.booked { background: #e8eef7; color: #2c4a72; }
pre.code { background: #2a1d18; color: #f6f1ea; padding: 14px 16px; border-radius: 12px; overflow-x: auto; font-size: .82rem; line-height: 1.5; white-space: pre; }
details.card summary { cursor: pointer; }
.steps .btn.small { margin-top: 8px; }
/* To-dos */
.nav .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: .75rem; line-height: 20px; text-align: center; font-weight: 700; }
.tasks-card { margin-bottom: 20px; border-left: 4px solid var(--accent); }
ul.tasks { list-style: none; margin: 0; padding: 0; }
ul.tasks li.task { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid #eee5dc; }
ul.tasks li.task:last-child { border-bottom: 0; }
.task form { margin: 0; }
.task .tick { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--accent); background: #fff; color: #fff; font-weight: 700; cursor: pointer; padding: 0; line-height: 1; flex: none; }
.task .tick:hover { background: var(--accent-soft); }
.task.done .tick { background: var(--accent); }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { font-weight: 600; line-height: 1.35; }
.task-meta { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.task.overdue .task-meta strong { color: var(--danger); font-weight: 600; }
.task-day { font-size: .9rem; margin: 14px 0 2px; color: var(--muted); font-weight: 600; }
.task-day:first-of-type { margin-top: 0; }
.tpl-list { display: grid; gap: 10px; margin-bottom: 12px; }
.tpl-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto auto; gap: 10px; align-items: center; }
.tpl-row.off input[type=text] { color: var(--muted); }
.tpl-row.new { padding-top: 10px; border-top: 1px dashed #e2d6ca; }
.tpl-when { display: flex; gap: 6px; }
.tpl-when input[type=number] { width: 64px; }
.tpl-row .check { font-weight: 400; white-space: nowrap; margin: 0; }
@media (max-width: 760px) {
  .tpl-row { grid-template-columns: 1fr 1fr; padding-bottom: 10px; border-bottom: 1px solid #eee5dc; }
  .tpl-row > input[type=text] { grid-column: 1 / -1; }
  .tpl-when { grid-column: 1 / -1; }
  .tpl-when select { flex: 1; }
}
/* Grid children must be allowed to shrink, so wide tables scroll inside .table-wrap instead of widening the page */
.main, .grid > *, .app > * { min-width: 0; }
@media (max-width: 420px) { .grid.cols-2 { grid-template-columns: 1fr; } }
.tpl-link { grid-column: 1 / -1; font-size: .9rem; }
.task-link { margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #2a1d18; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: .9rem; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
