:root {
  --bg: #eff1f5;
  --fg: #1a1a1a;
  --accent: #ff4124;
  --card: #ffffff;
  --card-fg: #1a1a1a;
  --header-bg: #222942;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

a {
  color: var(--accent);
}

/* Traffic info banner */
.traffic-banner {
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  border-radius: 6px;
  font-weight: 500;
}

.traffic-banner-info {
  background: #d1ecf1;
  color: #0c5460;
  border-left: 4px solid #17a2b8;
}

.traffic-banner-warning {
  background: #fff3cd;
  color: #856404;
  border-left: 4px solid #ffc107;
}

.traffic-banner-error {
  background: #f8d7da;
  color: #721c24;
  border-left: 4px solid #dc3545;
}

.site-header {
  background: var(--header-bg);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  position: relative;
}

.site-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
}

.header-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0.3rem;
  text-decoration: none;
}

.header-icon:hover {
  color: var(--accent);
}

.brand-logo {
  height: 40px;
  width: auto;
  display: block;
}

.brand-text {
  color: #fff;
  font-weight: 700;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
}

h1 {
  margin-top: 0;
}

.back {
  display: inline-block;
  margin-bottom: 1rem;
}

.muted {
  color: #666;
}

/* Departures list */
.day {
  background: var(--card);
  color: var(--card-fg);
  border: 1px solid #e2e5ea;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.day > summary {
  cursor: pointer;
  padding: 0.75rem 1rem;
  font-weight: 600;
  list-style: none;
}

.departures {
  list-style: none;
  margin: 0;
  padding: 0;
}

.departure {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid #eef0f3;
}

.departure-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  flex: 1;
  min-width: 0;
}

.departure-info .name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--fg);
}

.departure-info .route {
  font-size: 0.9rem;
  color: #444;
  font-weight: 500;
}

.departure-info .time {
  font-size: 0.85rem;
  color: #333;
  font-weight: 600;
}

.departure-action {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
  align-self: flex-start;
}

/* Badges */
.badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-available { background: #e3f5ec; color: #0b6e4f; }
.badge-few { background: #fff3d6; color: #8a6100; }
.badge-full { background: #fde3e3; color: #a11; }
.badge-departed { background: #e2e5ea; color: #555; }

/* Departed: keep seat colours but dim the row and disable the button. */
.departure.departed .departure-info { opacity: 0.6; }

/* Buttons */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
}

.btn[disabled],
.btn-disabled {
  background: #bbb;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  font-size: 1rem;
  padding: 0.6rem 1.2rem;
}

/* Forms */
.booking-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 360px;
}

.booking-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
}

.booking-form label:has(input[required]) .label-text::after,
.booking-form label:has(select[required]) .label-text::after {
  content: " *";
  color: var(--accent);
  font-weight: 700;
}

.booking-form input,
.booking-form select {
  padding: 0.5rem;
  border: 1px solid #c8ccd2;
  border-radius: 6px;
  font-size: 1rem;
}

.departure-summary {
  background: var(--card);
  color: var(--card-fg);
  border: 1px solid #e2e5ea;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.sms-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #e8f1ff;
  color: #1c4d8c;
  border: 1px solid #c5dcf7;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.sms-info .icon {
  flex-shrink: 0;
}

/* Ticket card */
.ticket-card {
  background: var(--card);
  color: var(--card-fg);
  border: 2px solid #e2e5ea;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 500px;
  margin: 0 auto;
}

.ticket-header {
  border-bottom: 2px solid #e2e5ea;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

.ticket-header h2 {
  margin: 0 0 0.5rem 0;
  font-size: 1.5rem;
}

.ticket-datetime {
  font-size: 1.3rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 0.5rem;
}

.ticket-countdown {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  min-height: 1.2rem;
}

.ticket-seats {
  font-size: 1rem;
  color: #555;
}

.ticket-details {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.ticket-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.ticket-row .label {
  color: #666;
  font-weight: 500;
}

.ticket-row .value {
  text-align: right;
  font-weight: 400;
}

.ticket-cancel {
  text-align: center;
  padding-top: 1rem;
  margin-top: 1rem;
  border-top: 1px solid #e2e5ea;
}

.ticket-cancel form {
  margin: 0;
}

.cancel-link {
  background: none;
  border: none;
  color: #666;
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

.cancel-link:hover {
  color: #dc3545;
}

.ticket-departed {
  text-align: center;
  color: #666;
  font-style: italic;
  margin: 1rem 0 0 0;
  padding-top: 1rem;
  border-top: 2px solid #e2e5ea;
}

/* Cancellation success card */
.success-card {
  background: var(--card);
  color: var(--card-fg);
  border: 2px solid #28a745;
  border-radius: 12px;
  padding: 2rem;
  max-width: 500px;
  margin: 0 auto;
  text-align: center;
}

.booking-summary {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 1rem;
  margin: 1.5rem 0;
}

.booking-summary p {
  margin: 0.5rem 0;
}

/* intl-tel-input: keep dial code compact and input full width */
.booking-form .iti {
  width: 100%;
}

.iti__selected-dial-code {
  font-size: 0.9rem;
}

.error-message {
  background: #fde3e3;
  color: #a11;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
}

.success-message {
  color: #0b6e4f;
  font-weight: 600;
}

.field-error {
  display: block;
  margin-top: 0.35rem;
  color: #a11;
  font-size: 0.9rem;
}

/* Ticket */
.ticket {
  background: var(--card);
  color: var(--card-fg);
  border: 1px solid #e2e5ea;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.ticket-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid #eef0f3;
}

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

.ticket-row span {
  color: #666;
}

.ticket-id strong {
  font-family: ui-monospace, monospace;
}

/* Admin */
.admin-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.admin-nav .inline {
  margin: 0;
}

.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.admin-head-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Statistics KPI cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0 1.75rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid #e2e5ea;
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.82rem;
  color: #777;
  margin-bottom: 0.4rem;
}

.stat-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--fg);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  color: var(--card-fg);
  border: 1px solid #e2e5ea;
  border-radius: 8px;
  overflow: hidden;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #eef0f3;
  vertical-align: middle;
}

.admin-table tbody tr:nth-child(even) {
  background: #f0f1f4;
}

.admin-table tr.past {
  color: #999;
}

/* Icon action buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid #d3d7dd;
  border-radius: 6px;
  background: #fff;
  color: #444;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
}

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

.icon-btn.icon-danger:hover {
  background: #a11;
  border-color: #a11;
}

.icon-btn .icon {
  display: block;
}

.direction-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.direction-group label {
  flex: 1;
}

.direction-group .icon-btn {
  flex-shrink: 0;
  height: 40px;
  width: 40px;
  margin-top: 1.5rem;
}

.direction-group .icon-btn .icon {
  transform: rotate(90deg);
}

.filter-group {
  margin-bottom: 1rem;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.filter-group .direction-group {
  width: 100%;
}

.filter-group label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.filter-group .label-text {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: left;
}

.filter-group select {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
  width: 100%;
}

.filter-group select option {
  white-space: normal;
}

.filter-group select:hover {
  border-color: var(--accent);
}

.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.filter-group .icon-btn {
  margin-top: 2rem;
  align-self: center;
  margin-bottom: 0.25rem;
}

.filter-group .icon-btn .icon {
  transition: transform 0.2s;
}

.datetime-group {
  display: flex;
  gap: 1rem;
}

.datetime-group label {
  flex: 1;
}

/* Admin forms (traffic info, etc.) */
.admin-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 600px;
}

.admin-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 500;
}

.admin-form label:has(input[required]) .label-text::after,
.admin-form label:has(select[required]) .label-text::after,
.admin-form label:has(textarea[required]) .label-text::after {
  content: " *";
  color: var(--accent);
  font-weight: 700;
}

.admin-form textarea {
  padding: 0.5rem;
  border: 1px solid #c8ccd2;
  border-radius: 4px;
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
}

.admin-form select {
  padding: 0.5rem;
  border: 1px solid #c8ccd2;
  border-radius: 4px;
  font-size: 1rem;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* SMS form */
.sms-info-box {
  background: #f8f9fa;
  border: 1px solid #e2e5ea;
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  max-width: 600px;
}

.sms-info-box h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1.25rem;
}

.sms-info-box p {
  margin: 0.4rem 0;
  font-size: 0.95rem;
}

.char-count {
  display: block;
  font-size: 0.85rem;
  color: #666;
  margin-top: 0.25rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background: #5a6268;
}

.error-details {
  margin-top: 1rem;
  padding: 1rem;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
}

.error-details h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
}

.error-details ul {
  margin: 0;
  padding-left: 1.5rem;
}

.error-details li {
  margin: 0.25rem 0;
  font-size: 0.9rem;
}

.admin-table input {
  padding: 0.3rem;
  border: 1px solid #c8ccd2;
  border-radius: 4px;
  font-size: 0.9rem;
  width: 100%;
}

.admin-table .seats-input {
  width: 4rem;
}

.admin-table .ticket-cell {
  font-family: ui-monospace, monospace;
  font-size: 0.68rem;
  color: #888;
  white-space: nowrap;
}

/* Sortable table headers */
.admin-table th.sort-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.admin-table th.sort-th::after {
  content: "\2195";
  margin-left: 0.35em;
  font-size: 0.85em;
  opacity: 0.3;
}

.admin-table th.sort-th[data-sort-dir="asc"]::after {
  content: "\2191";
  opacity: 1;
}

.admin-table th.sort-th[data-sort-dir="desc"]::after {
  content: "\2193";
  opacity: 1;
}

.actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  white-space: nowrap;
}

.inline {
  display: inline;
  margin: 0;
}

.btn-small {
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
}

.link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: 0.9rem;
  text-decoration: underline;
}

.link-danger {
  background: none;
  border: none;
  color: #a11;
  cursor: pointer;
  padding: 0;
  font-size: 0.9rem;
  text-decoration: underline;
}

/* Secondary subtext, e.g. arrival time / travel time */
.sub {
  display: block;
  color: #777;
  font-size: 0.82rem;
}

.departure-info .sub {
  margin-top: 0.15rem;
}

  .filter-group .icon-btn .icon {
    transform: rotate(90deg);
  }

/* ---- Responsive / mobile ---- */
@media (max-width: 640px) {
  main {
    padding: 1.25rem 0.85rem;
  }

  .site-header {
    padding: 1rem 1rem;
  }

  .brand-text {
    font-size: 1.3rem;
  }

  /* Stacked form groups
  .direction-group {
    flex-direction: column;
  } */

  /* Keep filter horizontal on mobile */
  .filter-group .direction-group {
    flex-direction: row;
    align-items: flex-end;
    gap: 0.5rem;
  }

  .filter-group .icon-btn {
    margin-bottom: 0;
    flex-shrink: 0;
  }



  .datetime-group {
    flex-direction: column;
    gap: 1rem;
  }

  /* Turn admin tables into stacked cards (no horizontal scroll) */
  .admin-table {
    border: none;
    background: none;
  }

  .admin-table thead {
    display: none;
  }

  .admin-table tbody,
  .admin-table tr,
  .admin-table td {
    display: block;
    width: 100%;
  }

  .admin-table tr {
    background: var(--card);
    border: 1px solid #e2e5ea;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    padding: 0.35rem 0.6rem;
  }

  .admin-table tbody tr:nth-child(even) {
    background: var(--card);
  }

  .admin-table td {
    border-bottom: 1px solid #f0f1f4;
    padding: 0.5rem 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }

  .admin-table td:last-child {
    border-bottom: none;
  }

  /* Label each cell using its data-label */
  .admin-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #555;
    flex-shrink: 0;
  }

  .admin-table td input {
    width: auto;
    flex: 1;
    text-align: right;
  }

  .admin-table .seats-input {
    width: 5rem;
  }

  .admin-table td.actions {
    justify-content: flex-end;
  }

  .admin-table td.actions::before {
    content: "";
  }
}

/* Custom modal dialogs */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s ease-out;
}

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

.modal-dialog {
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  max-width: 500px;
  width: 90%;
  animation: slideIn 0.2s ease-out;
}

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

.modal-content {
  padding: 1.5rem;
}

.modal-title {
  margin: 0 0 1rem 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #333;
}

.modal-message {
  margin: 0 0 1.5rem 0;
  color: #555;
  line-height: 1.5;
  white-space: pre-line;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.modal-actions .btn {
  min-width: 80px;
}

/* Return trip section */
.return-trip-checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
  margin-top: 0.5rem;
}

.return-trip-checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.return-trip-checkbox span {
  cursor: pointer;
}

.return-trip-section {
  background: #f8f9fa;
  border: 1px solid #e2e5ea;
  border-radius: 8px;
  padding: 1rem;
  margin: 0.5rem 0;
}

.return-trip-section h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  color: #333;
}

.return-trip-list select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #c8ccd2;
  border-radius: 6px;
  font-size: 0.95rem;
}

.loading-message {
  color: #666;
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

.booking-info {
  background: #f8f9fa;
  border: 2px solid #e2e5ea;
  margin-bottom: 1rem;
}

.return-ticket {
  margin-top: 1rem;
}

.return-ticket h3 {
  margin: 0 0 0.75rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e2e5ea;
  color: #333;
}

.ticket h3 {
  margin: 0 0 0.75rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e2e5ea;
  color: #333;
  font-size: 1.1rem;
}

.warning-message {
  background: #fff3cd;
  color: #856404;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  border-left: 4px solid #ffc107;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

/* Error page */
.error-page {
  max-width: 600px;
  margin: 3rem auto;
  padding: 2rem;
  text-align: center;
}

.error-page h1 {
  color: #333;
  margin-bottom: 1rem;
  font-size: 1.75rem;
}

.error-page p {
  color: #666;
  margin-bottom: 2rem;
  line-height: 1.6;
  font-size: 1.05rem;
}

.error-page .btn {
  display: inline-block;
}

/* Desktop: horizontal layout for departure actions */
@media (min-width: 600px) {
  .departure {
    padding: 0.75rem 1rem;
    gap: 1rem;
  }

  .departure-info .name {
    font-size: 1.05rem;
  }

  .departure-info .route {
    font-size: 1rem;
  }

  .departure-info .time {
    font-size: 0.9rem;
  }

  .departure-action {
    flex-direction: row;
    gap: 0.5rem;
  }
}
