:root {
  --bg: #fafaf9; --surface: #ffffff; --surface-2: #f4f4f2; --border: #e7e5e2;
  --text: #1c1917; --muted: #78716c; --accent: #ea580c; --accent-soft: #fff1e6;
  --on-accent: #ffffff; --danger: #dc2626; --ok: #16a34a;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f10; --surface: #18181a; --surface-2: #222225; --border: #2c2c30;
    --text: #f4f4f5; --muted: #a1a1aa; --accent: #fb923c; --accent-soft: #33200f;
    --on-accent: #1a0d02; --danger: #f87171; --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f10; --surface: #18181a; --surface-2: #222225; --border: #2c2c30;
  --text: #f4f4f5; --muted: #a1a1aa; --accent: #fb923c; --accent-soft: #33200f;
  --on-accent: #1a0d02; --danger: #f87171; --ok: #4ade80;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- auth pages ---------- */
body.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px 24px; box-shadow: var(--shadow);
}
.logo, .brand { font-weight: 700; letter-spacing: -.02em; }
.logo { color: var(--accent); font-size: 18px; margin-bottom: 20px; }
.card h1 { font-size: 24px; margin: 0 0 8px; letter-spacing: -.02em; }
.hint { color: var(--muted); margin: 0 0 16px; }
.hint.small { font-size: 14px; margin-top: 16px; }
.error {
  background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger);
  border-radius: 10px; padding: 10px 12px; margin: 0 0 16px; font-size: 15px;
}
.card form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 12px 14px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
input.code { font-size: 22px; letter-spacing: .2em; text-align: center; }
.primary {
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: var(--radius);
  padding: 13px 18px; font-weight: 600; text-align: center; text-decoration: none; display: block;
}
.primary:hover { filter: brightness(1.06); }
.qr { display: block; margin: 0 auto 12px; background: #fff; border-radius: 12px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px;
  overflow-wrap: anywhere; }
.codes { list-style: none; padding: 0; margin: 0 0 20px; display: grid;
  grid-template-columns: 1fr 1fr; gap: 8px; }
.codes li { background: var(--surface-2); border-radius: 10px; padding: 10px; text-align: center; }

/* ---------- app shell ---------- */
.top {
  position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 8px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { color: var(--accent); }
.actions { display: flex; justify-content: flex-end; gap: 4px; }
.actions form { margin: 0; }
.icon {
  width: 40px; height: 40px; border: 0; background: transparent; border-radius: 10px;
  font-size: 18px; color: var(--muted);
}
.icon:hover { background: var(--surface-2); color: var(--text); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 8px 18px; border-radius: 9px;
  color: var(--muted); font-weight: 600; min-height: 38px;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.small button { padding: 6px 12px; font-size: 14px; min-height: 34px; }

#view { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; }
.row { display: flex; align-items: center; gap: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 10px; margin: 0 -16px;
  scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 15px; min-height: 40px; white-space: nowrap;
}
.chip .n { color: var(--muted); margin-left: 6px; font-size: 13px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip.on .n { color: inherit; opacity: .8; }
.chip.ghost { border-style: dashed; color: var(--muted); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin: 6px 0 12px; }
.count { color: var(--muted); font-size: 14px; }

.add {
  display: flex; gap: 8px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 6px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.add input { border: 0; background: transparent; padding: 10px; min-width: 0; flex: 1; }
.add select { width: auto; max-width: 40%; border: 0; background: var(--surface-2); padding: 8px 10px; }
.add button {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 10px; font-size: 24px;
  line-height: 1; background: var(--accent); color: var(--on-accent);
}

.tasks { list-style: none; margin: 0; padding: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.task { display: flex; align-items: flex-start; gap: 4px; border-bottom: 1px solid var(--border); }
.task:last-child { border-bottom: 0; }
.check { flex: none; width: 48px; height: 52px; border: 0; background: transparent; display: grid;
  place-items: center; }
.check i {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted);
  display: grid; place-items: center; font-style: normal; font-size: 13px; color: transparent;
}
.check:hover i { border-color: var(--accent); }
.task.done .check i { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.body { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left;
  padding: 13px 14px 13px 0; }
.title { display: block; overflow-wrap: anywhere; }
.task.done .title { color: var(--muted); text-decoration: line-through; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; color: var(--muted); font-size: 13px;
  margin-top: 2px; }
.meta .late { color: var(--danger); font-weight: 600; }
.meta .p1 { color: var(--muted); } .meta .p2 { color: var(--accent); }
.meta .p3 { color: var(--danger); font-weight: 600; }
.sub .check { margin-left: 24px; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }
.empty .primary { display: inline-block; margin-top: 16px; }
.linkish { border: 0; background: none; color: var(--muted); text-decoration: underline;
  font-size: 13px; padding: 12px 0; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 20px; background: var(--surface);
  color: var(--text); padding: 20px; width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 14px; font-size: 19px; letter-spacing: -.01em; }
dialog form { display: grid; gap: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 11px 16px; font-weight: 600; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); margin-right: auto; }
.btn.mini { padding: 8px 10px; font-size: 13px; font-weight: 500; color: var(--muted); flex: none; }

.site { border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 12px; }
.site .row { margin-bottom: 8px; }
.site .row input { padding: 9px 12px; }
.site .rooms { padding-left: 14px; border-left: 2px solid var(--border); margin-left: 4px; }
.site .head input { font-weight: 600; }
.archived { opacity: .6; }
.section { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  margin: 18px 0 8px; }

#toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 16px;
  border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); z-index: 20;
  box-shadow: var(--shadow);
}

@media (max-width: 480px) {
  .brand { font-size: 15px; }
  .two { grid-template-columns: 1fr; }
  dialog { padding: 16px; }
}
