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

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #ede9fe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.07), 0 4px 12px rgba(0,0,0,0.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  background: var(--primary);
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.header-inner {
  max-width: 640px;
  margin: 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 1.4rem; }
.logo-text { color: #fff; font-size: 1.1rem; font-weight: 700; letter-spacing: -0.3px; }

/* Main */
.main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Section / Card */
.section { width: 100%; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Search */
.search-box {
  display: flex;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
}
input[type="text"] {
  flex: 1;
  border: none;
  outline: none;
  font-size: 1rem;
  color: var(--text);
  background: transparent;
  padding: 8px 8px;
  min-width: 0;
}
input[type="text"]::placeholder { color: #94a3b8; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 20px;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-primary:active:not(:disabled) { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-secondary:hover:not(:disabled) { background: var(--primary-light); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; border-radius: 8px; flex-shrink: 0; }
.btn-full { width: 100%; padding: 14px; font-size: 1rem; border-radius: var(--radius); }

/* Journey Summary Bar */
.journey-summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}
.journey-summary-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.js-train-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.js-train-num {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--primary-light);
  padding: 1px 8px;
  border-radius: 5px;
  white-space: nowrap;
}
.js-train-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.js-route-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  flex-wrap: wrap;
}
.js-arrow { color: var(--primary); }
.js-sep { color: var(--border); }

/* Spinner */
.spinner {
  width: 16px; height: 16px;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error */
.error-banner {
  margin-top: 8px;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.875rem;
}

/* Train card */
.train-badge {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.train-num {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 10px;
  border-radius: 6px;
}
.train-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.train-route {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 500;
}
.route-arrow { color: var(--primary); font-size: 1rem; }
.day-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.day-chip {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.day-chip.active { background: #dcfce7; color: #15803d; }
.day-chip.inactive { background: #f1f5f9; color: #94a3b8; }

/* Fields */
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.select-wrap { position: relative; }
.select-wrap::after {
  content: '▾';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
  font-size: 0.85rem;
}
select {
  width: 100%;
  padding: 10px 36px 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text);
  background: #fff;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
select:focus { border-color: var(--primary); }

/* Calendar */
.calendar {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #fafafa;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.9rem;
}
.cal-nav {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--primary);
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
  border-radius: 6px;
  transition: background 0.1s;
}
.cal-nav:hover { background: var(--primary-light); }
.cal-week-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #fafafa;
  border-bottom: 1px solid var(--border);
}
.cal-week-header span {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 6px 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.cal-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 4px;
  gap: 2px;
}
.cal-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  border-radius: 8px;
  cursor: default;
  color: #cbd5e1;
  font-weight: 500;
  transition: background 0.1s;
}
.cal-cell.available {
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}
.cal-cell.available:hover { background: var(--primary-light); color: var(--primary); }
.cal-cell.selected {
  background: var(--primary) !important;
  color: #fff !important;
  font-weight: 700;
}
.cal-cell.today:not(.selected) {
  color: var(--primary);
  font-weight: 700;
}

/* Selected date display */
.selected-date {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 14px;
  border-radius: 8px;
}

/* Seat finder */
.sf-info {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 14px;
  min-height: 36px;
  display: flex;
  align-items: center;
}
.sf-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sf-label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.counter { display: flex; align-items: center; gap: 0; border: 1.5px solid var(--border); border-radius: 8px; overflow: hidden; }
.counter-btn {
  width: 36px; height: 36px;
  border: none; background: #f8fafc; font-size: 1.2rem; font-weight: 700;
  cursor: pointer; color: var(--primary); transition: background 0.1s;
}
.counter-btn:hover { background: var(--primary-light); }
.counter-val { min-width: 36px; text-align: center; font-size: 1rem; font-weight: 700; border-left: 1.5px solid var(--border); border-right: 1.5px solid var(--border); }

/* Select-all button */
.select-all-btn {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1.5px solid var(--primary);
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  letter-spacing: 0.02em;
}
.select-all-btn:hover,
.coach-group.class-selected .select-all-btn {
  background: var(--primary);
  color: #fff;
}

/* Kind badges */
.kind-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.03em;
  margin-left: 6px;
  vertical-align: middle;
}
.kind-full    { background: #dcfce7; color: #15803d; }
.kind-change  { background: #fef9c3; color: #854d0e; }
.kind-partial { background: #ffedd5; color: #9a3412; }
.kind-none    { background: #fee2e2; color: #991b1b; }

/* Gap row */
.seg-gap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: #c2410c;
  background: #fff7ed;
  border: 1px dashed #fdba74;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-weight: 500;
}
.seg-gap-icon { font-size: 0.9rem; flex-shrink: 0; }

/* Coach selection states */
.coach-group.class-selected .class-badge { box-shadow: 0 0 0 2px var(--primary); }
.coach-chip.coach-selected { box-shadow: 0 0 0 2.5px var(--primary) !important; filter: brightness(0.92); }
.class-badge { cursor: pointer; transition: box-shadow 0.15s; }
.coach-chip { transition: box-shadow 0.15s, filter 0.15s; cursor: pointer; }

/* Seat results */
.result-passenger {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.result-passenger-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.result-segment {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
}
.result-segment:last-child { margin-bottom: 0; }
.seg-berth {
  font-size: 1.1rem;
  font-weight: 800;
  min-width: 50px;
  text-align: center;
}
.seg-coach {
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0.8;
}
.seg-route {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}
.seg-route strong { color: var(--text); font-weight: 700; }
.change-arrow {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #f97316;
  padding: 4px 10px;
  background: #ffedd5;
  border-radius: 6px;
  margin: 4px 0;
}
.result-none {
  background: #fef2f2;
  color: #dc2626;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
}
.debug-warn {
  background: #fef9c3;
  color: #713f12;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.8rem;
  margin-bottom: 10px;
}
.results-summary {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 500;
}
.comp-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* Composition */
.comp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.chart-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: #dcfce7;
  color: #15803d;
}

.coach-group { margin-bottom: 16px; }
.coach-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.class-badge {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.class-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}
.coach-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.coach-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  min-width: 58px;
  border: 2px solid transparent;
  cursor: default;
}
.coach-chip-name {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.coach-chip-berths {
  font-size: 0.7rem;
  font-weight: 600;
  margin-top: 3px;
  opacity: 0.75;
}

/* Coach class colour tokens */
.cls-1A { background: #fef9c3; border-color: #fde047; color: #854d0e; }
.cls-2A { background: #dbeafe; border-color: #93c5fd; color: #1e40af; }
.cls-3A { background: #dcfce7; border-color: #86efac; color: #166534; }
.cls-SL { background: #ffedd5; border-color: #fdba74; color: #9a3412; }
.cls-CC { background: #f3e8ff; border-color: #d8b4fe; color: #6b21a8; }
.cls-2S { background: #f1f5f9; border-color: #cbd5e1; color: #475569; }
.cls-GN { background: #f1f5f9; border-color: #cbd5e1; color: #475569; }
.cls-default { background: #f8fafc; border-color: #e2e8f0; color: #334155; }
