:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #dfe2e8;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --danger: #c53030;
  --done: #2f9e5a;
  --soft: #eef2fb;
  color-scheme: light;
}

/* theme.js sets data-theme from the switch (or the device's setting before the switch is used). */
:root[data-theme="dark"] {
  --bg: #14171c;
  --card: #1e2229;
  --text: #e6e8ec;
  --muted: #9aa1ad;
  --border: #333944;
  --accent: #5b8ff0;
  --accent-text: #0d1117;
  --danger: #f07171;
  --done: #4cc47e;
  --soft: #252c38;
  color-scheme: dark;
}

/* ---------- dark mode switch ---------- */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .85rem; color: var(--muted); user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 11px;
  background: var(--border);
  transition: background .2s;
  flex-shrink: 0;
}
.switch .thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.login-switch { display: flex; justify-content: center; margin-top: 18px; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; overflow-wrap: anywhere; }

input, textarea, select, button { font: inherit; color: inherit; }

input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--soft); }
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.small { padding: 4px 10px; font-size: .875rem; }
button.link { border: none; background: none; padding: 4px; color: var(--accent); }
button.link:hover { text-decoration: underline; }
button.danger { color: var(--danger); }
button.wide { width: 100%; }
button.icon { padding: 2px 9px; font-size: 1.15rem; line-height: 1.4; border-color: transparent; background: none; }
button.icon:hover { border-color: var(--border); }

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: .9rem; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
}
.login-card .muted { margin: 4px 0 20px; }

/* ---------- app ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.topbar { flex-wrap: wrap; }
.who { font-size: .9rem; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.who .switch { margin-right: 10px; }

.content { max-width: 760px; margin: 0 auto; padding: 20px 16px 60px; }

.group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 18px;
  overflow: hidden;
}
.group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.group-head h2 { flex: 1; }
.group-actions { display: flex; gap: 2px; flex-shrink: 0; }
.progress { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.progress.all-done { color: var(--done); font-weight: 600; }

.rename { display: flex; gap: 6px; flex: 1; }

.items { list-style: none; margin: 0; padding: 0; }
.items > li + li { border-top: 1px solid var(--border); }
.items .empty { padding: 12px 14px; color: var(--muted); font-size: .9rem; }

.item-row { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 14px; }
.item-main { flex: 1; display: flex; align-items: flex-start; gap: 10px; padding: 4px 0; cursor: pointer; min-width: 0; }
.item-main input[type="checkbox"] { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--done); flex-shrink: 0; cursor: pointer; }
.item-text { overflow-wrap: anywhere; }
.item.done .item-text { text-decoration: line-through; color: var(--muted); }
.done-by { font-size: .78rem; color: var(--done); white-space: nowrap; }

.edit-btn { font-size: .82rem; padding: 3px 10px; }
.edit-btn[aria-expanded="true"] { background: var(--soft); }

.item-notes { padding: 0 14px 10px 42px; }
textarea.notes {
  display: block;
  min-height: 0;
  resize: none;
  overflow: hidden;
  padding: 5px 9px;
  font-size: .9rem;
  border-style: dashed;
  background: transparent;
}
.item.has-notes textarea.notes { border-style: solid; background: var(--soft); }
textarea.notes:focus { background: var(--card); }

.item-details { padding: 0 14px 14px 42px; }
.meta { margin: 0; font-size: .78rem; color: var(--muted); }

.add-row { display: flex; gap: 8px; }
.add-item { padding: 10px 14px; border-top: 1px solid var(--border); background: var(--soft); }
.add-group { margin-top: 8px; }

.empty-state { text-align: center; color: var(--muted); padding: 30px 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: .9rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}

@media (max-width: 520px) {
  .item-details, .item-notes { padding-left: 14px; }
  .done-by { display: none; }
  .group-head { flex-wrap: wrap; }
}
