:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #1e3a8a;
  --primary-hover: #1d4ed8;
  --accent: #eab308;
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --radius: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 390px;
  max-width: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.06);
}

.brand-header {
  padding: 16px 18px 12px;
  background: var(--primary);
  color: #ffffff;
}

.brand-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lang-switch {
  display: flex;
  gap: 4px;
}

.lang-btn {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s, background 0.15s;
}

.lang-btn:hover,
.lang-btn.active {
  opacity: 1;
  background: rgba(255, 255, 255, 0.28);
  border-color: #ffffff;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.brand-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.78rem;
  opacity: 0.85;
}

.data-status {
  margin-top: 8px;
  font-size: 0.72rem;
  opacity: 0.8;
}

/* Search Section */
.search-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box input {
  width: 100%;
  padding: 10px 34px 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

.search-box input:focus {
  border-color: var(--primary);
}

.clear-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
}

.kazerne-filter {
  margin-top: 10px;
}

.kazerne-filter label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.kazerne-filter select,
.gate-selector-wrap select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  background: var(--bg);
  color: var(--text);
}

/* Results */
.results-section {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.results-header {
  padding: 8px 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.results-list {
  list-style: none;
}

.result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.result-item:hover,
.result-item.active {
  background: #f1f5f9;
}

.result-title {
  font-weight: 600;
  font-size: 0.94rem;
  color: var(--text);
}

.result-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Detail Panel */
.detail-panel {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  margin-bottom: 12px;
  padding: 4px 0;
}

.detail-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.badge {
  display: inline-block;
  align-self: flex-start;
  background: #e2e8f0;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}

.detail-card h2 {
  font-size: 1.15rem;
  line-height: 1.3;
}

.detail-meta {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.gate-selector-wrap label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.route-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: var(--bg);
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.route-stat {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
}

.fallback-notice {
  font-size: 0.8rem;
  background: #fef3c7;
  color: #92400e;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #fde68a;
}

.coords-box {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  padding: 8px 10px;
  border-radius: 8px;
  line-height: 1.5;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  display: block;
  width: 100%;
  text-align: center;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--blue);
  color: #ffffff;
}

.btn-secondary:hover {
  background: var(--blue-hover);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover {
  background: var(--bg);
}

.btn-outline.active {
  background: #dbeafe;
  border-color: var(--blue);
  color: var(--blue);
}

.sidebar-footer {
  padding: 10px 16px;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  text-align: center;
}

.sidebar-footer a {
  color: var(--primary);
}

/* Map */
.map-container {
  flex: 1;
  position: relative;
  height: 100%;
}

#map {
  width: 100%;
  height: 100%;
}

.mobile-toggle-btn {
  position: absolute;
  top: 12px;
  left: 54px;
  z-index: 900;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.88rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  cursor: pointer;
}

.print-header {
  display: none;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}

.modal-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 18px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-card h3 {
  font-size: 1.1rem;
  color: var(--primary);
}

.modal-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: -6px;
}

.modal-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.modal-label input[type="text"],
.modal-label textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
}

.modal-label input[type="text"]:focus,
.modal-label textarea:focus {
  border-color: var(--primary);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
  margin-top: 6px;
}

/* Mobile Responsive: Fullscreen Map + Floating Search + Bottom Sheet */
@media (max-width: 768px) {
  .app-layout {
    position: relative;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
  }

  .map-container {
    position: absolute;
    inset: 0;
    height: 100dvh;
    width: 100vw;
    z-index: 1;
  }

  .sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    box-shadow: none;
    pointer-events: none;
    z-index: 1000;
  }

  .brand-header,
  .sidebar-footer,
  .mobile-toggle-btn {
    display: none !important;
  }

  .search-section {
    pointer-events: auto;
    margin: 10px 12px 0;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  }

  .search-box input,
  .kazerne-filter select {
    font-size: 16px;
  }

  .results-section {
    pointer-events: auto;
    margin: 6px 12px 12px;
    max-height: 55dvh;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  }

  .result-item {
    min-height: 48px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .detail-panel {
    pointer-events: auto;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 52dvh;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.18);
    padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  }

  .action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .action-buttons .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-primary {
    grid-column: 1 / -1;
  }
}

/* Print / A4 PDF Stylesheet */
body.print-mode .sidebar,
body.print-mode .mobile-toggle-btn,
body.print-mode .leaflet-control-zoom {
  display: none !important;
}

body.print-mode .app-layout {
  display: block;
  height: auto;
  width: 100%;
  overflow: visible;
}

body.print-mode .print-header {
  display: block !important;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid #1e3a2f;
}

body.print-mode .map-container,
body.print-mode #map {
  width: 100% !important;
  height: 210mm !important;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  body, html {
    height: auto;
    background: #ffffff;
  }

  .sidebar,
  .mobile-toggle-btn,
  .leaflet-control-zoom {
    display: none !important;
  }

  .app-layout {
    display: block;
    height: auto;
    width: 100%;
    overflow: visible;
  }

  .print-header {
    display: block !important;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid #1e3a2f;
  }

  .print-header h1 {
    font-size: 16pt;
    color: #1e3a2f;
    margin-bottom: 4px;
  }

  .print-info {
    font-size: 10pt;
    color: #334155;
    line-height: 1.4;
  }

  .map-container {
    width: 100% !important;
    height: 210mm !important;
    page-break-inside: avoid;
  }

  #map {
    width: 100% !important;
    height: 210mm !important;
    border: 1px solid #cbd5e1;
  }
}
