:root {
  --bg: #ffffff;
  --bg-alt: #f5f6f8;
  --border: #dcdfe4;
  --text: #1c1f24;
  --muted: #6a7280;
  --accent: #1f5fbf;
  --accent-dark: #17458c;
  --danger: #c0392b;
  --ok: #2c8a4b;
  --sidebar-width: 400px;
  --radius: 7px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

body {
  display: flex;
  overflow: hidden;
}

/* ---------------------------------------------------------------- Layout */

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

#map { flex: 1; height: 100%; position: relative; }

.app-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.app-header h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

/* Umschaltung zwischen Planen und Plakatieren */
.app-modes {
  display: flex;
  gap: 4px;
  margin: 10px 0 8px;
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 3px;
}
.app-modes .appmode {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--muted);
  border-radius: calc(var(--radius) - 2px);
}
.app-modes .appmode:hover { background: rgba(0, 0, 0, 0.04); }
.app-modes .appmode.active {
  background: var(--bg);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.panel { padding: 14px 18px 28px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.panel-head h2, .panel-head h3 { margin: 0; }

h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
h3 { font-size: 13px; margin: 0 0 8px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { line-height: 1.5; }

/* --------------------------------------------------------------- Controls */

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 7px 12px;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: var(--bg-alt); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--bg-alt); color: var(--text); }
button.danger { color: var(--danger); }
button.small { padding: 5px 9px; font-size: 12px; }
button.back { padding-left: 0; margin-bottom: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--muted); }
.field input[type="text"],
.field input[type="number"],
.field select {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.field input:focus, .field select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.field.slider input[type="range"] { width: 100%; accent-color: var(--accent); }

.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-row .grow { flex: 1; }
.field-row .narrow { width: 92px; flex: none; }

.subsection {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 6px;
}
.subsection > summary { cursor: pointer; list-style: none; }
.subsection > summary::-webkit-details-marker { display: none; }
.subsection > summary h3 { display: inline; }
.subsection > summary::before { content: "▸ "; color: var(--muted); }
.subsection[open] > summary::before { content: "▾ "; }

.actions { display: flex; align-items: center; gap: 8px; margin: 16px 0 6px; }
.actions .primary { flex: 1; }

/* ------------------------------------------------------------ Gebietsliste */

.area-list { list-style: none; margin: 0; padding: 0; }

.area-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--bg);
}
.area-item:hover { background: var(--bg-alt); }
.area-item .dot {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  border: 1px solid rgba(0,0,0,0.25);
}
.area-item .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.area-item .name {
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.area-item .meta { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------- Auswahlinfo */

.selection-summary { margin-bottom: 12px; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 6px 3px 10px;
  font-size: 12px;
}
.chip button {
  border: none; background: none; padding: 0 3px;
  color: var(--muted); font-size: 14px; line-height: 1;
}
.chip button:hover { color: var(--danger); background: none; }

.field-label {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 4px;
}

.mode-buttons { display: flex; gap: 6px; margin-bottom: 8px; }
.mode-buttons .mode { flex: 1; font-size: 12px; padding: 6px 4px; }
.mode-buttons .mode.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.hint-box {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 7px 9px;
  margin: 0 0 12px;
}

/* Zeichenhilfe */
.draw-panel {
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 12px;
}
.draw-status {
  margin: 0 0 8px;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 500;
}
.draw-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.draw-buttons button { flex: 1; white-space: nowrap; }

/* -------------------------------------------------------------- Vorschläge */

.badge {
  display: inline-block;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}

.exports { font-size: 12px; }
.exports a { color: var(--accent); text-decoration: none; margin-left: 8px; }
.exports a:hover { text-decoration: underline; }

.progress {
  height: 5px;
  background: var(--bg-alt);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}
#progress-bar { height: 100%; background: var(--ok); width: 0%; transition: width 0.3s; }

.suggestions { list-style: none; margin: 0; padding: 0; }

.suggestion {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.suggestion.status-gehaengt { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 6%, transparent); }
.suggestion.status-abgelehnt { opacity: 0.55; }
.suggestion.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }

.suggestion-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 10px;
  cursor: pointer;
}
.suggestion-head:hover { background: var(--bg-alt); }
.suggestion .rank {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--muted);
  min-width: 22px;
}
.suggestion .where { flex: 1; min-width: 0; }
.suggestion .street { font-weight: 500; }
.suggestion .sub { font-size: 12px; color: var(--muted); }
.suggestion .score {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.suggestion-body {
  padding: 0 10px 10px 40px;
  border-top: 1px solid var(--border);
}
.reasons { list-style: none; margin: 8px 0; padding: 0; }
.reasons li {
  font-size: 12px;
  line-height: 1.5;
  padding-left: 16px;
  position: relative;
  margin-bottom: 3px;
}
.reasons li::before {
  position: absolute;
  left: 0;
  top: 0;
}
.reasons li.sichtbarkeit::before { content: "👁"; }
.reasons li.dichte::before { content: "🏠"; }
.reasons li.verteilung::before { content: "⊞"; }
.reasons li.manuell::before { content: "✎"; }

.route-start { margin-top: 6px; width: 100%; }

.status-buttons { display: flex; gap: 6px; margin-top: 8px; }
.status-buttons button { font-size: 11px; padding: 4px 8px; flex: 1; }
.status-buttons button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.status-buttons button.on.ok { background: var(--ok); border-color: var(--ok); }

/* -------------------------------------------------------- Plakatiermodus */

.suggestions.compact .suggestion-head { padding: 7px 10px; }
.suggestions.compact .suggestion { margin-bottom: 5px; }
.suggestion.next {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

.postering-bar {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  padding: 12px 14px;
  max-width: 620px;
  margin: 0 auto;
}

.pb-next { display: flex; align-items: center; gap: 12px; }

.pb-rank {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.pb-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pb-street {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pb-sub { font-size: 12px; color: var(--muted); }

.pb-distance { flex: none; text-align: right; display: flex; flex-direction: column; }
.pb-distance b { font-size: 18px; font-variant-numeric: tabular-nums; }
.pb-distance-note { font-size: 11px; color: var(--muted); }

.pb-actions { display: flex; gap: 8px; margin-top: 10px; }
.pb-actions button { flex: 1; padding: 9px 8px; }
.pb-actions .primary { flex: 2; }
.pb-actions button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.pb-status {
  margin: 9px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* ------------------------------------------------------------------ Extras */

#generate-info.warn { color: #a8620f; }

.tools { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 12px; }
.tools > summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.tools-body { padding-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.upload { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.upload input { font-size: 12px; }

.toast {
  position: fixed;
  left: calc(var(--sidebar-width) + 20px);
  bottom: 20px;
  background: #232830;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  z-index: 40;
  max-width: 460px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  line-height: 1.45;
}
.toast.error { background: var(--danger); }

.busy {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 50;
  font-weight: 500;
}
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Kartenpopups */
.maplibregl-popup-content {
  font-family: inherit;
  font-size: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  line-height: 1.5;
}
.maplibregl-popup-content h4 { margin: 0 0 4px; font-size: 13px; }
.popup-reasons { margin: 6px 0 0; padding-left: 16px; }
.popup-reasons li { margin-bottom: 2px; }
.popup-add { margin-top: 8px; width: 100%; }

/* PDF-Export-Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}
.modal-content {
  position: relative;
  background: var(--bg);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  padding: 22px 24px;
  max-width: 420px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-content h3 { margin: 0 0 6px; font-size: 16px; }
.modal-content > .muted { margin: 0 0 12px; font-size: 12px; }

.pdf-area-list {
  overflow-y: auto;
  max-height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.pdf-area-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.pdf-area-check:last-child { border-bottom: none; }
.pdf-area-check:hover { background: var(--bg-alt); }
.pdf-area-check input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.pdf-area-check .meta { font-size: 11px; color: var(--muted); }

.modal-actions { display: flex; gap: 8px; }
.modal-actions .primary { flex: 1; }

@media (max-width: 900px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; min-width: 0; height: 55%; border-right: none; border-bottom: 1px solid var(--border); }
  #map { height: 45%; }
  .toast { left: 20px; right: 20px; max-width: none; }

  /* Beim Plakatieren zählt die Karte – die Liste tritt zurück. */
  body.mode-plakatieren #sidebar { height: 38%; }
  body.mode-plakatieren #map { height: 62%; }
  .postering-bar { left: 8px; right: 8px; bottom: 8px; padding: 10px 11px; }
  .pb-actions button { padding: 11px 6px; }
}
