/* A tool page as one window (docs/plans/threat-model-prototype.md, K1 to K8;
   the Tools canvas's artboards 13 to 21, docs/design/tool_window.py). What
   this sheet keys, and on what:
   - the column, the shell's boxes above it and the tool's boxes in it, on
     `.aucra-content-window`, the class `layout.content` gives a tool page
     alone, so no other page matches them;
   - the fixed height ones under `:has()` as well, and a window 480 px tall
     or more: a browser without `:has()`, or a window under 480 px (200
     percent zoom, a phone on its side), keeps the scrolling page of
     pages_tools.css with its old clamps (WCAG 1.4.10, B10);
   - the compact head, the picker and the details panel's own controls, on
     their own `aucra-tool-*` classes, which only a tool page draws.
   Every colour is a brand.css token. */

/* ---- K1: the column: no measure, 16 px above and below, 20 at the sides ---- */
.aucra-content.aucra-content-window {
  max-width: none;
  padding: 16px 20px;
}
.nicegui-content:has(.aucra-content-window) {
  padding: 0;
}

/* ---- K2: what the assistant covers when it is open over the tool ---- */
body:has(.aucra-content-window) {
  --aucra-drawer: 0px;
}
@media (min-width: 768px) {
  body:has(.aucra-content-window):has(.aucra-ai-tab-open) {
    --aucra-drawer: min(340px, 100vw);
  }
}
@media (min-width: 1280px) {
  body:has(.aucra-content-window):has(.aucra-ai-tab-open) {
    --aucra-drawer: 400px;
  }
}
.aucra-content-window {
  /* The drawer's width less the column's own right padding. */
  --aucra-covered: max(0px, calc(var(--aucra-drawer, 0px) - 20px));
}

@media (min-height: 480px) {
  .q-page:has(.aucra-content-window) {
    height: calc(100vh - 56px);
    height: calc(100dvh - 56px);
    min-height: 0 !important;
    overflow: hidden;
  }
  .nicegui-content:has(.aucra-content-window) {
    height: 100%;
    flex-wrap: nowrap;
  }
  .aucra-region:has(.aucra-content-window),
  .aucra-subpages:has(.aucra-content-window) {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .aucra-content-window {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    flex-wrap: nowrap;
  }
  .aucra-content-window > .aucra-tool,
  .aucra-content-window .aucra-tool-body-slot,
  .aucra-content-window .aucra-tool-card {
    flex: 1 1 auto;
    min-height: 0;
  }
  .aucra-content-window .aucra-tool-main .aucra-canvas {
    flex: 1 1 auto;
    min-height: 0;
  }
  /* Under `:has()` too, so a browser without it keeps the old clamp (V7). */
  .q-page:has(.aucra-content-window) .aucra-tool-main .aucra-canvas-svg {
    height: 100%;
  }
  /* K4: the empty state scrolls on its own, its body centred by margins so
     an overflow is never cut at the top. */
  .aucra-content-window .aucra-tool-empty {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    align-items: flex-start;
    justify-content: flex-start;
  }
  .aucra-content-window .aucra-tool-empty-body {
    margin: auto;
  }
}
/* Below the floor the page scrolls and the canvas keeps its 480 px least. */
@media (max-height: 479px) {
  .aucra-content-window .aucra-tool-main .aucra-canvas-svg {
    height: clamp(480px, calc(100vh - 160px), 900px);
  }
}

/* ---- the tool's boxes ---- */
.aucra-content-window > .aucra-tool {
  display: flex;
  flex-direction: column;
  /* A NiceGUI column starts its children; the card takes the whole width. */
  align-items: stretch;
  gap: 12px;
}
.aucra-content-window .aucra-tool-body-slot {
  width: 100%;
}
.aucra-content-window .aucra-tool-body-slot,
.aucra-content-window .aucra-tool-card,
.aucra-content-window .aucra-tool-main {
  display: flex;
  flex-direction: column;
}
.aucra-content-window .aucra-tool-card {
  scroll-margin-top: 0;
}
.aucra-content-window .aucra-tool-body {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}
.aucra-content-window .aucra-tool-main {
  flex: 1 1 auto;
  min-width: 0;
  /* K5: the canvas takes the room the panel leaves once its slide ends. */
  transition: margin-right 0s linear 200ms;
}
.aucra-content-window .aucra-tool-status {
  flex: 0 0 auto;
  padding-right: calc(14px + var(--aucra-covered));
}
@container aucra-tool (max-width: 639px) {
  /* K4: two lines kept, so the canvas does not jump on each selection. */
  .aucra-content-window .aucra-tool-status {
    min-height: 54px;
  }
}

/* ---- K3: the compact head ---- */
.aucra-tool-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  flex: 0 0 auto;
  padding-right: var(--aucra-covered, 0px);
}
.aucra-tool-head .aucra-title {
  font-size: 22px;
  line-height: 1.2;
  white-space: nowrap;
}
.aucra-tool-rev {
  font-size: 13px;
  color: var(--muted);
}
.aucra-tool-strip,
.aucra-tool-picker {
  position: relative;
  display: inline-flex;
  max-width: 100%;
  min-width: 0;
}
.q-btn.aucra-tool-picker-button {
  height: 32px;
  min-height: 32px;
  max-width: 100%;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 400;
}
.q-btn.aucra-tool-picker-button[aria-expanded="true"] {
  background: var(--mist);
  border-color: var(--gold-deep);
}
.aucra-tool-picker .q-btn .q-btn__content {
  gap: 8px;
  flex-wrap: nowrap;
  min-width: 0;
}
.aucra-tool-picker-id {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11.5px;
  color: var(--muted);
}
.aucra-tool-picker-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aucra-tool-picker-button .aucra-tool-picker-name {
  font-weight: 600;
  max-width: 28em;
}
.aucra-tool-picker-chevron {
  font-size: 16px;
  color: var(--muted);
}
.aucra-tool-picker-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 6;
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 140px);
  overflow-y: auto;
  box-sizing: border-box;
  padding: 4px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(28, 33, 38, 0.18);
}
.aucra-tool-picker-head {
  padding: 8px 12px 4px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.aucra-tool-picker-line {
  padding: 6px 12px 8px;
}
.aucra-tool-picker-rule {
  height: 1px;
  margin: 4px 0;
  background: var(--line);
}
.aucra-tool-picker .q-btn.aucra-tool-picker-radio,
.aucra-tool-picker-actions .q-btn {
  display: flex;
  width: 100%;
  min-height: 34px;
  height: auto;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
  justify-content: flex-start;
}
.aucra-tool-picker .q-btn.aucra-tool-picker-radio .q-btn__content,
.aucra-tool-picker-actions .q-btn .q-btn__content {
  justify-content: flex-start;
  text-align: left;
  width: 100%;
}
.aucra-tool-picker .q-btn.aucra-tool-picker-on {
  background: var(--gold-wash);
}
.aucra-tool-picker-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  margin-left: 0;
}
.aucra-tool-picker-actions > * {
  width: 100%;
}
/* A question asked in the picker (Make primary, Remove diagram) and its two
   answers line up with the other actions, one row each, no gap (R9). */
.aucra-tool-picker-actions .aucra-confirm-row {
  gap: 0;
}
.aucra-tool-picker-actions .aucra-confirm-question {
  padding: 6px 12px 4px;
}
.aucra-tool-picker-actions .q-btn.aucra-confirm-keep {
  height: auto;
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}
.aucra-tool-picker .aucra-tool-starters-panel {
  margin: 4px 12px 8px;
  max-height: 320px;
  overflow-y: auto;
  /* The starters' columns follow the panel's own width, not the tool's (R1). */
  container: aucra-starters / inline-size;
}
@container aucra-starters (max-width: 639px) {
  .aucra-tool-starter-list {
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
  }
  .aucra-tool-starter-fits {
    margin-bottom: 8px;
  }
}

/* ---- K3, B9: the one line toolbar of icons ---- */
.aucra-content-window .aucra-tool-bar {
  flex: 0 0 auto;
  /* 6 px between the groups keeps a three digit Checks count on the line at 1440 (W3). */
  gap: 6px;
  padding: 8px 10px;
  padding-right: calc(10px + var(--aucra-covered));
}
.aucra-content-window .aucra-tool-bar-group {
  gap: 3px;
}
/* Details keeps its words at the line's end at every width (B18). */
.aucra-content-window .aucra-tool-end {
  display: flex;
  align-items: center;
  margin-left: auto;
  gap: 4px;
}
/* A worded button takes 7 px at its sides, the mockup's, and the end's own
   margin pushes it right with no spacer's gap, so the line keeps Checks with
   its count and Details at 1440 (W3). */
.aucra-content-window .aucra-tool-bar > .aucra-tool-spacer {
  display: none;
}
.aucra-content-window .aucra-tool-adds .q-btn,
.aucra-content-window .aucra-tool-end .q-btn {
  padding-left: 7px;
  padding-right: 7px;
}
.aucra-content-window .aucra-tool-bar .aucra-tool-adds .q-icon.on-left {
  display: none;
}
.aucra-content-window .aucra-tool-views .q-btn,
.aucra-content-window .aucra-tool-edits .q-btn,
.aucra-content-window .aucra-tool-removal > :not(.aucra-confirm-asking) .q-btn {
  width: 28px;
  min-width: 28px;
  padding: 0;
}
.aucra-content-window .aucra-tool-views .q-btn .q-icon,
.aucra-content-window .aucra-tool-edits .q-btn .q-icon,
.aucra-content-window .aucra-tool-removal > :not(.aucra-confirm-asking) .q-btn .q-icon {
  margin-right: 0;
}
/* On: the Details toggle open and the panel's pin, one look (K7, K23). */
.aucra-content-window .aucra-tool-bar .q-btn.aucra-pressed,
.aucra-content-window .aucra-tool-side-controls .q-btn.aucra-pressed {
  background: var(--mist);
  border-color: var(--gold-deep);
}
@media (max-width: 1279px) {
  .aucra-content-window .aucra-tool-bar .q-icon.aucra-tool-shape {
    display: inline-flex;
    margin-right: 0;
  }
  .aucra-content-window .aucra-tool-adds .q-btn {
    width: 28px;
    min-width: 28px;
    padding: 0;
  }
}
@layer base {
  .aucra-content-window .aucra-tool-views .q-btn .block,
  .aucra-content-window .aucra-tool-edits .q-btn .block,
  .aucra-content-window .aucra-tool-removal > :not(.aucra-confirm-asking) .q-btn .block {
    display: none !important;
  }
  @media (max-width: 1279px) {
    .aucra-content-window .aucra-tool-adds .q-btn .block {
      display: none !important;
    }
  }
}
/* While the removal asks, Details stays at the line's end (B18). */
.aucra-content-window .aucra-tool-bar:has(.aucra-confirm-open) > .aucra-tool-end {
  display: flex;
}
.aucra-content-window .aucra-tool-bar > .aucra-tool-removal.aucra-confirm-open {
  flex: 1 1 auto;
}

/* ---- K6 to K8: the details panel ---- */
.aucra-content-window .aucra-tool-side {
  position: absolute;
  top: 0;
  bottom: 0;
  right: var(--aucra-covered);
  z-index: 3;
  width: 340px;
  max-width: 100%;
  box-sizing: border-box;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  border: 0;
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(28, 33, 38, 0.1);
  transform: translateX(calc(100% + var(--aucra-covered)));
  visibility: hidden;
  transition: transform 200ms ease, visibility 0s linear 200ms;
}
.aucra-content-window .aucra-tool-side.aucra-tool-side-open {
  transform: none;
  visibility: visible;
  transition: transform 200ms ease, visibility 0s;
}
.aucra-tool-side-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  display: flex;
  gap: 6px;
}
.aucra-content-window .aucra-tool-side .aucra-tool-panel-head {
  padding-right: 112px;
}
.q-btn.aucra-tool-side-close {
  display: none;
}
/* The pin lies tilted while off and stands upright while on (U41, K23). */
.q-btn.aucra-tool-pin .q-icon {
  transform: rotate(45deg);
}
.q-btn.aucra-tool-pin.aucra-pressed .q-icon {
  transform: none;
}
@container aucra-tool (min-width: 960px) {
  /* Beside the canvas, which narrows once the slide ends (K5). */
  .aucra-content-window .aucra-tool-body:has(> .aucra-tool-side-open) > .aucra-tool-main {
    margin-right: 340px;
  }
  .aucra-content-window .aucra-tool-side {
    box-shadow: none;
  }
}
/* Over the canvas's right side, below 960 px or beside the assistant: the
   status line keeps clear of it (B6). */
@container aucra-tool (max-width: 959px) {
  .aucra-content-window .aucra-tool-body:has(> .aucra-tool-side-open) .aucra-tool-status {
    padding-right: calc(14px + var(--aucra-covered) + 340px);
  }
}
body:has(.aucra-ai-tab-open) .aucra-content-window .aucra-tool-body > .aucra-tool-main {
  margin-right: 0;
}
body:has(.aucra-ai-tab-open) .aucra-content-window .aucra-tool-body:has(> .aucra-tool-side-open) .aucra-tool-status {
  padding-right: calc(14px + var(--aucra-covered) + 340px);
}
/* Below 640 px: a modal dialog over the whole working area (K8, B4). */
@media (max-width: 639px) {
  .aucra-content-window .aucra-tool-side {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    /* Over the assistant's tab (1500), under its open drawer (3000). */
    z-index: 1600;
    width: auto;
    border-left: 0;
    padding-top: 52px;
    transform: translateX(100%);
  }
  .aucra-content-window .aucra-tool-side .aucra-tool-panel-head {
    padding-right: 0;
  }
  .q-btn.aucra-tool-pin {
    display: none;
  }
  .q-btn.aucra-tool-side-close {
    display: inline-flex;
  }
}
