/* ==========================================================================
   MTA 6 Train Live Tracker — Modern Mobile-First Stylesheet
   ========================================================================== */

:root {
  --mta-green: #00933C;
  --mta-green-light: #00ba4c;
  --mta-green-glow: rgba(0, 147, 60, 0.35);
  --bg-primary: #121316;
  --bg-secondary: #1a1c22;
  --bg-tertiary: #23262f;
  --bg-card: #1e2129;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(0, 147, 60, 0.5);
  --text-primary: #ffffff;
  --text-secondary: #9ea5b3;
  --text-muted: #646b79;
  --accent-yellow: #f59e0b;
  --accent-cyan: #38bdf8;
  --accent-red: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  overflow-x: hidden;
}

/* App Wrapper */
.app-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 16px 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Top Nav */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.subway-bullet {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--mta-green);
  color: #fff;
  font-size: 26px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px var(--mta-green-glow);
  flex-shrink: 0;
  letter-spacing: -0.5px;
}

.subway-bullet.mini {
  width: 32px;
  height: 32px;
  font-size: 19px;
}

.subway-bullet.express {
  border-radius: 6px;
  transform: rotate(45deg);
}

.subway-bullet.express span {
  transform: rotate(-45deg);
  display: block;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-text p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--mta-green);
}

.icon-btn:active {
  transform: scale(0.92);
}

.spinning {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Station Hero Card */
.station-hero {
  background: linear-gradient(145deg, #1d212b 0%, #15181f 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  position: relative;
  overflow: hidden;
}

.station-hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--mta-green), var(--mta-green-light));
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 147, 60, 0.15);
  color: var(--mta-green-light);
  border: 1px solid rgba(0, 147, 60, 0.3);
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
}

.live-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mta-green-light);
  box-shadow: 0 0 8px var(--mta-green-light);
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.location-badge {
  color: var(--text-secondary);
  font-weight: 500;
}

.select-station-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.select-station-btn svg {
  width: 14px;
  height: 14px;
}

.select-station-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--mta-green);
}

.hero-station-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.hero-station-title h2 {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.borough-badge {
  background: var(--bg-tertiary);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
}

.hero-details {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.detail-item svg {
  width: 15px;
  height: 15px;
  color: var(--mta-green-light);
}

.transfers-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Nearby Chips */
.nearby-chips-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  overflow-x: auto;
  scrollbar-width: none;
}

.nearby-chips-container::-webkit-scrollbar {
  display: none;
}

.nearby-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.nearby-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chip {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chip span.dist {
  color: var(--text-muted);
  font-size: 0.7rem;
}

.chip:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.chip.active {
  background: var(--mta-green);
  border-color: var(--mta-green);
  color: #fff;
  font-weight: 700;
}

.chip.active span.dist {
  color: rgba(255, 255, 255, 0.8);
}

/* Alerts Section */
.alerts-section {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.alerts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.alert-icon-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent-yellow);
  font-size: 0.85rem;
  font-weight: 700;
}

.alert-icon-title svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.toggle-link {
  font-size: 0.78rem;
  color: var(--accent-yellow);
  text-decoration: underline;
  font-weight: 600;
  cursor: pointer;
}

.alerts-list {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(245, 158, 11, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-item {
  font-size: 0.82rem;
  color: #ffd88a;
  line-height: 1.4;
  padding-left: 14px;
  position: relative;
}

.alert-item::before {
  content: '•';
  position: absolute;
  left: 2px;
  color: var(--accent-yellow);
}

/* Arrivals Grid (2 Columns on Desktop, 1 on Mobile) */
.arrivals-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 680px) {
  .arrivals-grid {
    grid-template-columns: 1fr;
  }
}

.arrival-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.direction-header {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 12px;
}

.dir-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.dir-arrow {
  color: var(--mta-green-light);
  font-size: 0.95rem;
}

.direction-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.terminal-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Trains List */
.trains-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.train-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.train-row:hover {
  background: var(--bg-tertiary);
  border-color: rgba(255, 255, 255, 0.15);
}

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

.route-pill {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--mta-green);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.route-pill.express {
  border-radius: 4px;
  transform: rotate(45deg);
  width: 26px;
  height: 26px;
  font-size: 15px;
  margin: 3px;
}

.route-pill.express span {
  transform: rotate(-45deg);
}

.train-info {
  min-width: 0;
}

.train-dest {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.train-clock {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.train-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
  padding-left: 10px;
}

.countdown-badge {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent-cyan);
  letter-spacing: -0.5px;
}

.countdown-badge.arriving {
  color: var(--mta-green-light);
  animation: pulse 1.2s infinite;
  font-size: 1.05rem;
  background: rgba(0, 147, 60, 0.15);
  border: 1px solid rgba(0, 147, 60, 0.35);
  padding: 2px 8px;
  border-radius: 12px;
}

.countdown-badge.one-min {
  color: var(--mta-green-light);
}

.empty-state, .loading-state {
  padding: 36px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--mta-green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Footer */
.app-footer {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.refresh-status {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.auto-refresh-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.pulse-ring {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mta-green);
}

.data-attribution {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Station Selector Modal / Drawer
   ========================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

@media (max-width: 600px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal-content {
    max-height: 90vh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding-bottom: var(--safe-bottom);
  }
}

.modal-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-title-wrap h3 {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
}

.modal-title-wrap p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 26px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-search {
  padding: 12px 16px;
  position: relative;
  display: flex;
  align-items: center;
}

.modal-search svg {
  position: absolute;
  left: 28px;
  width: 17px;
  height: 17px;
  color: var(--text-muted);
}

.modal-search input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 11px 40px 11px 40px;
  color: var(--text-primary);
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  transition: all 0.2s ease;
}

.modal-search input:focus {
  border-color: var(--mta-green);
  box-shadow: 0 0 0 3px var(--mta-green-glow);
}

.clear-btn {
  position: absolute;
  right: 28px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.modal-tabs {
  display: flex;
  gap: 6px;
  padding: 0 16px 12px 16px;
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  scrollbar-width: none;
}

.modal-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--mta-green);
  border-color: var(--mta-green);
  color: #fff;
}

.station-list {
  padding: 8px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.station-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
}

.station-item:hover {
  background: var(--bg-tertiary);
}

.station-item.current {
  background: rgba(0, 147, 60, 0.18);
  border: 1px solid rgba(0, 147, 60, 0.4);
}

.station-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.station-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  width: 22px;
  text-align: right;
}

.station-title-group h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.station-title-group p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.station-item-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.station-dist-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--mta-green-light);
  background: rgba(0, 147, 60, 0.12);
  padding: 3px 8px;
  border-radius: 10px;
}

.station-dist-badge.far {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
}

.hidden {
  display: none !important;
}
