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

/* Keep the [hidden] attribute authoritative — author rules like
   `.modal-overlay { display: grid }` would otherwise override it. */
[hidden] { display: none !important; }

:root {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #0f172a;
  --muted:     #64748b;
  --primary:   #2563eb;
  --primary-dk:#1d4ed8;
  --danger:    #dc2626;
  --success:   #16a34a;
  --warning:   #d97706;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.15);
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ─── Buttons / forms ────────────────────────────────────── */
.btn {
  font: inherit;
  padding: .5rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); border-color: var(--primary-dk); }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: #fef2f2; border-color: #fecaca; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(255,255,255,.15); }
.btn-block { width: 100%; }
.btn-sm { padding: .25rem .55rem; font-size: .8rem; }

.field { display: block; margin-bottom: .85rem; }
.field > span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
.field input, .field select, .field textarea {
  font: inherit;
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.field textarea { resize: vertical; min-height: 60px; }
.checkbox { display: flex; align-items: center; gap: .4rem; font-size: .85rem; margin-bottom: .85rem; }
.checkbox input { width: auto; }
.field-inline { display: flex; align-items: center; gap: .4rem; font-size: .85rem; margin-bottom: .35rem; }
.field-inline input { width: auto; }
.time-picker { display: flex; align-items: center; gap: .35rem; }
.time-picker select { width: auto; }
.form-row { display: flex; gap: .6rem; }
.form-row .field { flex: 1; }

/* ─── Auth pages ─────────────────────────────────────────── */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  padding: 1rem;
}
.auth-card {
  background: var(--surface);
  padding: 2rem;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
}
.auth-title { font-size: 1.5rem; }
.auth-subtitle { color: var(--muted); margin-bottom: 1.25rem; font-size: .9rem; }
.auth-foot { margin-top: 1rem; font-size: .85rem; text-align: center; color: var(--muted); }
.auth-foot a { color: var(--primary); }

.alert { padding: .6rem .8rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .85rem; }
.alert ul { margin-left: 1rem; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ─── Topbar / tabs ──────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.25rem;
  height: 58px;
  background: #0f172a;
  color: #fff;
}
.topbar-brand { font-weight: 600; }
.tabs { display: flex; gap: .25rem; flex: 1; }
.tab {
  font: inherit;
  background: transparent;
  border: none;
  color: #cbd5e1;
  padding: .45rem .8rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.tab:hover { background: rgba(255,255,255,.1); color: #fff; }
.tab.active { background: var(--primary); color: #fff; }
.topbar-user { display: flex; align-items: center; gap: .75rem; }
.topbar-user .username { font-size: .9rem; color: #cbd5e1; }
.topbar-user form { display: inline; }
/* Give the header action buttons a visible outline so they don't
   disappear into the dark topbar. */
.topbar-user .btn-ghost {
  border-color: rgba(255,255,255,.25);
  color: #e2e8f0;
}
.topbar-user .btn-ghost:hover { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.45); }

.trip-bar {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.trip-select { font: inherit; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); min-width: 220px; }

.content { padding: 1.25rem; }
.panel { max-width: 1200px; margin: 0 auto; }
.empty { color: var(--muted); text-align: center; padding: 3rem 1rem; }

/* ─── Itinerary board ────────────────────────────────────── */
.day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.day-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .6rem .9rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.day-head h3 { font-size: .95rem; }
.day-head .day-sub { font-size: .75rem; color: var(--muted); font-weight: 400; }
.day-list { list-style: none; padding: .6rem; min-height: 48px; }
.day-list.drag-over { background: #eff6ff; }

.event-card {
  display: flex;
  gap: .65rem;
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  margin-bottom: .5rem;
  background: var(--surface);
  cursor: grab; /* desktop: whole card is draggable */
}
.event-card:last-child { margin-bottom: 0; }
/* Drag handle: hidden on desktop (whole-card drag); shown only on touch devices,
   where it's the one place a drag starts so a normal touch scrolls the page.
   touch-action:none lets a touch on the handle begin a drag instead of scrolling. */
.event-card .ev-drag {
  display: none;
  cursor: grab;
  touch-action: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: .15rem .25rem;
  margin: -.15rem -.1rem -.15rem -.25rem;
  align-self: stretch;
  align-items: center;
  user-select: none;
}
.event-card .ev-drag:active { cursor: grabbing; }
@media (pointer: coarse) {
  .event-card { cursor: default; }          /* touch: only the handle drags */
  .event-card .ev-drag { display: flex; }
}
.event-card .ev-icon { font-size: 1.1rem; }
.event-card .ev-body { flex: 1; min-width: 0; }
.event-card .ev-title { font-weight: 600; font-size: .92rem; }
.event-card .ev-meta { font-size: .78rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .15rem; }
.event-card .ev-actions { display: flex; gap: .3rem; align-items: flex-start; }
.sortable-ghost { opacity: .4; }

.badge { font-size: .7rem; padding: .1rem .45rem; border-radius: 999px; background: #e0e7ff; color: #3730a3; white-space: nowrap; }
.badge-conf { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef3c7; color: #92400e; }

.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .72rem; padding: .15rem .4rem;
  background: #f1f5f9; border: 1px solid var(--border); border-radius: 6px;
}
.chip a { color: var(--primary); text-decoration: none; }
.chip button { border: none; background: none; color: var(--danger); cursor: pointer; font-size: .8rem; line-height: 1; }

/* type accent colors (left border) */
.t-activity { border-left-color: #2563eb; }
.t-flight   { border-left-color: #0891b2; }
.t-hotel    { border-left-color: #7c3aed; }
.t-train    { border-left-color: #db2777; }
.t-car      { border-left-color: #ca8a04; }
.t-food     { border-left-color: #ea580c; }
.t-other    { border-left-color: #64748b; }

/* ─── Tables (bookings / users) ──────────────────────────── */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); font-size: .85rem; }
.table th { background: #f8fafc; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }

.status-badge { font-size: .72rem; padding: .15rem .5rem; border-radius: 999px; text-transform: capitalize; }
.status-approved { background: #dcfce7; color: #166534; }
.status-pending  { background: #fef3c7; color: #92400e; }
.status-rejected { background: #fee2e2; color: #991b1b; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.section-head h2 { font-size: 1.15rem; }
.count-badge { background: var(--warning); color: #fff; border-radius: 999px; padding: .1rem .5rem; font-size: .75rem; margin-left: .4rem; }

/* ─── Map ────────────────────────────────────────────────── */
#map { height: 70vh; border-radius: var(--radius); box-shadow: var(--shadow); }

/* ─── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: grid; place-items: center; padding: 1rem; z-index: 1000;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 1.5rem;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: .6rem 1rem; border-radius: var(--radius);
  font-size: .85rem; box-shadow: var(--shadow-lg); z-index: 1100;
}
.toast.toast-error { background: var(--danger); }

.locate-row { display: flex; gap: .5rem; align-items: flex-end; }
.locate-row .field { flex: 1; margin-bottom: 0; }
.loc-map { height: 200px; border-radius: var(--radius); margin-bottom: .85rem; overflow: hidden; }
.map-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  font-size: 22px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.field-hint { display: block; font-size: .72rem; color: var(--muted); margin-top: .2rem; }
.ev-steps { font-size: .78rem; color: var(--muted); white-space: pre-wrap; margin-top: .3rem; }
.ev-booking { margin-top: .3rem; }
.file-viewer img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: var(--radius); }
.chip-dl { text-decoration: none; }

/* ─── Packing ────────────────────────────────────────────── */
.pack-actions { display: flex; gap: .5rem; }
.pack-list { list-style: none; padding: .4rem .6rem; }
.pack-item { display: flex; align-items: center; gap: .6rem; padding: .35rem .2rem; border-bottom: 1px solid var(--border); }
.pack-item:last-child { border-bottom: none; }
.pack-item .pack-name { flex: 1; }
.pack-item.packed .pack-name { text-decoration: line-through; color: var(--muted); }

/* ─── Share modal ────────────────────────────────────────── */
.share-link { display: flex; gap: .4rem; align-items: center; margin-bottom: .8rem; }
.share-link-input { flex: 1; font: inherit; padding: .4rem .5rem; border: 1px solid var(--border); border-radius: var(--radius); background: #f8fafc; }
.share-h { font-size: .9rem; margin: 1rem 0 .4rem; }
.share-row { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.share-row:last-child { border-bottom: none; }
.share-row .share-name { flex: 1; font-size: .9rem; }
.role-select { font: inherit; padding: .25rem .4rem; border: 1px solid var(--border); border-radius: var(--radius); }
.muted { color: var(--muted); font-size: .85rem; }

/* ─── Private / shared indicators ────────────────────────── */
.badge-private { background: #ede9fe; color: #5b21b6; }
.badge-shared  { background: #e0e7ff; color: #3730a3; }
.ev-title .badge { margin-left: .4rem; }
.itin-filter { display: flex; gap: .4rem; margin-bottom: .8rem; }

#panel-map { position: relative; }
.map-pin-private { border-style: dashed !important; border-color: #7c3aed !important; }
.map-legend {
  position: absolute; bottom: 12px; left: 12px; z-index: 500;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: .4rem .6rem; font-size: .75rem; box-shadow: var(--shadow);
}
.map-legend > div { display: flex; align-items: center; }
.map-legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .35rem; }
.map-legend .sw-shared { background: #fff; border: 2px solid var(--primary); }
.map-legend .sw-private { background: #fff; border: 2px dashed #7c3aed; }

/* ─── Responsive / mobile ────────────────────────────────── */
@media (max-width: 720px) {
  /* Header wraps: brand + user on the top row, tabs on their own
     horizontally-scrollable row below. */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    gap: .5rem 1rem;
    padding: .6rem .9rem;
  }
  .topbar-user { margin-left: auto; gap: .5rem; }
  .tabs {
    order: 3;
    flex-basis: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; }

  /* Trip selector stacks and goes full width. */
  .trip-bar { flex-wrap: wrap; padding: .6rem .9rem; }
  .trip-select { min-width: 0; flex: 1 1 100%; }

  .content { padding: .9rem; }

  /* Let wide tables scroll horizontally instead of overflowing. */
  .table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* Stack paired form fields. */
  .form-row { flex-direction: column; gap: 0; }
  .locate-row { flex-wrap: wrap; }

  .section-head { flex-wrap: wrap; gap: .5rem; }
  .modal { padding: 1.1rem; }

  /* Share modal + itinerary filter wrap on narrow screens. */
  .share-link { flex-wrap: wrap; }
  .share-link-input { flex: 1 1 100%; }
  .share-row { flex-wrap: wrap; }
  .itin-filter { flex-wrap: wrap; }
}

@media (max-width: 460px) {
  .topbar-user .username { display: none; }
}
.pack-item input[type=checkbox] { width: auto; }
