:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2230;
  --muted: #6b7385;
  --line: #e3e6ec;
  --accent: #3b6ef5;
  --accent-soft: #e8eefe;
  --danger: #d6455d;
  --ok: #1f9d6b;
  --warn-bg: #fff6e0;
  --warn-text: #7a5600;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.06), 0 2px 10px rgba(20, 30, 60, 0.05);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --card: #1b1f29;
    --text: #e8ebf2;
    --muted: #9099ad;
    --line: #2a303d;
    --accent: #6f93ff;
    --accent-soft: #232c45;
    --danger: #ff6b81;
    --ok: #4cc795;
    --warn-bg: #3a3016;
    --warn-text: #f2d48a;
    --shadow: none;
    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", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.page {
  max-width: 680px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px calc(var(--safe-bottom) + 24px);
}
.page.with-composer { padding-bottom: calc(var(--safe-bottom) + 96px); }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 8px; min-height: 48px; margin-bottom: 8px; }
.topbar h1 {
  flex: 1; margin: 0; font-size: 1.45rem; font-weight: 700; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar h1.editable { cursor: text; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 40px; height: 40px; padding: 0 10px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); cursor: pointer; font-size: 1.05rem;
}
.icon-btn:hover { background: var(--accent-soft); }
.back-btn {
  display: inline-flex; align-items: center; gap: 2px; flex: none;
  height: 40px; padding: 0 14px 0 8px; margin-right: 4px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 650; font-size: 0.98rem; white-space: nowrap;
}
.back-btn:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.back-btn:active { transform: scale(0.97); }
.back-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.back-btn svg { flex: none; }
.icon-btn.labelled { font-size: 0.95rem; font-weight: 600; color: var(--accent); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { height: 34px; padding: 0 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0 4px; }

input[type=text], input[type=password], input[type=url], select, textarea {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); outline: none;
}
textarea { height: auto; padding: 10px 12px; resize: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 16px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error-text { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; margin: 6px 0 0; }
.banner { background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; padding: 10px 12px; margin: 8px 0 12px; font-size: 0.92rem; }
.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); vertical-align: middle;
}
.badge.grey { background: var(--line); color: var(--muted); }
.badge.green { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.red { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

/* ---------- Auth ---------- */
.auth { max-width: 380px; margin: 10vh auto 0; }
.auth .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 12px; }
.auth h1 { text-align: center; margin: 0 0 4px; font-size: 1.5rem; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 20px; }

/* ---------- Home: lists ---------- */
.new-list { margin-bottom: 14px; }
.lists { list-style: none; margin: 0; padding: 0; }
.list-card {
  display: flex; align-items: center; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 10px;
}
.list-card a { flex: 1; min-width: 0; display: block; padding: 14px 14px 14px 4px; color: var(--text); }
.list-card .card-menu { flex: none; margin-right: 6px; color: var(--muted); font-size: 1.2rem; }
.list-card .title { font-weight: 650; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-card .meta { font-size: 0.85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

.handle {
  flex: none; width: 36px; align-self: stretch; display: flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; font-size: 1.1rem;
  opacity: 0.6;
}
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { box-shadow: 0 6px 24px rgba(20, 30, 60, 0.18); }

/* ---------- List view ---------- */
.access-bar {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 12px; margin-bottom: 8px; cursor: pointer; text-align: left;
}
.access-bar .who { flex: 1; min-width: 0; font-size: 0.9rem; }
.access-bar .who .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.avatars { display: flex; flex: none; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; color: #fff; border: 2px solid var(--card); margin-left: -6px; flex: none;
}
.avatars .avatar:first-child { margin-left: 0; }
.avatar.lg { width: 36px; height: 36px; font-size: 0.9rem; margin-left: 0; border: 0; }
.presence { font-size: 0.82rem; color: var(--ok); margin: 0 0 8px 4px; min-height: 1.2em; }
.presence .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; }

.items { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 2px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px; min-height: 50px;
  transition: opacity 0.2s, background 0.2s;
}
.item .check {
  flex: none; width: 44px; height: 48px; border: 0; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.item .box {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--muted);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px; line-height: 1;
}
.item.checked .box { background: var(--muted); border-color: var(--muted); }
.item .body { flex: 1; min-width: 0; padding: 8px 0; cursor: text; }
.item .text { word-break: break-word; }
.item .meta { font-size: 0.75rem; color: var(--muted); }
.item.has-desc, .item.editing { align-items: flex-start; }
.item .desc {
  font-size: 0.86rem; color: var(--muted); white-space: pre-wrap; word-break: break-word;
  margin-top: 2px; line-height: 1.4;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
}
.item .desc[hidden] { display: none; }
.item.expanded .desc { display: block; -webkit-line-clamp: unset; line-clamp: unset; }
.item.checked .desc { text-decoration: none; }
.readonly .item.has-desc .body { cursor: pointer; }
.item .editor { display: flex; flex-direction: column; gap: 6px; padding: 2px 0 4px; }
.item .edit-desc { min-height: 44px; font-size: 0.92rem; line-height: 1.4; }
.item .editor-actions { display: flex; justify-content: space-between; align-items: center; }
.item.checked { background: transparent; }
.item.checked .text { color: var(--muted); text-decoration: line-through; }
.item.checked .body, .item.checked .handle { opacity: 0.55; }
.item .del {
  flex: none; width: 40px; height: 44px; border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 1.2rem; opacity: 0.45;
}
.item .del:hover { opacity: 1; color: var(--danger); }
.item input.edit { height: 36px; }
.item.flash { animation: flash 1s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } }
.readonly .item .check, .readonly .item .body { cursor: default; }

.list-footer { display: flex; justify-content: space-between; align-items: center; margin: 12px 4px; font-size: 0.88rem; color: var(--muted); }

.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(var(--safe-bottom) + 10px);
}
.composer form { max-width: 680px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 140px; line-height: 1.4; }

/* ---------- Modal sheet ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 15, 30, 0.45);
  display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(var(--safe-bottom) + 20px); animation: rise 0.2s;
}
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.modal header { display: flex; align-items: center; margin-bottom: 10px; }
.modal header h2 { flex: 1; margin: 0; font-size: 1.2rem; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }

.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.people li:last-child { border-bottom: 0; }
.people .info { flex: 1; min-width: 0; }
.people .name { font-weight: 600; }
.people select { width: auto; height: 34px; padding: 0 8px; }
.link-icon {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; flex: none; font-size: 1.05rem;
}

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.seg label {
  display: block; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; background: var(--card);
}
.seg label b { display: block; font-size: 0.95rem; }
.seg label span { font-size: 0.8rem; color: var(--muted); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.seg label:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }

.copy-opts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.copy-opts label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.95rem; }
.copy-opts input { width: 18px; height: 18px; accent-color: var(--accent); }
.copy-preview { font-size: 0.92rem; line-height: 1.45; min-height: 150px; max-height: 45vh; resize: vertical; }
.export-btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.pick-list {
  list-style: none; margin: 0 0 12px; padding: 0; max-height: 280px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 10px;
}
.pick-list li + li { border-top: 1px solid var(--line); }
.pick-list label { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; }
.pick-list li.small { padding: 10px 12px; }
.pick-list input { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.pick-list .grow { flex: 1; min-width: 0; }
.pick-title { font-weight: 600; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.export-btn { height: auto; padding: 12px 14px; justify-content: flex-start; text-align: left; white-space: normal; color: var(--text); }
.export-btn b { display: block; font-size: 1rem; color: var(--accent); }
.export-btn .small { display: block; font-weight: 400; }
.url-box { display: flex; gap: 8px; margin-top: 10px; }
.url-box input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.82rem; }
.qr { display: block; width: 180px; height: 180px; margin: 12px auto 0; background: #fff; border-radius: 10px; padding: 8px; }

table.simple { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.simple td, table.simple th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.simple th { font-size: 0.78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.table-wrap { overflow-x: auto; }

ol.steps { padding-left: 20px; margin: 8px 0; }
ol.steps li { margin-bottom: 4px; }
details summary { cursor: pointer; font-weight: 600; margin: 8px 0; }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 100;
  bottom: calc(var(--safe-bottom) + 90px); display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: #222838; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 0.92rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); animation: rise 0.2s;
}
.toast.error { background: var(--danger); }
.spinner { text-align: center; color: var(--muted); padding: 40px; }
