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

:root {
  --bg: #f4f5f8;
  --bg2: #ffffff;
  --bg3: #eceef3;
  --border: #d8dbe6;
  --text: #1a1d2e;
  --text2: #6b7194;
  --accent: #4278f5;
  --accent2: #3163e0;
  --green: #1a9e6a;
  --orange: #d4870a;
  --red: #c0392b;
  --radius: 10px;
  --nav-h: 60px;
  --top-h: 52px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; }

/* ── Auth ── */
.auth-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e8eaf4 0%, #f4f5f8 100%);
}
.auth-box { width: 100%; max-width: 380px; padding: 0 24px; }
.auth-logo { font-size: 28px; font-weight: 700; text-align: center; margin-bottom: 28px; letter-spacing: -0.5px; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.auth-tab { flex: 1; padding: 10px; background: none; border: none; color: var(--text2); font-size: 15px; cursor: pointer; border-bottom: 2px solid transparent; transition: all .15s; }
.auth-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input { padding: 12px 14px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 15px; }
.auth-form input:focus { outline: none; border-color: var(--accent); }

/* ── App Shell ── */
.app { display: flex; flex-direction: column; height: 100%; }
.is-hidden { display: none !important; }

/* ── Top Bar ── */
.topbar {
  height: var(--top-h); display: flex; align-items: center; padding: 0 16px;
  background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0;
  position: relative;
}
.topbar-title { font-size: 17px; font-weight: 600; position: absolute; left: 50%; transform: translateX(-50%); }
.back-btn { background: none; border: none; color: var(--accent); font-size: 15px; cursor: pointer; padding: 4px 0; }
.topbar-right { margin-left: auto; display: flex; gap: 8px; }

/* ── Main Content ── */
.main-content { flex: 1; overflow: hidden; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; display: none; }
.view.is-active { display: block; }

/* ── Map View ── */
#view-map { overflow: hidden; }
#map { width: 100%; height: 100%; background: var(--bg3); }
.map-panel {
  position: absolute; top: 12px; right: 12px; z-index: 1000;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; min-width: 200px; max-width: 240px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}
.map-panel-toggle {
  width: 100%; padding: 10px 14px; background: none; border: none; color: var(--text2);
  cursor: pointer; text-align: left; font-size: 14px;
}
.map-panel-title { font-size: 13px; font-weight: 600; color: var(--text2); padding: 0 14px 8px; }
.map-panel-body { padding: 4px 0 10px; }
.map-trip-list { display: flex; flex-direction: column; gap: 2px; }
.map-trip-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 14px;
  cursor: pointer; font-size: 13px; color: var(--text); transition: background .1s;
}
.map-trip-item:hover { background: var(--bg3); }
.map-trip-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.map-panel.is-collapsed .map-panel-body { display: none; }

/* ── Trips View ── */
.view-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; gap: 12px; flex-wrap: wrap; }
.filter-bar { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-btn { padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border); background: none; color: var(--text2); font-size: 13px; cursor: pointer; transition: all .15s; }
.filter-btn.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.trips-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; padding: 0 16px 100px; }

.trip-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: border-color .15s, transform .15s, box-shadow .15s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.trip-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 16px rgba(66,120,245,0.12); }
.trip-card-cover { height: 140px; background: var(--bg3); position: relative; overflow: hidden; }
.trip-card-cover img { width: 100%; height: 100%; object-fit: cover; }
.trip-card-cover-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 48px; opacity: .2; }
.trip-card-status { position: absolute; top: 10px; right: 10px; }
.trip-card-body { padding: 14px; }
.trip-card-name { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.trip-card-dates { font-size: 13px; color: var(--text2); margin-bottom: 8px; }
.trip-card-meta { display: flex; gap: 12px; font-size: 12px; color: var(--text2); margin-bottom: 10px; flex-wrap: wrap; }
.trip-card-meta span { display: flex; align-items: center; gap: 4px; }
.trip-card-budget { height: 4px; background: var(--bg3); border-radius: 2px; overflow: hidden; }
.trip-card-budget-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s; }

/* ── Status Badges ── */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.badge-planned { background: rgba(66,120,245,.1); color: var(--accent); }
.badge-ongoing { background: rgba(26,158,106,.12); color: var(--green); }
.badge-completed { background: rgba(107,113,148,.1); color: var(--text2); }

/* ── Trip Detail ── */
.trip-header {
  padding: 20px 16px 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.trip-header-cover { height: 180px; margin: -20px -16px 16px; position: relative; overflow: hidden; }
.trip-header-cover img { width: 100%; height: 100%; object-fit: cover; }
.trip-header-cover-placeholder { width: 100%; height: 100%; background: linear-gradient(135deg, var(--bg3), var(--bg)); display: flex; align-items: center; justify-content: center; font-size: 64px; opacity: .2; }
.trip-header-name { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.trip-header-dates { font-size: 14px; color: var(--text2); margin-bottom: 8px; }
.trip-header-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.trip-header-actions { display: flex; gap: 8px; }

.trip-tabs {
  display: flex; gap: 0; overflow-x: auto; background: var(--bg2);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
  scrollbar-width: none;
}
.trip-tabs::-webkit-scrollbar { display: none; }
.trip-tab { padding: 12px 16px; background: none; border: none; color: var(--text2); font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; transition: all .15s; }
.trip-tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.trip-tab-content { padding: 16px 16px 100px; }

/* ── Overview ── */
.overview-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
.stat-card-value { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-card-label { font-size: 12px; color: var(--text2); margin-top: 2px; }
.overview-map { height: 220px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); margin-bottom: 20px; }

/* ── Component Lists ── */
.component-section { margin-bottom: 8px; }
.component-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.component-title { font-size: 16px; font-weight: 600; }
.component-list { display: flex; flex-direction: column; gap: 8px; }
.component-item {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; display: flex; align-items: flex-start; gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.component-item-icon { font-size: 20px; flex-shrink: 0; margin-top: 1px; }
.component-item-body { flex: 1; min-width: 0; }
.component-item-title { font-size: 15px; font-weight: 500; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.component-item-sub { font-size: 13px; color: var(--text2); }
.component-item-meta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; font-size: 12px; color: var(--text2); }
.component-item-actions { display: flex; gap: 6px; flex-shrink: 0; margin-top: 2px; }
.empty-section { text-align: center; color: var(--text2); font-size: 14px; padding: 32px 0; }

/* ── Budget breakdown ── */
.budget-breakdown { margin-bottom: 8px; }
.budget-cat-section { margin-bottom: 6px; }
.budget-cat-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); }
.budget-cat-icon { font-size: 16px; flex-shrink: 0; }
.budget-cat-name { flex: 1; font-size: 14px; font-weight: 500; }
.budget-cat-actual { font-size: 15px; font-weight: 600; flex-shrink: 0; }
.budget-cat-planned { font-size: 12px; color: var(--text2); flex-shrink: 0; }
.budget-line-item { display: flex; justify-content: space-between; align-items: center; padding: 5px 14px 5px 44px; font-size: 13px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--bg); }
.budget-line-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.budget-line-name { color: var(--text2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 8px; }
.budget-line-cost { flex-shrink: 0; font-size: 13px; }
.budget-line-orig { color: var(--text2); font-size: 11px; }

/* ── Budget ── */
.budget-summary { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
.budget-total-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.budget-total-label { font-size: 14px; color: var(--text2); }
.budget-total-value { font-size: 22px; font-weight: 700; }
.budget-bar { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.budget-bar-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.budget-bar-fill.under { background: var(--green); }
.budget-bar-fill.over { background: var(--red); }
.budget-categories { display: flex; flex-direction: column; gap: 6px; }
.budget-category-row { display: flex; justify-content: space-between; font-size: 13px; }
.budget-category-name { color: var(--text2); }
.budget-currency-note { font-size: 11px; color: var(--text2); margin-top: 8px; text-align: right; }

/* ── Settings ── */
.settings-content { padding: 20px 16px 100px; max-width: 480px; }
.settings-content h2 { font-size: 20px; font-weight: 700; margin-bottom: 24px; }
.settings-section { margin-bottom: 28px; }
.settings-section h3 { font-size: 13px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px; }
.settings-username { font-size: 15px; margin-bottom: 12px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: var(--radius); border: none; font-size: 14px; font-weight: 500; cursor: pointer; transition: opacity .15s, background .15s; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent2); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn-danger { background: rgba(192,57,43,.08); color: var(--red); border: 1px solid rgba(192,57,43,.25); }
.btn-danger:hover:not(:disabled) { background: rgba(192,57,43,.15); }
.btn-icon { padding: 6px 8px; background: var(--bg3); border: 1px solid var(--border); color: var(--text2); border-radius: 6px; font-size: 13px; }
.btn-icon:hover { color: var(--text); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── Bottom Nav ── */
.bottom-nav {
  height: var(--nav-h); display: flex; background: var(--bg2);
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none; border: none; color: var(--text2); cursor: pointer; transition: color .15s; }
.nav-btn.is-active { color: var(--accent); }
.nav-icon { font-size: 20px; }
.nav-label { font-size: 10px; font-weight: 500; }

/* ── Modal ── */
.modal { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal-box {
  position: relative; width: 100%; max-height: 92vh;
  background: var(--bg2); border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border); display: flex; flex-direction: column;
  overflow: hidden; box-shadow: 0 -4px 24px rgba(0,0,0,0.1);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-title { font-size: 17px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 4px; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }
.form-input, .select, .form-textarea {
  width: 100%; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 15px; font-family: var(--font);
}
.form-input:focus, .select:focus, .form-textarea:focus { outline: none; border-color: var(--accent); background: var(--bg2); }
.form-textarea { resize: vertical; min-height: 72px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 4px; }
.form-help { color: var(--text2); font-size: 12px; margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-actions .btn { flex: 1; }

/* Airport autocomplete */
.airport-suggestion {
  padding: 8px 12px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; gap: 8px;
}
.airport-suggestion:hover { background: var(--bg3); }
.airport-code { font-weight: 700; font-size: 14px; min-width: 40px; color: var(--accent); }
.airport-name { color: var(--text2); font-size: 12px; }
.suggestions-box {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 100;
  background: var(--bg2); border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius); max-height: 200px; overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.input-wrap { position: relative; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg2); border-radius: var(--radius);
  padding: 10px 20px; font-size: 14px; z-index: 3000; white-space: nowrap;
  animation: fadein .2s ease; box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.toast.error { background: var(--red); color: #fff; }
@keyframes fadein { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ── Misc ── */
.empty-state { text-align: center; color: var(--text2); padding: 48px 16px; font-size: 15px; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7194' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; cursor: pointer; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-right { text-align: right; }
.text-muted { color: var(--text2); }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; }

/* Return flight toggle */
.return-flight-toggle { margin: 4px 0 12px; }
.return-flight-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text2); cursor: pointer; user-select: none; }
.return-flight-label input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.return-flight-heading { font-size: 13px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px; }

/* Leaflet overrides */
.leaflet-popup-content-wrapper { background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.leaflet-popup-tip { background: var(--bg2); }
.leaflet-popup-content { margin: 12px 16px; }
.leaflet-control-zoom a { background: var(--bg2); color: var(--text); border-color: var(--border); }
.leaflet-control-zoom a:hover { background: var(--bg3); }
.leaflet-control-attribution { background: rgba(244,245,248,.85) !important; color: var(--text2) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--text2); }
.map-popup-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.map-popup-dates { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.map-popup-link { color: var(--accent); font-size: 13px; cursor: pointer; text-decoration: none; }

/* ── Map Pin Icons ── */
.tt-pin { display: flex; flex-direction: column; align-items: center; }
.tt-pin-head { border-radius: 50%; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,0.25); border: 2px solid rgba(255,255,255,0.9); color: #fff; font-style: normal; }
.tt-pin-stem { width: 2px; height: 10px; border-radius: 0 0 2px 2px; margin-top: -1px; opacity: 0.85; }

@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-box { max-width: 520px; margin: auto; border-radius: var(--radius); border: 1px solid var(--border); max-height: 85vh; }
  .overview-stats { grid-template-columns: repeat(4, 1fr); }
}
