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

:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --border: #e7e5e4;
  --text: #1c1917;
  --text-muted: #78716c;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 24px 16px 48px;
}

.container {
  max-width: 560px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 28px;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--primary);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

/* Saved trips bar */
.saved-trips-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}

.saved-trips-bar label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.saved-trips-controls {
  display: flex;
  gap: 8px;
  flex: 1;
}

.saved-trips-controls select {
  flex: 1;
}

/* Form card */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Sign-in call-to-action, shown only when signed out. */
.signin-cta {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  margin-bottom: 16px;
}

.signin-cta-text {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.signin-cta.denied {
  border-color: var(--danger);
}

.signin-cta.denied .signin-cta-text {
  color: var(--danger);
}

/* Visually disable the form until the user signs in. The real access control
   is server-side; this only prevents a confusing "type then get rejected" flow. */
body.signed-out .form-card {
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

/* Place input with location button */
.place-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.place-input-row input {
  flex: 1;
  min-width: 0;
}

/* Autocomplete dropdown */
.autocomplete-list {
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.10);
  margin-top: -2px;
}

.autocomplete-list li {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: background 0.1s;
}

.autocomplete-list li:hover,
.autocomplete-list li.active {
  background: #f0fdf4;
}

.autocomplete-list li:not(:last-child) {
  border-bottom: 1px solid var(--border);
}

.autocomplete-list .main-text {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.autocomplete-list .secondary-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

input[type="number"],
input[type="text"],
input[type="datetime-local"],
select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,118,110,0.12);
}

.field-error {
  font-size: 0.82rem;
  color: var(--danger);
  margin-top: 2px;
}

/* Arrival-time trigger — looks like an input, opens the custom dialog. */
.datetime-trigger {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.datetime-trigger:hover { border-color: var(--primary); }

.datetime-trigger:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,118,110,0.12);
}

/* Arrival-time dialog */
.datetime-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  max-width: 320px;
  width: calc(100% - 32px);
  color: var(--text);
  background: var(--surface);
}

.datetime-dialog::backdrop {
  background: rgba(0,0,0,0.35);
}

.datetime-dialog-title {
  margin: 0 0 14px;
  font-size: 1.1rem;
}

.datetime-dialog-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.datetime-dialog-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.datetime-dialog-error {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--danger);
}

.datetime-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.form-actions {
  display: flex;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  flex: 1;
}

.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover:not(:disabled) { background: #fef2f2; }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

/* Error box */
.error-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 0.88rem;
  color: #991b1b;
}

.error-box .dismiss {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: #991b1b;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
}

/* Results card */
.results-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px 20px;
  margin-top: 12px;
  box-shadow: var(--shadow);
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

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

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

.status-badge.live .badge-dot {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-badge.paused {
  background: #f5f5f4;
  color: var(--text-muted);
  border-color: var(--border);
}

.status-badge.paused .badge-dot { background: #a8a29e; animation: none; }

.status-badge.error {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fdba74;
}

.status-badge.error .badge-dot { background: #f97316; animation: none; }

.status-badge.departed {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fca5a5;
}

.status-badge.departed .badge-dot { background: var(--danger); animation: none; }

.status-badge.complete {
  background: #f5f5f4;
  color: var(--text-muted);
  border-color: var(--border);
}

.status-badge.complete .badge-dot { background: #a8a29e; animation: none; }

/* Departure hero */
.departure-hero {
  text-align: center;
  padding: 8px 0 20px;
}

.depart-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.depart-time {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--text);
  line-height: 1.1;
}

.departure-hero.departed .depart-time,
.departure-hero.departed .depart-label {
  color: var(--danger);
}

.depart-countdown {
  margin-top: 6px;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* Trip summary */
.trip-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.sep { color: var(--border); }

/* Notification prompt */
.notif-prompt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  margin-bottom: 16px;
}

.notif-prompt-text {
  font-size: 0.85rem;
  color: #166534;
}

.notif-prompt.denied {
  background: #f5f5f4;
  border-color: var(--border);
}

.notif-prompt.denied .notif-prompt-text {
  color: var(--text-muted);
}

.notif-prompt.ios-hint {
  background: #fffbeb;
  border-color: #fde68a;
}

.notif-prompt.ios-hint .notif-prompt-text {
  color: #92400e;
}

.notif-panel {
  margin-bottom: 16px;
}

.notif-panel .notif-prompt {
  margin-bottom: 0;
}

/* List of scheduled milestone notifications for the current trip. */
.notif-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.notif-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.notif-list li:not(:last-child) {
  border-bottom: 1px solid var(--border);
}

.notif-list-when {
  font-weight: 600;
  color: var(--text);
  min-width: 68px;
}

.notif-list-what {
  color: var(--text-muted);
}

/* Auth bar */
.auth-bar {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 30px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Utility */
[hidden] { display: none !important; }
