@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Inter:wght@300;400;500&display=swap');

:root {
  --bg:        #0d0d0d;
  --bg2:       #141414;
  --bg3:       #1a1a1a;
  --border:    #2a2a2a;
  --accent:    #44aaff;
  --accent2:   #2277cc;
  --text:      #e0e0e0;
  --text2:     #888;
  --text3:     #555;
  --danger:    #ff4444;
  --success:   #44ff88;
  --waypoint:  #ffaa00;
  --panel-w:   340px;
  --radius:    6px;
  --mono:      'JetBrains Mono', monospace;
  --sans:      'Inter', sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  overflow: hidden;
}

#app { display: flex; height: 100vh; position: relative; }
#map { flex: 1; height: 100%; }

/* Panel */
#panel {
  width: var(--panel-w);
  height: 100%;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  overflow: hidden;
  flex-shrink: 0;
}

/* Panel handle (mobile) */
#panel-handle {
  display: none;
  justify-content: center;
  align-items: center;
  height: 26px;
  cursor: pointer;
  color: var(--text3);
  font-size: 16px;
  flex-shrink: 0;
  user-select: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  transition: color 0.15s;
}
#panel-handle:hover { color: var(--text2); }

#panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#panel-header .logo { font-family: var(--mono); font-size: 18px; font-weight: 700; color: var(--accent); letter-spacing: 2px; }
#panel-header .subtitle { font-size: 11px; color: var(--text3); font-family: var(--mono); }

/* Mode toggle */
#mode-toggle {
  display: flex;
  margin: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}
.mode-btn {
  flex: 1; padding: 8px; background: none; border: none; color: var(--text2);
  cursor: pointer; font-family: var(--sans); font-size: 13px; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.mode-btn.active { background: var(--accent); color: #000; font-weight: 500; }
.mode-btn:hover:not(.active) { background: var(--bg3); color: var(--text); }

/* Inputs */
#inputs {
  padding: 0 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 10px;
  transition: border-color 0.15s;
  position: relative;
}
.input-row:focus-within { border-color: var(--accent); }

.input-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.input-dot.from     { background: var(--success); }
.input-dot.to       { background: var(--danger); }
.input-dot.waypoint { background: var(--waypoint); }

.input-row input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: var(--sans); font-size: 13px; padding: 10px 0;
}
.input-row input::placeholder { color: var(--text3); }

.input-loc-btn {
  background: none; border: none; color: var(--text3); cursor: pointer;
  padding: 4px; display: flex; align-items: center; border-radius: 3px;
  transition: color 0.15s; flex-shrink: 0;
}
.input-loc-btn:hover { color: var(--accent); }
.wp-remove-btn { font-size: 13px; line-height: 1; }
.wp-remove-btn:hover { color: var(--danger) !important; }

/* Add waypoint button */
#add-waypoint-btn {
  padding: 7px 10px; background: none;
  border: 1px dashed var(--border); color: var(--text3);
  border-radius: var(--radius); cursor: pointer;
  font-size: 12px; font-family: var(--sans);
  transition: all 0.15s; text-align: left;
}
#add-waypoint-btn:hover { border-color: var(--waypoint); color: var(--waypoint); }

/* Autocomplete */
.autocomplete {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); z-index: 100; max-height: 200px; overflow-y: auto;
}
.autocomplete-item {
  padding: 9px 12px; cursor: pointer; font-size: 12px; color: var(--text);
  border-bottom: 1px solid var(--border); line-height: 1.4;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--bg3); color: var(--accent); }
.autocomplete-item .place-name { font-weight: 500; }
.autocomplete-item .place-detail { color: var(--text3); font-size: 11px; }

/* Route button */
#route-btn {
  margin: 0 16px 12px; padding: 10px; background: var(--accent);
  color: #000; border: none; border-radius: var(--radius);
  font-family: var(--sans); font-weight: 500; font-size: 13px;
  cursor: pointer; transition: background 0.15s, opacity 0.15s;
  flex-shrink: 0;
}
#route-btn:hover { background: #66bbff; }
#route-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Route info */
#route-info {
  margin: 0 16px 8px; padding: 10px 12px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); display: none; gap: 16px;
  flex-shrink: 0;
}
#route-info.visible { display: flex; align-items: center; }
.route-stat { text-align: center; }
.route-stat .val { font-family: var(--mono); font-size: 18px; font-weight: 700; color: var(--accent); }
.route-stat .lbl { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; }

#share-btn {
  margin-left: auto; background: none; border: 1px solid var(--border);
  color: var(--text2); padding: 6px 10px; border-radius: var(--radius);
  cursor: pointer; font-size: 14px; transition: all 0.15s;
}
#share-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Nav button */
#nav-btn {
  margin: 0 16px 12px; padding: 9px 10px;
  background: none; border: 1px solid var(--success);
  color: var(--success); border-radius: var(--radius);
  font-family: var(--sans); font-size: 13px; cursor: pointer;
  transition: all 0.15s; flex-shrink: 0;
}
#nav-btn:hover { background: var(--success); color: #000; }

/* Steps */
#steps-container { flex: 1; overflow-y: auto; border-top: 1px solid var(--border); }
#steps-container::-webkit-scrollbar { width: 4px; }
#steps-container::-webkit-scrollbar-track { background: var(--bg); }
#steps-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#steps-header {
  padding: 10px 16px; font-size: 11px; color: var(--text3);
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 1px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg);
}
.step-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); transition: background 0.1s;
}
.step-item:hover { background: var(--bg2); }
.step-icon {
  width: 28px; height: 28px; border-radius: 50%; background: var(--bg3);
  border: 1px solid var(--border); display: flex; align-items: center;
  justify-content: center; font-size: 13px; flex-shrink: 0; margin-top: 1px;
}
.step-item.active-step { background: var(--bg3); }
.step-item.active-step .step-icon { border-color: var(--accent); }
.step-text { flex: 1; }
.step-instruction { font-size: 13px; line-height: 1.4; }
.step-dist { font-family: var(--mono); font-size: 11px; color: var(--text3); margin-top: 2px; }

/* Search box (desktop only) */
#search-box {
  position: absolute;
  top: 12px;
  left: calc(var(--panel-w) + 12px);
  width: min(380px, calc(100vw - var(--panel-w) - 80px));
  z-index: 20;
}
#search-input {
  width: 100%; padding: 10px 14px;
  background: rgba(20,20,20,0.95); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-family: var(--sans);
  font-size: 13px; outline: none; transition: border-color 0.15s;
  backdrop-filter: blur(4px);
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text3); }
#search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); z-index: 100; max-height: 220px;
  overflow-y: auto; display: none;
}
#search-results.visible { display: block; }

/* Toolbar */
#toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tool-btn {
  width: 36px; height: 36px;
  background: rgba(20,20,20,0.95); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); cursor: pointer;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; backdrop-filter: blur(4px);
}
.tool-btn:hover { border-color: var(--accent); }
.tool-btn.active { border-color: var(--waypoint); background: rgba(255,170,0,0.15); }

/* Coord popup */
#coord-popup {
  display: none;
  position: fixed;
  z-index: 200;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-width: 220px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
#coord-popup.visible { display: block; }
#coord-text {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 8px;
}
.coord-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.coord-actions button {
  padding: 4px 8px; background: none; border: 1px solid var(--border);
  color: var(--text2); border-radius: 3px; cursor: pointer; font-size: 11px;
  font-family: var(--sans); transition: all 0.15s;
}
.coord-actions button:hover { border-color: var(--accent); color: var(--accent); }
#coord-close { margin-left: auto; }

/* GPS Navigation overlay */
#nav-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 300;
  background: rgba(10,10,10,0.96);
  border-bottom: 2px solid var(--accent);
  padding: 12px 16px;
  gap: 12px;
  align-items: center;
  backdrop-filter: blur(8px);
}
#nav-overlay.visible { display: flex; }

#nav-maneuver {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}
#nav-icon {
  width: 52px; height: 52px; flex-shrink: 0;
  background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: #000; font-weight: bold;
}
#nav-info { flex: 1; min-width: 0; }
#nav-dist {
  font-family: var(--mono); font-size: 22px; font-weight: 700;
  color: var(--accent); line-height: 1.1;
}
#nav-instr {
  font-size: 13px; color: var(--text); line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#nav-controls {
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0;
}
#nav-speed {
  font-family: var(--mono); font-size: 11px; color: var(--text3);
}
#nav-stop-btn {
  padding: 6px 12px; background: none;
  border: 1px solid var(--danger); color: var(--danger);
  border-radius: var(--radius); cursor: pointer; font-size: 12px;
  font-family: var(--sans); transition: all 0.15s;
}
#nav-stop-btn:hover { background: var(--danger); color: #fff; }

/* Global default: mobile stop FAB hidden unless navigation active */
#nav-stop-fab { display: none; }

#clear-btn {
  margin: 0 16px 10px;
  width: calc(100% - 32px);
  padding: 8px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text3);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--sans);
  transition: all 0.15s;
}
#clear-btn:hover { border-color: var(--danger); color: var(--danger); }

/* Loading */
#loading {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 1000; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
}
#loading.visible { display: flex; }
#loading .spinner {
  width: 32px; height: 32px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
#loading .msg { font-family: var(--mono); font-size: 13px; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg2); border: 1px solid var(--accent); color: var(--accent);
  padding: 8px 16px; border-radius: var(--radius); font-family: var(--mono);
  font-size: 13px; z-index: 2000; opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
#toast.show { opacity: 1; }

/* Mobile */
@media (max-width: 640px) {
  #panel {
    position: absolute; bottom: 0; left: 0; right: 0;
    width: 100%; height: auto; max-height: 60vh;
    border-right: none; border-top: 2px solid var(--border);
    transition: max-height 0.25s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #panel.collapsed { max-height: 44px; }
  #panel-handle { display: flex; }
  #map { height: 100vh; }
  #app { flex-direction: column-reverse; }

  .maplibregl-ctrl-top-right {
    top: auto !important;
    bottom: calc(60vh + 16px) !important;
    right: 8px !important;
  }
  .maplibregl-ctrl-bottom-right {
    bottom: calc(60vh + 8px) !important;
  }

  #search-box { display: none; }
  #toolbar { top: auto; bottom: calc(60vh + 60px); right: 8px; }
  #toast { bottom: calc(60vh + 12px); }

  #nav-overlay { padding: 10px 12px; }
  #nav-dist { font-size: 18px; }
  #nav-icon { width: 44px; height: 44px; font-size: 20px; }
}

/* ═══════════════════════════════════════════════════════════════
   WAZE-STYLE MOBILE UI
   ═══════════════════════════════════════════════════════════════ */

/* ── Bottom sheet ── */
#sheet {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 44vh;
  background: var(--bg2);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
  z-index: 100;
  transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

#sheet-handle {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: none;
}

#sheet-handle::before {
  content: '';
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
}

#sheet-content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 14px 16px;
  height: calc(100% - 28px);
  box-sizing: border-box;
}

/* ── Sheet mode buttons ── */
#sheet-mode {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
#sheet-mode .mode-btn {
  flex: 1;
  padding: 8px 4px;
  font-size: 18px;
  border-radius: var(--radius);
}

/* ── Sheet inputs ── */
#sheet-inputs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

#sheet-add-waypoint {
  background: none;
  border: 1px dashed var(--border);
  color: var(--muted);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  margin: 2px 0;
}

/* ── Sheet route info bar ── */
.route-info-bar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: 10px 0;
}
.route-info-bar.visible { display: flex; }

.nav-start-btn {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}

/* ── Sheet steps ── */
#sheet-steps-header {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 10px 0 6px;
}

/* ── FAB buttons ── */
#fab-container {
  display: none;
  position: fixed;
  right: 14px;
  bottom: calc(44vh + 16px);
  flex-direction: column;
  gap: 10px;
  z-index: 90;
  transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fab {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(26, 26, 46, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }
.fab-blue { background: rgba(74,158,255,0.25); border-color: var(--accent); color: var(--accent); }

/* ── Mobile media query ── */
@media (max-width: 640px) {
  /* Hide desktop panel, show sheet + FABs */
  #panel { display: none !important; }
  #sheet { display: block; }
  #fab-container { display: flex; }
  #toolbar { display: none !important; }

  /* Full-screen map */
  #map { position: fixed; inset: 0; height: 100dvh; }
  #app { display: block; }

  /* Search box full width at top */
  #search-box {
    position: fixed;
    top: 10px; left: 10px; right: 10px;
    width: auto;
    transform: none;
    border-radius: 24px;
    z-index: 110;
  }

  /* MapLibre controls — move left of FABs */
  .maplibregl-ctrl-top-right {
    top: 68px !important;
    right: 70px !important;
  }
  .maplibregl-ctrl-bottom-right { display: none; }

  /* Toast above sheet */
  #toast { bottom: calc(44vh + 12px); }

  /* Nav overlay compact */
  #nav-overlay { padding: 10px 12px; }
  #nav-dist { font-size: 18px; }
  #nav-icon { width: 44px; height: 44px; font-size: 20px; }
}
