/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
  --ink:       #1a1a2e;      /* deep navy — primary text */
  --ink-muted: #6b7280;      /* muted text */
  --sky:       #0ea5e9;      /* sky blue — primary accent */
  --sky-dark:  #0284c7;      /* hover state */
  --sand:      #f8f5f0;      /* warm off-white background */
  --sand-dark: #ede9e3;      /* card / panel background */
  --border:    #d1cfc9;      /* subtle border */
  --plan:      #0ea5e9;      /* plan type indicator */
  --actual:    #10b981;      /* actual type indicator */
  --danger:    #ef4444;

  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'Courier New', monospace;

  --radius:   8px;
  --radius-lg: 16px;
  --shadow:   0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.06);
  --nav-h:    56px;
  --toolbar-h: 48px;
  --ai-bar-h:  72px;
}

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

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--sand);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Screens ────────────────────────────────────────────────── */
.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ─── Auth ───────────────────────────────────────────────────── */
#screen-auth, #screen-pending {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--ink) 0%, #16213e 60%, #0f3460 100%);
}

.auth-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: min(360px, 90vw);
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}

.auth-logo {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.auth-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  color: var(--ink);
  margin-bottom: 0.4rem;
}

.auth-sub {
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
}

.auth-divider {
  color: var(--ink-muted);
  font-size: 0.8rem;
  margin: 0.75rem 0;
  position: relative;
}

.auth-divider::before, .auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--sky);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--sky-dark); }

.btn-secondary {
  background: var(--sand-dark);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
}
.btn-ghost:hover:not(:disabled) { color: var(--ink); background: var(--sand-dark); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover:not(:disabled) { background: var(--danger); color: white; }

.btn-wide { width: 100%; }

/* ─── Nav ────────────────────────────────────────────────────── */
.nav {
  height: var(--nav-h);
  background: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  font-size: 1.25rem;
  color: white;
  flex-shrink: 0;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.nav-user {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  display: none;
}

@media (min-width: 600px) { .nav-user { display: block; } }

.trip-selector {
  background: rgba(255,255,255,0.1);
  color: white;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius);
  padding: 0.3rem 0.6rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  cursor: pointer;
  max-width: 220px;
}

.trip-selector option { background: var(--ink); }

.nav .btn-ghost { color: rgba(255,255,255,0.7); }
.nav .btn-ghost:hover { color: white; background: rgba(255,255,255,0.1); }

/* ─── Hamburger Menu ──────────────────────────────────────────── */
.burger-wrap {
  position: relative;
}

.burger-btn {
  font-size: 1.25rem;
  padding: 0.4rem 0.6rem;
}

.burger-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.35rem;
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  min-width: 160px;
  z-index: 200;
  overflow: hidden;
}

.burger-item {
  display: block;
  width: 100%;
  padding: 0.65rem 1rem;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.burger-item:hover { background: var(--sand); }

/* ─── Toolbar ────────────────────────────────────────────────── */
.toolbar {
  height: var(--toolbar-h);
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  gap: 0.75rem;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.type-toggle, .mode-toggle {
  display: flex;
  background: var(--sand-dark);
  border-radius: var(--radius);
  padding: 2px;
  border: 1px solid var(--border);
}

.toggle-btn {
  padding: 0.25rem 0.75rem;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font-body);
  color: var(--ink-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.toggle-btn.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.ai-badge {
  font-size: 0.75rem;
  color: var(--ink-muted);
  font-family: var(--font-mono);
}

/* ─── Content ─────────────────────────────────────────────────── */
.content {
  position: fixed;
  top: calc(var(--nav-h) + var(--toolbar-h));
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

.panel {
  height: 100%;
  overflow-y: auto;
  padding: 1.5rem 1.25rem;
}

#panel-preview {
  padding-bottom: calc(var(--ai-bar-h) + 1.5rem);
}

/* ─── Itinerary Rendering ─────────────────────────────────────── */
.itinerary-body {
  max-width: 720px;
  margin: 0 auto;
}

.itinerary-body h1 {
  font-family: var(--font-display);
  font-size: 1.9rem;
  color: var(--ink);
  margin-bottom: 0.25rem;
  border-bottom: 2px solid var(--sky);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

.itinerary-body h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--ink);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  padding: 0.4rem 0.75rem;
  background: var(--sand-dark);
  border-left: 3px solid var(--sky);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.itinerary-body h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.itinerary-body p {
  margin-bottom: 0.75rem;
  color: var(--ink);
}

.itinerary-body ul, .itinerary-body ol {
  padding-left: 1.5rem;
  margin-bottom: 0.75rem;
}

.itinerary-body li { margin-bottom: 0.25rem; }

.itinerary-body strong { font-weight: 600; }

.itinerary-body a { color: var(--sky); }

/* Tables with zebra striping */
.itinerary-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.875rem;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--border);
}

.itinerary-body th {
  background: var(--ink);
  color: white;
  padding: 0.6rem 0.875rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.itinerary-body td {
  padding: 0.55rem 0.875rem;
  border-bottom: 1px solid var(--border);
}

.itinerary-body tr:nth-child(even) td { background: var(--sand); }
.itinerary-body tr:nth-child(odd) td  { background: white; }
.itinerary-body tr:last-child td { border-bottom: none; }

/* ─── Editor ──────────────────────────────────────────────────── */
#panel-edit {
  padding: 1rem 1.25rem;
  padding-bottom: calc(var(--ai-bar-h) + 1rem);
}

.editor {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - var(--nav-h) - var(--toolbar-h) - var(--ai-bar-h) - 3rem);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--ink);
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
}

.editor:focus { border-color: var(--sky); }

/* ─── AI Bar ──────────────────────────────────────────────────── */
.ai-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--ai-bar-h);
  background: white;
  border-top: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 50;
}

.ai-input-wrap {
  display: flex;
  gap: 0.5rem;
}

.ai-input {
  flex: 1;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}

.ai-input:focus { border-color: var(--sky); }

.ai-status {
  font-size: 0.75rem;
  color: var(--ink-muted);
  font-style: italic;
}

/* ─── Empty State ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--ink-muted);
}

.empty-hint {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-top: 0.4rem;
}

/* ─── Modals ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,26,46,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: min(440px, 100%);
  box-shadow: var(--shadow);
}

.modal-wide { width: min(600px, 100%); }

.modal-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin-bottom: 1.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* ─── Forms ───────────────────────────────────────────────────── */
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 1rem;
  margin-bottom: 0.35rem;
}

.required { color: var(--danger); }

.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: white;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus { border-color: var(--sky); }

/* ─── History ─────────────────────────────────────────────────── */
.history-filters {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.pill {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.8rem;
  font-family: var(--font-body);
  cursor: pointer;
  color: var(--ink-muted);
  transition: all 0.15s;
}

.pill.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.history-list {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--sand);
  gap: 0.75rem;
}

.history-meta {
  flex: 1;
  min-width: 0;
}

.history-label {
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-detail {
  font-size: 0.75rem;
  color: var(--ink-muted);
  margin-top: 0.15rem;
}

.history-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.type-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.type-badge.plan   { background: #e0f2fe; color: var(--plan); }
.type-badge.actual { background: #d1fae5; color: var(--actual); }

/* ─── Admin ───────────────────────────────────────────────────── */
#panel-admin {
  position: fixed;
  top: calc(var(--nav-h) + var(--toolbar-h));
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 1.5rem 1.25rem 2rem;
  background: var(--sand);
  z-index: 60;
}

#panel-admin select,
#panel-admin button,
#panel-admin input {
  position: relative;
  z-index: 61;
}

.admin-wrap {
  max-width: 720px;
  margin: 0 auto;
}

.admin-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
}

.admin-section {
  margin-bottom: 2.5rem;
}

.admin-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 0.75rem;
  flex-wrap: wrap;
}

.user-info { flex: 1; min-width: 0; }

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.user-email {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.user-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.user-ai-count {
  font-size: 0.75rem;
  color: var(--ink-muted);
  font-family: var(--font-mono);
}

.form-select {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.8rem;
  background: white;
  color: var(--ink);
  cursor: pointer;
}

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  .toolbar { padding: 0 0.75rem; }
  .panel   { padding: 1rem 0.875rem; }
  .nav     { padding: 0 0.875rem; }
  .modal   { padding: 1.25rem; }

  .itinerary-body h1 { font-size: 1.5rem; }
  .itinerary-body h2 { font-size: 1.15rem; }
  .itinerary-body table { font-size: 0.8rem; }

  .user-item { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
