@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --paper: #FBF9F4;
  --ink: #17181A;
  --blue: #1D4E89;
  --blue-dark: #123763;
  --amber: #F2A900;
  --red: #D7263D;
  --green: #1E8A5F;
  --brown: #6D4C33;
  --line-gray: #C9C3B6;
  --card: #FFFFFF;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  flex-wrap: wrap;
  border-bottom: 3px solid var(--ink);
  background: var(--paper);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-mark img { width: 100%; height: 100%; border-radius: 50%; display: block; }
.brand h1 { font-family: 'Baloo 2', sans-serif; font-size: 20px; font-weight: 700; margin: 0; }
.brand p { margin: 0; font-size: 12px; color: #6b6656; }

.status-pill {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 600;
  font-size: 12.5px;
  padding: 6px 13px;
  border: 2.5px solid var(--ink);
  border-radius: 20px;
  background: var(--green);
  color: white;
  display: flex; align-items: center; gap: 7px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: white; animation: blink 1.4s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Body layout ---------- */
.body-layout {
  display: flex;
  align-items: flex-start;
  padding: 14px;
  gap: 14px;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 290px;
  max-height: 640px;
  flex-shrink: 0;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 5px 5px 0 var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head { padding: 14px 16px 10px; border-bottom: 2px dashed var(--line-gray); }
.sidebar-head h2 { font-family: 'Baloo 2', sans-serif; font-size: 15px; font-weight: 700; margin: 0 0 2px 0; }
.sidebar-head p { margin: 0; font-size: 12px; color: #8a8570; }
.train-list { overflow-y: auto; flex: 1; padding: 8px; }
.train-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 4px;
}
.train-item:hover { background: #F3F0E7; }
.train-item.active { border-color: var(--ink); background: #F3F0E7; box-shadow: 2px 2px 0 var(--ink); }
.train-item.inactive { opacity: 0.55; }
.train-item.inactive .ti-sub { font-style: italic; }
.ti-icon { width: 26px; height: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.ti-text { min-width: 0; }
.ti-name { font-family: 'Baloo 2', sans-serif; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-sub { font-size: 11px; color: #8a8570; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.legend { padding: 10px 16px 14px; border-top: 2px dashed var(--line-gray); font-size: 11.5px; }
.legend-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.legend-row:last-child { margin-bottom: 0; }

/* ---------- Map column ---------- */
.map-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }

.train-card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: 5px 5px 0 var(--ink);
  flex-shrink: 0;
}
.train-card-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px; }
.train-card-info { flex: 1; min-width: 140px; }
.loco-illustration { width: 96px; height: 44px; flex-shrink: 0; }
.loco-illustration svg { width: 100%; height: 100%; display: block; }
.train-name-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.train-name { font-family: 'Baloo 2', sans-serif; font-size: 18px; font-weight: 700; margin: 0 0 2px 0; }
.train-sub { font-size: 13px; color: #6b6656; margin: 0; }
.eta-box { text-align: right; font-family: 'Baloo 2', sans-serif; }
.eta-box .eta-label { font-size: 11px; color: #8a8570; font-weight: 600; }
.eta-box .eta-value { font-size: 20px; font-weight: 800; color: var(--blue-dark); }

.live-badge {
  font-family: 'Baloo 2', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: white;
  background: var(--red);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 2px 9px;
  letter-spacing: 0.5px;
}

.share-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px dashed var(--line-gray);
  flex-wrap: wrap;
}
.btn.small { padding: 7px 14px; font-size: 12px; min-width: 0; display: inline-block; text-decoration: none; color: var(--ink); }
.btn.tracking { background: var(--red); color: white; }

.beta-badge {
  font-family: 'Baloo 2', sans-serif;
  font-size: 10px;
  font-weight: 700;
  color: var(--ink);
  background: var(--amber);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  padding: 1px 7px;
  letter-spacing: 0.4px;
  cursor: help;
}
.daily-badge {
  font-family: 'Baloo 2', sans-serif;
  font-size: 10px;
  font-weight: 700;
  color: white;
  background: #2E7D32;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  padding: 1px 7px;
  margin-left: 4px;
  letter-spacing: 0.4px;
  cursor: help;
}
.popup-schedule-link {
  display: inline-block;
  margin-top: 6px;
  font-family: 'Baloo 2', sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--blue-dark);
  text-decoration: none;
}
.popup-schedule-link:hover { text-decoration: underline; }
.popup-share-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  font-family: 'Baloo 2', sans-serif;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
  background: var(--amber);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
}
.popup-share-btn:active { transform: translate(1px, 1px); }
.share-status { font-size: 12px; color: #6b6656; }

.map-wrap {
  position: relative;
  width: 100%;
  height: 560px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 5px 5px 0 var(--ink);
  overflow: hidden;
}
#map { width: 100%; height: 100%; }

.map-search {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 54px;
  max-width: 420px;
  z-index: 500;
}
.map-search-row { display: flex; gap: 8px; align-items: stretch; }
.map-search input {
  flex: 1;
  min-width: 0;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  padding: 11px 14px;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  outline: none;
}
.map-search input:focus { background: #fff; }
.map-near-btn {
  flex-shrink: 0;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 12.5px;
  padding: 0 12px;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  background: var(--amber);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.map-near-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.map-near-btn:disabled { opacity: 0.65; cursor: wait; }
.map-search-results {
  margin-top: 6px;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  max-height: 260px;
  overflow-y: auto;
}
.map-search-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px dashed var(--line-gray);
}
.map-search-item:last-child { border-bottom: 0; }
.map-search-item:hover,
.map-search-item.active { background: #F3F0E7; }
.map-search-kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #8a8570;
}
.map-search-title {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 14px;
}
.map-search-sub { font-size: 11.5px; color: #6b6656; }
.map-search-empty { padding: 12px; font-size: 13px; color: #8a8570; }

.btn {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 600;
  font-size: 13px;
  border: 2.5px solid var(--ink);
  background: var(--amber);
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .08s ease;
  white-space: nowrap;
  text-align: center;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.secondary { background: white; }

.leaflet-popup-content-wrapper { border: 2.5px solid var(--ink) !important; border-radius: 10px !important; box-shadow: 3px 3px 0 var(--ink) !important; }
.leaflet-popup-tip { display: none; }
.leaflet-popup-content { font-family: 'Inter', sans-serif; font-size: 13px; margin: 8px 10px !important; min-width: 170px; }
.leaflet-popup-content b { font-family: 'Baloo 2', sans-serif; }
.popup-title { font-family: 'Baloo 2', sans-serif; font-size: 13.5px; font-weight: 700; margin-bottom: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.popup-loco { width: 100px; height: 46px; margin-bottom: 6px; }
.popup-loco svg { width: 100%; height: 100%; display: block; }
.popup-route { color: #6b6656; margin-bottom: 3px; }
.popup-eta { font-family: 'Baloo 2', sans-serif; color: var(--blue-dark); font-weight: 700; }
.popup-live { display: inline-block; font-family: 'Baloo 2', sans-serif; font-size: 9.5px; font-weight: 700; color: white; background: var(--red); border: 1.5px solid var(--ink); border-radius: 8px; padding: 1px 6px; letter-spacing: 0.4px; }

/* ---------- Panel bawah: kereta yang akan datang di stasiun ---------- */
.arrivals-panel {
  margin: 0 14px 14px;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 5px 5px 0 var(--ink);
  padding: 16px 18px;
}
.arrivals-head { display: block; }
.arrivals-head h2 { font-family: 'Baloo 2', sans-serif; font-size: 16px; font-weight: 700; margin: 0 0 3px 0; }
.arrivals-head p { margin: 0; font-size: 12.5px; color: #8a8570; }
.arrivals-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.arrivals-list:empty { margin-top: 0; }
.arrival-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #F3F0E7;
  border: 2px solid var(--ink);
  border-radius: 10px;
}
.arrival-icon { flex-shrink: 0; display: flex; align-items: center; justify-content: center; width: 30px; }
.arrival-text { flex: 1; min-width: 0; }
.arrival-name { font-family: 'Baloo 2', sans-serif; font-size: 13.5px; font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.arrival-sub { font-size: 12px; color: #6b6656; margin-top: 1px; }
.arrival-eta {
  flex-shrink: 0;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 14px;
  color: var(--blue-dark);
  background: white;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 4px 10px;
  text-align: center;
  min-width: 64px;
}

/* ---------- Comic train icons ---------- */
.icon-penumpang { width: 24px; height: 16px; background: var(--amber); border: 2.5px solid var(--ink); border-radius: 5px; display: flex; align-items: center; justify-content: center; gap: 2px; }
.icon-penumpang i { width: 6px; height: 7px; background: var(--paper); border: 1.5px solid var(--ink); border-radius: 1px; display: block; }
.icon-krl { width: 18px; height: 18px; background: var(--blue); border: 2.5px solid var(--ink); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.icon-krl i { width: 6px; height: 6px; background: var(--paper); border-radius: 50%; display: block; }
.icon-barang { width: 30px; height: 13px; background: var(--brown); border: 2.5px solid var(--ink); border-radius: 3px; }

.footer-note {
  padding: 4px 20px 18px;
  font-size: 11.5px;
  color: #8a8570;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .body-layout { flex-direction: column; padding: 10px; gap: 10px; }
  .sidebar { width: 100%; max-height: 220px; }
  .map-wrap { height: 60vh; min-height: 360px; }
  .map-search { right: 12px; max-width: none; }
  .btn { padding: 10px 14px; }
  .arrivals-panel { margin: 0 10px 10px; padding: 14px; }
  .arrival-item { flex-wrap: wrap; }
  .loco-illustration { width: 74px; height: 34px; }
}
