:root {
  --bg: #f4f5fb;
  --panel: #ffffff;
  --text: #1f2333;
  --muted: #6b7083;
  --line: #e3e5ef;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --danger: #c0392b;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131a;
    --panel: #1c1e28;
    --text: #e8e9f0;
    --muted: #9a9db0;
    --line: #2c2f3d;
    --accent: #7c74ff;
    --accent-soft: #262844;
    --danger: #ff6b5b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-google { font-weight: 600; padding: 0.75rem 1.25rem; }
.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--text); }
input[type="text"], input[type="email"], input:not([type]) {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- screens ---------- */
.screen { min-height: 100%; }
.center { display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.06);
}
.signin-card { text-align: center; max-width: 380px; width: 100%; }
.signin-card h1 { margin: 0.75rem 0 0.25rem; }
.signin-card p { margin: 0.5rem 0 1.25rem; }
.signin-logo { width: 72px; height: 72px; border-radius: 18px; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- app layout ---------- */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  padding-top: max(0.6rem, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 1.15rem; }
.spacer { flex: 1; }
.sync { font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 99px; }
.sync-off { background: #fdecea; color: #a12a1d; }
.sync-busy { background: var(--accent-soft); color: var(--accent); }
.avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 1rem;
  overflow-y: auto;
}
.new-list { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.side-heading {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 1rem 0 0.4rem;
}
.list-nav { list-style: none; margin: 0; padding: 0; }
.nav-btn {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.nav-btn:hover { background: var(--accent-soft); }
.list-nav li.active .nav-btn { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-sub { font-size: 0.75rem; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; overflow-y: auto; padding: 1.25rem; padding-bottom: max(1.25rem, env(safe-area-inset-bottom)); }
#list-view, .empty { max-width: 720px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding-top: 3rem; }
.list-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.list-head h2 { font-size: 1.5rem; word-break: break-word; }
.list-head p { margin: 0.25rem 0 0; word-break: break-word; }
.list-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.add-item { display: flex; gap: 0.5rem; margin: 1.25rem 0 0.75rem; }

.items { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 0.4rem;
  padding-right: 0.3rem;
}
.item-label { flex: 1; display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0.8rem; cursor: pointer; min-width: 0; }
.item-label input { width: 1.25rem; height: 1.25rem; accent-color: var(--accent); flex-shrink: 0; }
.item-text { word-break: break-word; }
.item.done .item-text { text-decoration: line-through; color: var(--muted); }
.list-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 0.75rem; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  width: min(460px, calc(100vw - 2rem));
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dlg { padding: 1.25rem; }
.dlg h2 { font-size: 1.15rem; margin-bottom: 0.4rem; word-break: break-word; }
.row { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.member-list { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.member-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
  word-break: break-all;
}
.dlg-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  max-width: calc(100vw - 2rem);
  z-index: 50;
}
.toast-error { background: var(--danger); color: #fff; }

/* ---------- mobile ---------- */
.only-mobile { display: none; }
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 19; }
@media (max-width: 760px) {
  .only-mobile { display: inline-block; }
  .hide-narrow { display: none; }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 20;
    width: min(300px, 85vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    padding-top: max(1rem, env(safe-area-inset-top));
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 1rem; }
  .list-head h2 { font-size: 1.3rem; }
}
