:root {
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --panel-bg:     #ffffff;
  --panel-width:  300px;
  --header-h:     52px;
  --border:       #e5e7eb;
  --text:         #111827;
  --text-muted:   #6b7280;
  --radius:       6px;
}

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

[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
}

/* ── Layout ──────────────────────────────────────── */

#app {
  display: flex;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

#map {
  flex: 1;
  min-width: 0;
}

/* ── Panel – desktop ─────────────────────────────── */

#panel {
  display: flex;
  flex-direction: column;
  width: var(--panel-width);
  background: var(--panel-bg);
  box-shadow: -2px 0 12px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  overflow: hidden;
  transition: width 0.25s ease;
}

#panel.collapsed {
  width: 0;
  min-width: 0;
  flex-basis: 0;
  box-shadow: none;
}

#panel-show-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1001;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: var(--panel-bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

#panel-show-btn:hover { background: #f3f4f6; }

/* ── Panel header ────────────────────────────────── */

#panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#panel-header h1 {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  text-align: center;
}

#drag-handle {
  display: none;
}

#panel-collapse-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: var(--radius);
  line-height: 1;
  flex-shrink: 0;
}

#panel-collapse-btn:hover {
  background: #f3f4f6;
  color: var(--text);
}

/* ── Panel body ──────────────────────────────────── */

#panel-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* ── Dropzone ────────────────────────────────────── */

#dropzone {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
  flex-shrink: 0;
}

#dropzone.hover {
  background: #eff6ff;
}

.drop-hint {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

#file-input { display: none; }

/* ── Trace list ──────────────────────────────────── */

#trace-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
}

.empty-hint {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  pointer-events: none;
}

.trace-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.trace-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.trace-item input[type=checkbox] {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

.trace-item input[type=color] {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  padding: 2px;
  background: none;
}

.weight-slider {
  flex-shrink: 0;
  width: 52px;
  cursor: pointer;
  accent-color: var(--accent);
}

.trace-progress {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px 2px;
}

.progress-slider {
  flex: 1;
  cursor: pointer;
  accent-color: var(--accent);
}

.progress-dist {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.trace-cursor {
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.trace-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.trace-name small {
  color: var(--text-muted);
  margin-left: 4px;
}

.remove-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 3px 5px;
  border-radius: var(--radius);
  line-height: 1;
}

.remove-btn:hover {
  background: #fee2e2;
  color: #ef4444;
}

/* ── Share section ───────────────────────────────── */

#share-section {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

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

.btn-secondary {
  background: #f3f4f6;
  color: var(--text);
  flex: 1;
}

.btn-secondary:not(:disabled):hover { background: #e5e7eb; }

/* ── Locate button ───────────────────────────────── */

.locate-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: none;
  cursor: pointer;
  color: #444;
}

.locate-btn:hover { background: #f4f4f4; }

/* ── Toast ───────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 2000;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: toast-in 0.2s ease;
  pointer-events: none;
}

.toast-error   { background: #991b1b; color: white; }
.toast-success { background: #166534; color: white; }
.toast-info    { background: #1e3a5f; color: white; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Mobile ──────────────────────────────────────── */

@media (max-width: 640px) {
  #app { position: relative; }

  #map {
    position: absolute;
    inset: 0;
  }

  #panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60dvh;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(calc(100% - var(--header-h)));
    transition: transform 0.3s ease;
  }

  #panel.mobile-expanded {
    transform: translateY(0);
  }

  #panel-body {
    overflow-y: auto;
  }

  /* hide desktop-only controls on mobile */
  #panel-collapse-btn { display: none; }
  #panel-show-btn     { display: none !important; }

  #drag-handle {
    display: block;
    width: 32px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    flex-shrink: 0;
  }

  #panel-header {
    cursor: pointer;
    user-select: none;
  }

  #share-section {
    flex-direction: column;
  }
}
