/* Itinerary view (js/itinerary.js). Colors only through css/tokens.css, so light
   and dark both follow the theme button. */

/* Several blocks here set display, which would beat the hidden attribute. */
.itinerary [hidden], .it-toast[hidden], .it-placebar[hidden] { display: none !important; }

.tabs { display: flex; gap: var(--space-1); margin-right: auto; }
.tab {
  border: 1px solid transparent; background: none; color: var(--color-text-muted);
  font: inherit; font-size: var(--fs-sm); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm); cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--color-header-text); border-color: var(--color-border); font-weight: 600; }
.tab:focus-visible, .it-button:focus-visible, .it-chip:focus-visible, .it-day-head:focus-visible,
.it-status:focus-visible, .it-paid:focus-visible, .it-x:focus-visible { outline: 2px solid var(--color-link); outline-offset: 2px; }

body[data-tab="itinerary"] #app { max-width: none; padding-bottom: var(--space-5); }

.itinerary {
  display: grid;
  grid-template-columns: minmax(300px, 1.1fr) minmax(320px, 1fr);
  gap: var(--space-4);
  align-items: start;
}
.it-days, .it-side {
  position: sticky; top: calc(var(--header-height) + var(--space-2));
  max-height: calc(100vh - var(--header-height) - var(--space-5));
  overflow-y: auto;
}

/* ---------- dates ---------- */
.it-day {
  border-bottom: 1px dashed var(--color-border);
  padding: var(--space-2) var(--space-1);
  border-radius: var(--radius-sm);
}
.it-day.is-over, .it-pool.is-over { background: var(--status-candidate-bg); outline: 2px dashed var(--status-candidate); }
.it-day.is-target .it-day-head { cursor: copy; }
.it-day.is-selected { background: var(--color-bg-elevated); box-shadow: var(--shadow-sm); }
.it-day-head {
  display: flex; align-items: baseline; gap: var(--space-2); width: 100%;
  background: none; border: 0; padding: var(--space-1) 0; color: var(--color-text);
  font: inherit; text-align: left; cursor: pointer; min-height: 2.25rem;
}
.it-day-date { font-weight: 700; font-size: var(--fs-md); }
.it-day-weekday { color: var(--color-text-muted); font-size: var(--fs-sm); }
.it-day-city {
  font-size: var(--fs-sm); color: var(--color-text); background: var(--color-bg-elevated);
  border: 1px solid var(--color-border); border-radius: 999px; padding: 0 var(--space-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.it-day-city.is-empty { color: var(--color-text-muted); font-style: italic; border-style: dashed; }
.it-link {
  background: none; border: 0; padding: 0; font: inherit; color: var(--color-link);
  text-decoration: underline; cursor: pointer;
}
.it-day-alert { margin-left: auto; color: var(--status-out); font-size: var(--fs-sm); font-weight: 600; }
.it-warnings { margin: 0 0 var(--space-2); padding-left: var(--space-5); color: var(--status-out); font-size: var(--fs-sm); }
.it-day-cards { display: flex; flex-direction: column; gap: var(--space-2); min-height: 0.5rem; }
.it-lodging {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2);
  margin-top: var(--space-2); font-size: var(--fs-sm); color: var(--color-text-muted);
}
.it-lodging-label { font-weight: 600; }
.it-lodging-empty { font-style: italic; }
.it-lodging-cont { border: 1px dashed var(--kind-lodging); background: var(--kind-lodging-bg); border-radius: var(--radius-sm); padding: 0 var(--space-2); }
.it-lodging .it-card { flex: 1 1 100%; }

/* ---------- side: toolbar, pool, map ---------- */
.it-toolbar { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-2); }
.it-search {
  width: 100%; padding: var(--space-2) var(--space-3); font: inherit;
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-bg-elevated); color: var(--color-text);
}
.it-chips, .it-actions { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.it-chip, .it-button {
  border: 1px solid var(--color-border); background: var(--color-bg-elevated); color: var(--color-text);
  border-radius: 999px; padding: var(--space-1) var(--space-3); font: inherit; font-size: var(--fs-sm);
  cursor: pointer; min-height: 2rem;
}
.it-chip.is-on { background: var(--color-text); color: var(--color-bg); border-color: var(--color-text); }
.it-button:disabled { opacity: 0.5; cursor: default; }
.it-city {
  align-self: flex-start; font: inherit; font-size: var(--fs-sm); padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border); border-radius: 999px;
  background: var(--color-bg-elevated); color: var(--color-text); min-height: 2rem;
}
.it-new { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.it-new input, .it-new select {
  font: inherit; font-size: var(--fs-sm); padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-bg-elevated); color: var(--color-text);
}
.it-new input { flex: 1 1 12rem; }
/* Phone-only controls (see the media query at the end). */
.it-panebar, .it-placebar { display: none; }
/* Filters fold behind their button on every width (Élder 2026-11-15); the
   actions fold only on the phone, so its button shows only there. */
.it-fold-row { display: flex; gap: var(--space-2); }
.it-filters { display: flex; flex-direction: column; gap: var(--space-2); }
/* Filters and actions both fold behind their button on every width (Élder
   2026-11-15/16): the list beside the dates starts with only the search. */
.it-filters:not(.is-open), .it-actions:not(.is-open) { display: none; }
.it-placebar-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.it-count { margin: 0 0 var(--space-2); color: var(--color-text-muted); font-size: var(--fs-sm); }
.it-pool { display: flex; flex-direction: column; gap: var(--space-2); min-height: 8rem; border-radius: var(--radius-sm); }

.it-map svg { width: 100%; height: auto; display: block; }
.map-route, .map-point circle { vector-effect: non-scaling-stroke; }
.map-route { stroke: var(--color-text-muted); stroke-width: 1; opacity: 0.35; }
.map-route.is-highlight { stroke: var(--color-link); stroke-width: 2; opacity: 0.9; }
.map-point circle { fill: var(--color-text-muted); opacity: 0.45; }
.map-point.is-highlight circle { fill: var(--color-link); opacity: 1; stroke: var(--color-bg); stroke-width: 2; }
.map-point[data-region="Hokkaido"].is-highlight circle { fill: var(--mode-flight); }
.map-point[data-region="Kansai"].is-highlight circle { fill: var(--mode-ferry); }
.map-point-number {
  fill: var(--color-accent-contrast); font-size: 11px; font-weight: 700;
  text-anchor: middle; dominant-baseline: central; pointer-events: none;
}
.it-map-note { color: var(--color-text-muted); font-size: var(--fs-sm); }
.it-map-warning { color: var(--status-out); font-size: var(--fs-sm); }

/* ---------- cards ---------- */
/* Compact (Élder 2026-11-14): the card is as tall as the old 64px photo, two lines of content. */
.it-card {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: var(--space-2); align-items: center;
  background: var(--color-bg-elevated); border: 1px solid var(--color-border);
  border-left: 6px solid var(--kind-activity); border-radius: var(--radius-md);
  padding: var(--space-1); cursor: grab; box-shadow: var(--shadow-sm);
}
/* The edge tells the kind apart (Élder 2026-11-14); the status is the pill. */
.it-card.kind-transport { border-left-color: var(--kind-transport); background: var(--kind-transport-bg); }
.it-card.kind-lodging { border-left-color: var(--kind-lodging); background: var(--kind-lodging-bg); }
.it-card.state-rejected { opacity: 0.75; }
.it-kind { margin-right: var(--space-1); }
.it-card.is-paid { cursor: default; }
.it-card.is-sel { outline: 3px solid var(--status-candidate); }
.it-photo { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); background: var(--color-border); }
.it-body { min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.itinerary > * { min-width: 0; }
.it-line { display: flex; align-items: baseline; gap: var(--space-2); min-width: 0; white-space: nowrap; }
.it-line-2 { align-items: center; flex-wrap: wrap; white-space: normal; }
.it-name { font-weight: 600; line-height: 1.25; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.it-summary { font-size: var(--fs-sm); font-style: italic; flex: 0 10 auto; min-width: 3rem; overflow: hidden; text-overflow: ellipsis; }
.it-meta { color: var(--color-text-muted); font-size: var(--fs-sm); flex: 0 100 auto; min-width: 2rem; overflow: hidden; text-overflow: ellipsis; }
.it-card.is-sel .it-line { flex-wrap: wrap; white-space: normal; }
.it-card.is-sel .it-name, .it-card.is-sel .it-summary, .it-card.is-sel .it-meta { overflow-wrap: anywhere; }
.it-tags { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.it-status, .it-paid, .it-booking {
  font: inherit; font-size: 0.75rem; border-radius: 999px; padding: 0 var(--space-2);
  border: 1px solid transparent; min-height: 1.375rem; line-height: 1.6;
}
button.it-status, button.it-paid { cursor: pointer; }
.it-status.state-candidate { background: var(--status-fixed-bg); color: var(--status-fixed); }
.it-status.state-planned { background: var(--color-bg); color: var(--color-link); border-color: var(--color-link); }
.it-status.state-decided { background: var(--status-decided-bg); color: var(--status-decided); }
.it-status.state-rejected { background: var(--status-out-bg); color: var(--status-out); }
.it-paid { background: none; color: var(--color-text-muted); border-color: var(--color-border); }
.it-paid.is-on { background: var(--status-decided-bg); color: var(--status-decided); border-color: transparent; font-weight: 600; }
.it-booking { background: var(--status-candidate-bg); color: var(--status-candidate); }
.it-time { display: flex; align-items: center; gap: var(--space-2); font-size: 0.8125rem; }
.it-time-field, .it-nights {
  font: inherit; font-size: 0.8125rem; padding: 0 var(--space-1); height: 1.375rem;
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-bg); color: var(--color-text);
}
.it-nights { width: 4rem; }
.it-window { color: var(--color-text-muted); }
.it-time-fixed { font-weight: 600; font-size: var(--fs-sm); }
.it-about { margin: var(--space-1) 0 0; font-size: 0.875rem; line-height: 1.4; }
.it-caveat {
  margin: var(--space-1) 0 0; font-size: 0.8125rem; color: var(--color-text-muted);
  border-left: 2px solid var(--status-candidate); padding-left: var(--space-2);
}
.it-x {
  align-self: start; background: none; border: 0; color: var(--color-text-muted);
  font-size: 1.1rem; cursor: pointer; min-width: 1.75rem; min-height: 1.75rem; padding: 0; border-radius: var(--radius-sm);
}
.it-x:hover { background: var(--color-bg); }
.it-buttons { display: flex; flex-direction: column; align-items: center; }
.it-edit { font-size: 1rem; }

.it-toast {
  position: fixed; left: 50%; bottom: var(--space-5); transform: translateX(-50%);
  background: var(--color-text); color: var(--color-bg); padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md); z-index: 20; width: min(90vw, 34rem);
}

@media (max-width: 760px) {
  /* minmax(0, 1fr): a plain 1fr column grows to its longest unbreakable
     word, which pushed the cards past the phone's edge on real data. */
  .itinerary { grid-template-columns: minmax(0, 1fr); }
  .it-days, .it-side { position: static; max-height: none; overflow: visible; }

  /* One half at a time, switched by the bottom bar. */
  .itinerary[data-pane="days"] .it-side, .itinerary[data-pane="cards"] .it-days { display: none; }
  body[data-tab="itinerary"] #app { padding-bottom: calc(7rem + env(safe-area-inset-bottom, 0px)); }

  /* Filters and actions folded behind two buttons, so the cards start near the top. */
  .it-fold-btn:first-child { flex: 1 1 auto; }

  .it-panebar {
    display: grid; grid-template-columns: 1fr 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    background: var(--color-bg-elevated); border-top: 1px solid var(--color-border); box-shadow: var(--shadow-md);
    padding: var(--space-1) var(--space-3) calc(var(--space-1) + env(safe-area-inset-bottom, 0px));
  }
  .it-pane-btn {
    font: inherit; font-weight: 600; min-height: 3rem; border: 0; border-radius: var(--radius-sm);
    background: none; color: var(--color-text-muted); cursor: pointer;
  }
  .it-pane-btn[aria-pressed="true"] { color: var(--color-text); background: var(--color-bg); }
  .it-pane-btn:focus-visible { outline: 2px solid var(--color-link); outline-offset: -2px; }

  .it-placebar {
    display: flex; align-items: center; gap: var(--space-3); position: fixed; z-index: 15;
    left: var(--space-3); right: var(--space-3); bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
    background: var(--color-text); color: var(--color-bg); padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md); box-shadow: var(--shadow-md); font-size: var(--fs-sm);
  }
  .it-placebar .it-link { color: inherit; }
  .it-toast { bottom: calc(7.5rem + env(safe-area-inset-bottom, 0px)); }

  /* Date header: date and weekday on one line, the route on its own line. */
  .it-day-head { flex-wrap: wrap; row-gap: var(--space-1); }
  .it-day-date, .it-day-weekday { white-space: nowrap; }
  .it-day-alert { order: 1; }
  .it-day-city { order: 2; flex: 1 1 100%; }

  /* Smaller photo and tighter gaps so status, paid and time share the second line. */
  .it-card { grid-template-columns: 44px minmax(0, 1fr) auto; gap: var(--space-1); }
  .it-photo { width: 44px; height: 44px; }
  .it-line-2, .it-time { gap: var(--space-1); }
}

/* ---------- jump bar (one button per stay) and replacements ---------- */
.it-jump {
  position: sticky; top: 0; z-index: 2;
  display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: thin;
  padding: var(--space-2) 0; margin-bottom: var(--space-2);
  background: var(--color-bg); border-bottom: 1px solid var(--color-border);
}
.it-jump-btn {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start;
  border: 1px solid var(--color-border); background: var(--color-bg-elevated); color: var(--color-text);
  border-radius: var(--radius-sm); padding: var(--space-1) var(--space-2); font: inherit; cursor: pointer;
}
.it-jump-btn.is-on { border-color: var(--color-link); box-shadow: inset 0 0 0 1px var(--color-link); }
.it-jump-btn:focus-visible, .it-swap:focus-visible { outline: 2px solid var(--color-link); outline-offset: 2px; }
.it-jump-city { font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.it-jump-dates { font-size: var(--fs-xs, 0.75rem); color: var(--color-text-muted); white-space: nowrap; }
.it-day { scroll-margin-top: 4.5rem; }
.it-swap {
  border: 1px solid var(--color-link); background: var(--color-bg-elevated); color: var(--color-link);
  border-radius: 999px; padding: 0 var(--space-2); font: inherit; font-size: var(--fs-sm);
  cursor: pointer; white-space: nowrap; min-height: 1.75rem;
}

@media (max-width: 760px) {
  .it-jump { top: var(--header-height); }
  .it-day { scroll-margin-top: calc(var(--header-height) + 4.5rem); }
}
