/* ==========================================================================
   style.css — Parcoursplaner
   ========================================================================== */

:root {
  --accent: #2b6ef2;
  --danger: #d33;
  --bg: #f4f6f9;
  --panel-bg: #ffffff;
  --border: #d6dde5;
  --text: #1c2733;
  --text-muted: #6b7686;
  --grid-line: #dbe2ea;
  --grid-line-major: #b7c2cf;
  --field-bg: #ffffff;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
}
button { font: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0 0 .5em; }

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 26, 33, .55);
  display: flex; align-items: center; justify-content: center; z-index: 500;
}
.modal-box {
  background: var(--panel-bg); border-radius: var(--radius);
  padding: 28px 32px; width: 380px; max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-hint { color: var(--text-muted); font-size: .9em; margin-top: -4px; }
.start-choice-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.start-choice-actions .btn { padding: 12px; font-size: 1em; }

/* ---------------- Hilfe / Bedienungsanleitung ---------------- */
.help-box { width: 640px; max-width: 92vw; max-height: 86vh; padding: 0; display: flex; flex-direction: column; }
.help-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 26px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.help-header h1 { margin: 0; font-size: 1.3em; }
.help-header button { font-size: 1.1em; }
.help-content { padding: 16px 26px 26px; overflow-y: auto; }
.help-content h2 { font-size: 1.02em; margin: 18px 0 6px; color: var(--accent); }
.help-content h2:first-child { margin-top: 0; }
.help-content p { margin: 6px 0; line-height: 1.5; font-size: .92em; }
.help-content ul, .help-content ol { margin: 6px 0; padding-left: 22px; line-height: 1.5; font-size: .92em; }
.help-content li { margin-bottom: 3px; }
.help-content table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: .88em; }
.help-content th, .help-content td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); }
.help-content th { color: var(--text-muted); font-weight: 600; }
.help-content code { background: #eef2f7; border-radius: 4px; padding: 1px 6px; font-size: .92em; }
.help-content hr { border: none; border-top: 1px dashed var(--border); margin: 16px 0 10px; }
.help-content .help-tip { color: var(--text-muted); font-size: .85em; }
.field { display: block; margin-bottom: 14px; }
.field > span:first-child { display: block; font-size: .85em; font-weight: 600; margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: .95em;
}
.field.invalid input, .field.invalid select { border-color: var(--danger); background: #fff5f5; }
.field-error { display: none; color: var(--danger); font-size: .78em; margin-top: 3px; }
.field.invalid .field-error { display: block; }

.btn {
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 12px; font-size: .88em; color: var(--text); white-space: nowrap;
}
.btn:hover { background: #f0f3f7; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #2159c7; }
.btn-danger { background: #fdeceb; border-color: #f2b6b0; color: #a01d0f; }
.btn-danger:hover { background: #fbd8d5; }
.btn-block { width: 100%; padding: 10px; font-weight: 600; }
.btn-plain { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 5px 9px; font-size: .85em; }
.btn-plain:hover { background: #eef2f7; }

/* ---------------- Restore banner ---------------- */
.restore-banner {
  position: fixed; top: 8px; left: 50%; transform: translateX(-50%);
  background: #e8f3e8; border: 1px solid #a9d1a9; color: #1e5c1e;
  padding: 8px 14px; border-radius: 6px; z-index: 400;
  display: flex; align-items: center; gap: 10px; font-size: .88em;
}
.restore-banner button { background: none; border: none; cursor: pointer; color: inherit; font-size: 1em; }
.restore-banner[hidden] { display: none; }

/* ---------------- Top bar ---------------- */
#topBar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 14px; background: var(--panel-bg); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.stammdaten-anzeige { font-size: .85em; color: var(--text-muted); display: flex; gap: 14px; flex-wrap: wrap; }
.stammdaten-anzeige b { color: var(--text); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

/* ---------------- Main layout ---------------- */
#mainArea { display: flex; align-items: flex-start; gap: 0; min-height: calc(100vh - 54px); }

#leftToolbar {
  width: 92px; flex-shrink: 0; background: var(--panel-bg); border-right: 1px solid var(--border);
  padding: 10px 6px; display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 54px; align-self: flex-start;
}
.tool-group { display: flex; flex-direction: column; gap: 4px; }
.tool-group-label { font-size: .72em; color: var(--text-muted); text-align: center; margin-bottom: 2px; }
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: 1px solid transparent; border-radius: 6px;
  padding: 6px 2px; font-size: 1.1em; color: var(--text);
}
.tool-btn span { font-size: .58em; color: var(--text-muted); }
.tool-btn:hover { background: #eef2f7; }
.tool-btn.active { background: #e4edff; border-color: var(--accent); color: var(--accent); }
.tool-btn.active span { color: var(--accent); }

.color-group { align-items: center; }
.color-btn {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff;
  outline: 1px solid var(--border); background: var(--c); margin: 0 auto;
}
.color-btn.active { outline: 2px solid var(--accent); }

/* ---------------- Canvas ---------------- */
#canvasWrap { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 14px 18px; position: relative; min-width: 0; }
#canvasScrollArea { width: 100%; overflow: auto; display: flex; justify-content: center; }
#canvasSvg { background: var(--field-bg); border: 1px solid var(--border); border-radius: 4px; touch-action: none; flex-shrink: 0; }

.view-zoom-controls {
  background: var(--panel-bg); border: 1px solid var(--border); border-radius: 20px;
  padding: 4px 8px; display: flex; align-items: center; gap: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.08);
  margin-bottom: 10px;
}
.view-zoom-controls button { width: 24px; height: 24px; border-radius: 50%; padding: 0; line-height: 1; }
#viewZoomLabel { font-size: .78em; color: var(--text-muted); min-width: 34px; text-align: center; }
.field-bg { fill: #ffffff; }
.grid-line { stroke: var(--grid-line); stroke-width: 1; }
.grid-line-major { stroke: var(--grid-line-major); stroke-width: 1.3; }
.axis-label { font-size: 9px; fill: var(--text-muted); font-family: inherit; }

.element-group { cursor: pointer; }
.element-group.selected { filter: drop-shadow(0 0 0 1px var(--accent)) drop-shadow(0 0 4px var(--accent)); }
.sign-image { pointer-events: bounding-box; }
.sign-fallback-rect { fill: #fff7e0; stroke: #d9b34f; stroke-width: 1.4; }
.sign-fallback-text { font-size: 8px; fill: #6b5410; font-weight: 600; }

.badge-circle { fill: #fff; stroke: #222; stroke-width: 1.3; }
.badge-standalone { fill: #fff2cc; }
.badge-text { font-size: 10px; font-weight: 700; fill: #111; }

.draw-line, .draw-arrow, .draw-paw-base { stroke-width: 2.6; fill: none; }
.draw-arrow { stroke-dasharray: 7 5; }
.draw-paw-base { stroke-width: 1.6; stroke-dasharray: 2 5; opacity: .55; }
.draw-preview { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 4; }
.hurdle-leg { stroke-width: 3; stroke-linecap: round; }
.hurdle-bar { stroke-width: 2.4; }
.pylon-dot { stroke: rgba(0,0,0,.25); stroke-width: .6; }

/* ---------------- Properties panel ---------------- */
.properties-panel {
  position: absolute; right: 22px; top: 18px; background: var(--panel-bg);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12); display: flex; flex-direction: column; gap: 8px; min-width: 180px; z-index: 50;
}
.prop-row { display: flex; align-items: center; gap: 6px; font-size: .82em; }
.prop-row > span:first-child { width: 52px; color: var(--text-muted); }
.prop-row .color-btn { width: 20px; height: 20px; }
.properties-panel[hidden] { display: none; }

/* ---------------- Right panel: sign catalog ---------------- */
#rightPanel {
  width: 300px; flex-shrink: 0; background: var(--panel-bg); border-left: 1px solid var(--border);
  padding: 10px; position: sticky; top: 54px; align-self: flex-start; max-height: calc(100vh - 54px); overflow-y: auto;
}
.class-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.class-tab {
  background: #eef2f7; border: 1px solid var(--border); border-radius: 14px;
  padding: 4px 10px; font-size: .78em; color: var(--text);
}
.class-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.sign-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sign-thumb {
  border: 1px solid var(--border); border-radius: 6px; padding: 4px; text-align: center;
  background: #fbfcfe; cursor: grab; user-select: none;
}
.sign-thumb.msu-marked { border-color: var(--accent); background: #eaf1ff; }
.sign-thumb img { width: 100%; height: 46px; object-fit: contain; pointer-events: none; }
.sign-thumb .fallback-box {
  width: 100%; height: 46px; display: flex; align-items: center; justify-content: center;
  background: #fff7e0; border: 1px dashed #d9b34f; border-radius: 4px; font-size: .62em; font-weight: 700; color: #6b5410;
}
.sign-thumb .sign-id { font-size: .62em; font-weight: 700; margin-top: 3px; }
.sign-thumb .sign-kurztext { font-size: .58em; color: var(--text-muted); line-height: 1.15; height: 2.1em; overflow: hidden; }
.sign-thumb .msu-order-badge {
  display: inline-block; background: var(--accent); color: #fff; border-radius: 50%;
  width: 15px; height: 15px; font-size: .6em; line-height: 15px; margin-top: 2px;
}

.msu-hint { background: #eaf1ff; border: 1px solid #b9d0fb; border-radius: 6px; padding: 8px; margin-bottom: 10px; font-size: .8em; }
.msu-actions { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.msu-drag-handle {
  background: var(--accent); color: #fff; border-radius: 6px; padding: 5px 8px; font-size: .78em; cursor: grab;
}

/* ---------------- Schilderliste ---------------- */
#listView { padding: 16px 24px; background: var(--panel-bg); }
#signTable { width: 100%; border-collapse: collapse; font-size: .9em; }
#signTable th, #signTable td { border-bottom: 1px solid var(--border); padding: 7px 8px; text-align: left; vertical-align: middle; }
#signTable th { color: var(--text-muted); font-size: .82em; font-weight: 600; }
#signTable tr[draggable="true"] { cursor: grab; }
#signTable tr.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.list-thumb { width: 36px; height: 36px; object-fit: contain; }
.list-nr { font-weight: 700; width: 28px; text-align: center; }
.row-delete { color: var(--danger); background: none; border: none; font-size: 1em; }
.msu-tag { color: var(--accent); font-size: .82em; font-weight: 600; }
.list-empty { color: var(--text-muted); padding: 20px 0; }

/* ---------------- Print preview ---------------- */
.print-overlay {
  position: fixed; inset: 0; background: #333c46; z-index: 600; overflow: auto; padding: 20px;
}
.print-toolbar { display: flex; justify-content: space-between; max-width: 1000px; margin: 0 auto 14px; }
.print-sheet { background: #fff; max-width: 1000px; margin: 0 auto; padding: 24px; border-radius: 6px; }
.print-header { display: flex; gap: 20px; flex-wrap: wrap; font-size: .85em; border-bottom: 2px solid #222; padding-bottom: 8px; margin-bottom: 12px; }
.print-header b { display: block; font-size: .75em; color: #666; font-weight: 600; }
.print-canvas-wrap svg { width: 100%; height: auto; display: block; }
.print-page-2 h2 { font-size: 1.1em; margin-bottom: 10px; }
.print-list-wrap table { width: 100%; border-collapse: collapse; font-size: .82em; }
.print-list-wrap th, .print-list-wrap td { border-bottom: 1px solid #ccc; padding: 4px 6px; text-align: left; }
.print-footer { text-align: center; font-size: .74em; margin-top: 8px; padding-top: 6px; border-top: 1px solid #ccc; }
.print-footer a { color: #2b6ef2; text-decoration: none; }
.print-footer a:hover { text-decoration: underline; }

/* Bildschirm-Vorschau: beide Seiten untereinander, mit sichtbarem Abstand */
.print-page-1, .print-page-2 { margin-bottom: 26px; padding-bottom: 20px; border-bottom: 1px dashed #ccc; }
.print-page-2 { border-bottom: none; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  html, body { background: #fff !important; }
  /* Druckausgabe ist immer dunkler Text auf Weiß, unabhängig vom
     OS-Farbschema des Nutzers (siehe @media (prefers-color-scheme: dark)
     weiter unten) — sowohl die Custom Properties (fürs geklonte SVG-Feld)
     als auch "color" (für die geerbte HTML-Textfarbe) werden mit
     !important zurückgesetzt, da die Dark-Mode-Regel weiter unten in der
     Datei steht und bei gleicher Spezifität sonst gewinnen würde. */
  :root {
    --field-bg: #ffffff !important; --grid-line: #dbe2ea !important; --grid-line-major: #b7c2cf !important;
    --text-muted: #6b7686 !important; --border: #d6dde5 !important; --panel-bg: #ffffff !important;
  }
  .print-overlay { color: #1c2733 !important; }
  .field-bg { fill: #ffffff !important; }
  .grid-line { stroke: #dbe2ea !important; }
  .grid-line-major { stroke: #b7c2cf !important; }
  .axis-label { fill: #6b7686 !important; }
  .badge-circle { fill: #ffffff !important; stroke: #222 !important; }
  .badge-text { fill: #111 !important; }
  .sign-fallback-rect { fill: #fff7e0 !important; stroke: #d9b34f !important; }
  .sign-fallback-text { fill: #6b5410 !important; }
  /* display:none statt visibility:hidden: entfernt die übrige App komplett
     aus dem Layout, sonst bliebe ihre (unsichtbare) Höhe erhalten und
     Chromium würde zusätzliche leere Seiten anhängen. */
  body > *:not(.print-overlay) { display: none !important; }
  .print-overlay { position: static; background: #fff; padding: 0; overflow: visible; }
  .print-toolbar { display: none; }
  .print-sheet { box-shadow: none; margin: 0; max-width: none; padding: 0; }

  /* Seite 1: Parcoursfeld füllt die Seite (mit Rand durch @page-margin) */
  .print-page-1 {
    margin: 0; padding: 0; border: none;
    page-break-after: always;
    width: 277mm;    /* A4 quer 297mm − 2×10mm Rand */
    height: 190mm;   /* A4 quer 210mm − 2×10mm Rand */
    display: flex; flex-direction: column;
  }
  .print-header { flex: 0 0 auto; margin-bottom: 4mm; padding-bottom: 2mm; }
  .print-canvas-wrap { flex: 1 1 auto; min-height: 0; }
  .print-canvas-wrap svg { display: block; width: 100%; height: 100%; }
  .print-footer { flex: 0 0 auto; border-color: #ccc !important; }
  .print-footer a { color: #2b6ef2 !important; }

  /* Seite 2: Schilderliste */
  .print-page-2 { margin: 0; padding: 0; border: none; width: 277mm; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1f24; --panel-bg: #262b31; --border: #3a414a; --text: #e7ebef; --text-muted: #9aa5b1;
    --grid-line: #333a42; --grid-line-major: #454e58; --field-bg: #1f242a;
  }
  .sign-fallback-rect { fill: #3a3320; }
  .badge-circle { fill: #262b31; }
}

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  #mainArea { flex-direction: column; }
  #leftToolbar { width: 100%; flex-direction: row; position: static; overflow-x: auto; }
  .tool-group { flex-direction: row; }
  #rightPanel { width: 100%; position: static; max-height: none; }
  .sign-grid { grid-template-columns: repeat(4, 1fr); }
}
