:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --muted: #8b91a0;
  --accent: #3b82f6;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
}
button {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px;
  cursor: pointer; user-select: none;
}
button:hover { border-color: var(--accent); }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}

/* --- centrado para login / nuevo proyecto --- */
.center {
  height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; padding: 24px;
}
.center h1 { font-weight: 600; font-size: 22px; margin: 0; }
.big-date { font-size: 28px; padding: 18px 22px; text-align: center; }
.error { color: #f87171; min-height: 18px; }

/* --- lista de proyectos --- */
.list { max-width: 740px; max-height: calc(100vh - 64px); overflow-y: auto; margin: 32px auto; padding: 0 16px; }
.list header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.proj {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 10px; cursor: pointer;
}
.proj:hover { border-color: var(--accent); }
.proj .meta { color: var(--muted); font-size: 12px; }
.proj .del { background: transparent; border: none; color: var(--muted); }
.proj .del:hover { color: #f87171; }
textarea { resize: vertical; line-height: 1.5; }
button:disabled { opacity: .5; cursor: wait; }
.list header > div { display: flex; align-items: center; gap: 12px; }
.proj-open { flex: 1; border: none; background: transparent; text-align: left; padding: 0; }
.proj-open > div:first-child { font-size: 17px; font-weight: 600; }

/* --- menú SPA --- */
.app-menu { height: 100vh; overflow-y: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 32px 20px; }
.menu-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; width: min(100%, 540px); }
.menu-tile { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 22px 12px; }
.menu-tile strong { font-size: 24px; font-weight: 600; }
.app-error { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); padding: 12px 16px; border: 1px solid #6b2330; border-radius: 8px; background: var(--panel); color: #f87171; z-index: 30; }

/* --- timeline --- */
.tl { height: 100vh; display: flex; flex-direction: column; }
.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.toolbar input.name {
  font-weight: 600; flex: 1; min-width: 0;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
}
.toolbar input.name:hover { border-color: var(--border); }
.toolbar input.name:focus { border-color: var(--accent); background: var(--bg); outline: none; }
.toolbar .zoom { font-size: 12px; color: var(--muted); min-width: 70px; text-align: center; }
.toolbar .menu-btn { font-size: 18px; line-height: 1; padding: 6px 12px; }
.toolbar .edit-toggle { display: flex; align-items: center; padding: 8px; }
.toolbar .edit-toggle.active { color: var(--accent); border-color: var(--accent); }
button:focus-visible, .event:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.surface {
  position: relative; flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; background: var(--bg);
  scrollbar-color: var(--muted) var(--bg); scrollbar-width: thin;
  touch-action: none; /* clave: desactiva scroll/zoom nativo para manejar gestos */
  cursor: crosshair;
}
.surface-content { position: relative; min-height: 100%; }
.timeline-header { position: sticky; top: 0; height: 50px; z-index: 3; background: var(--bg); }
.surface.readonly, .surface.readonly .event { cursor: grab; }
.tick {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: var(--border); pointer-events: none;
}
.tick-label {
  position: absolute; top: 30px; left: 4px; font-size: 11px; color: var(--muted);
  white-space: nowrap;
}
.header-tick { position: absolute; top: 0; height: 50px; width: 1px; background: var(--border); }
.date-chip {
  position: absolute; top: 4px; left: 0; z-index: 3; pointer-events: none;
  font-size: 12px; font-weight: 600; color: var(--text);
  background: var(--panel); border: 1px solid var(--border);
  padding: 2px 9px; border-radius: 6px; white-space: nowrap;
}
.event {
  position: absolute; height: 40px; border-radius: 6px; overflow: hidden;
  display: flex; align-items: center; color: #fff; font-size: 13px;
  box-shadow: 0 1px 3px rgba(0,0,0,.4); cursor: grab;
}
.event-title { padding: 0 8px; pointer-events: none; white-space: nowrap; overflow: hidden; }
.event.draft { opacity: .6; }
.event:hover, .event:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.event-tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  max-width: min(320px, calc(100vw - 16px)); padding: 10px 12px;
  color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5); font-size: 13px; line-height: 1.6;
  white-space: pre-line; overflow-wrap: anywhere;
}

.scrollbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-top: 1px solid var(--border); background: var(--panel);
}
.scrollbar .grow { flex: 1; text-align: center; color: var(--muted); font-size: 12px; }

/* --- editor modal --- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px;
}
.modal .menu-section { font-size: 12px; font-weight: 600; color: var(--muted); margin: 0; text-transform: uppercase; letter-spacing: .04em; }
.modal label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.modal .row { display: flex; gap: 10px; justify-content: space-between; }
.modal .danger { color: #f87171; border-color: #6b2330; }
.modal input[type=color] { padding: 2px; width: 56px; height: 34px; cursor: pointer; }
.project-delete { color: var(--text); }
.project-delete::backdrop { background: rgba(0,0,0,.5); }
.project-delete h2 { margin: 0; font-size: 18px; }
.project-delete p { margin: 0; line-height: 1.5; overflow-wrap: anywhere; }

/* --- organizer --- */
.organizer-page { height: 100vh; overflow-y: auto; padding: 28px max(20px, calc((100vw - 1160px) / 2)); scrollbar-color: var(--muted) var(--bg); color-scheme: dark; }
.organizer-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.organizer-header > div { flex: 1; min-width: 0; }
.organizer-header h1 { font-size: 28px; margin: 0; overflow-wrap: anywhere; }
.organizer-header h2, .day-detail h2 { margin: 0; font-size: 22px; }
.trip-overview { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 24px; margin-bottom: 28px; }
.trip-overview h1 { margin: 0 0 8px; font-size: clamp(24px, 3vw, 36px); overflow-wrap: anywhere; }
.trip-dates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.travelers { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.traveler-card { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px; overflow-wrap: anywhere; }
.traveler-card summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 8px; }
.traveler-card p { white-space: pre-wrap; color: var(--muted); font-size: 14px; margin-bottom: 0; }
.traveler-card h3 { font-size: 16px; margin: 0; }
.trip-overview > .form-actions { justify-content: space-between; margin: 0 0 18px; }
.trip-overview h2 { margin: 0; font-size: 18px; }
.organizer-page .meta { color: var(--muted); font-size: 13px; line-height: 1.6; }
.day-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; padding-bottom: 24px; }
.day-card { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; text-align: left; min-height: 160px; padding: 20px; }
.day-card strong { font-size: 18px; font-weight: 600; }
.day-card span { color: var(--muted); font-size: 13px; }
.day-card ul { margin: 0; padding-left: 16px; font-size: 13px; line-height: 1.6; color: var(--text); }
.itinerary-toolbar { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 12px 0; }
.day-detail { margin-top: 24px; padding-bottom: 24px; scroll-margin-top: 108px; }
.day-detail > .form-actions { justify-content: space-between; margin-bottom: 20px; }
.day-detail > .event-form { max-width: none; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-bottom: 16px; }
.itinerary-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-bottom: 16px; overflow-wrap: anywhere; }
.itinerary-card header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.itinerary-card h3 { margin: 8px 0; font-size: 20px; }
.itinerary-card p { font-size: 14px; color: var(--muted); white-space: pre-wrap; line-height: 1.6; }
.event-kind { color: var(--muted); text-transform: uppercase; font-size: 11px; font-weight: 600; letter-spacing: .08em; }
.itinerary-card .event-times { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.6; }
.itinerary-card dl.fields-list { display: block; margin: 16px 0 0; font-size: 14px; }
.itinerary-card .field-pair { display: grid; grid-template-columns: minmax(100px, 180px) 1fr; gap: 8px 20px; margin-bottom: 10px; }
.itinerary-card dt { color: var(--muted); }
.itinerary-card dd { margin: 0; white-space: pre-wrap; }
.empty-state { color: var(--muted); line-height: 1.6; padding: 20px 0; }
.trip-form, .event-form { display: flex; flex-direction: column; gap: 18px; width: 100%; max-width: 760px; margin: 0 auto; }
.trip-form fieldset, .event-form fieldset { display: flex; flex-direction: column; gap: 18px; border: 0; min-width: 0; margin: 0; padding: 0; }
.trip-form label, .event-form label { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
.trip-form input, .trip-form textarea, .trip-form select, .event-form input, .event-form textarea, .event-form select { width: 100%; min-width: 0; }
.trip-form textarea, .event-form textarea { min-height: 100px; }
.trip-form h2, .event-form h2 { font-size: 22px; margin: 0; }
.trip-form h3, .event-form h3 { font-size: 16px; margin: 0; }
.traveler-editor { display: flex; flex-direction: column; gap: 14px; padding: 18px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.traveler-editor > button { align-self: flex-end; }
.fields-list { display: flex; flex-direction: column; gap: 10px; }
.field-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) auto; align-items: end; gap: 10px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.form-actions button[type=submit] { border-color: var(--accent); background: var(--accent); color: #fff; }
.organizer-modal { width: min(100%, 810px); margin: 0 auto; }
.organizer-modal > h2 { margin-top: 0; font-size: 22px; }
.organizer-modal > .trip-form, .organizer-modal > .event-form { background: var(--panel); padding: 24px; border: 1px solid var(--border); border-radius: 12px; }
.organizer-page .danger, .organizer-modal .danger { color: #f87171; }
@media (max-width: 600px) {
  .list { margin: 16px auto; max-height: calc(100vh - 32px); }
  .list header { align-items: flex-start; gap: 16px; flex-wrap: wrap; }
  .menu-choices { gap: 12px; }
  .menu-tile { gap: 12px; }
  .menu-tile strong { font-size: 20px; }
  .menu-tile svg { width: 44px; height: 44px; }
  .organizer-page { padding: 20px 16px; }
  .organizer-header h1 { font-size: 24px; }
  .trip-overview, .itinerary-card { padding: 18px; }
  .day-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .day-card { padding: 14px; min-height: 140px; }
  .day-card strong { font-size: 15px; }
  .itinerary-card header { flex-wrap: wrap; }
  .field-pair { grid-template-columns: minmax(0, 1fr) auto; }
  .field-pair label:first-child { grid-column: 1 / -1; }
  .organizer-modal { padding: 16px 12px; }
  .organizer-modal > .trip-form, .organizer-modal > .event-form { padding: 20px 16px; }
}
