: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);
}

.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: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #eef0f3;
}

.departure-info {
  display: flex;
  flex-direction: column;
}

.departure-info .time {
  font-weight: 700;
}

.departure-info .route {
  color: #666;
  font-size: 0.9rem;
}

.departure-action {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* 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; }

/* 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] {
  background: #bbb;
  cursor: not-allowed;
}

.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 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;
}

/* 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;
}

/* 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: stretch;
  gap: 0.6rem;
}

.direction-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
}

.direction-group .icon-btn {
  align-self: center;
  height: 40px;
  width: 40px;
}

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

.datetime-group label {
  flex: 1;
}

.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;
}

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

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

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

  /* Stack departure list rows */
  .departure {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .departure-action {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

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

  .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: "";
  }
}
