:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f4f1ea;
  --ink: #23201b;
  --ink-soft: #6b6459;
  --line: #e7e2d8;
  --accent: #b4623a;
  --accent-soft: #f0e3da;
  --origin: #3a7a5c;
  --shadow: 0 1px 2px rgba(35, 32, 27, .06), 0 8px 24px rgba(35, 32, 27, .06);
  --radius: 16px;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, "Georgia", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --surface: #211e17;
    --surface-2: #2a261d;
    --ink: #ece7dc;
    --ink-soft: #a49d8e;
    --line: #35301f;
    --accent: #d98a5f;
    --accent-soft: #33291f;
    --origin: #6bbd8f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="light"] {
  --bg: #faf8f4; --surface: #fff; --surface-2: #f4f1ea; --ink: #23201b;
  --ink-soft: #6b6459; --line: #e7e2d8; --accent: #b4623a; --accent-soft: #f0e3da;
  --origin: #3a7a5c; --shadow: 0 1px 2px rgba(35,32,27,.06), 0 8px 24px rgba(35,32,27,.06);
}
:root[data-theme="dark"] {
  --bg: #17150f; --surface: #211e17; --surface-2: #2a261d; --ink: #ece7dc;
  --ink-soft: #a49d8e; --line: #35301f; --accent: #d98a5f; --accent-soft: #33291f;
  --origin: #6bbd8f; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 720px; margin: 0 auto; padding: 0 20px 80px; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 600; font-size: 1.35rem; letter-spacing: -.01em;
  color: var(--ink); text-decoration: none;
}
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 8px; align-items: center; }

/* Language switcher — a small segmented NB / EN control */
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang-switch .lang-opt {
  font-family: var(--sans); font-size: .72rem; font-weight: 600; letter-spacing: .03em;
  border: none; border-radius: 0; background: transparent; color: var(--ink-soft);
  padding: 5px 9px; cursor: pointer;
}
.lang-switch .lang-opt:hover { background: var(--surface-2); }
.lang-switch .lang-opt.active { background: var(--accent); color: #fff; }

/* Typography */
h1 { font-size: 1.9rem; letter-spacing: -.02em; margin: .6em 0 .2em; }
h2 { font-size: 1.3rem; letter-spacing: -.01em; margin: 0; }
.muted { color: var(--ink-soft); }
.sans { font-family: var(--sans); }
small { color: var(--ink-soft); }
a { color: var(--accent); }

/* Buttons */
.btn, button, input[type=submit] {
  font-family: var(--sans); font-size: .95rem; font-weight: 500;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 16px; border-radius: 999px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover, button:hover { background: var(--surface-2); }
.btn:active, button:active { transform: translateY(1px); }
.btn-primary, input[type=submit] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover, input[type=submit]:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 11px; font-size: .85rem; }
.btn-danger:hover { color: #c0392b; border-color: #c0392b; }

/* Forms */
label { font-family: var(--sans); font-size: .82rem; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 5px; }
input, textarea, select {
  width: 100%; font-family: var(--sans); font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; line-height: 1.5; }
.field { margin-bottom: 16px; }
.field .helptext, .errorlist { font-family: var(--sans); font-size: .8rem; }
.errorlist { color: #c0392b; list-style: none; padding: 0; margin: 6px 0 0; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}

/* Auth pages */
.auth { max-width: 380px; margin: 8vh auto 0; padding: 0 20px; }
.auth .card { padding: 28px; }
.auth h1 { margin-top: 0; text-align: center; }

/* Trip list */
.trip-grid { display: grid; gap: 16px; margin-top: 24px; }
.trip-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px;
  transition: transform .1s, box-shadow .15s;
}
.trip-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,.08), 0 16px 40px rgba(0,0,0,.1); }
.trip-card h2 { margin-bottom: 4px; }
.pill {
  font-family: var(--sans); font-size: .72rem; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; padding: 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.pill.done { background: var(--surface-2); color: var(--ink-soft); }

/* Samlinger (place groupings) */
.samlinger { margin: 20px 0; }
.samling-list { display: flex; flex-wrap: wrap; gap: 8px; }
.samling-tag {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .85rem; font-weight: 600; padding: 5px 8px 5px 12px;
  border-radius: 999px; background: var(--surface-2); color: var(--ink);
  text-decoration: none; transition: background .12s, transform .1s;
}
.samling-tag:hover { background: var(--accent-soft); color: var(--accent); transform: translateY(-1px); }
.samling-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  font-size: .72rem; background: var(--accent-soft); color: var(--accent);
}
.samling-chip {
  display: inline-block; margin-top: 6px;
  font-size: .74rem; font-weight: 600; letter-spacing: .01em;
  color: var(--accent); background: var(--accent-soft);
  padding: 2px 10px; border-radius: 999px;
}

/* Wishlist / to-do */
.wishlist { margin: 20px 0; }
.todo-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.todo-item:first-child { border-top: 1px solid var(--line); }
.todo-text { flex: 1; font-size: .98rem; }
.todo-text a { text-decoration: none; }
.todo-text a:hover { text-decoration: underline; }
.todo-link-ico { font-size: .8em; opacity: .7; }
.todo-item.done .todo-text { color: var(--ink-soft); text-decoration: line-through; }
.todo-check {
  flex: none; width: 24px; height: 24px; padding: 0; border-radius: 999px;
  border: 2px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .8rem; line-height: 1; color: #fff;
}
.todo-check:hover { border-color: var(--accent); background: var(--surface); }
.todo-item.done .todo-check { background: var(--accent); border-color: var(--accent); }
.todo-del {
  flex: none; width: 28px; height: 28px; padding: 0; border-radius: 999px;
  border-color: transparent; background: transparent; color: var(--ink-soft);
  justify-content: center; font-size: .85rem;
}
.todo-del:hover { color: #c0392b; background: var(--surface-2); }
.todo-empty { font-size: .92rem; padding: 4px 0 12px; }
.todo-add { margin-top: 14px; }
.todo-add-row { display: flex; gap: 8px; margin-bottom: 8px; }
.todo-add-row input { flex: 1; }
.todo-add-row .btn { flex: none; }

/* Presentation entry */
.present-cta { margin: 4px 0 4px; }

/* Map */
#map { height: 300px; border-radius: var(--radius); border: 1px solid var(--line);
  box-shadow: var(--shadow); margin: 20px 0; z-index: 1; }
.leaflet-container { font-family: var(--sans); background: var(--surface-2); }

/* Timeline */
.timeline { position: relative; margin: 24px 0; padding-left: 26px; }
.timeline::before {
  content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line);
}
.stop { position: relative; margin-bottom: 22px; }
.stop::before {
  content: ""; position: absolute; left: -26px; top: 22px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--bg);
}
.stop .card { padding: 18px 20px; }
.stop-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.stop-head h2 { margin-right: auto; }
.stop-date { font-family: var(--sans); font-size: .8rem; color: var(--ink-soft); }
.drag-handle {
  cursor: grab; color: var(--ink-soft); font-size: 1.1rem; line-height: 1;
  user-select: none; touch-action: none; align-self: center;
  padding: 2px 2px; opacity: .55; transition: opacity .12s;
}
.drag-handle:hover { opacity: 1; }
.drag-handle:active { cursor: grabbing; }
.stop-dragging { opacity: .4; }
.stop-notes { margin: 10px 0 0; white-space: pre-wrap; }
.stop-actions { display: flex; gap: 4px; margin-top: 12px; }
.no-coords { font-family: var(--sans); font-size: .78rem; color: var(--accent); }

/* Photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin-top: 12px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; transition: transform .25s ease; }
.photo img:hover { transform: scale(1.05); }
.photo form { position: absolute; top: 4px; right: 4px; margin: 0; }
.photo button {
  padding: 0; width: 22px; height: 22px; border-radius: 50%; font-size: .7rem;
  background: rgba(0,0,0,.55); color: #fff; border: none; line-height: 1;
  opacity: 0; transition: opacity .15s;
}
.photo:hover button { opacity: 1; }
.photo-add { font-family: var(--sans); font-size: .82rem; margin-top: 10px; }
.photo-add input[type=file] { font-size: .82rem; padding: 6px; }
.file-count { margin: 8px 0 0; font-size: .8rem; }
.upload-row { display: flex; align-items: center; gap: 10px; }
.upload-status { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.spinner {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Travelers */
.travelers { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0; }
.traveler-chip {
  font-family: var(--sans); font-size: .8rem; font-weight: 600;
  padding: 4px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft);
}
.stop-meta { font-size: .8rem; margin: 8px 0 0; }
.participants-field { display: flex; flex-wrap: wrap; gap: 4px 14px; font-family: var(--sans); font-size: .9rem; }
.participants-field > div, .participants-field > div > div { display: contents; }
.participants-field label {
  display: flex; align-items: center; gap: 6px;
  font-weight: 400; text-transform: none; color: var(--ink); margin: 0;
}
.participants-field input[type=checkbox] { width: auto; }
.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; }
.member-list li + li { border-top: 1px solid var(--line); }

/* Add-destination composer */
.composer { margin-top: 8px; }
.composer summary { list-style: none; cursor: pointer; }
.composer summary::-webkit-details-marker { display: none; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.flash { font-family: var(--sans); font-size: .9rem; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); margin: 12px 0; }
.center { text-align: center; }
.spacer { height: 8px; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---- Photo lightbox ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, #000 82%, transparent);
  backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
  -webkit-tap-highlight-color: transparent;
}
.lightbox.open { opacity: 1; pointer-events: auto; }
.lightbox-stage {
  position: relative; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  box-sizing: border-box;
}
.lightbox-img {
  max-width: min(100%, 1200px); max-height: 100%;
  object-fit: contain; border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  transform: scale(.96); transition: transform .25s ease;
  -webkit-user-select: none; user-select: none;
}
.lightbox.open .lightbox-img { transform: scale(1); }
.lightbox-cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 40px 20px calc(18px + env(safe-area-inset-bottom));
  text-align: center; color: #fff; font-family: var(--sans); font-size: .95rem;
  background: linear-gradient(to top, rgba(0,0,0,.55), transparent);
  pointer-events: none;
}
.lightbox-cap:empty { display: none; }
.lightbox-btn {
  position: absolute; z-index: 2;
  width: 48px; height: 48px; border-radius: 50%;
  border: none; cursor: pointer;
  background: rgba(255,255,255,.14); color: #fff;
  font-size: 1.5rem; line-height: 1;
  display: grid; place-items: center;
  backdrop-filter: blur(6px);
  transition: background .15s, transform .15s;
}
.lightbox-btn:hover { background: rgba(255,255,255,.28); }
.lightbox-btn:active { transform: scale(.92); }
.lightbox-btn:disabled { opacity: 0; pointer-events: none; }
.lightbox-prev { left: max(12px, env(safe-area-inset-left)); top: 50%; transform: translateY(-50%); }
.lightbox-prev:active { transform: translateY(-50%) scale(.92); }
.lightbox-next { right: max(12px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%); }
.lightbox-next:active { transform: translateY(-50%) scale(.92); }
.lightbox-close { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); font-size: 1.25rem; }
.lightbox-count {
  position: absolute; top: max(18px, calc(env(safe-area-inset-top) + 6px)); left: 0; right: 0;
  text-align: center; color: rgba(255,255,255,.85);
  font-family: var(--sans); font-size: .78rem; font-weight: 600; letter-spacing: .08em;
  pointer-events: none;
}
@media (max-width: 560px) {
  .lightbox-prev, .lightbox-next { width: 42px; height: 42px; font-size: 1.3rem; }
}
