:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #000000;
  --muted: #8e8e93;
  --line: #d1d1d6;
  --accent: #007aff;
  --danger: #ff3b30;
  --check: #007aff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --muted: #8e8e93;
    --line: #38383a;
    --accent: #0a84ff;
    --danger: #ff453a;
    --check: #0a84ff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 80px);
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
.link { color: var(--accent); text-decoration: none; }
.danger { color: var(--danger); }

/* ---------- Toppfelt ---------- */
.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 44px;
}
.bar .link { font-size: 17px; padding: 8px 0; }
.bar .more { font-size: 22px; padding: 4px 6px; letter-spacing: 1px; }
h1 {
  font-size: 32px;
  font-weight: 700;
  margin: 4px 0 6px;
  word-break: break-word;
}

/* ---------- Heim ---------- */
.lists {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
}
.lists li + li .listrow { border-top: 0.5px solid var(--line); }
.listrow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: inherit;
  text-decoration: none;
}
.dot {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-size: 15px; font-weight: 600;
  flex: none;
}
.listrow .name { flex: 1; min-width: 0; }
.listrow .sub { display: block; font-size: 13px; color: var(--muted); }
.listrow .n { color: var(--muted); }
.listrow .chev { color: var(--muted); font-size: 20px; }

.wide {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 4px;
  color: var(--accent);
  font-weight: 500;
}

/* ---------- Listevising ---------- */
.meta {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 10px;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.basisbar {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin: 8px 0 14px;
}
.basisbar p { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.basisbar .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.primary {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 600;
}
.primary:disabled { opacity: .4; }
.secondary {
  border-radius: 10px;
  padding: 9px 14px;
  background: color-mix(in srgb, var(--muted) 18%, transparent);
}
select {
  border: 0.5px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 10px;
  max-width: 100%;
}

.sec { margin-top: 14px; }
.sec-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
  padding: 4px 0;
}
.sec-head .chev {
  width: 26px;
  color: var(--accent);
  font-size: 15px;
  transition: transform .15s;
}
.sec.collapsed .chev { transform: rotate(-90deg); }
.sec-head .sname { flex: 1; min-width: 0; text-align: left; }
.sec-head .count { color: var(--muted); font-size: 15px; font-weight: 400; }
.sec.collapsed .items, .sec.collapsed .add { display: none; }

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 2px;
}
.item, .add {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding-left: 2px;
  border-bottom: 0.5px solid var(--line);
}
.check {
  width: 24px; height: 24px;
  flex: none;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
  display: grid; place-items: center;
}
.check.on { border-color: var(--check); }
.check.on::after {
  content: "";
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--check);
}
.item .text {
  flex: 1;
  min-width: 0;
  padding: 10px 0;
  text-align: left;
  word-break: break-word;
}
.item.done .text { color: var(--muted); }
.basis .item.done .text { color: var(--text); }
.badge {
  font-size: 12px;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 8px;
  padding: 1px 6px;
  white-space: nowrap;
}
.handle {
  flex: none;
  width: 40px;
  align-self: stretch;
  display: grid; place-items: center;
  color: var(--muted);
  font-size: 20px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.add .dashed {
  width: 24px; height: 24px;
  flex: none;
  border-radius: 50%;
  border: 1.5px dashed var(--muted);
}
.add input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 10px 0;
}
.add input::placeholder { color: var(--muted); }

/* ---------- Dra og slepp ---------- */
.dragging-ghost {
  position: fixed;
  z-index: 50;
  background: var(--card);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  border-radius: 10px;
  pointer-events: none;
  padding-right: 4px;
}
.item.placeholder { opacity: .25; }
body.dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }

/* ---------- Ark ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  border-radius: 14px 14px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { margin: 0 0 12px; font-size: 17px; text-align: center; }
.sheet label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.sheet input[type=text], .sheet select {
  width: 100%;
  border: 0.5px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
.sheet .checkrow { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 17px; margin-top: 14px; }
.sheet .checkrow input { width: 20px; height: 20px; }
.sheet .buttons { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.sheet .buttons button { flex: 1; padding: 12px; border-radius: 10px; background: var(--card); font-weight: 500; }
.sheet .buttons .primary { background: var(--accent); color: #fff; }
.sheet .buttons .danger { color: var(--danger); }
.sheet .hint { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* ---------- Melding ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(40,40,40,.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }
