/* 60_changes.css - KP Equipment slice 2: move mode, History, drawer actions, the Changes menu. Tokens only (01_tokens). */

.tool-btn-primary { background: var(--brand-solid); border-color: var(--brand-solid); color: var(--on-brand); font-weight: 600; }
.tool-btn-primary:hover, .tool-btn-primary:active { background: var(--brand-solid-hover); border-color: var(--brand-solid-hover); }
.tool-btn:disabled { opacity: .55; cursor: default; }
.tool-btn:focus-visible, .menu-item:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---- Changes (N) ---- */
.changes { position: relative; }
.changes-btn { white-space: nowrap; font-variant-numeric: tabular-nums; }
.changes-btn.has-changes { border-color: var(--warning); background: var(--warning-bg); color: var(--warning-fg); }
/* F9b: the menu now holds a list, so it is 340 px wide (the width 37_sync_ui gives it when signed in) and scrolls
   inside itself instead of running off the bottom of the screen. */
.changes-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; box-sizing: border-box; width: 340px; max-height: calc(100vh - 140px); max-height: calc(100dvh - 140px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: var(--sp-2); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-lg); }
.changes-menu[hidden] { display: none; }
.changes-note { margin: var(--sp-1) var(--sp-2) var(--sp-2); color: var(--ink-soft); font-size: 13px; line-height: 1.4; }
.menu-item { display: block; width: 100%; min-height: 44px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink); font: inherit; font-size: 15px; font-weight: 500; text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--surface-alt); }
.menu-item:disabled { color: var(--ink-muted); cursor: default; background: transparent; }

/* ---- Changes list (F9b): what changed, when, who, and whether it is saved. Classes come from 60_changes.js.
   The state is always written as a word ("Saved", "Not saved yet", "Refused", "Discarded"); the mark in front of the
   word and the colour only back it up. Rows are text, not buttons. The newest change is first. ---- */
.changes-list { margin-bottom: var(--sp-2); padding-bottom: var(--sp-2); border-bottom: 1px solid var(--line); }
.changes-rows { list-style: none; max-height: min(336px, 40vh); margin: 0 0 var(--sp-2); padding: 0; overflow-y: auto; scrollbar-width: thin; border: 1px solid var(--line); border-radius: var(--r-sm); }
.changes-rows:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
/* FIX-R1 (blocker 7): what sits under the list must stay in reach (the buttons, and "Discarded on this device" with Restore).
   1. The list does not hold on to the wheel or the finger any more (no overscroll-behavior on .changes-rows): at the end
      of the list the scroll passes on to the menu. The menu keeps its own "contain", so the page behind still stays put.
   2. A list of three rows or more gives way before the menu overflows: it shrinks, down to about two rows, so the rest
      of the menu stays on screen. The menu itself scrolls only when even that is not enough. A list of one or two rows,
      a hidden menu or list, print, and a browser without :has() all keep the plain block layout, untouched.
   A flex box does not fold two touching margins into one the way the block layout does, so the smaller margin of each
   touching pair is taken out (the last three rules). With that, nothing else in the menu moves. */
@media screen {
  @supports selector(:has(*)) {
    .changes-menu:not([hidden]):has(> .changes-list:not([hidden]) > .changes-rows > :nth-child(3)) { display: flex; flex-direction: column; }
    :where(.changes-menu:has(> .changes-list:not([hidden]) > .changes-rows > :nth-child(3))) > * { flex: none; }
    .changes-menu > .changes-list:not([hidden]):has(> .changes-rows > :nth-child(3)) { display: flex; flex-direction: column; flex: 0 1 auto; min-height: min(168px, calc(36vh + 32px)); }
    :where(.changes-menu > .changes-list:not([hidden]):has(> .changes-rows > :nth-child(3))) > * { flex: none; }
    .changes-menu > .changes-list:not([hidden]):has(> .changes-rows > :nth-child(3)) > .changes-rows { flex: 0 1 auto; min-height: 0; }
    .changes-menu > .changes-list:not([hidden]):has(> .changes-rows > :nth-child(3)) > .changes-rows + .note { margin-top: 0; }
    .changes-menu > .changes-list:not([hidden]):has(> .changes-rows > :nth-child(3)) + .changes-note { margin-top: 0; }
    .changes-menu:has(> .changes-list:not([hidden]) > .changes-rows > :nth-child(3)) > .menu-note:not([hidden]) + .dft-discarded-host { margin-top: 0; }
  }
}
.changes-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 3px var(--sp-2); padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 13px; line-height: 1.4; }
.changes-row:first-child { border-top: 0; }
.changes-what { grid-column: 1 / 3; grid-row: 1; min-width: 0; color: var(--ink); font-size: 15px; font-weight: 500; line-height: 1.35; overflow-wrap: anywhere; }
.changes-when { grid-column: 1; grid-row: 2; white-space: nowrap; font-variant-numeric: tabular-nums; }
.changes-who { grid-column: 2 / 4; grid-row: 2; min-width: 0; padding-left: var(--sp-2); border-left: 1px solid var(--line); overflow-wrap: anywhere; }
.changes-who:empty { display: none; }
.changes-when:empty { display: none; }
.changes-when:empty ~ .changes-who { grid-column: 1 / 4; padding-left: 0; border-left: 0; }
.changes-state { grid-column: 3; grid-row: 1; display: inline-flex; align-items: center; gap: 6px; margin-top: 1px; padding: 1px var(--sp-2); border: 1px solid transparent; border-radius: var(--r-pill); color: var(--ink-soft); font-size: 13px; font-weight: 600; line-height: 18px; white-space: nowrap; }
.changes-state::before { content: ""; flex: none; box-sizing: border-box; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
/* saved: quiet, a tick and the word, no box */
.changes-row.is-saved .changes-state::before { width: 6px; height: 10px; margin: -3px 3px 0 1px; border: solid var(--success-fg); border-width: 0 2px 2px 0; border-radius: 0; background: none; transform: rotate(45deg); }
/* not saved yet: the one state that asks for something, so it carries the box and the edge mark */
.changes-row.is-pending { box-shadow: inset 3px 0 0 var(--warning); }
.changes-row.is-pending .changes-state { border-color: var(--warning); background: var(--warning-bg); color: var(--ink); }
.changes-row.is-pending .changes-state::before { border: 2px solid var(--warning-fg); background: none; }
/* refused */
.changes-row.is-refused { box-shadow: inset 3px 0 0 var(--danger); }
.changes-row.is-refused .changes-state { border-color: var(--danger); background: var(--danger-bg); color: var(--danger-fg); }
.changes-row.is-refused .changes-state::before { border-radius: 1px; transform: rotate(45deg); }
/* discarded: still readable, stepped back */
.changes-row.is-discarded .changes-what { color: var(--ink-soft); font-weight: 400; }
.changes-row.is-discarded .changes-state { border-color: var(--ink-muted); }
.changes-row.is-discarded .changes-state::before { height: 2px; border-radius: 1px; }
.changes-list .note { margin: var(--sp-1) var(--sp-2) 0; color: var(--ink-soft); font-size: 13px; line-height: 1.4; }

/* ---- drawer: History + actions ---- */
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; flex-direction: column; gap: 2px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 15px; line-height: 1.35; }
.history li.is-import { color: var(--ink-soft); }
.history li.is-move { font-weight: 600; }
.history .history-sub { color: var(--ink-muted); font-size: 13px; font-weight: 400; }
.drawer-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-2) var(--sp-3); margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--line); }
.drawer-actions .note { flex-basis: 100%; margin: 0; color: var(--ink-muted); font-size: 14px; }
.drawer-actions .area-pick { display: flex; flex-direction: column; gap: 4px; flex: 1 1 180px; min-width: 0; }
.drawer-actions .area-pick .select { max-width: none; width: 100%; min-height: 44px; }

/* ---- move mode ---- */
.movebar { position: absolute; left: 50%; bottom: var(--sp-4); transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: var(--sp-2) var(--sp-4); width: max-content; max-width: calc(100% - 2 * var(--sp-3)); padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: var(--r); box-shadow: var(--shadow-lg); }
.movebar[hidden] { display: none; }
.movebar.is-outside { border-left-color: var(--danger); }
.movebar-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; margin: 0; font-size: 15px; line-height: 1.3; }
/* D372: the coloured area phrase stays whole. As one piece it drops to the next line instead of breaking inside itself; only a name longer than a full line wraps, inside the bar (max-width), so nothing is cut off and the bar never grows wider than the screen. */
.movebar-area { display: inline-block; max-width: 100%; overflow-wrap: anywhere; color: var(--brand); }
.movebar.is-outside .movebar-area { color: var(--danger-fg); }
.movebar-hint { color: var(--ink-muted); font-size: 13px; }
.movebar-btns { display: flex; gap: var(--sp-2); flex: 0 0 auto; }
body.is-moving .hint { display: none; }
.machine.is-moving > .hit { fill: var(--brand); fill-opacity: .16; stroke: var(--brand); stroke-width: .14; stroke-dasharray: .45 .3; }
.plan-svg.is-dragging { cursor: grabbing; }

@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .movebar { left: var(--sp-2); right: var(--sp-2); bottom: calc(var(--sp-2) + env(safe-area-inset-bottom)); transform: none; width: auto; max-width: none; flex-wrap: wrap; padding: var(--sp-2) var(--sp-3); }
  .movebar-btns { flex: 1 1 100%; }
  .movebar-btns .tool-btn { flex: 1 1 0; }
  /* 30_plan makes the menu a sheet along the bottom of a phone; it keeps to 84 % of the screen height and scrolls */
  .changes-menu { left: 0; right: auto; width: min(340px, calc(100vw - 2 * var(--sp-3))); max-height: 84vh; max-height: 84dvh; }
  .changes-rows { max-height: min(300px, 36vh); }
}
