:root {
  --primary: #e85d04;
  --primary-dark: #c44d00;
  --primary-light: #fff4ed;
  --navy: #1a2b4a;
  --navy-light: #2d4263;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --on-time: #16a34a;
  --delayed: #d97706;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(26, 43, 74, 0.08);
  --shadow-lg: 0 12px 40px rgba(26, 43, 74, 0.12);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* Header */
.header {
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
  font-weight: 800;
  font-size: 1.35rem;
}

.logo-icon { font-size: 1.6rem; }
.logo-text .accent { color: var(--primary); }

.nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.nav-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-btn.active { background: var(--primary); color: #fff; }

/* Hero */
.hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 60%, #3d5a80 100%);
  color: #fff;
  padding: 48px 0 56px;
  text-align: center;
}

.hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  margin-bottom: 12px;
}

.hero p {
  font-size: 1.05rem;
  opacity: 0.85;
  max-width: 560px;
  margin: 0 auto;
}

/* Main */
.main { padding: 32px 20px 64px; }

.panel { display: none; }
.panel.active { display: block; }

.search-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.search-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--navy);
}

.card-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: -12px 0 20px;
}

.form-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field {
  flex: 1;
  min-width: 180px;
  position: relative;
}

.field-wide { flex: 2; min-width: 260px; }

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input,
.field select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s;
  background: #fff;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
}

.swap-btn {
  width: 44px;
  height: 44px;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 1.2rem;
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 0;
  transition: all 0.2s;
}

.swap-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.2s, transform 0.1s;
  align-self: flex-end;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.98); }

/* Autocomplete */
.autocomplete-wrap { position: relative; }

.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  list-style: none;
  z-index: 50;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 4px;
}

.suggestions li {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.suggestions li:last-child { border-bottom: none; }
.suggestions li:hover,
.suggestions li.selected { background: var(--primary-light); }

.suggestions .sub { font-size: 0.78rem; color: var(--text-muted); }

/* Results */
.result-area { animation: fadeIn 0.3s ease; }

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

.train-header {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 28px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
}

.train-header h3 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--navy);
}

.train-header .meta {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-badge.on-time { background: #dcfce7; color: var(--on-time); }
.status-badge.delayed { background: #fef3c7; color: var(--delayed); }
.status-badge.running { background: #dbeafe; color: #2563eb; }
.status-badge.cancelled { background: #fee2e2; color: var(--danger); }

.current-position {
  background: linear-gradient(135deg, var(--primary-light), #fff);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
}

.current-position strong { color: var(--primary); }

/* Route timeline */
.route-timeline {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.route-timeline .timeline-header {
  background: var(--navy);
  color: #fff;
  padding: 14px 20px;
  font-weight: 600;
  font-size: 0.9rem;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 80px;
  gap: 8px;
}

.station-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 80px;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  align-items: center;
  transition: background 0.2s;
}

.station-row:last-child { border-bottom: none; }
.station-row.passed { opacity: 0.55; }
.station-row.current {
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  font-weight: 600;
}

.station-name { font-weight: 500; }
.station-code { font-size: 0.78rem; color: var(--text-muted); }

.delay-tag {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}

.delay-tag.on-time { color: var(--on-time); }
.delay-tag.late { color: var(--delayed); background: #fef3c7; }

/* Tables */
.data-table {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border-collapse: collapse;
}

.data-table th {
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  text-align: left;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }

.data-table .train-link {
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.data-table .train-link:hover { text-decoration: underline; }

.train-type {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: #e0e7ff;
  color: #3730a3;
  font-weight: 600;
}

/* PNR card */
.pnr-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pnr-top {
  background: var(--navy);
  color: #fff;
  padding: 20px 24px;
}

.pnr-top h3 { font-size: 1.1rem; margin-bottom: 8px; }

.pnr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  padding: 20px 24px;
}

.pnr-item label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: block;
  margin-bottom: 4px;
}

.pnr-item span { font-weight: 600; font-size: 0.95rem; }

.passenger-list { padding: 0 24px 20px; }

.passenger-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.passenger-row:last-child { border-bottom: none; }

.status-cnf { color: var(--success); font-weight: 700; }
.status-rac { color: #2563eb; font-weight: 700; }
.status-wl { color: var(--warning); font-weight: 700; }

/* Station board */
.board-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.board-tab {
  padding: 8px 20px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  font-size: 0.88rem;
}

.board-tab.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.refresh-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-refresh {
  background: none;
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.btn-refresh:hover { border-color: var(--primary); color: var(--primary); }

/* Empty / Error */
.empty-state, .error-state {
  text-align: center;
  padding: 48px 24px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.empty-state .icon, .error-state .icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p, .error-state p { color: var(--text-muted); }

/* Loader */
.loader {
  position: fixed;
  inset: 0;
  background: rgba(26, 43, 74, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
  color: #fff;
  font-weight: 500;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Footer */
.footer {
  background: var(--navy);
  color: rgba(255,255,255,0.6);
  padding: 24px 0;
  text-align: center;
  font-size: 0.82rem;
}

.footer-note { margin-top: 6px; opacity: 0.7; }

.hidden { display: none !important; }

.server-banner {
  background: #fef3c7;
  border-bottom: 2px solid #d97706;
  color: #92400e;
  padding: 12px 0;
  font-size: 0.9rem;
  text-align: center;
}

.server-banner code {
  background: rgba(0,0,0,0.08);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.85rem;
}

.server-banner a { color: #c44d00; font-weight: 600; }

/* Punctuality / History */
.history-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 6px;
}

.grade-card {
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  color: #fff;
  border-radius: var(--radius);
  padding: 24px 28px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.grade-badge {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 800;
  flex-shrink: 0;
}

.grade-badge.A { background: #16a34a; }
.grade-badge.B { background: #22c55e; }
.grade-badge.C { background: #d97706; }
.grade-badge.D { background: #ea580c; }
.grade-badge.F { background: #dc2626; }

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  margin: 24px 0 12px;
}

.delay-chart {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 24px;
}

.chart-row {
  display: grid;
  grid-template-columns: 90px 1fr 70px;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.82rem;
}

.chart-bar-wrap {
  background: #e2e8f0;
  border-radius: 4px;
  height: 22px;
  overflow: hidden;
}

.chart-bar {
  height: 100%;
  border-radius: 4px;
  min-width: 2px;
  transition: width 0.4s ease;
}

.chart-bar.on-time { background: #16a34a; }
.chart-bar.mild { background: #d97706; }
.chart-bar.heavy { background: #dc2626; }

.chart-delay {
  font-weight: 600;
  text-align: right;
  color: var(--text-muted);
}

.btn-secondary {
  background: #fff;
  color: var(--primary);
  border: 2px solid var(--primary);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-secondary:hover {
  background: var(--primary-light);
}

/* Responsive */
@media (max-width: 768px) {
  .timeline-header,
  .station-row {
    grid-template-columns: 1.5fr 1fr 1fr;
  }

  .timeline-header span:nth-child(4),
  .timeline-header span:nth-child(5),
  .station-row span:nth-child(4),
  .station-row span:nth-child(5) { display: none; }

  .data-table { font-size: 0.8rem; }
  .data-table th, .data-table td { padding: 10px 10px; }

  .nav { width: 100%; overflow-x: auto; }
  .nav-btn { white-space: nowrap; font-size: 0.8rem; padding: 7px 12px; }
}