:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e5e9;
  --text: #1a1d23;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 0.75rem; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
}

/* Used only by the trip planner page, so its map can fill the full
   right-hand side of the viewport instead of being boxed into the
   centered 1200px reading column. */
.container-fullbleed {
  max-width: none;
  margin: 0;
  padding: 1.25rem 1.5rem;
  height: calc(100vh - 62px); /* 62px ≈ topbar height */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (max-width: 900px) {
  .container-fullbleed {
    height: auto;
    overflow: visible;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.auth-card, .form-card { max-width: 420px; margin: 2rem auto; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.trip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.trip-card { display: block; color: var(--text); }
.trip-card:hover { text-decoration: none; border-color: var(--primary); }
.trip-card h2 { margin-top: 0; }

.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-state p { margin-bottom: 1rem; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary-dark);
  font-weight: 600;
}

.stack { display: flex; flex-direction: column; gap: 0.9rem; }
.row { display: flex; gap: 0.9rem; flex-wrap: wrap; align-items: flex-end; }
.row > label, .row > input { flex: 1; min-width: 140px; }

label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; font-weight: 500; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }

.route-style-field {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem 1rem;
  margin: 0;
}
.route-style-field legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0 0.3rem;
}
.route-style-field .radio-option {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  margin-top: 0.4rem;
}
.route-style-field .radio-option input { width: auto; }
.route-style-field p.hint { margin: 0.4rem 0 0; }

input, textarea, select {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--surface);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f2f3f5; text-decoration: none; }
.btn-danger { background: transparent; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; text-decoration: none; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

.inline-form { display: inline; }

.flash {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.planner-layout {
  display: flex;
  gap: 1.5rem;
  flex: 1 1 auto;
  min-height: 0; /* let flex children scroll instead of overflowing the page */
}
@media (max-width: 900px) {
  .planner-layout { flex-direction: column; }
}

.stops-column {
  flex: 0 0 400px;
  max-width: 400px;
  overflow-y: auto;
  padding-right: 0.25rem;
}
@media (max-width: 900px) {
  .stops-column { flex: none; max-width: none; overflow: visible; }
}

.stops-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.stop-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.stop-card.dragging { opacity: 0.5; }
.stop-main { display: flex; gap: 0.7rem; align-items: flex-start; }
.drag-handle { cursor: grab; color: var(--muted); }
.stop-index {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.stop-info { flex: 1; }
.stop-notes { margin-top: 0.3rem; font-size: 0.85rem; }

.stop-edit { margin-top: 0.6rem; }
.stop-edit summary { cursor: pointer; color: var(--primary); font-size: 0.85rem; font-weight: 600; }
.stop-edit-form { margin: 0.75rem 0; }

.leg-connector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}
.leg-badge {
  flex: 0 0 auto;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.leg-badge-fastest { background: #eef2ff; color: var(--primary-dark); }
.leg-badge-scenic { background: #ecfdf3; color: #15803d; }

.leg-reset-btn {
  flex: 0 0 auto;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0;
}
.leg-reset-btn:hover { color: var(--primary); text-decoration: underline; }

.map-click-hint { margin: 0.6rem 0 0; }

.add-stop { margin-top: 0.4rem; }
.add-stop summary { list-style: none; }
.add-stop summary::-webkit-details-marker { display: none; }
.add-stop[open] summary { margin-bottom: 0.75rem; }
.add-stop form { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 0.5rem; }

.share-panel { margin-top: 1.5rem; }
.share-link-row { display: flex; gap: 0.5rem; }
.share-link-row input { flex: 1; }
.collab-list { list-style: none; padding: 0; margin: 0.5rem 0; display: flex; flex-direction: column; gap: 0.4rem; }
.collab-list li { display: flex; align-items: center; gap: 0.5rem; }

.map-column {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#map {
  width: 100%;
  flex: 1 1 auto;
  min-height: 320px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #eef0f2;
}
@media (max-width: 900px) {
  #map { height: 60vh; flex: none; }
}
.route-summary {
  flex: 0 0 auto;
  margin-top: 0.6rem;
  text-align: right;
}

.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }

.error-detail {
  white-space: pre-wrap;
  background: #f8f8f8;
  padding: 1rem;
  border-radius: 8px;
  font-size: 0.8rem;
  overflow-x: auto;
}
