:root {
  --primary: #1d3a6e;
  --primary-ink: #fff;
  --bg: #f3f5f9;
  --surface: #fff;
  --ink: #1b2330;
  --muted: #6b7587;
  --line: #dde2ea;
  --under: #d9480f;
  --under-bg: #fff4e6;
  --room: #2b8a3e;
  --room-bg: #ebfbee;
  --help: #c92a2a;
  --high: #c92a2a;
  --medium: #e67700;
  --low: #5c7cfa;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #4c7bd9;
    --bg: #11151c;
    --surface: #1b212b;
    --ink: #e8ecf2;
    --muted: #96a0b2;
    --line: #2c3442;
    --under: #ff8a4c;
    --under-bg: #33220f;
    --room: #69db7c;
    --room-bg: #14301b;
    --help: #ff6b6b;
  }
}

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

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

main { max-width: 760px; margin: 0 auto; padding: 12px 16px 48px; }

h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

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

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--primary); color: var(--primary-ink);
}
.topbar h1 { font-size: 1.2rem; }

.chip {
  border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.12); color: inherit;
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .9rem; cursor: pointer;
  text-decoration: none; white-space: nowrap; max-width: 55vw; overflow: hidden; text-overflow: ellipsis;
}

/* Filtre */
.filters { display: flex; gap: 8px; margin: 4px 0 14px; }
.filters button {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.filters button.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* Kort */
.task-list { display: grid; gap: 10px; }
.card {
  display: flex; gap: 12px; padding: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  border-left: 6px solid var(--line); cursor: pointer;
}
.card:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.card.state-under { border-left-color: var(--under); background: var(--under-bg); }
.card.state-room { border-left-color: var(--room); background: var(--room-bg); }
.card.status-closed, .card.status-approved { opacity: .65; }
.card.mine { box-shadow: 0 0 0 2px var(--primary) inset; }
.card-body { flex: 1; min-width: 0; }
.card h3 { margin-bottom: 2px; overflow-wrap: anywhere; }
.loc { margin: 2px 0; color: var(--muted); font-size: .92rem; }

.thumb { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; flex-shrink: 0; background: var(--line); }
.thumb.placeholder { display: grid; place-items: center; font-size: 1.8rem; }

.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0 0; font-size: .88rem; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--line); color: var(--ink); }
.prio-high { background: var(--high); color: #fff; }
.prio-medium { background: var(--medium); color: #fff; }
.prio-low { background: var(--low); color: #fff; }
.badge.help { background: var(--help); color: #fff; }
.badge.mine-badge { background: var(--primary); color: #fff; }
.people { font-weight: 600; }
.need { font-weight: 700; }
.state-under .need { color: var(--under); }
.state-room .need { color: var(--room); }

/* Dialoger */
dialog.sheet {
  width: min(560px, 100vw); max-height: 92vh; margin: auto auto 0; padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border: 0; border-radius: 18px 18px 0 0; background: var(--surface); color: var(--ink);
}
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: 18px; } }
dialog::backdrop { background: rgba(0,0,0,.45); }

.sheet-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.icon-btn { border: 0; background: var(--line); color: var(--ink); width: 36px; height: 36px; border-radius: 50%; font-size: 1rem; cursor: pointer; flex-shrink: 0; }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; }
#detail h3 { margin-top: 16px; }
.signups { margin: 6px 0 0; padding-left: 20px; }

.picker-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 55vh; overflow: auto; }
.picker-list button {
  width: 100%; text-align: left; padding: 12px; border: 0; border-bottom: 1px solid var(--line);
  background: none; color: var(--ink); font: inherit; cursor: pointer;
}
.picker-list button:hover, .picker-list button:focus { background: var(--bg); }
.picker-list li.muted { padding: 12px; }
#picker h2 { margin-bottom: 10px; }
#picker .logout { width: 100%; margin-top: 12px; }
.topbar .row > * { flex: 0 0 auto; }
.login-form { display: grid; gap: 12px; max-width: 420px; margin: 40px auto 0; }
.login-form p { margin: 0; }

#lightbox { padding: 0; border: 0; background: transparent; max-width: 100vw; max-height: 100vh; }
#lightbox img { max-width: 100vw; max-height: 100vh; display: block; }

.gallery { display: flex; gap: 8px; overflow-x: auto; margin: 12px 0; }
.gallery img { height: 140px; border-radius: 10px; cursor: zoom-in; }
.gallery.small { flex-wrap: wrap; margin: 8px 0; }
.gallery.small:empty { display: none; }
.gallery figure { position: relative; margin: 0; }
.gallery.small img { width: 80px; height: 80px; object-fit: cover; }
.remove {
  position: absolute; top: 2px; right: 2px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: .75rem; cursor: pointer;
}

/* Knapper og formularer */
.actions { display: grid; gap: 8px; margin-top: 18px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; }
.btn {
  padding: 13px 14px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; min-height: 48px;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn.small { padding: 6px 10px; min-height: 36px; font-size: .9rem; flex: 0 0 auto; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--help); border-color: var(--help); }
.btn.help { background: var(--help); color: #fff; font-size: 1.1rem; min-height: 56px; }
.help-banner { margin: 0; padding: 12px; border-radius: 12px; background: var(--help); color: #fff; font-weight: 600; text-align: center; }

input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: inherit;
}
textarea { resize: vertical; }
label { display: grid; gap: 4px; font-weight: 600; font-size: .92rem; }

/* Admin */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel > h2, .panel-head { margin-bottom: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-head select { width: auto; }
.panel.alert { border: 3px solid var(--help); animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { from { box-shadow: 0 0 0 0 rgba(201,42,42,.0); } to { box-shadow: 0 0 0 8px rgba(201,42,42,.25); } }
.help-list, .member-list { list-style: none; margin: 0; padding: 0; }
.help-list li, .member-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.help-list li:last-child, .member-list li:last-child { border-bottom: 0; }
.task-form { display: grid; gap: 12px; }
.admin-tasks { display: grid; gap: 10px; }
.admin-task { cursor: default; }
.admin-task-head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.admin-task-head select { width: auto; padding: 6px 8px; }
.admin-task .desc { margin: 6px 0; font-size: .92rem; }
.admin-task .row { margin-top: 8px; }
.narrow { max-width: 130px; }
details { margin: 10px 0; }
details form { display: grid; gap: 8px; margin-top: 8px; }
summary { cursor: pointer; color: var(--primary); font-weight: 600; }
#memberSearch { margin: 8px 0; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); opacity: 0;
  padding: 12px 18px; border-radius: 12px; background: #222; color: #fff; z-index: 100;
  transition: .2s; pointer-events: none; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--help); }
