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

:root {
  --tpg: #00a870;
  --tpg-dark: #007a52;
  --blue: #1565c0;
  --orange: #e65100;
  --purple: #4a148c;
  --yellow: #f57f17;
  --teal: #00695c;
  --gray: #546e7a;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #212121;
  --muted: #757575;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); }

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100%; }

/* ── Header ── */
#header {
  flex-shrink: 0;
  background: var(--tpg);
  color: #fff;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  z-index: 900;
  position: relative;
}
.tpg-badge {
  background: #fff;
  color: var(--tpg);
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: -.5px;
  padding: 3px 9px;
  border-radius: 5px;
}
#header h1 { font-size: 1rem; font-weight: 600; }
#karios-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: 42px;
  width: 42px;
  object-fit: contain;
  pointer-events: none;
  mix-blend-mode: screen;
}
#header-status { margin-left: auto; font-size: .78rem; opacity: .9; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#spinner { display: flex; }

/* ── Progress bar ── */
#progress-bar { flex-shrink: 0; height: 3px; background: rgba(0,168,112,.25); }
#progress-fill { height: 100%; background: var(--tpg); width: 0; transition: width .3s; }

/* ── Body ── */
#body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ── */
#sidebar {
  width: 290px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
}

#search-wrap { padding: 10px; border-bottom: 1px solid var(--border); position: relative; }
#search-wrap svg { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
#search { width: 100%; padding: 8px 10px 8px 30px; border: 1.5px solid var(--border); border-radius: 7px; font-size: .88rem; outline: none; background: var(--bg); transition: border-color .2s; }
#search:focus { border-color: var(--tpg); background: #fff; }

#filters { padding: 9px 10px; border-bottom: 1px solid var(--border); }
#filters label { font-size: .68rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); display: block; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .74rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid currentColor;
  user-select: none;
  transition: background .15s, color .15s;
}
.chip.on { background: currentColor; }
.chip.on .chip-label { color: #fff; }
.chip-label { color: inherit; }

#stop-count { padding: 6px 12px; font-size: .72rem; color: var(--muted); border-bottom: 1px solid var(--border); }

#stop-list { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #ddd transparent; }
.stop-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px;
  border-bottom: 1px solid #f5f5f5;
  cursor: pointer;
  transition: background .12s;
}
.stop-item:hover { background: #f0fbf6; }
.stop-item.sel { background: #e6f7f0; border-left: 3px solid var(--tpg); padding-left: 8px; }
.stop-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.stop-text { flex: 1; min-width: 0; }
.stop-name { font-size: .86rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stop-sub { font-size: .72rem; color: var(--muted); margin-top: 1px; }

/* ── Map ── */
#map-wrap { flex: 1; position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; }

/* ── Info panel ── */
#info {
  position: absolute;
  bottom: 22px; right: 14px;
  width: 316px;
  background: var(--surface);
  border-radius: 11px;
  box-shadow: 0 8px 30px rgba(0,0,0,.22);
  z-index: 800;
  display: none;
  overflow: hidden;
  animation: slideUp .18s ease;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } }
.info-head { background: var(--tpg); color: #fff; padding: 13px 36px 13px 14px; position: relative; }
.info-stop-name { font-size: .97rem; font-weight: 700; }
.info-stop-meta { font-size: .73rem; opacity: .85; margin-top: 2px; }
#info-close {
  position: absolute; top: 9px; right: 9px;
  background: rgba(255,255,255,.25); border: none; color: #fff;
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
  font-size: .9rem; display: flex; align-items: center; justify-content: center;
}
#info-close:hover { background: rgba(255,255,255,.4); }

.info-section { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.info-section-title { font-size: .68rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 5px; }
#info-lines { display: flex; flex-wrap: wrap; gap: 4px; min-height: 20px; }
.lbadge {
  padding: 2px 7px; border-radius: 4px; font-size: .72rem; font-weight: 700;
  color: #fff; cursor: default;
}

#info-departures { max-height: 230px; overflow-y: auto; }
.dep-row { display: flex; align-items: center; gap: 7px; padding: 7px 10px; border-bottom: 1px solid #f8f8f8; }
.dep-line {
  min-width: 38px; height: 22px; border-radius: 4px;
  background: var(--blue); color: #fff;
  font-size: .71rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.dep-dest { flex: 1; font-size: .81rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep-time { font-size: .81rem; font-weight: 700; color: var(--tpg); min-width: 48px; text-align: right; }
.dep-time.now { color: #c62828; }
.dep-time.soon { color: #e65100; }
.msg { padding: 16px 10px; text-align: center; font-size: .82rem; color: var(--muted); }

#info-refresh { width: 100%; border: none; background: none; color: var(--tpg); font-size: .78rem; padding: 7px; cursor: pointer; border-top: 1px solid var(--border); font-weight: 600; }
#info-refresh:hover { background: #f0fbf6; }

/* ── Legend ── */
#legend {
  position: absolute; top: 10px; right: 10px; z-index: 700;
  background: rgba(255,255,255,.95); border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
  padding: 9px 12px; font-size: .75rem; backdrop-filter: blur(4px);
}
#legend h4 { font-size: .7rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 7px; }
.leg-item { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.leg-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ── Line type color swatch ── */
#legend-lines { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 7px; }

/* ── Cluster icon ── */
.cluster-icon {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--tpg); border: 2px solid #fff;
  color: #fff; font-weight: 700; font-size: .72rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

/* ── Scrollbar ── */
#stop-list::-webkit-scrollbar { width: 5px; }
#stop-list::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }
#info-departures::-webkit-scrollbar { width: 4px; }
#info-departures::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

/* ── Attribution override ── */
.leaflet-control-attribution { font-size: .65rem !important; }
