/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --blue:      #2563eb;
  --blue-dark: #1d4ed8;
  --blue-light:#dbeafe;
  --green:     #10b981;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --gray-50:   #f8fafc;
  --gray-100:  #f1f5f9;
  --gray-200:  #e2e8f0;
  --gray-300:  #cbd5e1;
  --gray-400:  #94a3b8;
  --gray-500:  #64748b;
  --gray-700:  #334155;
  --gray-900:  #0f172a;
  --white:     #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow:    0 4px 12px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.14);
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--gray-900);
  background: var(--gray-50);
  height: 100%;
  overflow-x: hidden;
}
input, select, button, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--blue); text-decoration: none; }
ul { list-style: none; }

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

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 14px;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--blue); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-ghost    { color: var(--gray-700); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-block    { width: 100%; }
.btn-lg       { padding: 13px 24px; font-size: 16px; }
.btn-back     { padding: 8px 12px; font-size: 14px; color: var(--gray-700); }
.btn-icon     { padding: 8px; font-size: 18px; }
.btn-sm       { padding: 6px 12px; font-size: 13px; }
.btn-outline  { border: 1.5px solid var(--blue); color: var(--blue); background: transparent; }
.btn-outline:hover { background: var(--blue-light); }

/* ── Views ───────────────────────────────────────────────────────────────── */
.view { min-height: 100dvh; }

/* ── App Header ──────────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 16px;
}
.header-inner {
  max-width: 960px;
  margin: 0 auto;
  height: 56px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.header-logo { font-weight: 700; font-size: 17px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.trip-header-title {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
  flex: 1;
  text-align: center;
}

/* ── Lang switch ─────────────────────────────────────────────────────────── */
.lang-switch { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--gray-400); }
.lang-btn { font-size: 12px; font-weight: 600; padding: 3px 6px; border-radius: 4px; color: var(--gray-500); }
.lang-btn.active { color: var(--blue); background: var(--blue-light); }

/* ── Auth View ───────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(135deg, #eff6ff 0%, #e0f2fe 100%);
}
.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo .logo-icon { font-size: 48px; display: block; margin-bottom: 8px; }
.auth-logo h1 { font-size: 28px; font-weight: 800; color: var(--blue-dark); }
.logo-sub { color: var(--gray-500); margin-top: 4px; }

.auth-card {
  width: 100%; max-width: 400px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--gray-200);
}
.tab-btn {
  flex: 1;
  padding: 14px;
  font-weight: 500;
  color: var(--gray-500);
  font-size: 14px;
  transition: color .15s, border-bottom .15s;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

.auth-form { padding: 24px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Form fields ─────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--gray-900);
  transition: border-color .15s;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--blue); }
.field input::placeholder { color: var(--gray-300); }

.form-error {
  padding: 10px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: 13px;
  margin-bottom: 14px;
}

.form-success {
  padding: 10px 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  color: var(--green);
  font-size: 13px;
  margin-bottom: 14px;
}

.auth-hint {
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 18px;
  line-height: 1.5;
}

.auth-link-row {
  text-align: center;
  margin-top: 14px;
}

.btn-text-link {
  font-size: 13px;
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn-text-link:hover { color: var(--blue-dark); }

/* ── Autocomplete ────────────────────────────────────────────────────────── */
.autocomplete-field { position: relative; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 200;
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 200px; overflow-y: auto;
  margin-top: 2px;
}
.autocomplete-list:empty { display: none; }
.autocomplete-list li {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.autocomplete-list li:last-child { border-bottom: none; }
.autocomplete-list li:hover { background: var(--blue-light); color: var(--blue-dark); }

/* ── Dashboard ───────────────────────────────────────────────────────────── */
.dashboard-main {
  max-width: 960px; margin: 0 auto;
  padding: 24px 16px;
}
.dashboard-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.dashboard-top h2 { font-size: 22px; font-weight: 700; }

.trips-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.trip-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
  border: 1.5px solid var(--gray-200);
}
.trip-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.trip-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.trip-card-title { font-size: 15px; font-weight: 600; color: var(--gray-900); flex: 1; }
.trip-card-status {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 20px;
  white-space: nowrap;
}
.status-ready    { background: #dcfce7; color: #166534; }
.status-planning { background: #fef9c3; color: #713f12; }
.status-error    { background: #fee2e2; color: #991b1b; }

.trip-card-route { font-size: 13px; color: var(--gray-500); margin-bottom: 8px; }
.trip-card-meta  { font-size: 12px; color: var(--gray-400); display: flex; gap: 12px; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 20px;
}
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state p { color: var(--gray-500); margin-bottom: 20px; font-size: 15px; }

/* ── Create form ─────────────────────────────────────────────────────────── */
.create-main {
  max-width: 640px; margin: 0 auto;
  padding: 24px 16px;
}
.create-main h2 { font-size: 22px; font-weight: 700; margin-bottom: 20px; }
.create-form { }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 500px) { .form-row { grid-template-columns: 1fr; } }

/* ── Trip detail: map ────────────────────────────────────────────────────── */
#trip-map {
  width: 100%;
  height: 280px;
}
@media (min-width: 768px) { #trip-map { height: 380px; } }

/* ── Trip meta bar ───────────────────────────────────────────────────────── */
.trip-meta-bar {
  display: flex; gap: 16px; align-items: center;
  padding: 10px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  font-size: 13px; color: var(--gray-600);
  overflow-x: auto;
}
.trip-meta-bar span { white-space: nowrap; }

/* ── Day tabs ────────────────────────────────────────────────────────────── */
.day-tabs-wrap {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky; top: 56px; z-index: 50;
}
.day-tabs {
  display: flex;
  overflow-x: auto;
  padding: 0 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.day-tabs::-webkit-scrollbar { display: none; }
.day-tab {
  flex-shrink: 0;
  padding: 12px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--gray-500);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-bottom-color .15s;
  white-space: nowrap;
}
.day-tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.day-tab:hover { color: var(--gray-700); }

/* ── Day content ─────────────────────────────────────────────────────────── */
.day-content {
  max-width: 720px; margin: 0 auto;
  padding: 16px;
}

.day-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.day-header h3 { font-size: 17px; font-weight: 700; }
.day-header-date { font-size: 13px; color: var(--gray-400); }

.stops-list { display: flex; flex-direction: column; gap: 12px; }

/* ── Stop Card ───────────────────────────────────────────────────────────── */
.stop-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--gray-200);
  overflow: hidden;
  transition: box-shadow .15s;
}
.stop-card.is-manual { border-color: var(--amber); }

.stop-card-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
}
.stop-type-badge {
  font-size: 18px; flex-shrink: 0;
}
.stop-time { font-size: 12px; font-weight: 600; color: var(--gray-400); flex-shrink: 0; }
.stop-type-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stop-type-label.hotel      { color: #1e40af; }
.stop-type-label.restaurant { color: #166534; }
.stop-type-label.activity   { color: #7c2d12; }
.stop-manual-badge { margin-left: auto; font-size: 11px; color: var(--amber); font-weight: 600; }

.stop-card-body { padding: 12px 14px; }
.stop-selected-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; color: var(--gray-900); }
.stop-selected-address { font-size: 12px; color: var(--gray-400); margin-bottom: 8px; }
.stop-selected-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.stop-rating { font-size: 12px; color: var(--amber); }
.stop-price  { font-size: 12px; color: var(--gray-500); font-weight: 600; }
.stop-category { font-size: 11px; color: var(--gray-400); background: var(--gray-100); padding: 2px 6px; border-radius: 4px; }

.stop-card-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--gray-100);
  display: flex; align-items: center; gap: 8px;
}
.btn-booking {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  padding: 6px 12px;
  background: var(--blue);
  color: var(--white);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background .15s;
}
.btn-booking:hover { background: var(--blue-dark); }
.btn-alternatives {
  font-size: 12px; font-weight: 500; color: var(--gray-500);
  padding: 6px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
}
.btn-alternatives:hover { background: var(--gray-100); }
.alternatives-count {
  font-size: 11px; color: var(--gray-400); margin-left: auto;
}

/* ── Planning overlay ────────────────────────────────────────────────────── */
.planning-overlay {
  display: flex; align-items: center; justify-content: center;
  min-height: 60vh;
  padding: 40px 20px;
}
.planning-card {
  text-align: center;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
}
.planning-card p { font-size: 16px; font-weight: 600; margin: 16px 0 8px; }
.planning-card small { color: var(--gray-400); font-size: 13px; }

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error state ─────────────────────────────────────────────────────────── */
.error-state {
  text-align: center;
  padding: 60px 20px;
}
.error-icon { font-size: 48px; margin-bottom: 16px; }
.error-state p { color: var(--gray-600); margin-bottom: 20px; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
@media (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 20px; }
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%; max-width: 560px;
  max-height: 85dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
@media (min-width: 600px) {
  .modal { border-radius: var(--radius-lg); }
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { font-size: 18px; color: var(--gray-400); padding: 4px 8px; }
.modal-close:hover { color: var(--gray-700); }
.modal-body { overflow-y: auto; padding: 12px; }

.alt-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.alt-card:hover { border-color: var(--blue); background: var(--blue-light); }
.alt-card.selected { border-color: var(--green); background: #f0fdf4; }
.alt-icon { font-size: 24px; flex-shrink: 0; }
.alt-info { flex: 1; min-width: 0; }
.alt-name { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.alt-address { font-size: 12px; color: var(--gray-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alt-meta { display: flex; gap: 8px; margin-top: 4px; align-items: center; flex-wrap: wrap; }
.alt-score { font-size: 11px; font-weight: 700; color: var(--green); }
.alt-booking {
  font-size: 11px; font-weight: 600; color: var(--blue); padding: 3px 8px;
  border: 1px solid var(--blue); border-radius: 4px; text-decoration: none; flex-shrink: 0;
}
.alt-booking:hover { background: var(--blue-light); }

/* ── Fallback banner ─────────────────────────────────────────────────────── */
.fallback-notice {
  background: #fef9c3;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: #713f12;
  margin-bottom: 8px;
}

/* ── Responsive tweaks ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .dashboard-top h2 { font-size: 18px; }
  .trips-grid { grid-template-columns: 1fr; }
  .trip-meta-bar { gap: 10px; font-size: 12px; }
  #trip-map { height: 220px; }
}

/* ── Leaflet overrides ───────────────────────────────────────────────────── */
.leaflet-container { font-family: var(--font); }
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow) !important;
}
