/* ============================================================
   RIDGELINE — Gaia-style light UI
   Icon rail + slide-out panels, white surfaces, olive-green accent
   ============================================================ */

:root {
  --panel: #ffffff;
  --bg: #eef0ec;
  --ink: #24303a;
  --ink-dim: #5f6e79;
  --ink-faint: #97a4ad;
  --line: #e2e6e2;
  --green: #77a22d;
  --green-dark: #5d831f;
  --green-tint: rgba(119, 162, 45, 0.12);
  --danger: #e5484d;
  --blue: #1c7ed6;
  --shadow: 0 2px 14px rgba(20, 30, 24, 0.14);
  --font: 'Inter', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --rail-w: 56px;
  --panel-w: 344px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; font-family: var(--font); color: var(--ink); background: var(--bg); }
button { font-family: var(--font); }

#shell { display: flex; height: 100%; position: relative; }
#map { flex: 1; height: 100%; background: #dfe5dc; }

/* ============ ICON RAIL ============ */
#rail {
  width: var(--rail-w); flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0;
  z-index: 700;
}
.rail-logo {
  width: 38px; height: 38px; border-radius: 9px; background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px; margin-bottom: 10px; user-select: none;
}
.rail-btn {
  width: 42px; height: 42px; border: none; background: none; border-radius: 9px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  position: relative; transition: background 0.15s;
}
.rail-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink-dim); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn svg .fill { fill: var(--ink-dim); stroke: none; }
.rail-btn:hover { background: var(--bg); }
.rail-btn.active { background: var(--green-tint); }
.rail-btn.active svg { stroke: var(--green-dark); }
.rail-btn.active svg .fill { fill: var(--green-dark); }
.rail-btn.recording svg { stroke: var(--danger); }
.rail-btn.recording svg .fill { fill: var(--danger); }
.rail-spacer { flex: 1; }

/* ============ PANEL ============ */
#panel {
  width: var(--panel-w); flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line);
  display: none; flex-direction: column; z-index: 650; box-shadow: var(--shadow);
}
#panel.open { display: flex; }
#panel-header {
  height: 54px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--line);
}
#panel-title { font-size: 16px; font-weight: 700; }
#panel-close { border: none; background: none; font-size: 14px; color: var(--ink-faint); cursor: pointer; padding: 6px; }
#panel-close:hover { color: var(--ink); }
#panel-body { flex: 1; overflow-y: auto; }
#panel-body::-webkit-scrollbar { width: 8px; }
#panel-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

/* Panel building blocks */
.p-section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.p-section h4 { margin: 0 0 10px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.p-note { font-size: 12px; color: var(--ink-dim); line-height: 1.5; }

.p-btn {
  display: block; width: 100%; padding: 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.15s; text-align: center;
}
.p-btn:hover { border-color: var(--green); color: var(--green-dark); }
.p-btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.p-btn.primary:hover { background: var(--green-dark); color: #fff; }
.p-btn.danger { color: var(--danger); border-color: var(--danger); }
.p-btn + .p-btn { margin-top: 8px; }

/* Search */
.search-box {
  display: flex; align-items: center; gap: 8px; margin: 14px 16px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.search-box input {
  flex: 1; border: none; background: none; padding: 11px 0; font-size: 14px; color: var(--ink);
  font-family: var(--font); outline: none;
}
.search-result { padding: 11px 16px; cursor: pointer; border-bottom: 1px solid var(--line); }
.search-result:hover { background: var(--bg); }
.search-result .sr-name { font-size: 13px; font-weight: 600; }
.search-result .sr-detail { font-size: 11px; color: var(--ink-dim); margin-top: 2px; }

/* Active layers list */
.active-layer {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--panel);
}
.al-row { display: flex; align-items: center; gap: 8px; }
.al-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.al-name { flex: 1; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.al-btn { border: none; background: none; cursor: pointer; color: var(--ink-faint); font-size: 13px; padding: 3px 5px; line-height: 1; }
.al-btn:hover { color: var(--ink); }
.al-btn.del:hover { color: var(--danger); }
.al-slider-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.al-slider-row input[type=range] { flex: 1; accent-color: var(--green); height: 4px; }
.al-pct { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); width: 36px; text-align: right; }

/* Layer gallery */
.gallery-cat { border-bottom: 1px solid var(--line); }
.gallery-cat-header {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 16px;
  cursor: pointer; user-select: none; font-size: 13px; font-weight: 700;
}
.gallery-cat-header:hover { background: var(--bg); }
.gallery-cat-header .arrow { font-size: 10px; color: var(--ink-faint); transition: transform 0.2s; }
.gallery-cat.collapsed .gallery-grid { display: none; }
.gallery-cat.collapsed .arrow { transform: rotate(-90deg); }
.gallery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 4px 16px 14px; }
.gallery-card {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer;
  transition: all 0.15s; position: relative; background: var(--panel);
}
.gallery-card:hover { border-color: var(--green); box-shadow: var(--shadow); }
.gallery-card.added { border-color: var(--green); }
.gc-thumb { height: 54px; position: relative; }
.gc-name { padding: 7px 9px; font-size: 11px; font-weight: 600; line-height: 1.3; min-height: 40px; }
.gc-add {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.92); border: none; cursor: pointer; font-size: 13px; font-weight: 700;
  color: var(--green-dark); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.gallery-card.added .gc-add { background: var(--green); color: #fff; }

/* Saved lists */
.saved-tabs { display: flex; border-bottom: 1px solid var(--line); }
.saved-tab {
  flex: 1; padding: 12px 4px; border: none; background: none; cursor: pointer;
  font-size: 12px; font-weight: 700; color: var(--ink-dim); border-bottom: 2px solid transparent;
}
.saved-tab.active { color: var(--green-dark); border-bottom-color: var(--green); }
.saved-row { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.saved-row:hover { background: var(--bg); }
.saved-row .icon { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 14px; color: #fff; }
.saved-row .info { flex: 1; min-width: 0; }
.saved-row .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-row .meta { font-size: 11px; color: var(--ink-dim); font-family: var(--mono); margin-top: 1px; }
.saved-row .actions { display: flex; gap: 0; }
.empty-note { padding: 22px 16px; font-size: 12px; color: var(--ink-faint); text-align: center; }

/* Recording pill */
#rec-card {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 720;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 18px; padding: 10px 18px;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
.rec-block { text-align: center; }
.rec-val { font-family: var(--mono); font-size: 17px; font-weight: 700; color: var(--ink); }
.rec-label { font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
#rec-stop {
  background: var(--danger); color: #fff; border: none; border-radius: 9px;
  padding: 9px 18px; font-size: 13px; font-weight: 700; cursor: pointer;
}
#rec-pause {
  background: var(--panel); color: var(--ink-dim); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 14px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.rec-dot.paused { animation: none; background: var(--ink-faint); }

#shared-banner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 715;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; font-size: 13px;
  max-width: calc(100% - 120px);
}
#shared-banner .sb-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#shared-banner .sb-meta { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); flex-shrink: 0; }
#shared-banner button {
  border: none; border-radius: 8px; padding: 7px 12px; font-size: 12px; font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.slope-legend { display: flex; gap: 2px; margin-top: 8px; }
.slope-legend .sl-chip { flex: 1; text-align: center; font-size: 8.5px; color: #fff; padding: 3px 0; border-radius: 3px; font-weight: 600; }

/* Offline panel */
.progress-wrap { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress-bar { height: 100%; background: var(--green); border-radius: 4px; transition: width 0.2s; width: 0; }
.dl-est { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); margin: 6px 0; }
.zoom-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.zoom-row input[type=range] { flex: 1; accent-color: var(--green); }
.zoom-row .zv { font-family: var(--mono); font-size: 12px; width: 28px; text-align: right; color: var(--ink); }
.p-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; font-family: var(--font); color: var(--ink); background: var(--panel);
  outline: none; margin-bottom: 8px;
}
.p-input:focus { border-color: var(--green); }

/* Modal (track detail) */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 24, 0.5); z-index: 900;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow);
  width: 100%; max-width: 460px; max-height: 85vh; overflow-y: auto; padding: 20px;
}
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal .m-date { font-size: 11px; color: var(--ink-faint); font-family: var(--mono); margin-bottom: 14px; }
.m-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.m-stat { background: var(--bg); border-radius: 10px; padding: 10px 6px; text-align: center; }
.m-stat .v { font-family: var(--mono); font-size: 15px; font-weight: 700; }
.m-stat .l { font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); margin-top: 2px; }
.modal svg { width: 100%; height: 110px; margin-bottom: 12px; }
.m-close { width: 100%; }

/* Auth */
.auth-status { display: flex; align-items: center; justify-content: space-between; font-size: 13px; margin-bottom: 10px; }
.auth-email { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }

/* Route builder card */
#route-card {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 720;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  padding: 12px 16px; width: 380px; max-width: calc(100% - 90px);
}
.rc-stats { display: flex; gap: 22px; margin-bottom: 6px; }
.rc-stat .v { font-family: var(--mono); font-size: 17px; font-weight: 700; color: var(--ink); }
.rc-stat .l { font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
#rc-profile { display: block; width: 100%; height: 64px; margin: 4px 0 8px; }
.rc-actions { display: flex; gap: 6px; }
.rc-actions button {
  flex: 1; padding: 8px 4px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  font-size: 12px; font-weight: 600; cursor: pointer; color: var(--ink-dim);
}
.rc-actions button:hover { color: var(--ink); border-color: var(--ink-faint); }
.rc-actions button.primary { background: var(--green); border-color: var(--green); color: #fff; }

/* Status bar */
#shell:has(#panel.open) #statusbar { left: calc(var(--rail-w) + var(--panel-w)); }
#statusbar {
  position: absolute; bottom: 0; left: var(--rail-w); z-index: 640;
  background: rgba(255,255,255,0.9); border-top-right-radius: 8px;
  padding: 4px 12px; font-family: var(--mono); font-size: 11px; color: var(--ink-dim);
  display: flex; gap: 10px; backdrop-filter: blur(4px);
}
.sb-sep { color: var(--line); }

/* Settings */
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: var(--panel); padding: 6px 14px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--ink-dim); }
.seg button.on { background: var(--green); color: #fff; }

/* MapLibre chrome */
.maplibregl-ctrl-group { border-radius: 10px !important; box-shadow: var(--shadow) !important; }
.maplibregl-popup-content { border-radius: 10px; font-family: var(--font); box-shadow: var(--shadow); padding: 12px 14px; }
.maplibregl-popup-content b { font-size: 13px; }

/* ============ MOBILE ============ */
@media (max-width: 700px) {
  #shell { flex-direction: column-reverse; }
  #rail {
    width: 100%; height: 58px; flex-direction: row; justify-content: space-around;
    border-right: none; border-top: 1px solid var(--line); padding: 0 6px;
  }
  .rail-logo { display: none; }
  .rail-spacer { display: none; }
  #panel {
    position: fixed; left: 0; right: 0; bottom: 58px; top: auto; width: 100%;
    max-height: 62vh; border-radius: 16px 16px 0 0; border-right: none;
    box-shadow: 0 -4px 24px rgba(20,30,24,0.2);
  }
  #statusbar { left: 0; bottom: 58px; }
  #route-card { bottom: 70px; }
  #rec-card { gap: 10px; padding: 8px 12px; }
}
