/* Kinexion itinerary web app */

/* The `hidden` attribute is our show/hide switch, but the browser's default
   `[hidden]{display:none}` is low-specificity and gets overridden by any
   `display:` rule (e.g. `.overlay{display:flex}`). Force it to win so hidden
   overlays/panels stay hidden until JS reveals them. */
[hidden] { display: none !important; }

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c1e26;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --ok: #1e8e3e;
  --warn: #b7791f;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 24, 40, .08), 0 4px 16px rgba(20, 24, 40, .05);
  /* family colors (match the map pins) */
  --k-stop: #e0493e;       /* short-term */
  --k-stay: #b7791f;       /* real visit, not overnight */
  --k-lodging: #2f6fed;    /* overnight */
  --k-departure: #1e8e3e;
  --k-return: #7b2fed;
  --k-transit: #0e7d83;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- chrome ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 17px; cursor: pointer; }
.brand span { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; color: var(--muted); }

.view { max-width: 1280px; margin: 0 auto; padding: 22px 20px 60px; }
h1 { font-size: 22px; margin: 6px 0 4px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 7px 14px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.btn:hover { border-color: #c9cdd6; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 12.5px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}

/* ---------- login ---------- */
.login-card { max-width: 420px; margin: 8vh auto 0; }
.login-card label { display: block; margin: 14px 0 10px; font-weight: 600; font-size: 13px; }
.login-card input {
  display: block; width: 100%; margin-top: 5px;
  padding: 9px 11px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 8px;
}
.login-card .btn { margin-right: 8px; margin-top: 4px; }

/* ---------- trips ---------- */
.trip-grid {
  margin-top: 18px;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}
.trip-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .08s ease;
}
.trip-card:hover { transform: translateY(-2px); }
.trip-card .cover {
  height: 120px; background: linear-gradient(135deg, #b8c6e6, #dde4f2);
  background-size: cover; background-position: center;
}
.trip-card .body { padding: 10px 12px 12px; }
.trip-card .name { font-weight: 650; }
.trip-card .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

/* ---------- trip view ---------- */
.trip-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.trip-head h1 { margin: 0; }

.trip-panes {
  display: grid; gap: 18px; margin-top: 16px;
  grid-template-columns: minmax(380px, 5fr) minmax(320px, 4fr);
  align-items: start;
}
@media (max-width: 980px) { .trip-panes { grid-template-columns: 1fr; } }

.pane-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.pane-toolbar .spacer { flex: 1; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg-btn { border: 0; background: transparent; padding: 7px 14px; font-size: 14px; cursor: pointer; color: var(--muted); }
.seg-btn.active { background: var(--accent); color: #fff; }

/* ---------- itinerary list ---------- */
.itinerary-list { display: flex; flex-direction: column; gap: 10px; }
.group-head { margin: 14px 0 2px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.item {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  border-left: 4px solid var(--line);
}
.item.k-STOP      { border-left-color: var(--k-stop); }
.item.k-STAY      { border-left-color: var(--k-stay); }
.item.k-LODGING   { border-left-color: var(--k-lodging); }
.item.k-DEPARTURE { border-left-color: var(--k-departure); }
.item.k-RETURN    { border-left-color: var(--k-return); }
.item.k-TRANSIT   { border-left-color: var(--k-transit); }

.item .icon { font-size: 20px; line-height: 1.2; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 650; }
.item .when { color: var(--muted); font-size: 13px; margin-top: 1px; }
.item .notes { font-size: 13px; margin-top: 4px; }
.item .row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em;
  border-radius: 999px; padding: 2px 8px; margin-left: 8px; vertical-align: 1px;
}
.badge.src-MANUAL  { background: #e8f0fe; color: #1a56c4; }
.badge.src-DERIVED { background: #eef2f1; color: #4a5b57; }
.badge.src-EMAIL   { background: #fef3e2; color: #9a6614; }
.badge.family { background: #f1f2f5; color: #555c69; }
.badge.rating { background: #fff7da; color: #8a6d00; }

.suggestion {
  margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  background: #fff8e8; border: 1px solid #efd9a8;
  font-size: 13px;
}
.suggestion .btn { margin-left: 6px; }
.suggestion .div-flag { font-weight: 650; color: var(--warn); }

.empty {
  color: var(--muted); text-align: center; padding: 34px 0;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
}

/* ---------- item form ---------- */
.item-form { margin-bottom: 14px; }
.item-form h3 { margin: 0 0 10px; }
.form-grid { display: grid; gap: 10px 14px; grid-template-columns: 1fr 1fr; }
.form-grid label { font-size: 12.5px; font-weight: 650; color: var(--muted); }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  font-size: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.form-actions { margin-top: 12px; display: flex; gap: 8px; }

/* place-search picker (location / destination fields) */
.loc-field { position: relative; }
.loc-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow);
  max-height: 240px; overflow-y: auto; margin-top: 3px;
}
.loc-row { padding: 8px 12px; cursor: pointer; }
.loc-row:hover { background: #eef3fc; }
.loc-row .loc-name { font-weight: 600; font-size: 13.5px; color: var(--ink); }
.loc-row .loc-addr { font-size: 12px; color: var(--muted); }
.pick-chip {
  margin-top: 5px; display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 500; color: var(--ink);
  background: #e8f0fe; border-radius: 999px; padding: 3px 10px;
  max-width: 100%; overflow: hidden;
}
.pick-chip .muted { font-weight: 400; }
.pick-chip .chip-x {
  border: 0; background: transparent; color: var(--muted);
  font-size: 13px; cursor: pointer; padding: 0 2px; line-height: 1;
}

/* ---------- map ---------- */
.map-pane { position: sticky; top: 64px; }
.map-wrap { position: relative; }
.map {
  height: 560px; border-radius: var(--radius);
  border: 1px solid var(--line); overflow: hidden; background: #dfe5ee;
}
.map-expand {
  position: absolute; top: 10px; right: 10px; z-index: 10;
  width: 42px; height: 42px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; line-height: 1;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px;
  box-shadow: var(--shadow); cursor: pointer;
  touch-action: manipulation;
}
.map-expand:hover { background: #f2f4f8; }

/* expanded: the map pane takes the whole viewport */
body.map-expanded { overflow: hidden; }
body.map-expanded .map-pane {
  position: fixed; inset: 0; z-index: 80;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding: calc(0.6rem + env(safe-area-inset-top))
           calc(0.75rem + env(safe-area-inset-right))
           calc(0.75rem + env(safe-area-inset-bottom))
           calc(0.75rem + env(safe-area-inset-left));
}
body.map-expanded .map-wrap { flex: 1; min-height: 0; }
body.map-expanded .map { height: 100%; }
body.map-expanded .map-note { display: none; }
.map-toolbar { font-size: 13.5px; color: var(--muted); }
.chk { display: inline-flex; gap: 5px; align-items: center; margin-right: 6px; }
.map-note { font-size: 12.5px; margin-top: 8px; }

/* place dot annotation */
.place-dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
/* transit destination dot */
.dest-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 3.5px solid var(--k-transit);
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #23262f; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 50;
  max-width: 80vw;
}

/* ---------- moment links on items (photos / chat icons) ---------- */
.item-links { display: inline-flex; gap: 4px; margin-left: 6px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--card); cursor: pointer;
  border-radius: 8px; padding: 2px 7px; font-size: 14px; line-height: 1.4; color: var(--ink);
}
.icon-btn:hover { border-color: var(--accent); }
.cat-icon { width: 20px; height: 20px; object-fit: contain; vertical-align: middle; border-radius: 4px; }

/* ---------- overlays (chat panel + gallery) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(20, 24, 40, .38);
  display: flex; justify-content: flex-end;
}
/* Docked panel (photo gallery): the same right-side panel, but with NO
   full-screen backdrop — the itinerary list underneath stays clickable, so
   tapping another item's photo icon switches the gallery instead of a
   backdrop-click closing it. */
.dock { position: fixed; top: 0; right: 0; height: 100%; width: min(440px, 100%); z-index: 55; }
.side-panel {
  width: min(440px, 100%); height: 100%; background: var(--bg);
  display: flex; flex-direction: column; box-shadow: var(--shadow);
  animation: slideIn .18s ease;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.panel-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); background: var(--card);
}
.panel-title { font-weight: 650; font-size: 15px; }
.spacer { flex: 1 1 auto; }

/* chat */
.chat-msgs { flex: 1 1 auto; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 80%; padding: 7px 11px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.msg.mine { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.msg .who { font-size: 11.5px; color: var(--muted); margin-bottom: 1px; }
.msg.mine .who { color: rgba(255,255,255,.85); }
.msg .txt { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.msg .when { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.msg.mine .when { color: rgba(255,255,255,.8); }
.chat-empty { color: var(--muted); text-align: center; margin: auto; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--card); }
.chat-form input { flex: 1 1 auto; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }

/* gallery */
.gallery-grid { flex: 1 1 auto; overflow-y: auto; padding: 12px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; align-content: start; }
.gallery-grid img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 8px; cursor: zoom-in;
  background: var(--line); border: 1px solid var(--line); }
.gallery-empty { color: var(--muted); grid-column: 1 / -1; text-align: center; margin: 24px 0; }
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.86);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; object-fit: contain; border-radius: 6px; }
/* prev/next arrows over the enlarged photo */
.lb-nav {
  position: fixed; top: 50%; transform: translateY(-50%); z-index: 71;
  width: 52px; height: 52px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; line-height: 1; color: #fff; background: rgba(255, 255, 255, .15);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); transition: background .12s;
}
.lb-nav:hover { background: rgba(255, 255, 255, .32); }
.lb-prev { left: 18px; }
.lb-next { right: 18px; }
