/* ── RESET & VARIABLES ─────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Premium Dark / Neon Color Palette */
  --bg-dark:      #050806;
  --panel-bg:     rgba(13, 26, 17, 0.65);
  --panel-bg-hov: rgba(20, 38, 25, 0.85);
  --border:       rgba(0, 200, 83, 0.15);
  --border-light: rgba(255, 255, 255, 0.1);
  --green:        #10b981;
  --green-glow:   rgba(16, 185, 129, 0.4);
  --green2:       #34d399;
  --red:          #ef4444;
  --red-glow:     rgba(239, 68, 68, 0.4);
  --gold:         #fbbf24;
  --gold-glow:    rgba(251, 191, 36, 0.4);
  --text:         #f8fafc;
  --muted:        #94a3b8;
  --mono:         'Space Mono', monospace;
  --sans:         'Inter', sans-serif;
  --bn:           'Tiro Bangla', serif;
  
  --br: 16px; /* border radius */
  --glass-blur: blur(16px);
}

html, body { 
  height: 100%; 
  overflow: hidden; 
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ── LANGUAGE TOGGLE LOGIC ─────────────────────────────────────────── */
.lang-en .lang-show-bn { display: none !important; }
.lang-bn .lang-show-en { display: none !important; }
.lang-en .lang-show-bn-input { display: none !important; }
.lang-bn .lang-show-en-input { display: none !important; }

/* ── UTILS ─────────────────────────────────────────────────────────── */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-light);
}

/* ── HEADER ────────────────────────────────────────────────────────── */
header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  border-bottom: 1px solid var(--border-light);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--green), var(--green2));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  color: #fff;
  box-shadow: 0 4px 12px var(--green-glow);
}
.logo-text { display: flex; flex-direction: column; }
.logo-en { font-family: var(--sans); font-size: 15px; font-weight: 800; color: var(--text); letter-spacing: 0.5px; }
.logo-bn { font-family: var(--bn); font-size: 16px; font-weight: 700; color: var(--text); }

.header-center { flex: 1; display: flex; justify-content: center; align-items: center; }

.live-pill {
  display: flex; align-items: center; gap: 8px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 30px;
  padding: 6px 16px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
  letter-spacing: 1px;
  box-shadow: 0 0 10px var(--red-glow);
}
.live-dot {
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  animation: blink 1.2s ease-in-out infinite;
  box-shadow: 0 0 8px var(--red);
}
@keyframes blink { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.4;transform:scale(.7)} }

.header-right { display: flex; align-items: center; gap: 24px; }

.lang-toggle-wrap {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  padding: 4px;
  border: 1px solid var(--border-light);
}
.lang-opt {
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 16px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.3s;
}
.lang-opt.active {
  background: var(--green);
  color: #fff;
  box-shadow: 0 2px 8px var(--green-glow);
}

.stats-wrap { display: flex; gap: 16px; }
.hstat { font-size: 13px; color: var(--muted); font-weight: 500; }
.hstat b { font-family: var(--mono); font-size: 14px; font-weight: 700; margin-left: 4px; color: var(--text); }
.on-time-txt b { color: var(--green2); }
.delayed-txt b { color: var(--red); }

/* ── MAIN APP & MAP ────────────────────────────────────────────────── */
.app-body { 
  display: flex; 
  height: 100vh; 
  width: 100vw;
  position: relative; 
}

#map { 
  width: 100%; 
  height: 100%; 
  position: absolute;
  top: 0; left: 0;
  z-index: 1;
}

/* Premium Dark map filter */
.leaflet-tile { filter: brightness(0.4) saturate(0.5) hue-rotate(90deg) contrast(1.2); }
.leaflet-container { background: #020403; font-family: var(--sans); }

/* ── FLOATING UI - SIDEBAR / BOTTOM SHEET ──────────────────────────── */
.sidebar {
  position: absolute;
  top: 88px;
  left: 24px;
  bottom: 24px;
  width: 340px;
  border-radius: var(--br);
  display: flex; flex-direction: column;
  overflow: hidden;
  z-index: 500;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-drag-handle { display: none; }

.search-wrap { padding: 16px; border-bottom: 1px solid var(--border-light); }
.search-inner {
  position: relative;
  width: 100%;
}
.search-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 16px;
}
.search-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 12px 14px 12px 40px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: all 0.3s;
}
.search-input:focus { 
  border-color: var(--green); 
  background: rgba(255, 255, 255, 0.08); 
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}
.search-input::placeholder { color: rgba(255,255,255,0.3); }

.section-label {
  padding: 16px 20px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 1px;
}

.train-list { overflow-y: auto; flex: 1; padding: 8px; }
.train-list::-webkit-scrollbar { width: 4px; }
.train-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

/* ── TRAIN CARD ────────────────────────────────────────────────────── */
.train-card {
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  background: rgba(255, 255, 255, 0.02);
}
.train-card:hover { 
  background: var(--panel-bg-hov); 
  border-color: rgba(255,255,255,0.05);
}
.train-card.active {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  box-shadow: inset 0 0 20px rgba(16, 185, 129, 0.05);
}
.card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.card-num { 
  font-family: var(--mono); 
  font-size: 12px; 
  color: var(--green2); 
  font-weight: 700; 
  background: rgba(16, 185, 129, 0.15);
  padding: 2px 8px;
  border-radius: 6px;
}
.card-badge {
  font-size: 11px; padding: 4px 10px; border-radius: 20px;
  font-weight: 600; letter-spacing: 0.5px;
}
.badge-on-time  { background: rgba(16, 185, 129, 0.15);  color: var(--green2); border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-delayed  { background: rgba(239, 68, 68, 0.15);   color: var(--red);    border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-arrived  { background: rgba(251, 191, 36, 0.15);  color: var(--gold);   border: 1px solid rgba(251, 191, 36, 0.3); }

.card-name   { font-size: 15px; font-weight: 600; margin-bottom: 6px; color: #fff; }
.card-route  { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.card-arrow  { color: var(--green); font-size: 14px; }
.card-speed  { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 10px; display: flex; align-items: center; justify-content: space-between;}
.card-speed i { color: var(--green); margin-right: 4px; }


/* ── DETAIL PANEL ──────────────────────────────────────────────────── */
.detail-panel {
  position: absolute;
  top: 88px; right: 24px;
  width: 320px;
  border-radius: var(--br);
  padding: 20px;
  z-index: 500;
  display: none;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  animation: slideInRight 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.detail-panel.open { display: block; }
@keyframes slideInRight { from{opacity:0;transform:translateX(30px) scale(0.95)} to{opacity:1;transform:none} }

.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.detail-number { font-family: var(--mono); font-size: 13px; color: var(--green2); margin-bottom: 4px; font-weight: 700; }
.detail-name   { font-size: 18px; font-weight: 700; color: #fff; }
.icon-btn  {
  background: rgba(255,255,255,0.05); 
  border: 1px solid rgba(255,255,255,0.1); 
  color: var(--muted);
  width: 32px; height: 32px; border-radius: 50%;
  cursor: pointer; font-size: 18px; 
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.icon-btn:hover { color: #fff; background: rgba(255,255,255,0.1); transform: scale(1.05); }

.detail-tags { display: flex; gap: 8px; margin-bottom: 20px; }
.detail-tag { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 20px; }
.speed-tag { background: rgba(255,255,255,0.1); color: #fff; font-family: var(--mono); }

.detail-grid { display: grid; gap: 12px; margin-bottom: 20px; }
.detail-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
}
.dr-label { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dr-label i { color: var(--green); opacity: 0.8; }
.dr-val { font-weight: 600; color: var(--text); }

.next-station-box {
  background: linear-gradient(145deg, rgba(16, 185, 129, 0.1), rgba(16, 185, 129, 0.02));
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 12px;
  padding: 16px;
  position: relative;
  overflow: hidden;
  margin-bottom: 16px;
}
.next-station-box::after {
  content: ''; position: absolute; right: -20px; bottom: -20px;
  width: 80px; height: 80px;
  background: var(--green); filter: blur(40px); opacity: 0.2;
}
.ns-label { font-size: 11px; font-weight: 700; color: var(--green2); letter-spacing: 1px; margin-bottom: 6px; }
.ns-name  { font-size: 18px; font-weight: 700; color: #fff; margin-bottom: 8px; }
.ns-eta   { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); font-weight: 500; }
.ns-eta i { color: var(--gold); }

.tracking-info-box {
  background: rgba(0,0,0,0.2);
  border-radius: 12px;
  padding: 16px;
}
.track-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--muted);
  margin-bottom: 8px;
}
.track-row:last-child { margin-bottom: 0; }
.track-row i { color: var(--green); font-size: 14px; }
.track-row b { color: var(--text); font-family: var(--mono); margin-left: 4px; }


/* ── LEAFLET & MAP MARKERS ─────────────────────────────────────────── */
.custom-marker-wrap {
  width: 100%; height: 100%;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.custom-marker-ring {
  position: absolute; inset: -4px;
  border-radius: 50%; border: 2px solid currentColor;
  animation: pulse-ring 2s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
}
@keyframes pulse-ring { 0% { transform: scale(0.8); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }

.leaflet-popup-content-wrapper {
  background: var(--panel-bg) !important;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-light) !important;
  border-radius: 12px !important;
  color: var(--text) !important;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
}
.leaflet-popup-tip { background: var(--panel-bg) !important; border: 1px solid var(--border-light); }
.leaflet-popup-content { margin: 16px !important; font-family: var(--sans) !important; min-width: 180px; }
.pu-num  { font-family: var(--mono); font-size: 12px; color: var(--green2); font-weight: 700; margin-bottom: 4px; }
.pu-name { font-size: 15px; font-weight: 700; margin-bottom: 12px; color: #fff; }
.pu-row  { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between;}
.pu-row span { color: var(--text); font-weight: 600; font-family: var(--mono); }


/* ── RESPONSIVE & MOBILE / BOTTOM SHEET ────────────────────────────── */
@media (max-width: 768px) {
  header { height: 60px; padding: 0 16px; }
  .logo-icon { width: 32px; height: 32px; font-size: 16px; border-radius: 8px; }
  .logo-en { font-size: 13px; }
  .logo-bn { font-size: 14px; }
  
  .header-center { display: none; }
  .stats-wrap { display: none; }

  /* Map takes full screen below header */
  .app-body { flex-direction: column; }
  #map { 
    height: calc(100vh - 60px); 
    top: 60px; 
  }
  
  /* Detail panel floating above bottom sheet */
  .detail-panel {
    top: 76px; left: 16px; right: 16px; width: auto;
    max-height: 40vh; overflow-y: auto;
    animation: slideInDown 0.3s ease;
  }
  @keyframes slideInDown { from{opacity:0;transform:translateY(-20px)} to{opacity:1;transform:none} }

  /* Bottom Sheet implementation */
  .sidebar {
    position: absolute;
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: 50vh;
    border-radius: 24px 24px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    border-top: 1px solid var(--border-light);
    transform: translateY(0);
    z-index: 600;
  }
  
  .mobile-drag-handle {
    display: block;
    width: 40px; height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 4px;
    margin: 12px auto;
  }
  
  /* If train detail is open, we can auto-hide sidebar or let it be. Let's rely on JS to add .hide-mobile to sidebar if detail is open, or just overlay nicely. */
  .sidebar.hide-mobile {
    transform: translateY(100%);
  }
}
