:root {
  --bg: #080d1a;
  --bg-elev: #0f172a;
  --bg-card: #131d33;
  --bg-card-hover: #182542;
  --bg-input: #0b1222;
  --border: #23314f;
  --border-strong: #33486e;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #14b8a6;
  --accent-hover: #0d9488;
  --accent-soft: rgba(20, 184, 166, 0.14);
  --cyan: #38bdf8;
  --violet: #a78bfa;
  --amber: #fbbf24;
  --rose: #fb7185;
  --emerald: #34d399;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #f8fafc;
  --border: #cbd5e1;
  --border-strong: #94a3b8;
  --text: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-soft: rgba(13, 148, 136, 0.12);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

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

.hidden { display: none !important; }

/* Top Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.94);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  cursor: pointer;
}
.brand-badge {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  display: grid;
  place-items: center;
  font-size: 17px;
  color: #06131a;
  font-weight: 800;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-btn:hover {
  color: var(--text);
  background: var(--bg-card);
}
.nav-btn.active {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 13px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #041314;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}
.btn-secondary {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.4);
  color: var(--cyan);
}
.btn-secondary:hover {
  background: rgba(56, 189, 248, 0.24);
}
.btn-ai {
  background: rgba(167, 139, 250, 0.15);
  border-color: rgba(167, 139, 250, 0.45);
  color: var(--violet);
}
.btn-ai:hover {
  background: rgba(167, 139, 250, 0.25);
}
.btn-danger {
  background: rgba(251, 113, 133, 0.12);
  border-color: rgba(251, 113, 133, 0.4);
  color: var(--rose);
}
.btn-danger:hover {
  background: rgba(251, 113, 133, 0.24);
}
.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}
.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
}

/* Containers */
.container {
  max-width: 1220px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}
.studio-shell {
  max-width: 1680px;
  margin: 0 auto;
  padding: 14px 18px 60px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* Auth View */
.auth-wrapper {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
  padding: 28px 16px;
}
.auth-grid {
  width: 100%;
  max-width: 960px;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 24px;
  align-items: stretch;
}
.auth-hero {
  background: linear-gradient(155deg, #0d2538 0%, #111827 60%, #141d38 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #f8fafc;
}
.auth-hero h1 {
  font-size: 28px;
  line-height: 1.2;
  margin: 12px 0;
}
.feature-list {
  list-style: none;
  padding: 0;
  margin: 20px 0 0;
  display: grid;
  gap: 10px;
}
.feature-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13.5px;
  color: #cbd5e1;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 18px;
}
.auth-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.auth-tab.active {
  background: var(--bg-card-hover);
  color: var(--text);
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.field-hint {
  font-size: 11.5px;
  color: var(--text-dim);
}

/* Chips */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}
.chip.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
}
.badge-teal { background: rgba(20, 184, 166, 0.18); color: #2dd4bf; }
.badge-cyan { background: rgba(56, 189, 248, 0.18); color: #38bdf8; }
.badge-amber { background: rgba(251, 191, 36, 0.18); color: #fbbf24; }
.badge-violet { background: rgba(167, 139, 250, 0.18); color: #c4b5fd; }
.badge-rose { background: rgba(251, 113, 133, 0.18); color: #fb7185; }
.badge-emerald { background: rgba(52, 211, 153, 0.18); color: #34d399; }

/* Dashboard */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.section-header h2 {
  margin: 0;
  font-size: 22px;
}
.trips-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.trip-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.trip-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.trip-card h3 {
  margin: 0;
  font-size: 16px;
}
.trip-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.trip-card-actions {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Family Members */
.member-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 12px;
}
.member-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

/* Studio Toolbar */
.studio-toolbar {
  position: sticky;
  top: 56px;
  z-index: 30;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
[data-theme="light"] .studio-toolbar {
  background: rgba(255, 255, 255, 0.95);
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.day-pill {
  padding: 6px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.day-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #041314;
}

/* Studio Summary Banner */
.studio-info-strip {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}
.info-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.budget-bars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 6px;
}
.budget-mini {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
}
.budget-mini .val {
  font-weight: 700;
  font-size: 13.5px;
}
.budget-mini.over .val { color: var(--rose); }
.budget-mini.ok .val { color: var(--emerald); }

/* Studio Workspace Split */
.studio-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.85fr);
  gap: 16px;
  align-items: start;
}
#studioLeftCol {
  min-width: 0;
}
.studio-workspace.map-hidden {
  grid-template-columns: 1fr;
}

/* Day Container */
.day-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
  transition: border-color 0.15s ease;
}
.day-section.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.55);
  border-bottom: 1px solid var(--border);
  border-left: 4px solid var(--cyan);
}
[data-theme="light"] .day-header {
  background: #f8fafc;
}
.day-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
}
.day-stops-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 70px;
}

/* Stop Card */
.stop-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  transition: border-color 0.15s ease, transform 0.12s ease;
}
.stop-card:hover {
  border-color: var(--border-strong);
}
.stop-card.highlighted {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.28);
}
.stop-card.dragging {
  opacity: 0.45;
}
.stop-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.stop-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.drag-handle {
  cursor: grab;
  color: var(--text-dim);
  font-weight: 700;
  user-select: none;
  padding: 2px 4px;
}
.stop-index {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #041314;
  flex-shrink: 0;
}
.stop-name {
  font-weight: 700;
  font-size: 14.5px;
}
.stop-time {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--cyan);
  white-space: nowrap;
}
.stop-address {
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0 6px 30px;
}
.stop-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 8px 30px;
}
.stop-notes {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 8px 30px;
}

/* Comparable Alternatives Dropdown */
.alt-swap-bar {
  margin: 8px 0 8px 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: rgba(56, 189, 248, 0.06);
  border: 1px dashed rgba(56, 189, 248, 0.35);
  border-radius: 8px;
  padding: 6px 10px;
}
.alt-swap-bar label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--cyan);
  white-space: nowrap;
}
.alt-select {
  flex: 1;
  min-width: 210px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 12px;
}

/* Restaurant Picks inside Meal Card */
.restaurant-grid {
  margin: 8px 0 8px 30px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 8px;
}
.rest-option {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 12px;
}
.rest-option:hover {
  border-color: var(--accent);
}
.rest-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.rest-option-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  margin-bottom: 4px;
}
.rest-detail {
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.38;
}

/* Stop Footer & Next Leg */
.stop-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.14);
}
.next-leg {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stop-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Holding Section */
.holding-section {
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.holding-section.drag-over {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.22);
}
.holding-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.holding-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.holding-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 6px;
}

/* Interactive Map Pane */
.map-pane {
  position: sticky;
  top: 126px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.map-canvas {
  width: 100%;
  height: 540px;
  background: #0b1324;
}

/* Master Schedule Table */
.schedule-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
}
.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.schedule-table th,
.schedule-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.schedule-table th {
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}
.schedule-table.compact th,
.schedule-table.compact td {
  padding: 5px 8px;
  font-size: 11.8px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(3, 7, 18, 0.75);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 760px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 17px; }
.option-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.option-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Loading Overlay & Toast */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(8, 13, 26, 0.84);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
}
.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 500;
}
.toast.error { border-color: var(--rose); }

/* Responsive */
@media (max-width: 1080px) {
  .studio-workspace { grid-template-columns: 1fr; }
  .map-pane { position: static; }
  .map-canvas { height: 400px; }
  .studio-info-strip { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .auth-grid, .form-grid, .form-grid-3, .budget-bars { grid-template-columns: 1fr; }
  .stop-address, .stop-specs, .stop-notes, .alt-swap-bar, .restaurant-grid { margin-left: 0; }
}
