/* =========================================================
   VTC Train Alert — "Glass Transit" Design System
   Mobile-first, épuré, moderne
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  --bg-deep: #0a0e1a;
  --bg-surface: #111827;
  --bg-elevated: #1a2235;
  --bg-glass: rgba(26, 34, 53, 0.7);
  --bg-glass-light: rgba(255, 255, 255, 0.03);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-gold: #fbbf24;
  --accent-gold-soft: rgba(251, 191, 36, 0.15);
  --accent-blue: #3b82f6;
  --accent-blue-soft: rgba(59, 130, 246, 0.12);
  
  --status-success: #22c55e;
  --status-warning: #f59e0b;
  --status-danger: #ef4444;
  
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.1);
  
  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 40px rgba(251, 191, 36, 0.15);
  
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
}

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

html { -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; }
html, body { height: 100%; overflow-x: hidden; }

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-deep);
  background-image: 
    radial-gradient(ellipse 80% 50% at 50% -20%, var(--accent-blue-soft), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(251, 191, 36, 0.06), transparent);
  background-attachment: fixed;
}

.container { width: 100%; max-width: 720px; margin: 0 auto; padding: 0 var(--space-md); }

.topbar {
  position: sticky; top: 0; z-index: 50;
  padding: var(--space-md) 0;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar .container { display: flex; flex-direction: column; gap: var(--space-md); }
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); }

.brand { display: flex; align-items: center; gap: var(--space-sm); font-size: 17px; font-weight: 700; color: var(--text-primary); }
.brand-icon { font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-sm); }

.status {
  width: 100%; display: flex; align-items: center; gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  background: var(--bg-glass-light);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
}

.status::before {
  content: ''; flex-shrink: 0; width: 8px; height: 8px;
  background: var(--accent-gold); border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1); }
}

.status.active::before { background: var(--status-success); }
.status.error::before { background: var(--status-danger); }

button {
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; border: none; outline: none;
  transition: all var(--duration-fast) var(--ease-out);
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  color: var(--bg-deep);
  background: linear-gradient(135deg, var(--accent-gold), #f59e0b);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm), var(--shadow-glow);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-md), 0 0 50px rgba(251, 191, 36, 0.25); }
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-secondary, button.secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--text-secondary);
  background: var(--bg-glass-light);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
}
.btn-secondary:hover:not(:disabled), button.secondary:hover:not(:disabled) {
  color: var(--text-primary); background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.15);
}

.chip-btn { padding: var(--space-sm) var(--space-md); font-size: 13px; border-radius: var(--radius-full); }
.btnrow { display: flex; gap: var(--space-sm); }
.btnrow button { flex: 1; }

.card {
  margin-top: var(--space-lg); padding: var(--space-lg);
  background: var(--bg-glass); backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-md);
}
.card h1 { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.card > p { margin-top: var(--space-sm); font-size: 14px; color: var(--text-secondary); }
.muted { color: var(--text-muted); }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-md); margin-top: var(--space-lg); }
@media (max-width: 600px) { .grid { grid-template-columns: 1fr; gap: var(--space-sm); } }

label { display: block; margin-bottom: var(--space-xs); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }

input[type="number"], input[type="text"] {
  width: 100%; padding: var(--space-md);
  font-family: var(--font-mono); font-size: 14px;
  color: var(--text-primary); background: var(--bg-surface);
  border: 1px solid var(--border-medium); border-radius: var(--radius-md);
  outline: none; transition: all var(--duration-fast) var(--ease-out);
}
input:focus { border-color: var(--accent-gold); box-shadow: 0 0 0 3px var(--accent-gold-soft); }
input::placeholder { color: var(--text-muted); }

.popup {
  position: fixed; inset: auto var(--space-md) var(--space-md) var(--space-md);
  max-width: 480px; margin: 0 auto; z-index: 100;
  display: flex; flex-direction: column; max-height: 70vh;
  background: var(--bg-elevated); border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  overflow: hidden; animation: slideUp var(--duration-normal) var(--ease-out);
}
.popup.hidden { display: none; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.popup-head {
  flex-shrink: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: linear-gradient(135deg, var(--accent-blue-soft), var(--accent-gold-soft));
  border-bottom: 1px solid var(--border-subtle);
}

.popup-title { flex: 1; min-width: 0; }
.popup-station-name { display: block; font-size: 15px; font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.popup-nav-links { display: flex; gap: var(--space-sm); margin-top: var(--space-sm); }

.nav-link {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; font-size: 12px; font-weight: 600;
  text-decoration: none; border-radius: var(--radius-full);
  transition: all var(--duration-fast) var(--ease-out);
}
.nav-maps { color: #fff; background: linear-gradient(135deg, #4285f4, #34a853); border: 1px solid rgba(255,255,255,0.2); }
.nav-maps:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(66, 133, 244, 0.4); }
.nav-waze { color: #000; background: linear-gradient(135deg, #33ccff, #00d4ff); border: 1px solid rgba(0,0,0,0.1); }
.nav-waze:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(51, 204, 255, 0.4); }

.popup-close {
  flex-shrink: 0; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}
.popup-close:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.1); }

.popup-body { flex: 1; overflow-y: auto; padding: var(--space-md); -webkit-overflow-scrolling: touch; }

.board-section { margin-bottom: var(--space-lg); }
.board-section:last-child { margin-bottom: 0; }

.section-title {
  display: flex; align-items: center; gap: var(--space-sm);
  margin-bottom: var(--space-md); padding-bottom: var(--space-sm);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); border-bottom: 1px solid var(--border-subtle);
}

.board-empty {
  padding: var(--space-lg); text-align: center; font-size: 13px; color: var(--text-muted);
  background: var(--bg-glass-light); border: 1px dashed var(--border-medium); border-radius: var(--radius-md);
}

.board-list { display: flex; flex-direction: column; gap: var(--space-sm); }

.board-row {
  display: grid; grid-template-columns: auto 1fr; gap: var(--space-md); padding: var(--space-md);
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-out);
}
.board-row:hover { border-color: var(--border-medium); background: var(--bg-elevated); }

.col-time {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 70px; padding-right: var(--space-md); border-right: 1px solid var(--border-subtle);
}
.time-main { font-family: var(--font-mono); font-size: 22px; font-weight: 700; color: var(--accent-gold); line-height: 1; }
.planned { margin-top: var(--space-xs); font-size: 11px; color: var(--text-muted); }
.planned-empty { visibility: hidden; }

.col-info { display: flex; flex-direction: column; justify-content: center; gap: var(--space-xs); min-width: 0; }
.dest-main { font-size: 14px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dest-sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.row-status { display: inline-flex; align-items: center; gap: var(--space-xs); margin-top: var(--space-xs); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); }
.status-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }

.st-ontime .status-dot { background: var(--status-success); }
.st-ontime .status-label { color: var(--status-success); }
.st-delayed .status-dot { background: var(--status-warning); }
.st-delayed .status-label { color: var(--status-warning); }
.st-delayed .time-main { color: var(--status-warning); }
.st-cancelled .status-dot { background: var(--status-danger); }
.st-cancelled .status-label { color: var(--status-danger); }
.st-cancelled .time-main { color: var(--status-danger); text-decoration: line-through; opacity: 0.7; }

.pill { display: inline-flex; align-items: center; padding: 2px 8px; font-size: 11px; font-weight: 700; border-radius: var(--radius-full); background: var(--bg-glass-light); border: 1px solid var(--border-subtle); }
.pill-delay { color: var(--status-warning); background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.2); }

.stations-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-md); }
.stations-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.stations-subtitle { margin-top: var(--space-xs); font-size: 13px; color: var(--text-secondary); }
.stations-search { display: flex; gap: var(--space-sm); margin-top: var(--space-md); }
#stationFilter { flex: 1; }
#stationFilterClear { flex-shrink: 0; width: 44px; height: 44px; font-size: 14px; color: var(--text-muted); }
.stations-footnote { margin-top: var(--space-md); font-size: 12px; color: var(--text-muted); }

.station-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-md);
  padding: var(--space-md); margin-bottom: var(--space-sm);
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-out);
}
.station-row:hover { border-color: var(--border-medium); }
.station-info { min-width: 0; flex: 1; }
.station-name { font-size: 14px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.station-meta { display: flex; align-items: center; gap: var(--space-sm); margin-top: var(--space-xs); font-size: 12px; color: var(--text-muted); }
.station-meta .dot { opacity: 0.5; }

.toggle { display: flex; align-items: center; gap: var(--space-sm); cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track { position: relative; width: 44px; height: 26px; background: var(--bg-deep); border: 1px solid var(--border-medium); border-radius: var(--radius-full); transition: all var(--duration-fast) var(--ease-out); }
.toggle .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: var(--text-secondary); border-radius: 50%; transition: all var(--duration-fast) var(--ease-out); }
.toggle input:checked + .track { background: var(--accent-gold-soft); border-color: var(--accent-gold); }
.toggle input:checked + .track::after { transform: translateX(18px); background: var(--accent-gold); }
.toggle .txt { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); min-width: 24px; }
.toggle input:checked ~ .txt { color: var(--accent-gold); }

.err { padding: var(--space-md); color: var(--status-danger); background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.2); border-radius: var(--radius-md); font-weight: 600; }
.hidden { display: none !important; }

@media (max-width: 600px) {
  :root { --space-lg: 20px; }
  .container { padding: 0 var(--space-sm); }
  .topbar { padding: var(--space-sm) 0; }
  .brand { font-size: 15px; }
  .card { margin-top: var(--space-md); padding: var(--space-md); border-radius: var(--radius-lg); }
  .card h1 { font-size: 18px; }
  .btnrow { flex-direction: column; }
  .btnrow button { width: 100%; }
  .popup { inset: auto var(--space-sm) var(--space-sm) var(--space-sm); max-height: 65vh; border-radius: var(--radius-lg); }
  .popup-head { padding: var(--space-md); }
  .popup-body { padding: var(--space-sm); }
  .board-row { padding: var(--space-sm); gap: var(--space-sm); }
  .col-time { min-width: 60px; padding-right: var(--space-sm); }
  .time-main { font-size: 18px; }
  .dest-main { font-size: 13px; }
  .stations-head { flex-direction: column; align-items: stretch; }
  .stations-head button { width: 100%; }
}

@media (max-width: 380px) {
  .brand-icon { display: none; }
  .time-main { font-size: 16px; }
  .col-time { min-width: 50px; }
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .popup { padding-bottom: env(safe-area-inset-bottom); }
}

.stations-actions {
  display: flex;
  gap: var(--space-sm);
}

@media (max-width: 600px) {
  .stations-actions {
    flex-direction: column;
    width: 100%;
  }
  
  .stations-actions button {
    width: 100%;
  }
}
