:root {
  --bg: #f4f4f6;
  --card: #ffffff;
  --text: #111113;
  --muted: #6e6e78;
  --border: #e6e6eb;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --success: #0d8a4e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.03);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  /* Type scale */
  --fs-title: 1.375rem;   /* 22px */
  --fs-section: 0.75rem;  /* 12px */
  --fs-card: 1rem;        /* 16px */
  --fs-body: 0.9375rem;   /* 15px */
  --fs-meta: 0.8125rem;   /* 13px */
  --fs-chip: 0.75rem;     /* 12px */

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 28px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

button, input, textarea {
  font: inherit;
}

.app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px calc(28px + var(--safe-bottom));
}

/* —— Top bar —— */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(244,244,246,.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: calc(10px + var(--safe-top)) 0 12px;
  margin: 0 -4px;
  padding-left: 4px;
  padding-right: 4px;
  border-bottom: 1px solid transparent;
}

.topbar-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.topbar-main {
  flex: 1;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding-top: 2px;
}

.brand {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
}

.title {
  margin: 2px 0 0;
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.meta {
  margin-top: 4px;
  font-size: var(--fs-meta);
  color: var(--muted);
  line-height: 1.35;
}

.meta .conf-chip {
  margin-left: 2px;
  vertical-align: middle;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  padding: 7px 11px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  font-size: var(--fs-meta);
  font-weight: 550;
}
.icon-btn:active { transform: scale(.98); }
.icon-btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
  padding-left: 6px;
  padding-right: 6px;
  font-weight: 600;
}

.section {
  margin-top: 14px;
}

/* —— Trip list cards —— */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.card:active { transform: scale(.995); }
.card.highlight {
  border-color: #c5d9f7;
  box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow);
}
.card-label {
  font-size: 1.0625rem; /* 17px */
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.25;
}
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef0f4;
  color: #5a6270;
  flex-shrink: 0;
}
.badge.upcoming { background: #e8f5ee; color: var(--success); }
.badge.current { background: var(--accent-soft); color: var(--accent); }
.badge.past { background: #efeff2; color: #888; }
.card-dates {
  font-size: var(--fs-meta);
  color: var(--muted);
  margin-top: 8px;
}
.card-conf {
  margin-top: 10px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 12px;
  font-size: var(--fs-body);
}

/* —— Detail —— */
.detail-header .title { font-size: 1.375rem; }
.detail-header .topbar-row {
  align-items: center;
  margin-bottom: 8px;
}
.detail-header .topbar-actions { padding-top: 0; }
.detail-header .topbar-main { margin-top: 0; }
.detail-header > .topbar-row .icon-btn.ghost {
  padding-left: 0;
  font-size: var(--fs-meta);
}

.day-group { margin-top: 26px; }
.day-group:first-child { margin-top: 4px; }
.day-header {
  font-size: var(--fs-section);
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--muted);
  text-transform: uppercase;
  margin: 0 0 6px 2px;
  line-height: 1.3;
}

.timeline {
  position: relative;
  padding-left: 0;
}

/* Unified event cards (flight / hotel / ground / dayitem / manual) */
.event {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  align-items: start;
}
.event:last-child { margin-bottom: 0; }

.event-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f2f5;
  font-size: 18px;
  line-height: 1;
}
.event.flight .event-icon { background: #eaf2ff; }
.event.hotel .event-icon { background: #f3eefc; }
.event.ground .event-icon { background: #eef8f1; }
.event.manual .event-icon { background: #fff6e8; }
.event.dayitem .event-icon { background: #eef6ff; }

.event-time {
  font-size: var(--fs-meta);
  font-weight: 650;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.event-tz {
  font-weight: 500;
  color: var(--muted);
  margin-left: 4px;
}
.event-title {
  margin-top: 3px;
  font-size: var(--fs-card);
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.3;
}
.event-sub {
  margin-top: 4px;
  font-size: var(--fs-meta);
  color: var(--muted);
  line-height: 1.4;
}
.event-sub + .event-sub { margin-top: 2px; }
.event-actions { margin-top: 8px; }
.event-actions .icon-btn.ghost {
  padding: 4px 0;
  font-size: var(--fs-chip);
}

/* —— Login —— */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(244,244,246,.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.overlay[hidden] { display: none !important; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.login-card h2 {
  margin: 0 0 6px;
  font-size: 1.25rem;
}
.login-card p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: var(--fs-meta);
}
.primary-btn {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-block;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
  font-size: var(--fs-body);
}
.primary-btn:disabled { opacity: .6; cursor: wait; }
.google-btn { margin-top: 4px; }
.user-email {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.login-error {
  color: #c62828;
  font-size: var(--fs-meta);
  margin: 0 0 10px;
  min-height: 1.2em;
}

.hidden { display: none !important; }
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  background: #fdecea;
  color: #8a1f1f;
  border: 1px solid #f5c6c2;
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 10px;
  font-size: var(--fs-meta);
}

/* —— FlightAware / maps —— */
.flight-number {
  display: inline-block;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--accent);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.flight-number:hover { text-decoration: underline; }

.maps-link {
  color: var(--accent);
  text-decoration: none;
  word-break: break-word;
}
.maps-link:hover { text-decoration: underline; }

/* —— Add item / packing —— */
.add-item-card {
  margin-top: var(--space-6);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.add-item-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.add-item-hint {
  margin: 4px 0 14px;
  font-size: var(--fs-meta);
  color: var(--muted);
}
.field {
  display: block;
  margin-bottom: 10px;
}
.field span {
  display: block;
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fafafa;
}
.field input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.add-item-error {
  color: #c62828;
  font-size: var(--fs-meta);
  margin: 0 0 10px;
}
.add-item-card .primary-btn {
  margin-top: 4px;
}

.past-link {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: var(--fs-card);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.past-link:active { transform: scale(.99); }

/* —— Toast —— */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(12px);
  background: #1c1c1e;
  color: #fff;
  font-size: var(--fs-meta);
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast[hidden] { display: none !important; }

/* —— Flight status badges —— */
.badge.status-flight {
  margin-left: 6px;
  vertical-align: middle;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge.on_time { background: #e8f5ee; color: var(--success); }
.badge.delayed { background: #fff4e5; color: #b45f06; }
.badge.cancelled { background: #fdecea; color: #c62828; }
.badge.landed { background: #e8f0fe; color: var(--accent); }
.badge.scheduled { background: #eef0f4; color: #5a6270; }
.badge.diverted { background: #f3eefc; color: #6a1b9a; }

/* —— Today / weather —— */
.day-group.day-today .day-header { color: var(--accent); }
.today-chip {
  display: inline-block;
  margin-left: 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: middle;
}
.day-weather {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 10px 2px;
  line-height: 1.3;
}

/* —— Confirmation copy chip —— */
.conf-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: #fafafa;
  color: var(--text);
  font-size: var(--fs-chip);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.2;
}
.conf-chip:active {
  transform: scale(.97);
  background: var(--accent-soft);
  border-color: #c5d9f7;
}

/* —— Packing notes —— */
.packing-card details summary {
  cursor: pointer;
  list-style: none;
}
.packing-card details summary::-webkit-details-marker { display: none; }
.packing-textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fafafa;
  font: inherit;
  resize: vertical;
  min-height: 88px;
}
.packing-textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
#packing-save { margin-top: 10px; }

/* —— Offline banner —— */
.offline-banner {
  background: #fff8e6;
  color: #7a5b00;
  border: 1px solid #f0d78c;
  border-radius: 10px;
  padding: 8px 12px;
  margin-top: 10px;
  font-size: var(--fs-meta);
  font-weight: 600;
}

/* —— Check-in reminder —— */
.event.checkin {
  border-color: #d0e4ff;
  background: #f7faff;
}
.event.checkin .event-icon {
  background: #dcecff;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}
.event.checkin .event-time {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 11px;
  font-weight: 700;
}
.checkin-link {
  display: inline-block;
  margin-top: 4px;
  color: var(--accent);
  font-weight: 650;
  font-size: var(--fs-meta);
  text-decoration: none;
}
.checkin-link:hover { text-decoration: underline; }

/* —— Sticky flight-status alert toast —— */
.toast.sticky.flight-alert {
  bottom: auto;
  top: calc(12px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  border-radius: 14px;
  padding: 12px 16px;
  max-width: min(440px, calc(100vw - 24px));
  background: #1a1a1c;
  border: 1px solid #3a3a3c;
  box-shadow: 0 8px 28px rgba(0,0,0,.35);
  pointer-events: auto;
  cursor: pointer;
  font-size: var(--fs-meta);
  line-height: 1.35;
  text-align: left;
}
.toast.sticky.flight-alert.show {
  transform: translateX(-50%) translateY(0);
}

/* Phone-native tweaks */
@media (max-width: 430px) {
  .app { padding-left: 14px; padding-right: 14px; }
  .title { font-size: 1.3125rem; }
  .detail-header .title { font-size: 1.3125rem; }
}
