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

/* ── Base ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f172a;
  color: #eee;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─────────────────────────────────────────────
   HEADER
───────────────────────────────────────────── */
#app-header {
  height: 44px;
  background: #12182b;
  border-bottom: 1px solid #2a3550;
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 200;
}
.app-title {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  letter-spacing: 0.3px;
}
.header-sep {
  width: 1px;
  height: 20px;
  background: #2a3550;
  flex-shrink: 0;
}
.header-config {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.header-config select {
  background: #1a2540;
  border: 1px solid #2a3550;
  color: #eee;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  max-width: 180px;
  min-width: 0;
}
.header-config button {
  background: #1f2a45;
  border: 1px solid #2a3550;
  color: #aaa;
  padding: 4px 9px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}
.header-config button:hover { background: #2d3a5e; color: #eee; }
#header-info {
  font-size: 12px;
  color: #556080;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ─────────────────────────────────────────────
   MAIN LAYOUT
───────────────────────────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─────────────────────────────────────────────
   SIDEBAR
───────────────────────────────────────────── */
#sidebar {
  width: 380px;
  flex-shrink: 0;
  background: #1a1a2e;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid #2a3550;
}

/* scrollable accordion area */
#sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
#sidebar-content::-webkit-scrollbar { width: 4px; }
#sidebar-content::-webkit-scrollbar-track { background: transparent; }
#sidebar-content::-webkit-scrollbar-thumb { background: #2a3550; border-radius: 2px; }

/* ─────────────────────────────────────────────
   ACCORDION
───────────────────────────────────────────── */
.accordion-section {
  border-bottom: 1px solid #1f2a40;
}
.accordion-header {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 9px 14px;
  background: #1f2a45;
  border: none;
  color: #8888aa;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}
.accordion-header:hover { background: #243050; color: #aaa; }
.accordion-header .chevron { font-size: 9px; flex-shrink: 0; }
.accordion-header .section-title { flex: 1; }
.badge {
  background: #4ecdc4;
  color: #000;
  border-radius: 9px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}
.accordion-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.accordion-body.collapsed { display: none; }

/* ─────────────────────────────────────────────
   FORM ELEMENTS
───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: #aaa; }
.field input, .field select {
  padding: 8px;
  border: 1px solid #333;
  border-radius: 4px;
  background: #16213e;
  color: #eee;
  font-size: 13px;
}
.field select option { background: #16213e; }
.hint { font-size: 11px; color: #555; margin-top: 2px; }
.unit-label { font-size: 11px; color: #556080; flex-shrink: 0; }
.field-row { display: flex; gap: 14px; align-items: center; padding: 4px 0; }
.check-label { display: flex; align-items: center; gap: 5px; font-size: 12px; color: #aaa; cursor: pointer; user-select: none; }
.check-label input[type="checkbox"] { accent-color: #4ecdc4; cursor: pointer; }

/* ─────────────────────────────────────────────
   DROP ZONE
───────────────────────────────────────────── */
#drop-zone {
  border: 2px dashed #2a3550;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  color: #556080;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 13px;
  line-height: 1.5;
}
#drop-zone:hover, #drop-zone.active { border-color: #4ecdc4; color: #4ecdc4; }
#drop-zone.loaded {
  border-color: #27ae60;
  color: #27ae60;
  padding: 8px 16px;
  font-size: 12px;
}

/* ─────────────────────────────────────────────
   TRACK LIST
───────────────────────────────────────────── */
#track-list { display: flex; flex-direction: column; gap: 6px; }
.track-item {
  background: #16213e;
  border-radius: 6px;
  overflow: hidden;
  border-left: 3px solid transparent; /* color set inline */
}
.track-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 8px 7px 0;
  cursor: pointer;
  user-select: none;
}
.track-header:hover { background: rgba(255,255,255,0.02); }
.track-chevron {
  width: 20px;
  text-align: center;
  font-size: 8px;
  color: #556080;
  flex-shrink: 0;
  padding-left: 6px;
}
.track-name-stats {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.track-name {
  font-size: 12px;
  color: #ccc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.track-stats {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  font-size: 10px;
  color: #7ecef4;
}
.track-stats span { white-space: nowrap; }
.track-delete {
  background: none; border: none; color: #556080;
  cursor: pointer; font-size: 15px; padding: 0 3px; flex-shrink: 0;
}
.track-delete:hover { color: #e74c3c; }

/* Collapsible details */
.track-details { display: none; padding: 0 10px 10px; }
.track-item.expanded .track-details {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.track-details-row {
  display: flex;
  gap: 6px;
}
.track-details-row .field { flex: 1; }
.track-details-row .field label { font-size: 10px; color: #7a8aaa; }
.track-details-row .field input {
  padding: 5px 6px;
  border: 1px solid #2a3550;
  border-radius: 4px;
  background: #0f172a;
  color: #eee;
  font-size: 12px;
  width: 100%;
}

.track-simplify-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: #aaa;
}
.track-simplify-row input[type="checkbox"] { accent-color: #4ecdc4; }
.simplify-tolerance {
  width: 80px; padding: 4px 6px;
  border: 1px solid #333; border-radius: 4px;
  background: #0f172a; color: #eee; font-size: 11px;
}

/* ─────────────────────────────────────────────
   MARKER SECTION
───────────────────────────────────────────── */
.marker-controls-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.marker-controls-row input[type="color"] {
  width: 28px; height: 28px; padding: 0;
  border: none; cursor: pointer; border-radius: 50%; flex-shrink: 0;
}
.marker-controls-row input[type="number"] { width: 52px; }
.marker-controls-row .secondary-btn { flex: 1; padding: 6px 8px; font-size: 12px; }

#marker-list { display: flex; flex-direction: column; gap: 6px; }
.marker-item {
  display: flex; align-items: center; gap: 7px;
  background: #16213e; padding: 7px 10px; border-radius: 6px;
}
.marker-badge {
  min-width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 10px; flex-shrink: 0; color: #fff;
}
.marker-label-input {
  flex: 1; padding: 5px 7px;
  border: 1px solid #333; border-radius: 4px;
  background: #0f172a; color: #eee; font-size: 12px;
}
.marker-delete {
  background: none; border: none; color: #556080;
  cursor: pointer; font-size: 15px; padding: 0 2px; flex-shrink: 0;
}
.marker-delete:hover { color: #e74c3c; }
.marker-order-btn {
  background: none; border: none; color: #556080;
  cursor: pointer; font-size: 10px; padding: 0 1px; flex-shrink: 0; line-height: 1;
}
.marker-order-btn:hover:not(:disabled) { color: #4ecdc4; }
.marker-order-btn:disabled { opacity: 0.25; cursor: default; }
.marker-icon-btn {
  background: none; border: 1px solid #2a3550; color: #8888aa;
  cursor: pointer; font-size: 11px;
  width: 26px; height: 26px;
  padding: 0;
  border-radius: 4px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.marker-icon-btn:hover { border-color: #4ecdc4; color: #4ecdc4; }

/* ─────────────────────────────────────────────
   EXPORT PANEL (fixed bottom of sidebar)
───────────────────────────────────────────── */
#export-panel {
  flex-shrink: 0;
  background: #141d30;
  border-top: 2px solid #2a3550;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.export-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.export-row select {
  flex: 1;
  background: #1a2540;
  border: 1px solid #2a3550;
  color: #eee;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.export-dims-row {
  display: flex;
  align-items: center;
  gap: 5px;
}
.export-dims-row input[type="number"] {
  flex: 1;
  background: #1a2540;
  border: 1px solid #2a3550;
  color: #eee;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
  min-width: 0;
}
.dims-sep { font-size: 12px; color: #2a3550; flex-shrink: 0; }

.export-format-group {
  display: flex; align-items: center; gap: 6px; flex: 1;
}
.export-format-group select { flex: 1; }

#quality-field {
  display: flex; align-items: center; gap: 4px;
}
.quality-label { font-size: 11px; color: #556080; white-space: nowrap; }
#jpeg-quality { width: 55px; accent-color: #4ecdc4; }

#pixel-info {
  font-size: 11px;
  color: #4ecdc4;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Split button ── */
.split-btn-wrapper { position: relative; }
.split-btn { display: flex; width: 100%; border-radius: 6px; overflow: hidden; }
.split-btn #zip-btn {
  flex: 1;
  background: #e74c3c;
  color: #fff;
  border: none;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
}
.split-btn #zip-btn:hover { background: #c0392b; }
.split-btn #zip-btn:disabled { background: #555; cursor: not-allowed; }
#export-dropdown-toggle {
  background: #c0392b;
  color: #fff;
  border: none;
  border-left: 1px solid rgba(255,255,255,0.15);
  padding: 10px 11px;
  font-size: 10px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
#export-dropdown-toggle:hover { background: #a93226; }
#export-dropdown-toggle:disabled { background: #555; cursor: not-allowed; }
#export-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 100;
  background: #1a2540;
  border: 1px solid #2a3550;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.5);
}
#export-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  background: none;
  border: none;
  color: #eee;
  font-size: 12px;
  cursor: pointer;
}
#export-dropdown button:hover { background: #243050; }

#status {
  font-size: 11px;
  color: #556080;
  min-height: 15px;
}

/* ── Shared secondary button ── */
.secondary-btn {
  padding: 7px 12px;
  background: #2d3a5e;
  color: #eee;
  border: 1px solid #4a5a8e;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
  white-space: nowrap;
}
.secondary-btn:hover { background: #3a4a7e; }
.secondary-btn.active { background: #4ecdc4; color: #000; border-color: #4ecdc4; }

/* ─────────────────────────────────────────────
   MAP AREA
───────────────────────────────────────────── */
#map-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
#map {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ─────────────────────────────────────────────
   ELEVATION PANEL (bottom, below map)
───────────────────────────────────────────── */
#elevation-panel {
  flex-shrink: 0;
  height: 220px;
  background: #fff;
  border-top: 2px solid #2a3550;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#elevation-panel.collapsed { height: auto; }
#elevation-toggle {
  background: #1f2a45;
  border: none;
  color: #8888aa;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: 7px 14px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
#elevation-toggle:hover { background: #243050; color: #aaa; }
#elevation-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
#elevation-body canvas { flex: 1; display: block; width: 100%; min-height: 0; }
#elevation-panel.collapsed #elevation-body { display: none; }

/* Elevation Tab-Leiste */
#elevation-tabs {
  display: flex;
  gap: 2px;
  padding: 4px 8px 0;
  background: #fff;
  flex-shrink: 0;
  overflow-x: auto;
}
#elevation-tabs::-webkit-scrollbar { height: 2px; }
#elevation-tabs::-webkit-scrollbar-thumb { background: #ddd; }
.elevation-tab {
  background: #f0f0f0;
  border: none;
  border-top: 3px solid transparent;
  padding: 3px 8px;
  font-size: 10px;
  color: #666;
  cursor: pointer;
  border-radius: 3px 3px 0 0;
  white-space: nowrap;
  transition: background 0.1s;
}
.elevation-tab:hover { background: #e0e0e0; }
.elevation-tab.active { background: #fff; color: #333; font-weight: 600; border-top-color: #4ecdc4; }

/* ─────────────────────────────────────────────
   HISTORY PANEL (right, collapsible)
───────────────────────────────────────────── */
#history-panel {
  width: 24px;
  flex-shrink: 0;
  background: #1a1a2e;
  border-left: 1px solid #2a3550;
  display: flex;
  overflow: hidden;
  transition: width 0.22s ease;
  position: relative;
}
#history-panel.open { width: 220px; }
#history-toggle {
  width: 24px;
  flex-shrink: 0;
  background: #1f2a45;
  border: none;
  border-right: 1px solid #2a3550;
  color: #556080;
  cursor: pointer;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 14px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
#history-toggle:hover { background: #243050; color: #aaa; }
#history-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 196px;
}
.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #8888aa;
}
#history-list { display: flex; flex-direction: column; gap: 8px; }
.history-entry {
  background: #16213e;
  border-radius: 6px;
  overflow: hidden;
}
.history-thumb {
  width: 100%;
  aspect-ratio: 3/2;
  object-fit: cover;
  display: block;
  background: #0f172a;
}
.history-meta {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.history-filename { font-size: 10px; color: #aaa; word-break: break-all; line-height: 1.3; }
.history-date { font-size: 10px; color: #556080; }
.history-actions { display: flex; gap: 4px; margin-top: 4px; }
.history-actions button {
  flex: 1;
  background: #1f2a45;
  border: 1px solid #2a3550;
  color: #aaa;
  padding: 4px 5px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  transition: background 0.15s;
}
.history-actions button:hover { background: #2d3a5e; color: #eee; }

/* ─────────────────────────────────────────────
   MAP OVERLAYS
───────────────────────────────────────────── */
#print-area {
  position: absolute;
  pointer-events: none;
  border: 2px dashed rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
  z-index: 1;
}
.map-marker {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: bold;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  cursor: default;
  pointer-events: none;
  line-height: 1;
}
