/* ==========================================================================
   SKTED — the itinerary planner.

   Same furniture as the guide map: a full-bleed map with the app header
   floating over it, and one panel that holds the state of what you are doing.
   The panel is a right-hand column on a desk and a bottom sheet on a phone,
   because a route is read as a list and the list is what you hold in your hand
   while walking it.

   Everything shared — buttons, inputs, labels, the header, the status badge —
   comes from theme.css. Only what is particular to a route lives here.
   ========================================================================== */

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink-900);
}

#itinerary-map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---- The day strip: the shape of the route, over the map ---------------- */

.day-strip {
  position: fixed;
  top: calc(var(--header-h) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  gap: 6px;
  padding: 6px;
  max-width: min(560px, calc(100vw - 32px));
  overflow-x: auto;
  scrollbar-width: none;
  background: rgba(6, 8, 11, 0.86);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  backdrop-filter: blur(14px);
  box-shadow: var(--sh-md);
}

.day-strip::-webkit-scrollbar { display: none; }

.day-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--paper-dim);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out);
}

.day-chip:hover { color: var(--paper); }

.day-chip.active {
  background: var(--ember);
  color: var(--ink-900);
}

.day-chip-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: rgba(242, 239, 232, 0.14);
  font-size: 0.66rem;
}

.day-chip.active .day-chip-count {
  background: rgba(6, 8, 11, 0.24);
}

/* ---- The panel ---------------------------------------------------------- */

.plan-panel {
  position: fixed;
  z-index: 8;
  top: var(--header-h);
  right: 0;
  bottom: 0;
  width: min(420px, 92vw);
  display: flex;
  background: rgba(6, 8, 11, 0.94);
  border-left: 1px solid var(--hairline);
  backdrop-filter: blur(18px);
  transition: transform 0.4s var(--ease-out);
}

.plan-panel.collapsed {
  transform: translateX(calc(100% - 26px));
}

.panel-grip {
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-right: 1px solid var(--hairline-soft);
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.panel-grip-bar {
  width: 3px;
  height: 46px;
  border-radius: var(--r-pill);
  background: var(--paper-faint);
  transition: background 0.2s var(--ease-out);
}

.panel-grip:hover .panel-grip-bar { background: var(--ember); }

.plan-panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 20px 32px;
}

.panel-view { display: block; }
.panel-view[hidden] { display: none; }

.panel-head { margin-bottom: 18px; }

.panel-back {
  margin-bottom: 14px;
  padding-left: 0;
  font-size: 0.72rem;
}

.panel-title {
  margin: 8px 0 6px;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2rem);
  line-height: 1.05;
  color: var(--paper);
}

.panel-sub {
  margin: 0 0 4px;
  color: var(--paper-dim);
  font-size: 0.86rem;
  line-height: 1.55;
}

.panel-cta {
  width: 100%;
  margin-bottom: 10px;
  text-align: center;
}

.plan-title-input {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin-bottom: 8px;
}

.plan-summary-input {
  min-height: 62px;
  margin-bottom: 8px;
}

.plan-meta {
  margin: 10px 0 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--paper-faint);
}

/* ---- The list of itineraries on a map ----------------------------------- */

.itinerary-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.itinerary-card {
  display: block;
  width: 100%;
  padding: 15px 16px;
  text-align: left;
  background: var(--ink-700);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  color: var(--paper);
  cursor: pointer;
  transition: border-color 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}

.itinerary-card:hover {
  border-color: var(--ember);
  transform: translateY(-1px);
}

.itinerary-card-badge {
  display: inline-block;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ember);
}

.itinerary-card-title {
  margin: 0 0 5px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  line-height: 1.15;
}

.itinerary-card-sub {
  margin: 0 0 8px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--paper-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.itinerary-card-meta {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: var(--paper-faint);
}

.itinerary-empty,
.tray-empty,
.stop-empty {
  padding: 16px;
  border: 1px dashed var(--hairline);
  border-radius: var(--r-lg);
  color: var(--paper-faint);
  font-size: 0.84rem;
  line-height: 1.55;
}

.itinerary-empty-title {
  margin: 0 0 6px;
  color: var(--paper);
  font-weight: 500;
}

/* ---- Days and stops ----------------------------------------------------- */

.plan-days { display: grid; gap: 16px; }

.plan-day {
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-lg);
  padding: 12px;
  transition: border-color 0.25s var(--ease-out);
}

.plan-day.active {
  border-color: var(--hairline);
  background: rgba(242, 239, 232, 0.02);
}

.plan-day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.plan-day-name {
  padding: 0;
  border: 0;
  background: none;
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 1.1rem;
  cursor: pointer;
}

.plan-day.active .plan-day-name { color: var(--ember); }

.plan-day-meta {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--paper-faint);
}

.stop-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  min-height: 42px;
  border-radius: var(--r-sm);
  transition: background 0.15s var(--ease-out);
}

.stop-list.drop-target {
  background: rgba(232, 98, 44, 0.09);
  outline: 1px dashed var(--ember);
  outline-offset: 3px;
}

.stop-row {
  display: flex;
  gap: 10px;
  padding: 10px;
  background: var(--ink-700);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-sm);
  cursor: grab;
}

.stop-row.dragging { opacity: 0.4; }

.stop-lead {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stop-number {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: var(--r-pill);
  background: var(--ember);
  color: var(--ink-900);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
}

.stop-icon { font-size: 0.95rem; }

.stop-body { flex: 1 1 auto; min-width: 0; }

.stop-title {
  margin: 0;
  color: var(--paper);
  font-size: 0.92rem;
  line-height: 1.3;
}

.stop-title-missing { color: var(--signal-bad); }

.stop-category {
  margin: 2px 0 0;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--paper-faint);
}

.stop-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.stop-controls .form-input {
  min-width: 0;
  padding: 6px 8px;
  font-size: 0.76rem;
}

/* The three fields want different room, and giving them one flex basis made
   the day picker as wide as the duration it sits next to. Time is fixed —
   "09:30" is always the same width — and the two selects share what is left,
   the duration taking more because its labels are words. */
.stop-time {
  flex: 0 0 auto;
  width: 6.5em;
}

.stop-duration {
  flex: 2 1 92px;
}

.stop-day {
  flex: 1 1 68px;
}

.stop-note {
  margin-top: 6px;
  padding: 6px 8px !important;
  font-size: 0.78rem !important;
}

.stop-readonly-meta {
  margin: 6px 0 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--glacier);
}

.stop-readonly-note {
  margin: 5px 0 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--paper-dim);
}

.stop-actions {
  display: flex;
  gap: 5px;
  margin-top: 8px;
}

.stop-btn {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--paper-dim);
  font-size: 0.76rem;
  cursor: pointer;
  transition: border-color 0.2s var(--ease-out), color 0.2s var(--ease-out);
}

.stop-btn:hover:not(:disabled) {
  border-color: var(--ember);
  color: var(--paper);
}

.stop-btn:disabled { opacity: 0.28; cursor: default; }
.stop-btn.danger:hover { border-color: var(--signal-bad); color: var(--signal-bad); }

/* ---- Panel actions ------------------------------------------------------ */

.plan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline-soft);
}

.plan-actions .btn-primary,
.plan-actions .btn-ghost {
  flex: 1 1 auto;
  text-align: center;
}

.plan-actions .danger { color: var(--signal-bad); }

.plan-status {
  margin: 12px 0 0;
  min-height: 1.2em;
  font-size: 0.8rem;
  color: var(--paper-dim);
}

.plan-status[data-kind="bad"] { color: var(--signal-bad); }

/* ---- The tray of pins --------------------------------------------------- */

.pin-tray {
  position: fixed;
  z-index: 9;
  right: calc(min(420px, 92vw) + 14px);
  bottom: 22px;
  width: min(340px, 92vw);
  max-height: min(62vh, 560px);
  display: flex;
  flex-direction: column;
  padding: 16px;
  background: rgba(6, 8, 11, 0.96);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  backdrop-filter: blur(18px);
  box-shadow: var(--sh-lg);
}

.pin-tray[hidden] { display: none; }

.tray-title {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--paper);
}

.tray-search { margin: 12px 0; }

.tray-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 5px;
}

.tray-item.used { opacity: 0.55; }

.tray-add {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  text-align: left;
  background: transparent;
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-sm);
  color: var(--paper);
  cursor: pointer;
  transition: border-color 0.2s var(--ease-out), background 0.2s var(--ease-out);
}

.tray-add:hover {
  border-color: var(--ember);
  background: rgba(232, 98, 44, 0.07);
}

.tray-icon { font-size: 1rem; }
.tray-text { flex: 1 1 auto; min-width: 0; display: grid; gap: 2px; }

.tray-name {
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tray-cat {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--paper-faint);
}

.tray-plus { color: var(--ember); font-size: 1rem; }

/* ---- Route markers ------------------------------------------------------ */

.route-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-pill);
  background: var(--ember);
  border: 2px solid var(--ink-900);
  box-shadow: var(--sh-md);
  cursor: pointer;
}

.route-marker-number {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-900);
}

.route-marker-icon {
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 0.78rem;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.8));
}

/* ---- Phones ------------------------------------------------------------- */

@media (max-width: 860px) {
  .plan-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 62vh;
    flex-direction: column;
    border-left: 0;
    border-top: 1px solid var(--hairline);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    transition: transform 0.4s var(--ease-out);
  }

  /* Collapsed leaves the grip standing proud of the bottom edge, so the map
     is whole again and the way back is still visible. */
  .plan-panel.collapsed {
    transform: translateY(calc(100% - 30px));
  }

  .panel-grip {
    flex: 0 0 30px;
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--hairline-soft);
  }

  .panel-grip-bar {
    width: 46px;
    height: 3px;
  }

  .pin-tray {
    right: 12px;
    left: 12px;
    bottom: calc(62vh + 12px);
    width: auto;
    max-height: 40vh;
  }

  .day-strip {
    top: calc(var(--header-h) + 8px);
  }
}
