:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #17202b;
  --muted: #5d6b7c;
  --border: #d9e0e9;
  --accent: #1a7ad9;
  --accent-text: #ffffff;
  --accent-soft: #e3f0fc;
  --salt: #b45309;
  --salt-soft: #fdf0dc;
  --snow: #1565c0;
  --snow-soft: #e1eefb;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --ok: #1b7f3b;
  --warn: #9a6400;
  --warn-soft: #fff4d6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --surface: #1a212b;
    --surface-2: #232c38;
    --text: #e8edf3;
    --muted: #9aa8b8;
    --border: #2f3a48;
    --accent: #4da3f0;
    --accent-text: #0b1520;
    --accent-soft: #1c3350;
    --salt: #f2b45c;
    --salt-soft: #3a2c14;
    --snow: #7fb8f5;
    --snow-soft: #18304c;
    --danger: #ef8a8a;
    --danger-soft: #3d1c1c;
    --ok: #6fcf8c;
    --warn: #f0c14b;
    --warn-soft: #3a3013;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

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

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.loading { padding: 48px; text-align: center; color: var(--muted); }

/* --- Ramme --- */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 700; font-size: 1.15rem; padding: 4px 10px 2px; }
.org-name { color: var(--muted); font-size: 0.875rem; padding: 0 10px 14px; overflow-wrap: anywhere; }
.nav a {
  display: block;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar .spacer { flex: 1; }
.main { padding: 28px 32px 120px; max-width: 1180px; width: 100%; min-width: 0; }
.page-head { margin-bottom: 20px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px; }
  .nav { display: flex; gap: 4px; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .sidebar .spacer, .sidebar .who { display: none; }
  .main { padding: 20px 16px 120px; }
}

/* --- Byggeklodser --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }

label.field { display: grid; gap: 4px; font-size: 0.875rem; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="time"],
input[type="number"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 40px;
  max-width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input[type="number"] { width: 76px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  min-height: 40px;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; min-height: 0; }
button.icon { padding: 6px 10px; min-height: 36px; }
button:disabled { opacity: 0.5; cursor: default; }

.notice { border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 0.925rem; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--text); }

.tag { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.tag.now { background: var(--danger); color: #fff; }
.tag.ok { background: var(--ok); color: #fff; }
.tag.info { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--danger-soft); color: var(--danger); }
.tag.claim { background: var(--warn); color: #fff; }
a.button {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
}
a.button.primary { background: var(--accent); color: var(--accent-text); }
textarea { width: 100%; resize: vertical; }
.notice a { color: inherit; font-weight: 600; }
.tag.joker { background: var(--surface-2); color: var(--muted); }

/* --- Login --- */
.auth { max-width: 420px; margin: 8vh auto; padding: 0 16px; }
.auth h1 { text-align: center; margin-bottom: 6px; }
.auth .lead { text-align: center; color: var(--muted); margin-bottom: 22px; }
.auth form { display: grid; gap: 12px; }
.auth .switch { text-align: center; margin-top: 14px; }

/* --- Vagtplan --- */
.toolbar { display: flex; gap: 18px; flex-wrap: wrap; align-items: end; }
.week-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 0; }
.week-tabs button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.week-tabs .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-left: 6px; }

.grid-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 860px; }
table.grid th { text-align: left; font-size: 0.8rem; color: var(--muted); font-weight: 600; padding: 6px 6px; }
table.grid th.day { width: 12%; }
table.grid td { padding: 3px; vertical-align: top; }
table.grid tr.slot-head td {
  padding: 16px 6px 4px;
  font-weight: 600;
}
table.grid tr.slot-head .time { color: var(--muted); font-weight: 400; margin-left: 6px; }
table.grid td.role { font-size: 0.8rem; color: var(--muted); padding-top: 12px; white-space: nowrap; width: 110px; }
.cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  min-height: 62px;
  padding: 6px;
  text-align: left;
  border-radius: 8px;
  align-items: stretch;
}
.cell.salt { background: var(--salt-soft); border-color: transparent; }
.cell.snow { background: var(--snow-soft); border-color: transparent; }
.cell:hover { border-color: var(--accent); }
.cell.short { box-shadow: inset 0 0 0 1.5px var(--warn); }
.cell .name { font-size: 0.85rem; line-height: 1.25; overflow-wrap: anywhere; }
.cell.salt .name { color: var(--salt); font-weight: 600; }
.cell.snow .name { color: var(--snow); font-weight: 600; }
.cell .add { color: var(--muted); font-size: 0.8rem; }
.cell .count { font-size: 0.72rem; color: var(--warn); font-weight: 600; margin-top: auto; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); margin-top: 12px; }
.legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.slots-edit .slot-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
details > summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: 12px; }

.load-row { display: grid; grid-template-columns: minmax(110px, 180px) 1fr auto; gap: 10px; align-items: center; padding: 4px 0; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; display: flex; }
.bar .salt { background: var(--salt); }
.bar .snow { background: var(--snow); }

/* --- Lister --- */
.list { display: grid; gap: 8px; }
.list-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: 0; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 0.9rem; color: var(--muted); }
.check input { width: 18px; height: 18px; }

/* --- App-kode --- */
.code-box {
  font: 700 2rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 18px 22px;
  display: inline-block;
  user-select: all;
}
ol.steps { padding-left: 20px; margin: 0; }
ol.steps li { margin-bottom: 6px; }

/* --- Gem-bjælke --- */
.savebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(16, 24, 40, 0.1);
  padding: 12px 20px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  z-index: 10;
}
.savebar .msg { margin-right: auto; font-weight: 600; }

/* --- Vælger --- */
dialog#picker {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(460px, calc(100vw - 24px));
  max-height: min(640px, calc(100vh - 24px));
}
dialog#picker::backdrop { background: rgba(10, 16, 24, 0.5); }
#picker-body { display: flex; flex-direction: column; max-height: inherit; }
.picker-head { padding: 16px 18px 10px; border-bottom: 1px solid var(--border); }
.picker-list { overflow-y: auto; padding: 6px 10px; }
.picker-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.picker-item:hover { background: var(--surface-2); }
.picker-item input { width: 18px; height: 18px; }
.picker-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
