:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #f5f7fa;
  --border: #d4dae2;
  --border-strong: #b9c2cd;
  --text: #1b2733;
  --muted: #5b6775;
  --accent: #d62828;
  --accent-2: #0d8a6f;
  --blue: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);

  --fms1: #1f8a3b;
  --fms2: #1565c0;
  --fms3: #e6a700;
  --fms4: #e15412;
  --fms6: #6b7280;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 6px 24px; flex-wrap: wrap;
  background: #15202b; padding: 0 22px;
  position: sticky; top: 0; z-index: 1100;
}
.brand { font-size: 18px; font-weight: 700; padding: 14px 0; white-space: nowrap; color: #fff; text-decoration: none; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tab {
  display: inline-block; text-decoration: none; color: #9fb0c0;
  padding: 16px 15px; font-size: 14px; border-bottom: 3px solid transparent;
}
.tab:hover { color: #fff; }
.tab.active { color: #fff; border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 24px 22px; max-width: 1280px; margin: 0 auto; }

/* ---------- Headings / Panels ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 20px; }
.section-head h3 { margin: 0; font-size: 16px; }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow);
}

/* ---------- Three-column incident layout ---------- */
.inc-grid {
  display: grid;
  grid-template-columns: 3fr 1.5fr;
  gap: 0 22px;
  align-items: start;
}
.inc-data {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 0 18px;
  align-items: start;
  min-width: 0;
}
.inc-left, .inc-mid { min-width: 0; }
.inc-right {
  min-width: 0;
  position: sticky;
  top: calc(60px + 1.5rem);
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}
input[readonly], select[disabled], textarea[readonly] {
  background: var(--panel-2);
  color: var(--muted);
  cursor: not-allowed;
}

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card {
  display: block; text-decoration: none; color: inherit; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s, transform .1s;
}
.card:hover { border-color: var(--accent); box-shadow: 0 4px 12px rgba(16,24,40,.10); transform: translateY(-1px); }
.card.archiv { opacity: .7; background: var(--panel-2); }
.card h3 { margin: 0 0 8px; font-size: 15.5px; }
.card .meta { color: var(--muted); font-size: 12.5px; line-height: 1.7; }

/* ---------- Buttons ---------- */
button { font-family: inherit; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: #fff;
  border: 1px solid transparent; padding: 9px 15px; border-radius: 7px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; text-decoration: none; line-height: 1.1;
}
.btn:hover { filter: brightness(.95); }
.btn.secondary { background: #fff; border-color: var(--border-strong); color: var(--text); }
.btn.secondary:hover { background: var(--panel-2); filter: none; }
.btn.ghost { background: #fff; border-color: var(--border); color: var(--muted); font-weight: 500; }
.btn.ghost:hover { color: var(--text); border-color: var(--border-strong); filter: none; }
.btn.danger { background: #b42318; }
.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn.icon { padding: 5px 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.link { color: var(--blue); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }
.back { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 14px; }
.back:hover { color: var(--text); }

/* ---------- Forms ---------- */
form { margin: 0; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
input, select, textarea {
  width: 100%; background: #fff; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 7px; padding: 9px 11px;
  font-size: 13.5px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,235,.25); outline-offset: 0; border-color: var(--blue); }
textarea { resize: vertical; min-height: 64px; }
.field { margin-bottom: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid .full { grid-column: 1 / -1; }
label.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; margin: 0; font-weight: 500; }
label.check input { width: auto; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--panel-2); }
tfoot td { font-weight: 600; border-top: 2px solid var(--border-strong); }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.status-new      { background: #e2e8f0; color: #334155; }
.status-assigned { background: #dbeafe; color: #1e40af; }
.status-active   { background: #dcfce7; color: #166534; }
.status-closed   { background: #e7e5e4; color: #57534e; }
.badge.ok-badge { background: #d1fae5; color: #065f46; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.busy { background: #ffedd5; color: #9a3412; }
.badge.nb   { background: #e7e5e4; color: #57534e; }
.badge.mutter { background: #ede9fe; color: #5b21b6; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 1px 7px; }

/* ---------- Section badge (EA 1–9) ---------- */
.ea-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: #fff; border: 2px solid var(--border-strong);
  font-size: 12px; font-weight: 700; color: var(--text);
  flex-shrink: 0;
}

/* ---------- Strength display ---------- */
.strength { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- FMS ---------- */
.fms-dot {
  width: 28px; height: 28px; border-radius: 7px; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.fms-1 { background: var(--fms1); }
.fms-2 { background: var(--fms2); }
.fms-3 { background: var(--fms3); color: #3b2f00; }
.fms-4 { background: var(--fms4); }
.fms-6 { background: var(--fms6); }

.fms-timeline { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---------- Availability ---------- */
.cand-warn td { background: #fff7ed; }
.ok { color: var(--accent-2); font-weight: 600; font-size: 12.5px; }

/* ---------- Bool icons ---------- */
.bool-yes { color: var(--accent-2); font-size: 16px; }
.bool-no  { color: var(--muted); font-size: 16px; }

/* ---------- KV list ---------- */
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- Rückmeldungen ---------- */
.log { display: flex; flex-direction: column; gap: 8px; }
.log-item { background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--blue); border-radius: 8px; padding: 10px 13px; }
.log-item.status { border-left-color: var(--fms3); background: #fffdf5; }
.log-head { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.log-route { font-weight: 600; color: var(--text); }
.log-msg { font-size: 13.5px; }
.log-actions { display: flex; gap: 12px; margin-top: 6px; }

.duration { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent-2); }

/* ---------- Swap row ---------- */
.swap-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }
.swap-btn { background: #fff; border: 1px solid var(--border-strong); color: var(--text); border-radius: 7px; height: 38px; width: 42px; cursor: pointer; font-size: 16px; }
.swap-btn:hover { border-color: var(--blue); }

/* ---------- Map ---------- */
.map { height: 340px; border-radius: 8px; border: 1px solid var(--border-strong); position: relative; z-index: 0; background: #e8edf2; }
.map-large { height: 620px; }
.map-small { height: 220px; }
.map-search { display: flex; gap: 8px; margin-bottom: 8px; }
.map-search input { flex: 1; }
.map-fallback { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); padding: 16px; text-align: center; }

/* ---------- Modal (dialog) ---------- */
dialog.modal {
  border: none; padding: 0; border-radius: 12px; background: var(--panel); color: var(--text);
  width: min(600px, calc(100vw - 28px)); box-shadow: 0 24px 64px rgba(16,24,40,.30);
}
dialog.modal::backdrop { background: rgba(16,24,40,.45); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 16px; font-weight: 600; }
.modal-body { padding: 18px 20px; max-height: 76vh; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.modal-section-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.modal-section-label:first-child { margin-top: 0; }

/* ---------- Flash ---------- */
.flash { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; padding: 11px 16px; border-radius: 8px; margin-bottom: 18px; font-weight: 500; }
.flash.error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ---------- Rg-list (radio groups on incident) ---------- */
.rg-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.rg-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.rg-badge { background: #ede9fe; color: #5b21b6; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.rg-fn { color: var(--muted); font-size: 12px; }

/* ---------- Utilities ---------- */
.mt { margin-top: 13px; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 28px; font-style: italic; }
.hidden { display: none !important; }

@media (max-width: 1200px) {
  .inc-data { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .inc-grid { grid-template-columns: 1fr; }
  .inc-right { position: static; max-height: none; overflow: visible; }
}
@media (max-width: 640px) {
  .form-grid, .swap-row { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 120px 1fr; gap: 6px 12px; }
  .topbar { padding: 0 12px; }
  .brand { padding: 12px 0; font-size: 16px; }
  .tab { padding: 12px 10px; }
  main { padding: 14px 12px; }
  .panel { padding: 14px; }
  .section-head h2 { font-size: 18px; }
  .panel { overflow-x: auto; }
  table { min-width: 520px; }
}
