:root {
  color-scheme: light dark;
  --bg: #fff;
  --orange-h: #e69138;
  --orange-c: rgba(252, 229, 205, .93);
  --blue-h: #6d9eeb;
  --blue-c: rgba(201, 218, 248, .93);
  --ink: #1f2937;
  --muted: #4b5563;
  --line: #fff;
  --field-focus: #fff;
  --code-bg: #f3f4f6;
  --box-bg: #fff7ed;
  --box-line: #fed7aa;
  --btn2-bg: #fff;
  --btn2-line: #d1d5db;
  --danger-bg: #fff;
  --danger-line: #fca5a5;
  --danger-ink: #b91c1c;
  --dock-bg: #fff;
  --dock-line: #e5e7eb;
  --nav-ink: #6b7280;
  --link: #1a56b0;
  --radius: 14px;
  --logo-opacity: .1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --orange-h: #c9772a;
    --orange-c: rgba(230, 145, 56, .2);
    --blue-h: #3d6bb5;
    --blue-c: rgba(109, 158, 235, .2);
    --ink: #e5e7eb;
    --muted: #9ca3af;
    --line: #111418;
    --field-focus: #1f2937;
    --code-bg: #1f2937;
    --box-bg: #2a1f14;
    --box-line: #6b4a24;
    --btn2-bg: #1f2937;
    --btn2-line: #374151;
    --danger-bg: #1f2937;
    --danger-line: #7f2d2d;
    --danger-ink: #f87171;
    --dock-bg: #181b20;
    --dock-line: #2b3037;
    --nav-ink: #9ca3af;
    --link: #8ab4f8;
    --logo-opacity: .07;
  }
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; background: transparent; color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-top: env(safe-area-inset-top);
}

/* Halvtransparent logotyp i bakgrunden (stängs av i config.json) */
body.has-logo::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: url(icons/logo.png) no-repeat center 58% / min(86vw, 460px);
  opacity: var(--logo-opacity);
}

[hidden] { display: none !important; }
.top {
  display: flex; align-items: center; gap: 10px; max-width: 640px; margin: 0 auto;
  padding: 12px 16px 0; font-weight: 800; font-size: 1.15rem; letter-spacing: .2px;
}
.top span { flex: 1; }
.top img { border-radius: 8px; }
button.icon-btn { background: transparent; color: var(--ink); width: 44px; min-width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-right: -8px; }

main { max-width: 640px; margin: 0 auto; padding: 8px 16px 96px; }
h1 { font-size: 1.5rem; margin: 8px 0 12px; }
h2 { font-size: 1.15rem; margin: 24px 0 8px; }

.summary { margin: 4px 0 14px; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .9rem; margin: 8px 0; }
.hint code { background: var(--code-bg); padding: 0 4px; border-radius: 4px; }
.box { background: var(--box-bg); border: 1px solid var(--box-line); border-radius: 8px; padding: 10px 12px; }
.status { min-height: 1.4em; font-size: .95rem; }

/* Kolumnbredder anpassar sig efter innehållet: första kolumnen (avfallstyp) tar all ledig plats, övriga bara det de behöver */
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: auto; }
.grid th, .grid td { text-align: left; padding: 10px 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.grid th { color: #fff; font-weight: 700; font-size: .92rem; }
.orange th { background: var(--orange-h); }
.orange td { background: var(--orange-c); }
.orange tr.next td { font-weight: 700; }
.blue th { background: var(--blue-h); }
.blue td { background: var(--blue-c); padding: 0; }
.grid th:first-child, .orange td:first-child { padding-left: 10px; }
/* Rundade yttre hörn på tabellerna (inte invändigt) */
.grid thead th:first-child { border-top-left-radius: var(--radius); }
.grid thead th:last-child { border-top-right-radius: var(--radius); }
.grid tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
.grid tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
.grid th:last-child, .grid td:last-child { border-right: 0; }

.grid input, .kv input, .kv select {
  width: 100%; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; padding: 10px; min-height: 44px; border-radius: 0;
}
.kv select { appearance: none; -webkit-appearance: none; background: var(--blue-c); border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.grid input:focus, .kv input:focus { outline: 2px solid var(--blue-h); outline-offset: -2px; background: var(--field-focus); }
.grid input[type=number] { text-align: left; }

.kv { display: grid; grid-template-columns: 40% 1fr; margin-top: 12px; }
.kv label { background: var(--blue-h); color: #fff; font-weight: 700; padding: 12px 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.kv input, .kv select { background: var(--blue-c); border: 0; border-bottom: 1px solid var(--line); }
.kv > :nth-child(1) { border-top-left-radius: var(--radius); }
.kv > :nth-child(2) { border-top-right-radius: var(--radius); }
.kv > :nth-last-child(2) { border-bottom-left-radius: var(--radius); }
.kv > :last-child { border-bottom-right-radius: var(--radius); }
.kv > :nth-last-child(-n+2) { border-bottom: 0; }

/* Färgpunkt: i översikten före namnet, och som knapp i inställningarna */
.dot { flex: none; display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; margin-right: 8px;
  box-shadow: inset 0 0 0 1px rgba(128, 128, 128, .55); }
.name-cell { display: flex; align-items: center; }
.name-cell input { flex: 1; min-width: 0; }
button.dot-btn { flex: none; width: 30px; min-width: 30px; height: 44px; min-height: 44px; padding: 0; border-radius: 0; background: transparent; display: flex; align-items: center; justify-content: center; }
button.dot-btn .dot { margin: 0; width: 20px; height: 20px; }
.grid tr.palette td { padding: 8px 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
button.swatch { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(128, 128, 128, .55); }
button.swatch[aria-pressed=true] { border-color: var(--ink); }
button.add-row { width: 100%; margin-top: 10px; background: transparent; color: var(--blue-h); border: 1px dashed var(--blue-h); font-size: 1.3rem; line-height: 1; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
button {
  font: inherit; font-weight: 600; padding: 12px 16px; border-radius: 10px; border: 0;
  background: var(--orange-h); color: #fff; min-height: 46px; cursor: pointer;
}
button.secondary { background: var(--btn2-bg); color: var(--ink); border: 1px solid var(--btn2-line); }
button.danger { background: var(--danger-bg); color: var(--danger-ink); border: 1px solid var(--danger-line); }
button:active { opacity: .85; }

details.hint { margin-top: 12px; }
details summary { cursor: pointer; font-weight: 600; }

/* Nederkant: debugpanel + flikar */
#dock { position: fixed; left: 0; right: 0; bottom: 0; background: var(--dock-bg); border-top: 1px solid var(--dock-line); padding-bottom: env(safe-area-inset-bottom); }
nav { display: flex; }
nav button { flex: 1; background: transparent; color: var(--ink); border-radius: 0; min-height: 60px; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .85rem; }
nav button svg { color: var(--orange-h); }
nav button + button { border-left: 1px solid var(--dock-line); }

#debug { background: #1f2937; color: #e5e7eb; padding: 5px 10px 6px; font-size: .85rem; }
.dbg-head { display: flex; align-items: center; gap: 10px; }
#dbg-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#debug button { background: #374151; color: #fff; min-height: 30px; padding: 3px 8px; border-radius: 8px; font-size: .85rem; }
#debug button#dbg-toggle { background: #b45309; }
.dbg-row { display: flex; gap: 6px; margin-top: 4px; }
.dbg-row > * { flex: 1; }
#debug input { font: inherit; font-size: 16px; min-height: 38px; border-radius: 8px; border: 0; padding: 4px 8px; background: #fff; color: #111; flex: 2; min-width: 0; }

/* Versionsvisning (längst ned vid uppdateringsknappen) och uppdateringsbanner */
.version-block { margin-top: 28px; }
.version-line { text-align: center; margin-top: 6px; }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(10px + env(safe-area-inset-top)); z-index: 60;
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: calc(100% - 32px); box-sizing: border-box; text-align: center;
}
#toast[hidden] { display: none; }

a { color: var(--link); }
.grid input::placeholder { color: var(--muted); opacity: .7; }

.grid th:first-child, .grid td:first-child { width: 100%; }
.grid th:not(:first-child), .grid td:not(:first-child) { width: 1%; }
.grid th:not(:first-child) { white-space: nowrap; }
.orange td:not(:first-child) { white-space: nowrap; padding-left: 10px; padding-right: 10px; }
.blue th:last-child { white-space: normal; }
.grid td input[type=date] { width: auto; min-width: 0; padding: 10px 2px 10px 6px; }
.grid input[type=date]::-webkit-calendar-picker-indicator { margin: 0; padding: 2px; }
.grid td input[type=number] { width: 100%; min-width: 0; padding: 10px 6px; }
.grid td input[data-f=name] { padding-left: 6px; padding-right: 4px; }

/* Inställningstabellen: fasta, förnuftiga bredder för datum och intervall; avfallstyp får resten (alltid mest plats) */
table.grid.blue { table-layout: fixed; }
.blue th:first-child, .blue td:first-child { width: auto; }
.blue th:nth-child(2), .blue td:nth-child(2) { width: 7.5rem; }
.blue th:nth-child(3), .blue td:nth-child(3) { width: 4.4rem; }
.grid td input[type=date] { width: 100%; }
button.dot-btn { width: 26px; min-width: 26px; }
button.dot-btn .dot { width: 16px; height: 16px; }
@media (max-width: 340px) {
  .blue th:nth-child(2), .blue td:nth-child(2) { width: 7.4rem; }
  .blue th:nth-child(3), .blue td:nth-child(3) { width: 4.2rem; }
  .grid th { font-size: .85rem; }
  .kv label { font-size: .88rem; padding-left: 8px; padding-right: 6px; }
}

/* Admin (1.1.1) */
button.icon-btn.rooster { color: #d32f2f; margin-right: -6px; }
button.icon-btn.rooster[hidden] { display: none; }
#server-msg { white-space: pre-wrap; overflow-wrap: anywhere; margin: 14px 0 8px; }
#view-admin textarea { width: 100%; box-sizing: border-box; font: inherit; font-size: 16px; padding: 8px; border-radius: 8px; border: 1px solid var(--box-line); background: var(--box-bg); color: var(--ink); resize: vertical; }
#view-admin .lbl { display: block; margin-top: 8px; font-size: .9rem; }
.chart { margin: 8px 0; border: 1px solid var(--box-line); border-radius: 8px; padding: 6px; background: var(--box-bg); color: var(--ink); }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 10px; }
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet[hidden] { display: none; }
.sheet-box { background: var(--bg, #fff); color: var(--ink); width: 100%; max-width: 640px; box-sizing: border-box; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); border-radius: 16px 16px 0 0; display: flex; flex-direction: column; gap: 10px; }
.sheet-box p { margin: 0 0 4px; }
#dbg-out { margin: 5px 2px 0; font-size: .8rem; line-height: 1.3; color: #d1fae5; max-height: 4.2em; overflow-y: auto; }
#dbg-out.err { color: #fecaca; }
.status { overflow-wrap: anywhere; }
