:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --accent: #0f766e;
  --text: #0f172a;
  --muted: #64748b;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, sans-serif; color: var(--text); background: var(--bg); }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--accent); color: white;
}
.topbar h1 { margin: 0; font-size: 1.1rem; }
.topbar-actions { display: flex; gap: 10px; align-items: center; font-size: 0.85rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  height: calc(100% - 48px);
}

.panel {
  padding: 12px; overflow-y: auto; background: var(--panel);
  border-right: 1px solid #e2e8f0;
}
.panel-toggle {
  display: none;
}
.panel-body {
  display: contents;
}
.panel label { display: block; margin-bottom: 10px; font-size: 0.85rem; }
.panel label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.panel label.checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
}
.field-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.3;
}
.panel input:not([type="checkbox"]), .panel select, .panel button {
  width: 100%; margin-top: 4px; padding: 8px; font-size: 1rem;
}
.panel .loc-input-row input {
  width: auto;
  flex: 1;
  margin-top: 0;
  min-width: 0;
}
.loc-field { margin-top: 4px; }
.loc-input-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.loc-gps-btn {
  width: 40px !important;
  flex-shrink: 0;
  margin-top: 0 !important;
  padding: 0 !important;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f1f5f9;
  color: var(--accent);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.loc-gps-btn:disabled { opacity: 0.5; cursor: default; }
.loc-gps-btn:not(:disabled):active { background: #e2e8f0; }
.loc-status {
  margin: 4px 0 0;
  font-size: 0.75rem;
  min-height: 1.1em;
  line-height: 1.3;
  color: var(--muted);
}
.loc-status--ok { color: #15803d; }
.loc-status--warn { color: #b45309; }
.loc-status--error { color: #b45309; }
.loc-status--pending { color: var(--muted); font-style: italic; }

.box-popup { font-size: 0.85rem; min-width: 140px; }
.box-popup-meta { color: var(--muted); font-size: 0.8rem; }
.box-popup-disabled {
  margin: 6px 0 0;
  color: #64748b;
  font-size: 0.8rem;
  font-style: italic;
}
.box-popup--disabled b { color: #64748b; }
.box-popup-actions {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.box-pick-btn {
  flex: 1 1 auto;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #f1f5f9;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}
.box-pick-btn:active { background: #e2e8f0; }
.primary { background: var(--accent); color: white; border: none; border-radius: 8px; }
.secondary { background: #e2e8f0; border: none; border-radius: 8px; margin-top: 8px; }
.hidden { display: none !important; }
.status { font-size: 0.8rem; color: var(--muted); min-height: 1.2em; }

.map-wrap { position: relative; }
#map { width: 100%; height: 100%; }

.map-controls {
  position: absolute; right: 10px; bottom: 10px; z-index: 500;
  display: flex; flex-direction: column; gap: 6px;
}
.map-tool-btn {
  width: 40px; height: 40px; padding: 0; margin: 0;
  border: none; border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--accent); font-size: 1.35rem; line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  cursor: pointer;
}
.map-tool-btn:active { background: #e2e8f0; }
.map-tool-btn:disabled { opacity: 0.5; cursor: default; }
.map-tool-btn--busy { animation: locate-pulse 1s ease-in-out infinite; }
@keyframes locate-pulse {
  50% { opacity: 0.55; }
}

.route-card {
  position: absolute; top: 10px; right: 10px; z-index: 500;
  background: rgba(255,255,255,0.95); border-radius: 8px;
  max-width: 280px; font-size: 0.85rem; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  overflow: hidden;
}
.route-card-header { border-bottom: 1px solid transparent; }
.route-card.collapsed .route-card-header { border-bottom: none; }
.route-card-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 8px 10px; border: none; background: transparent;
  font: inherit; font-size: 0.8rem; font-weight: 600; color: var(--text);
  cursor: pointer; text-align: left;
}
.route-card-chevron {
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  margin: -6px -4px -6px 0;
  transition: transform 0.2s ease;
}
.route-card.collapsed .route-card-chevron { transform: rotate(-90deg); }
.route-card-body { padding: 0 12px 10px; }
.route-card.collapsed .route-card-body { display: none; }

.guidance {
  position: absolute; left: 10px; bottom: 10px; z-index: 500;
  background: rgba(255,255,255,0.95); padding: 10px; border-radius: 8px;
  display: flex; gap: 10px; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.compass {
  width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem;
}
.compass-arrow { transition: transform 0.2s ease; }
.guidance-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
#guidanceText { font-size: 0.85rem; max-width: 220px; }
.guidance-step {
  display: flex; align-items: center; gap: 6px; justify-content: center;
}
.guidance-step-label {
  font-size: 0.75rem; color: var(--muted); min-width: 3.5em; text-align: center;
}
.guidance-step-btn {
  width: 36px; height: 32px; padding: 0; margin: 0;
  border: 1px solid #cbd5e1; border-radius: 6px; background: #f1f5f9;
  font-size: 0.75rem; cursor: pointer; flex-shrink: 0;
}
.guidance-step-btn:disabled { opacity: 0.4; cursor: default; }
.guidance-step-btn:not(:disabled):active { background: #e2e8f0; }

.user-loc-marker {
  background: transparent !important;
  border: none !important;
}
.user-loc {
  position: relative;
  width: 48px;
  height: 48px;
}
.user-loc-heading {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  transition: transform 0.2s ease;
  pointer-events: none;
}
.user-loc-heading--unknown .user-loc-cone {
  opacity: 0.25;
}
.user-loc-cone {
  position: absolute;
  left: 50%;
  top: 2px;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 26px solid rgba(37, 99, 235, 0.55);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}
.user-loc-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.22);
  border: 2px solid rgba(37, 99, 235, 0.35);
  box-shadow: 0 0 0 6px rgba(59, 130, 246, 0.12);
}
.user-loc-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #2563eb;
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  z-index: 2;
  transition: background 0.2s ease;
}
.user-loc--weak .user-loc-dot {
  background: #94a3b8;
}
.user-loc--weak .user-loc-cone {
  opacity: 0.15;
}
.gps-ok { color: var(--muted); font-size: 0.75rem; }
.gps-warn { color: #b45309; font-size: 0.75rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .panel {
    padding: 0;
    overflow: hidden;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
  }
  .panel-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px 10px;
    border: none;
    background: var(--panel);
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
  }
  .panel-toggle-handle {
    display: block;
    width: 32px;
    height: 4px;
    border-radius: 2px;
    background: #cbd5e1;
    flex-shrink: 0;
  }
  .panel-toggle-label {
    flex: 1;
    text-align: left;
  }
  .panel-toggle-chevron {
    color: var(--muted);
    font-size: 1.35rem;
    line-height: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    margin: -6px -4px -6px 0;
    transition: transform 0.2s ease;
  }
  .panel.collapsed .panel-toggle-chevron {
    transform: rotate(-90deg);
  }
  .panel-body {
    display: block;
    padding: 0 12px 12px;
    overflow-y: auto;
    max-height: min(45vh, 360px);
  }
  .panel.collapsed .panel-body {
    display: none;
  }
  .map-wrap { min-height: 0; }
}
