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

:root {
  --navy: #14324f;
  --navy-dark: #0d2137;
  --bus: #1d6fd1;
  --bus-tint: #f2f7fd;
  --bus-tint-2: #e3eefb;
  --car: #2e9e44;
  --car-tint: #f2f9f4;
  --car-tint-2: #e2f3e6;
  --line: #e3e8ee;
  --text-sub: #5a6b7a;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #f4f6f8;
}

/* ---------- top bar ---------- */

header {
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy) 55%, #1a4166 100%);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  border-bottom: 3px solid var(--bus);
  box-shadow: 0 2px 10px rgba(13, 33, 55, 0.35);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

header .region {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}


.legend {
  display: flex;
  gap: 8px;
  font-size: 0.78rem;
  align-items: center;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 3px 10px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.bus { background: var(--bus); box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }
.dot.car { background: var(--car); box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }
.dot.stop { background: #fff; border: 2px solid var(--navy); }

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.conn.on { background: rgba(46, 158, 68, 0.25); color: #7ee89a; }
.conn.on .conn-dot { animation: pulse 1.6s ease-in-out infinite; }
.conn.off { background: rgba(194, 39, 63, 0.3); color: #ff9fae; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#about-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font: italic 700 0.8rem Georgia, serif;
  cursor: pointer;
  flex-shrink: 0;
}
#about-btn:hover { background: rgba(255, 255, 255, 0.25); }

/* ---------- layout + sidebar ---------- */

main { flex: 1; display: flex; min-height: 0; position: relative; }

#sidebar {
  position: relative;
  flex: 0 0 300px;
  width: 300px;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow: hidden;
  transition: flex-basis 0.25s ease, width 0.25s ease;
}

body.sidebar-hidden #sidebar { flex-basis: 0; width: 0; border-right: none; }

.sidebar-inner {
  width: 300px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* sidebar tab (à la karte.vislatvijas.com) — a short rounded tab at the top
   edge that slides along with the sidebar and flips its arrow */
#sidebar-tab {
  position: absolute;
  top: 12px;
  left: 300px;
  width: 19px;
  height: 56px;
  z-index: 11;
  border: 1px solid var(--line);
  border-left: none;
  border-radius: 0 9px 9px 0;
  padding: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  box-shadow: 2px 1px 8px rgba(20, 50, 79, 0.14);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left 0.25s ease, background 0.15s ease;
}
#sidebar-tab:hover { background: #eef3f8; }
#sidebar-tab::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 6px solid var(--navy); /* ◄ collapse */
  margin-right: 1px;
}
body.sidebar-hidden #sidebar-tab { left: 0; }
body.sidebar-hidden #sidebar-tab::before {
  border-right: none;
  border-left: 6px solid var(--navy); /* ► expand */
  margin-right: 0;
  margin-left: 1px;
}

.sidebar-scroll { overflow-y: auto; flex: 1; }

.sidebar-scroll::-webkit-scrollbar { width: 8px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: #c9d3dc; border-radius: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb:hover { background: #aab8c5; }

/* eco savings banner */
#eco:not(:empty) {
  padding: 8px 14px;
  font-size: 0.74rem;
  color: #1e6b31;
  background: var(--car-tint);
  border-bottom: 1px solid var(--line);
  line-height: 1.4;
}
.eco-leaf {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  background: var(--car);
  border-radius: 0 70% 0 70%;
}

/* collapsible section headers (also toggle map visibility for bus/car) */
.sec-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--navy);
  cursor: pointer;
  user-select: none;
}
.sec-head:hover { color: var(--bus); }
.sec-head .sec-name { flex: 0 1 auto; }
.sec-head .cnt {
  color: var(--text-sub);
  font-weight: 600;
  flex: 1;
}
.sec-head .chev {
  flex-shrink: 0;
  transition: transform 0.2s;
  color: var(--text-sub);
}
.sec-head.closed .chev { transform: rotate(-90deg); }
.sec-head.closed .dot { filter: grayscale(1); opacity: 0.5; }
.sec-head.closed { color: var(--text-sub); }

/* vehicle cards — two calm lines, tinted by type */
.veh-card {
  margin: 0 8px 6px;
  padding: 9px 12px;
  border-radius: 10px;
  border-left: 3px solid;
  cursor: pointer;
  font-size: 0.82rem;
  transition: filter 0.15s, transform 0.15s;
}
.veh-card:hover { filter: brightness(0.97); transform: translateX(2px); }
.veh-card.bus { background: var(--bus-tint); border-left-color: var(--bus); }
.veh-card.car { background: var(--car-tint); border-left-color: var(--car); }

.veh-card .row1 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.veh-card .row2 {
  margin-top: 3px;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.route-num {
  font-weight: 700;
  color: #fff;
  background: var(--bus);
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 0.76rem;
  flex-shrink: 0;
}
.route-name {
  font-weight: 600;
  color: var(--navy);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.veh-card .drv { font-weight: 600; color: var(--navy); flex: 1; }
.veh-card .rate { font-size: 0.76rem; color: var(--text-sub); flex-shrink: 0; }

/* flat text star (replaces emoji) */
.star { color: #e2a615; font-style: normal; }

/* ride requests */
.req-hint {
  padding: 0 14px 6px;
  font-size: 0.7rem;
  color: var(--text-sub);
}
.req-empty {
  margin: 0 8px 10px;
  padding: 10px 12px;
  font-size: 0.78rem;
  color: var(--text-sub);
  background: #fafbfc;
  border: 1px dashed var(--line);
  border-radius: 10px;
}
#req-add {
  border: 1px solid var(--car);
  border-radius: 999px;
  background: var(--car-tint-2);
  color: #1e6b31;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 10px;
  cursor: pointer;
  letter-spacing: 0.02em;
}
#req-add:hover { background: #d2ecd9; }

.req-card {
  margin: 0 8px 6px;
  padding: 9px 12px;
  border-radius: 10px;
  background: #fafbfc;
  border: 1px solid var(--line);
  font-size: 0.8rem;
}
.req-route { font-weight: 600; color: var(--navy); }
.req-meta { color: var(--text-sub); margin-top: 2px; font-size: 0.76rem; }
.req-note { color: var(--text-sub); margin-top: 3px; font-size: 0.74rem; font-style: italic; }

#requests { padding-bottom: 10px; }

/* ---------- watched stops ---------- */

#watched:not(:empty) { border-bottom: 1px solid var(--line); padding: 8px 12px; background: #fffbf0; }

.watched-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #a07d1c;
  margin-bottom: 6px;
}

.watched-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.8rem;
}
.watched-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.watched-info b { color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.watched-info small { color: var(--text-sub); }

.unwatch-btn {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-sub);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.unwatch-btn:hover { background: #f0dfae; color: var(--navy); }

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(340px, calc(100vw - 28px));
}

.toast {
  background: var(--navy);
  color: #fff;
  border-left: 4px solid var(--bus);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.82rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: none; }
.toast span { color: #c8d6e4; word-break: break-all; }

/* ---------- modals + forms ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(13, 33, 55, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.hidden { display: none; }

.modal-box {
  position: relative;
  background: #fff;
  border-radius: 14px;
  padding: 22px 24px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  font-size: 0.88rem;
  line-height: 1.5;
}
.modal-box h2 { color: var(--navy); font-size: 1.15rem; margin-bottom: 10px; }
.modal-box p { margin-bottom: 10px; }
.modal-box ul { padding-left: 18px; margin-bottom: 10px; }
.modal-box li { margin-bottom: 6px; }
.modal-box .muted { color: var(--text-sub); font-size: 0.8rem; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: #f0f3f6;
  color: var(--text-sub);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: #e0e6ec; color: var(--navy); }

#req-form label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 10px;
}
#req-form .opt { font-weight: 400; color: var(--text-sub); }
#req-form input,
#req-form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
}
#req-form input:focus,
#req-form select:focus {
  outline: none;
  border-color: var(--bus);
  background: #fff;
}
.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; }
.form-error { color: #c2273f; font-size: 0.78rem; min-height: 1.2em; margin-bottom: 8px; }

.btn-primary {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--car);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: #278a3b; }

/* ---------- map markers ---------- */

.veh-dot {
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}
.veh-dot.bus { width: 16px; height: 16px; background: var(--bus); }
.veh-dot.car { width: 13px; height: 13px; background: var(--car); }

/* ---------- map popups (colored header strip per type) ---------- */

.maplibregl-popup-content {
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  font-size: 0.82rem;
}

.pp { min-width: 220px; }

.pp-head { padding: 10px 14px 9px; color: #fff; }
.pp-bus .pp-head { background: linear-gradient(120deg, #1a5cad, var(--bus)); }
.pp-car .pp-head { background: linear-gradient(120deg, #237a35, var(--car)); }
.pp-stop .pp-head { background: linear-gradient(120deg, var(--navy-dark), var(--navy)); }

.pp-kindrow { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.pp-kind {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
}
.pp-sub { font-size: 0.7rem; opacity: 0.8; }
.pp-title { font-size: 0.92rem; font-weight: 700; margin-top: 2px; line-height: 1.3; }

.pp-body { padding: 10px 14px 12px; background: #fff; }
.pp-state { color: var(--navy); margin-bottom: 6px; }
.pp-state:last-child { margin-bottom: 0; }

.pp-etas { display: flex; flex-direction: column; }
.pp-eta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid #f0f3f6;
}
.pp-eta:last-child { border-bottom: none; }
.pp-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--navy);
}
.pp-line span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pp-eta .t { flex-shrink: 0; color: var(--navy); }
.pp-eta .t small { color: var(--text-sub); }

.pp-eco {
  margin-top: 8px;
  padding: 6px 9px;
  font-size: 0.74rem;
  color: #1e6b31;
  background: var(--car-tint);
  border-radius: 8px;
}

.pp-note {
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--text-sub);
  line-height: 1.4;
}

.pp-actions { display: flex; gap: 6px; margin-top: 10px; }

.watch-btn {
  flex: 1;
  border: 1.5px solid var(--bus);
  border-radius: 8px;
  background: var(--bus-tint);
  color: var(--navy);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 6px 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.watch-btn:hover { background: var(--bus-tint-2); }
.watch-btn.on { background: var(--car-tint-2); border-color: var(--car); }

.share-btn {
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  color: var(--text-sub);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
}
.share-btn:hover { background: #f0f3f6; color: var(--navy); }

.maplibregl-popup-close-button {
  color: rgba(255, 255, 255, 0.85);
  font-size: 1.15rem;
  padding: 2px 8px;
}
.maplibregl-popup-close-button:hover { color: #fff; background: transparent; }

/* the popup arrow tip should match the header color it points at */
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #fff; }

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

/* ---------- map controls (zoom / compass) ---------- */

.maplibregl-ctrl-group {
  background: rgba(255, 255, 255, 0.88) !important;
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 10px !important;
  box-shadow: 0 2px 10px rgba(20, 50, 79, 0.16) !important;
  overflow: hidden;
}
.maplibregl-ctrl-group button {
  width: 34px !important;
  height: 34px !important;
  background-color: transparent !important;
}
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl-group button:hover { background-color: var(--bus-tint) !important; }

.maplibregl-ctrl button.maplibregl-ctrl-zoom-in .maplibregl-ctrl-icon {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 29 29'%3E%3Cpath d='M14.5 9v11M9 14.5h11' stroke='%2314324f' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") !important;
}
.maplibregl-ctrl button.maplibregl-ctrl-zoom-out .maplibregl-ctrl-icon {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 29 29'%3E%3Cpath d='M9 14.5h11' stroke='%2314324f' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") !important;
}
.maplibregl-ctrl button.maplibregl-ctrl-compass .maplibregl-ctrl-icon {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 29 29'%3E%3Cpath d='M14.5 5.5l4.2 9h-8.4z' fill='%2314324f'/%3E%3Cpath d='M14.5 23.5l4.2-9h-8.4z' fill='%23c2cbd4'/%3E%3C/svg%3E") !important;
}

/* ---------- bottom-sheet drag handle (mobile only) ---------- */

#sheet-handle {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 10px 0 8px;
  cursor: grab;
  touch-action: none;
  flex-shrink: 0;
}
#sheet-handle span {
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: #c9d3dc;
}

/* ---------- mobile: bottom sheet over a full-screen map ---------- */

@media (max-width: 700px) {
  header { padding: 8px 12px; gap: 6px 10px; }
  header h1 { font-size: 0.92rem; }
  header .region { display: none; }
  .legend-item { display: none; } /* the sheet sections already label the dots */

  #sidebar-tab { display: none; }
  #sheet-handle { display: flex; }

  #sidebar,
  body.sidebar-hidden #sidebar {
    position: absolute;
    inset: auto 0 0 0;
    width: 100%;
    flex: none;
    height: 62dvh;
    display: flex;
    flex-direction: column;
    border-right: none;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.2);
    transition: height 0.25s ease;
    z-index: 10;
  }
  body.sheet-peek #sidebar { height: 34px; overflow: hidden; }

  .sidebar-inner { width: 100%; flex: 1; min-height: 0; }

  /* roomier touch targets */
  .sec-head { padding: 12px 16px 10px; }
  .veh-card { padding: 12px 14px; }
  .pp-actions button { padding: 9px 10px; }

  /* popups must fit narrow screens */
  .maplibregl-popup { max-width: min(320px, 92vw) !important; }
  .pp { min-width: 200px; }

  /* toasts go under the header so the sheet never covers them */
  #toasts {
    top: 58px;
    bottom: auto;
    left: 12px;
    right: 12px;
    max-width: none;
  }

  /* modals become bottom sheets */
  .modal { align-items: flex-end; padding: 0; }
  .modal-box {
    max-width: 100%;
    max-height: 88dvh;
    border-radius: 16px 16px 0 0;
    padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  }

  .maplibregl-ctrl-top-right { top: 6px; right: 6px; }
}
