/* Route Planner — scoped styles. Reuses the site's tokens verbatim
   (assets/css/style.css) but stands alone: the applet never loads the
   marketing stylesheet. */

:root {
  --bg: #050608;
  --bg-2: #0a0f0c;
  --card: rgba(16, 22, 17, 0.82);
  --stroke: rgba(255, 255, 255, 0.08);
  --primary: #0071e3;
  --primary-rgb: 0, 113, 227;
  --accent: #ffd84d;
  --text: #f7f9f4;
  --muted: #b0b7b0;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --ok: #3ddc84;
  --warn: #ffb84d;
  --danger: #ff5d5d;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ── Header ──────────────────────────────────────────────────────────────── */

.plan-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px clamp(16px, 3vw, 40px);
  background: #0f1117;
  border-bottom: 1px solid var(--stroke);
}

.plan-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.plan-header .brand img { height: 26px; width: auto; display: block; }

.plan-header .btn.ghost { padding: 7px 14px; font-size: 13px; }

.plan-header .venue {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-state {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.save-state .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
}

.save-state.saving .dot { background: var(--warn); }
.save-state.failed { color: var(--danger); }
.save-state.failed .dot { background: var(--danger); }

/* ── Layout: rail + content ──────────────────────────────────────────────── */

.plan-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 51px);
  max-width: 1280px;
  margin: 0 auto;
}

.rail {
  padding: 28px 18px;
  border-right: 1px solid var(--stroke);
}

.rail-step {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  margin: 2px 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.rail-step .n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--stroke);
  font-size: 12px;
  flex: none;
}

.rail-step.active { color: var(--text); background: rgba(var(--primary-rgb), 0.12); }
.rail-step.active .n { border-color: var(--primary); color: var(--primary); }
.rail-step.done .n { background: var(--primary); border-color: var(--primary); color: #fff; }
.rail-step:disabled { opacity: 0.45; cursor: default; }
.rail-step .opt { font-size: 11px; font-weight: 400; color: var(--muted); }

.content {
  padding: 32px clamp(18px, 4vw, 56px) 120px;
  min-width: 0;
}

.content h1 { font-size: clamp(26px, 3vw, 38px); margin: 0 0 8px; letter-spacing: -0.02em; }
.content .lead { color: var(--muted); font-size: 16px; line-height: 1.6; margin: 0 0 26px; max-width: 640px; }

/* ── Cards / form primitives ─────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

label.field { display: block; margin-bottom: 16px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

input[type="text"], input[type="email"], input[type="date"], input[type="password"],
select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  background: none;
  color: var(--text);
}

.btn.primary { background: linear-gradient(135deg, #0071e3, #0b84ff); color: #fff; }
.btn.ghost { border-color: var(--stroke); background: rgba(255, 255, 255, 0.02); }
.btn.danger { border-color: rgba(255, 93, 93, 0.4); color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ── Point lists (origins / destinations) ────────────────────────────────── */

.point-list { display: flex; flex-direction: column; gap: 8px; margin: 0 0 14px; }

.point-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 10px;
}

.point-row .name { flex: 1; min-width: 0; font-weight: 600; }
.point-row input.name-edit { flex: 1; }
.point-row .meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.point-row .num {
  flex: none;
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(var(--primary-rgb), 0.15);
  color: var(--primary);
  border-radius: 50%;
  font-size: 12px; font-weight: 700;
}

.point-row .x {
  flex: none;
  border: 0; background: none; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 4px 6px; border-radius: 6px;
}
.point-row .x:hover { color: var(--danger); background: rgba(255, 93, 93, 0.1); }

.prio {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  width: auto;
}
.prio.high { color: #ff8a8a; border-color: rgba(255, 93, 93, 0.45); }
.prio.medium { color: var(--accent); border-color: rgba(255, 216, 77, 0.4); }
.prio.low { color: #9ad0ff; border-color: rgba(0, 113, 227, 0.45); }
.prio.remove, .prio.combine { color: var(--muted); text-decoration: line-through; }
.prio.combine { text-decoration: none; font-style: italic; }

.add-row { display: flex; gap: 10px; margin-top: 6px; }
.add-row input { flex: 1; }

.dupe-hint {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 184, 77, 0.1);
  border: 1px solid rgba(255, 184, 77, 0.35);
  color: var(--warn);
  font-size: 13px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px dashed var(--stroke);
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--primary); }

/* ── Matrix (connect step) ───────────────────────────────────────────────── */

.matrix-origin {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  margin-bottom: 14px;
  overflow: hidden;
}

.matrix-origin > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  user-select: none;
}
.matrix-origin > summary::-webkit-details-marker { display: none; }
.matrix-origin > summary .count {
  margin-left: auto;
  font-size: 13px;
  color: var(--primary);
  font-weight: 700;
  white-space: nowrap;
}
.matrix-origin > summary .chev { transition: transform 0.15s; color: var(--muted); }
.matrix-origin[open] > summary .chev { transform: rotate(90deg); }

.matrix-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 18px 12px;
}

.matrix-dests { padding: 0 10px 12px; }

.dest-check {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.dest-check:hover { background: rgba(255, 255, 255, 0.03); }
.dest-check input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--primary);
  flex: none;
}
.dest-check .dname { flex: 1; min-width: 0; }
.dest-check .flag { font-size: 12px; color: var(--warn); }
.dest-check.excluded { opacity: 0.5; }

.route-counter {
  position: fixed;
  right: clamp(14px, 3vw, 40px);
  bottom: 84px;
  background: #0f1117;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 16px;
  font-size: 14px;
  z-index: 15;
}
.route-counter strong { color: var(--accent); font-size: 18px; }

/* ── Details step ────────────────────────────────────────────────────────── */

.route-detail-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 2fr;
  gap: 10px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--stroke);
}
.route-detail-row .rname { font-size: 14px; padding-top: 8px; }
.route-detail-row .rname .rno { color: var(--muted); font-size: 12px; }

/* ── Floorplans ──────────────────────────────────────────────────────────── */

.floor-canvas-wrap {
  position: relative;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-2);
  touch-action: none;
}
.floor-canvas-wrap img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }

.pin {
  position: absolute;
  transform: translate(-50%, -100%);
  cursor: grab;
  font-size: 22px;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}
.pin .pin-label {
  position: absolute;
  top: -18px; left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 600;
  background: #0f1117;
  border: 1px solid var(--stroke);
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
}

.pin-tray { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.pin-tray .chip.placed { opacity: 0.4; text-decoration: line-through; }

/* ── Review ──────────────────────────────────────────────────────────────── */

.review-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.review-table th, .review-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--stroke);
}
.review-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.review-table td.r { text-align: right; font-variant-numeric: tabular-nums; }
.review-table tr.total td { font-weight: 700; color: var(--accent); border-top: 2px solid var(--stroke); }

.warning-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 184, 77, 0.35);
  background: rgba(255, 184, 77, 0.08);
  margin-bottom: 8px;
  font-size: 14px;
}
.warning-item.dupe { border-color: rgba(255, 93, 93, 0.4); background: rgba(255, 93, 93, 0.08); }
.warning-item .actions { margin-left: auto; display: flex; gap: 6px; flex: none; }

/* ── Notes ───────────────────────────────────────────────────────────────── */

.note {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.02);
  margin-bottom: 8px;
  font-size: 14px;
}
.note.staff { border-color: rgba(var(--primary-rgb), 0.4); background: rgba(var(--primary-rgb), 0.07); }
.note .who { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.note .who .staff-tag { color: var(--primary); font-weight: 700; }

/* ── Footer nav ──────────────────────────────────────────────────────────── */

.step-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--stroke);
  z-index: 18;
}
.step-nav .btn { min-width: 120px; }

/* ── Gate (passcode screen) ──────────────────────────────────────────────── */

.gate {
  max-width: 420px;
  margin: 10vh auto;
  padding: 0 18px;
  text-align: center;
}
.gate .card { text-align: left; }
.gate img.logo { height: 34px; margin-bottom: 18px; }
.gate .error { color: var(--danger); font-size: 14px; margin-top: 10px; }
.gate .lead { color: var(--muted); font-size: 15px; line-height: 1.6; margin: 0 0 22px; }
.gate input.passcode {
  text-align: center;
  font-size: 24px;
  letter-spacing: 0.5em;
  font-variant-numeric: tabular-nums;
}

/* ── Admin ───────────────────────────────────────────────────────────────── */

.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--stroke); }
.admin-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.admin-table tbody tr { cursor: pointer; }
.admin-table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--stroke);
}
.badge.draft { color: var(--muted); }
.badge.in_progress { color: var(--accent); border-color: rgba(255, 216, 77, 0.4); }
.badge.submitted { color: var(--ok); border-color: rgba(61, 220, 132, 0.4); }
.badge.approved { color: var(--primary); border-color: rgba(var(--primary-rgb), 0.5); }
.badge.revoked, .badge.expired { color: var(--danger); border-color: rgba(255, 93, 93, 0.4); }
.badge.active { color: var(--ok); border-color: rgba(61, 220, 132, 0.4); }

.progress-bar {
  width: 90px; height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}
.progress-bar > i { display: block; height: 100%; background: var(--primary); }

.tree-origin { margin-bottom: 6px; }
.tree-origin > summary { cursor: pointer; font-weight: 600; padding: 8px 10px; border-radius: 8px; }
.tree-origin > summary:hover { background: rgba(255, 255, 255, 0.03); }
.tree-route {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 10px 6px 28px;
  font-size: 14px;
  border-radius: 8px;
}
.tree-route:hover { background: rgba(255, 255, 255, 0.03); }
.tree-route .rno { color: var(--muted); font-size: 12px; }

.modal-back {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.modal {
  background: #12151c;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow: auto;
  padding: 22px;
}
.modal h2 { margin-top: 0; }

.share-box {
  font-family: ui-monospace, Consolas, monospace;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 12px;
  word-break: break-all;
  margin: 8px 0;
  font-size: 13px;
}

/* ── Floating chat ───────────────────────────────────────────────────────── */

.chat-widget {
  position: fixed;
  right: clamp(14px, 3vw, 28px);
  bottom: var(--chat-bottom, 20px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.chat-fab {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: linear-gradient(135deg, #0071e3, #0b84ff);
  box-shadow: var(--shadow);
  cursor: pointer;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-fab .ico { font-size: 22px; line-height: 1; }
.chat-fab:hover { filter: brightness(1.1); }

.chat-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  animation: chat-pop 0.25s ease;
}
@keyframes chat-pop {
  from { transform: scale(0.4); }
  to { transform: scale(1); }
}

.chat-badge.inline {
  position: static;
  display: inline-flex;
  margin-left: 8px;
  vertical-align: middle;
  animation: none;
  font-size: 11px;
  height: 18px;
}

.chat-panel {
  width: min(340px, calc(100vw - 28px));
  height: min(440px, 70vh);
  display: flex;
  flex-direction: column;
  background: #12151c;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--stroke);
  background: #0f1117;
}
.chat-title { font-weight: 700; font-size: 15px; }
.chat-sub { font-size: 12px; color: var(--muted); }
.chat-close {
  margin-left: auto;
  border: 0; background: none; color: var(--muted);
  font-size: 15px; cursor: pointer; padding: 4px 6px; border-radius: 6px;
}
.chat-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-empty { color: var(--muted); font-size: 13px; text-align: center; margin: auto 10px; }

.chat-msg {
  max-width: 85%;
  align-self: flex-start;
  padding: 8px 12px;
  border-radius: 12px 12px 12px 4px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
  font-size: 14px;
}
.chat-msg.mine {
  align-self: flex-end;
  border-radius: 12px 12px 4px 12px;
  border-color: rgba(var(--primary-rgb), 0.4);
  background: rgba(var(--primary-rgb), 0.14);
}
.chat-msg .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.chat-msg .body { word-wrap: break-word; }

.chat-input {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--stroke);
  background: #0f1117;
}
.chat-input input { flex: 1; }

.chat-toast {
  display: none;
  width: min(300px, calc(100vw - 28px));
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(var(--primary-rgb), 0.4);
  background: #12151c;
  box-shadow: var(--shadow);
  font-size: 13px;
  cursor: default;
}
.chat-toast.show { display: block; animation: chat-pop 0.2s ease; }
.chat-toast .who { color: var(--primary); font-weight: 700; font-size: 11px; margin-bottom: 2px; }

/* connect-step route counter sits at the same corner — step it up past the fab */
body.has-chat .route-counter { bottom: 148px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .plan-layout { grid-template-columns: 1fr; }
  .rail {
    display: flex;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--stroke);
    padding: 10px 12px;
    gap: 4px;
    position: sticky;
    top: 51px;
    background: var(--bg);
    z-index: 16;
  }
  .rail-step { flex: none; padding: 8px 10px; }
  .rail-step .label-txt { display: none; }
  .content { padding: 22px 16px 130px; }
  .route-detail-row { grid-template-columns: 1fr; }
  .route-counter { bottom: 76px; padding: 8px 12px; }
}

/* ── Review-step route map ─────────────────────────────────────────────────── */
.rm-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.rm-stat {
  font-size: 13px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke);
  border-radius: 100px;
  padding: 6px 14px;
}
.rm-stat b {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.rm-wrap {
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.015);
  padding: 10px 6px;
  overflow-x: auto;
}
.rm-svg {
  display: block;
  width: 100%;
  min-width: 520px;
  height: auto;
}
.rm-head {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
}
.rm-link {
  fill: none;
  stroke: rgba(255, 255, 255, 0.17);
  stroke-width: 1.5;
  transition: stroke 0.15s ease, stroke-width 0.15s ease, opacity 0.15s ease;
}
.rm-focused .rm-link { opacity: 0.13; }
.rm-focused .rm-link.on {
  opacity: 1;
  stroke: rgba(var(--primary-rgb), 0.95);
  stroke-width: 2.4;
}
.rm-node { cursor: pointer; outline: none; }
.rm-box {
  fill: rgba(255, 255, 255, 0.035);
  stroke: var(--stroke);
  stroke-width: 1;
  transition: fill 0.15s ease, stroke 0.15s ease, opacity 0.15s ease;
}
.rm-node--origin .rm-box {
  fill: rgba(var(--primary-rgb), 0.14);
  stroke: rgba(var(--primary-rgb), 0.45);
}
.rm-node--dest .rm-box {
  fill: rgba(255, 216, 77, 0.09);
  stroke: rgba(255, 216, 77, 0.32);
}
.rm-label {
  fill: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  pointer-events: none;
}
.rm-count {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-anchor: end;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.rm-focused .rm-node { opacity: 0.3; }
.rm-focused .rm-node.on { opacity: 1; }
.rm-node:focus-visible .rm-box,
.rm-node.on .rm-box { stroke-width: 1.8; }
.rm-node--origin.on .rm-box { fill: rgba(var(--primary-rgb), 0.3); }
.rm-node--dest.on .rm-box { fill: rgba(255, 216, 77, 0.2); }
.rm-hint {
  color: var(--muted);
  font-size: 12px;
  margin: 10px 0 0;
}
@media (prefers-reduced-motion: reduce) {
  .rm-link, .rm-box { transition: none; }
}
