/* Kapacitetsplanlaegger - visuelt sprog laant fra KNOWISION-portalen
   (mork navy, blaa accent, status groen/gul/roed). Ingen afhaengigheder.
   v2: borgerkort med individuel besoegsliste. */

:root {
  color-scheme: dark;
  --bg: #0b0f17;
  --bg2: #0d131f;
  --panel: #121826;
  --panel2: #0f1623;
  --line: #1f2a3b;
  --line2: #243149;
  --text: #e6edf3;
  --muted: #8b9bb4;
  --muted2: #61728c;
  --accent: #3b82f6;
  --accent2: #60a5fa;

  --good: #22c55e;
  --good-bg: rgba(34, 197, 94, .12);
  --good-line: rgba(34, 197, 94, .40);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, .12);
  --warn-line: rgba(245, 158, 11, .40);
  --bad: #ef4444;
  --bad-bg: rgba(239, 68, 68, .12);
  --bad-line: rgba(239, 68, 68, .42);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 12px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(59, 130, 246, .08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'tnum' 1;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 32px 24px 80px; }

/* ---------- Header ---------- */
header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 24px; letter-spacing: .2px; }
.brand p { margin: 6px 0 0; color: var(--muted); font-size: 14px; max-width: 64ch; }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.save-state { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 7px; }
.save-state .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted2); }
.save-state[data-dirty="true"] .dot { background: var(--warn); }
.save-state[data-dirty="false"] .dot { background: var(--good); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line2);
  background: var(--panel); color: var(--text); font-size: 13px; font-weight: 600;
  font-family: inherit; transition: border-color .15s, background .15s, color .15s, transform .05s;
}
.btn:hover { border-color: #3a4a66; background: #161f30; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2f6fe0; border-color: #2f6fe0; }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--bad-line); background: var(--bad-bg); color: #ffd5d5; }
.btn:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

/* ---------- Status banner ---------- */
.status-banner {
  margin-top: 22px; border-radius: var(--radius); border: 1px solid var(--line2);
  background: var(--panel); padding: 20px 22px; display: grid;
  grid-template-columns: auto 1fr auto; gap: 22px; align-items: center; box-shadow: var(--shadow);
}
.status-banner .glyph {
  width: 52px; height: 52px; border-radius: 13px; display: grid; place-items: center;
  background: var(--panel2); border: 1px solid var(--line2);
}
.status-banner .glyph svg { width: 26px; height: 26px; }
.status-banner .headline { font-size: 19px; font-weight: 700; margin: 0; }
.status-banner .sub { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.status-banner .diff { text-align: right; }
.status-banner .diff .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
.status-banner .diff .value { font-size: 30px; font-weight: 750; line-height: 1.1; margin-top: 2px; font-variant-numeric: tabular-nums; }

.status-banner[data-status="under"] { border-color: var(--good-line); }
.status-banner[data-status="under"] .glyph { background: var(--good-bg); border-color: var(--good-line); color: var(--good); }
.status-banner[data-status="balanced"] { border-color: var(--warn-line); }
.status-banner[data-status="balanced"] .glyph { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.status-banner[data-status="over"] { border-color: var(--bad-line); }
.status-banner[data-status="over"] .glyph { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }

/* Difference farves efter FORTEGN: minus = roed (undertid), plus = blaa (overarbejde). */
.diff .value[data-sign="neg"] { color: var(--bad); }
.diff .value[data-sign="pos"] { color: var(--accent2); }
.diff .value[data-sign="zero"] { color: var(--text); }

.util { grid-column: 1 / -1; margin-top: 4px; }
.util-track { height: 9px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); overflow: hidden; }
.util-fill { height: 100%; width: 0; border-radius: 999px; transition: width .3s ease, background .3s ease; background: var(--good); }
.status-banner[data-status="balanced"] .util-fill { background: var(--warn); }
.status-banner[data-status="over"] .util-fill { background: var(--bad); }
.util-meta { display: flex; justify-content: space-between; margin-top: 7px; font-size: 12px; color: var(--muted); }

/* ---------- Section headings ---------- */
.section-head {
  margin: 30px 0 14px; font-size: 12px; font-weight: 700; letter-spacing: 1.6px;
  text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 10px;
}
.section-head.with-action { justify-content: space-between; }
.section-head h2 { margin: 0; font: inherit; display: flex; align-items: center; gap: 10px; }
.section-head .count {
  font-weight: 600; letter-spacing: 0; text-transform: none; font-size: 11px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line); padding: 1px 8px; border-radius: 999px;
}

/* ---------- Settings ---------- */
.settings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.field {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 13px 14px;
}
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.field .input-row { display: flex; align-items: baseline; gap: 8px; }
.field input {
  width: 100%; background: var(--bg2); border: 1px solid var(--line2); border-radius: 7px;
  color: var(--text); font-family: inherit; font-size: 16px; font-weight: 600; padding: 8px 10px;
  font-variant-numeric: tabular-nums;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 130, 246, .18); }
.field input.invalid { border-color: var(--bad-line); box-shadow: 0 0 0 3px var(--bad-bg); }
.field .hint { font-size: 11px; color: var(--muted2); margin-top: 6px; }

/* ---------- Citizen cards ---------- */
.citizens { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); align-items: start; }

.citizen-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}

.cc-head { display: flex; align-items: center; gap: 10px; }
.cc-name {
  flex: 1; min-width: 0; background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px;
  color: var(--text); font-family: inherit; font-size: 15px; font-weight: 600; padding: 9px 11px;
}
.cc-name:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 130, 246, .18); }
.cc-real { text-align: right; line-height: 1.1; flex: none; }
.cc-real-label { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.cc-real-val { display: block; font-size: 21px; font-weight: 750; color: var(--accent2); font-variant-numeric: tabular-nums; margin-top: 2px; }

/* Min-hoejde svarer til 3 besoegsraekker + "Tilfoej besoeg"
   (3 x 37.6 + 3 x 8 gap + 33.2 ~= 170), saa alle kort er lige store - mindst
   plads til 3 besoeg. Kort med 4+ besoeg vokser fortsat. */
.cc-visits { display: flex; flex-direction: column; gap: 8px; min-height: 170px; }
.visit-row { display: flex; align-items: center; gap: 10px; }
.visit-no { flex: 1; font-size: 13px; color: var(--muted); }
.visit-input {
  width: 104px; flex: none; text-align: center; background: var(--bg2); border: 1px solid var(--line2);
  border-radius: 8px; color: var(--text); font-family: inherit; font-size: 15px; font-weight: 600;
  padding: 8px 10px; font-variant-numeric: tabular-nums;
}
.visit-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 130, 246, .18); }
.visit-input.invalid { border-color: var(--bad-line); box-shadow: 0 0 0 3px var(--bad-bg); }

.visit-type {
  width: 104px; flex: none; background: var(--bg2); border: 1px solid var(--line2);
  border-radius: 8px; color: var(--text); font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 8px 10px; cursor: pointer; appearance: none;
}
.visit-type:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 130, 246, .18); }

.icon-btn {
  width: 32px; height: 32px; flex: none; display: inline-grid; place-items: center; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 8px; color: var(--muted);
  transition: color .15s, background .15s, border-color .15s;
}
.icon-btn:hover { color: var(--bad); background: var(--bad-bg); border-color: var(--bad-line); }
.icon-btn svg { width: 16px; height: 16px; }
.cc-del { color: var(--muted2); }

.add-visit {
  display: inline-flex; align-items: center; gap: 7px; align-self: flex-start; cursor: pointer;
  background: transparent; border: 1px dashed var(--line2); border-radius: 8px; color: var(--accent2);
  font-family: inherit; font-size: 13px; font-weight: 600; padding: 7px 12px; margin-top: 2px;
  transition: border-color .15s, background .15s;
}
.add-visit:hover { border-color: var(--accent); background: rgba(59, 130, 246, .08); }
.add-visit svg { width: 14px; height: 14px; }

.cc-breakdown {
  display: flex; flex-wrap: wrap; gap: 6px 16px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted);
}
.cc-breakdown b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.empty-state {
  grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: 14px;
  background: var(--panel); border: 1px dashed var(--line2); border-radius: var(--radius); padding: 40px 16px;
}

/* ---------- Summary ---------- */
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 20px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; }
.chip .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.chip .v { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.chip.accent .v { color: var(--accent2); }
/* Sekundaert tal i en chip (fx telefontider ved siden af besoeg) - mindre og daempet. */
.chip .v .v-sub { font-size: 15px; font-weight: 600; color: var(--muted); }

.drift-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 14px;
  padding: 13px 16px; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--muted);
}
.drift-bar b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.drift-bar .op { color: var(--muted2); font-weight: 700; }
.drift-bar .drift-total { color: var(--text); }
.drift-bar .drift-total b { color: var(--accent2); }

.footer-actions { margin-top: 18px; display: flex; justify-content: flex-end; }

.footnote { margin-top: 26px; color: var(--muted2); font-size: 12px; line-height: 1.6; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel); border: 1px solid var(--good-line); color: var(--text);
  padding: 11px 18px; border-radius: 10px; font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
  display: inline-flex; align-items: center; gap: 9px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { width: 16px; height: 16px; color: var(--good); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3, 6, 12, .68); display: none; place-items: center; z-index: 60; padding: 20px;
}
.modal-backdrop.show { display: grid; }
.modal {
  background: var(--panel); border: 1px solid var(--line2); border-radius: var(--radius);
  max-width: 420px; width: 100%; padding: 24px; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .settings { grid-template-columns: repeat(2, 1fr); }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .citizens { grid-template-columns: 1fr; }
  .status-banner { grid-template-columns: auto 1fr; }
  .status-banner .diff { grid-column: 1 / -1; text-align: left; }
  .status-banner .diff .value { font-size: 26px; }
}
@media (max-width: 520px) {
  .wrap { padding: 22px 14px 60px; }
  .settings, .summary-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
