/* ================================================================
   NYC SUBWAY TRANSIT PLANNER — styles.css
   iOS-optimised, iPhone-first responsive design
   ================================================================ */

/* ─── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:    #0039A6;
  --bg:      #F2F2F7;      /* iOS system background */
  --surface: #FFFFFF;
  --text:    #1C1C1E;
  --sub:     #6C6C70;
  --border:  rgba(60,60,67,.12);
  --radius:  14px;
  --shadow:  0 2px 12px rgba(0,0,0,.08);
  --green:   #34C759;      /* iOS green */
  --red:     #FF3B30;
  --yellow:  #FFCC00;
}

html {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text',
               'Helvetica Neue', sans-serif;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  /* Respect iPhone notch / Dynamic Island */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ─── App Shell ─────────────────────────────────────────────────── */
.app {
  max-width: 430px;
  margin: 0 auto;
  padding-bottom: 40px;
}

/* ─── Header ────────────────────────────────────────────────────── */
.app-header {
  background: var(--blue);
  color: #fff;
  padding: 56px 20px 28px;
  position: relative;
  overflow: hidden;
}

/* Multi-colour stripe inspired by the subway map legend */
.subway-stripe {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(90deg,
    #EE352E 14.28%,   /* 1/2/3 */
    #00933C 28.56%,   /* 4/5/6 */
    #B933AD 42.84%,   /* 7     */
    #0039A6 57.12%,   /* A/C/E */
    #FF6319 71.40%,   /* B/D/F/M */
    #FCCC0A 85.68%,   /* N/Q/R/W */
    #A7A9AC 100%      /* L     */
  );
}

.app-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.5px;
}

.subtitle {
  font-size: 14px;
  opacity: .75;
  margin-top: 4px;
}

/* ─── Form ──────────────────────────────────────────────────────── */
.main-content { padding: 20px 16px 0; }

.planner-form {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.form-group input[type="text"],
.form-group input[type="time"] {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 16px;          /* prevents iOS zoom */
  color: var(--text);
  background: var(--bg);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s;
}

.form-group input:focus {
  border-color: var(--blue);
  background: #fff;
}

/* Origin row: text input + locate button */
.input-with-button {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-with-button input { flex: 1; }

.icon-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active { background: #e5e5ea; }

.icon-btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.icon-btn.spinning svg {
  animation: spin .9s linear infinite;
}

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

/* Time picker */
input[type="time"]::-webkit-calendar-picker-indicator {
  opacity: .5;
}

/* ─── Submit Button ──────────────────────────────────────────────── */
.search-btn {
  width: 100%;
  height: 50px;
  border: none;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .15s, transform .1s;
}

.search-btn:active {
  opacity: .85;
  transform: scale(.98);
}

.search-btn svg { width: 18px; height: 18px; }

/* ─── Loading ────────────────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 48px 20px;
  color: var(--sub);
  font-size: 15px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* ─── Error ──────────────────────────────────────────────────────── */
.error-state {
  margin-top: 20px;
  background: #fff5f5;
  border: 1px solid #fecdcd;
  border-radius: var(--radius);
  padding: 16px;
  color: var(--red);
  font-size: 15px;
  text-align: center;
}

/* ─── Results ────────────────────────────────────────────────────── */
.results { margin-top: 28px; }

.results-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 14px;
  padding-left: 2px;
}

/* ─── Route Card ─────────────────────────────────────────────────── */
.route-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin-bottom: 14px;
  position: relative;
  border: 2px solid transparent;
  transition: border-color .2s;
}

.route-card.recommended {
  border-color: var(--green);
}

.rec-badge {
  display: inline-block;
  background: var(--green);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  border-radius: 6px;
  padding: 3px 8px;
  margin-bottom: 12px;
}

/* Line bullets */
.route-lines {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.line-bullet {
  display: inline-flex;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

/* ─── Leave-by display ───────────────────────────────────────────── */
.leave-by {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.leave-label {
  font-size: 14px;
  color: var(--sub);
  font-weight: 500;
  white-space: nowrap;
}

.leave-time {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.5px;
  color: var(--text);
  line-height: 1;
}

/* ─── Detail rows ────────────────────────────────────────────────── */
.route-details {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.detail-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--sub);
  line-height: 1.4;
}

.detail-icon { flex-shrink: 0; font-size: 15px; }

.detail-row strong { color: var(--text); }

/* Live / Scheduled badges */
.live-badge, .sched-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  border-radius: 4px;
  padding: 2px 5px;
  vertical-align: middle;
  margin-left: 4px;
}

.live-badge {
  background: #eafaf0;
  color: #1a7a3f;
  border: 1px solid #a3d9b4;
}

.sched-badge {
  background: #f5f5f5;
  color: #7a7a7a;
  border: 1px solid #ddd;
}

.live-time   { color: #1a7a3f; }
.sched-time  { color: var(--text); }

/* ─── Itinerary timeline ─────────────────────────────────────────── */
.itinerary {
  display: flex;
  flex-direction: column;
}

.itin-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

/* Left column: icon + vertical connector */
.itin-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 28px;
  flex-shrink: 0;
}

.itin-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.walk-icon {
  background: #f0f0f5;
  color: var(--sub);
}

.walk-icon svg {
  width: 16px;
  height: 16px;
}

.dest-icon {
  font-size: 16px;
  line-height: 28px;
}

.itin-bullet {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

/* Vertical connector line between rows */
.itin-connector {
  width: 2px;
  flex: 1;
  min-height: 12px;
  background: var(--border);
  margin: 3px 0;
}

.transit-connector {
  width: 0;
  border-left: 3px solid;          /* color set inline */
  border-color: var(--border);     /* overridden inline */
  background: transparent;
  margin: 2px 0 2px 1px;           /* keep centered under 28 px bullet */
}

/* Right column content */
.itin-body {
  flex: 1;
  padding-bottom: 14px;
  min-width: 0;                    /* prevent overflow in flex */
}

.walk-body {
  font-size: 14px;
  color: var(--sub);
  padding-top: 5px;
}

.transit-body {
  padding-top: 2px;
}

.dest-body {
  font-size: 14px;
  color: var(--text);
  padding-top: 5px;
  padding-bottom: 0;
}

/* Station row (board + alight) */
.transit-station {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 3px;
}

.alight-station {
  margin-top: 6px;
  margin-bottom: 0;
}

.station-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.station-time {
  font-size: 13px;
  font-weight: 500;
}

.transit-direction {
  font-size: 13px;
  color: var(--sub);
  margin-bottom: 6px;
}

/* Intermediate stop dots */
.stop-list {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 4px 0 4px 2px;
}

.stop-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  border: 1.5px solid var(--sub);
  flex-shrink: 0;
}

.stop-count-label {
  font-size: 12px;
  color: var(--sub);
  white-space: nowrap;
}

/* ─── Saved Trips Row ────────────────────────────────────────────── */
.saved-trips-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.saved-trips-row::-webkit-scrollbar { display: none; }

.trip-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 6px 10px 6px 12px;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.trip-chip:active { background: #e5e5ea; }

.chip-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.chip-time {
  font-size: 12px;
  color: var(--blue);
  font-weight: 500;
}
.chip-delete {
  background: none;
  border: none;
  color: var(--sub);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.chip-delete:active { color: var(--red); }

/* ─── Form row (arrive by + buffer side by side) ─────────────────── */
.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.form-group-grow { flex: 1; }
.form-group-buffer { flex-shrink: 0; }

/* ─── Buffer stepper ─────────────────────────────────────────────── */
.buffer-stepper {
  display: flex;
  align-items: center;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  overflow: hidden;
}
.stepper-btn {
  width: 36px;
  height: 100%;
  border: none;
  background: none;
  font-size: 20px;
  color: var(--blue);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.stepper-btn:active { background: #e5e5ea; }
#bufferDisplay {
  flex: 1;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

/* ─── Form actions row (Find Trains + Save) ──────────────────────── */
.form-actions {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.form-actions .search-btn { flex: 1; }

.save-btn {
  flex-shrink: 0;
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 12px;
  background: #f0f4ff;
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}
.save-btn:active { background: #dce6ff; }
.save-btn svg { width: 20px; height: 20px; }

/* ─── Save Trip Modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
}
.modal-check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  color: var(--text);
}
.modal-check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}
.modal-hint {
  font-size: 12px;
  color: var(--sub);
  margin-top: -8px;
}
.modal-actions {
  display: flex;
  gap: 10px;
}
.modal-btn {
  flex: 1;
  height: 48px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.modal-btn-secondary {
  background: #f0f0f5;
  color: var(--text);
}
.modal-btn-primary {
  background: var(--blue);
  color: #fff;
}

/* ─── Utility ─────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* Google Places autocomplete dropdown — bump up z-index on iPhone */
.pac-container {
  z-index: 9999 !important;
  border-radius: 10px !important;
  overflow: hidden;
  box-shadow: var(--shadow) !important;
}
