.tool-workbench__vision-panel > .perspective-detection-details { flex: 0 0 100%; grid-column: 1 / -1; width: 100%; }
.perspective-detection-details { min-width: 0; font-size: 12px; line-height: 1.6; color: var(--ts-muted); }
.perspective-detection-details[hidden] { display: none; }
.perspective-detection-details summary { cursor: pointer; }
.perspective-detection-details p { margin: 6px 0 0; overflow-wrap: anywhere; }
.tool-detail[data-tstudio="v1"] .ic [data-ic-workspace][hidden], .tool-detail[data-tstudio="v1"] .ic [data-ic-welcome][hidden] { display: none !important; }

/* ---- Panel entry (v2): a button beside the tool's export, a popover on desktop, a bottom sheet on phones. ---- */
.tool-ai-trigger { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.tool-ai-spark { flex: none; width: 16px; height: 16px; fill: currentColor; }
.tool-ai-trigger .tool-ai-spark { color: var(--ts-accent); }
.tool-ai-trigger__dot { position: absolute; top: 6px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--ts-accent); box-shadow: 0 0 0 2px var(--ts-surface); }
.tool-ai-trigger[hidden], .tool-ai-trigger__dot[hidden], .tool-ai-empty[hidden], .tool-ai-panel [hidden] { display: none !important; }
.tool-ai-empty { display: grid; gap: 8px; margin-top: 10px; font-size: 12.5px; line-height: 1.5; }
.tool-ai-empty__link { color: var(--ts-accent-strong, var(--ts-accent)); font-weight: 600; text-decoration: none; }
.tool-ai-empty__link:hover { text-decoration: underline; text-underline-offset: 3px; }
.tool-ai-offer { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; margin: 0; padding: 8px 10px; border: 1px solid var(--ts-line-strong); border-radius: 10px; background: var(--ts-surface-2); color: var(--ts-ink); font-size: 12.5px; line-height: 1.5; }
.tool-ai-offer p { flex: 1 1 100%; margin: 0; }
.tool-ai-link, .tool-ai-more { min-height: 32px; padding: 4px 2px; border: 0; background: none; color: var(--ts-accent-strong, var(--ts-accent)); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.tool-ai-link:focus-visible, .tool-ai-more:focus-visible, .tool-ai-trigger:focus-visible, .tool-ai-empty__link:focus-visible { outline: 2px solid var(--ts-accent); outline-offset: 2px; }
/* Hosts: the trigger sits with each tool's export buttons and borrows their button class. */
.space-light-lab .sll-dock > .tool-ai-trigger { width: 100%; }
.palette-tool .pt-export > .tool-ai-trigger { width: 100%; margin-bottom: 8px; }
.material-segment .tool-control-strip--segment > .tool-ai-trigger { flex: 0 0 auto; min-height: 36px; }
body.tool-dense-ui .space-light-lab .sll-panel > .sll-dock > .tool-ai-trigger { min-height: 36px; }
.watermark-workbench .actions > .tool-ai-trigger { grid-column: 1 / -1; }
/* The compact shell lays these out as a 3-column grid; keep remove/download/start-over on one row and the AI entry below it. */
body.tool-dense-ui.tool-app-shell .watermark-workbench [data-tool-controls] .actions > .tool-ai-trigger { order: 1; height: 40px !important; min-height: 40px !important; font-size: 12.5px; }
/* Export row pinned to the bottom of the control area, so download and the AI entry never need a scroll to the end. */
body.tool-dense-ui.tool-app-shell .watermark-workbench [data-tool-controls] .actions { position: sticky; bottom: 0; z-index: 6; margin: 7px 0 0; padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--ts-line); background: var(--ts-surface-2); }
@media (max-width: 1023px) {
  body.tool-dense-ui .space-light-lab .sll-panel > .sll-dock { position: sticky; bottom: 0; z-index: 4; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--ts-line); }
  /* The export note is long; on a phone the pinned bar keeps only the actions. */
  body.tool-dense-ui .space-light-lab .sll-panel > .sll-dock > .sll-dock-note { display: none; }
  body.tool-dense-ui .space-light-lab .sll-panel > .sll-dock > .sll-export-more { grid-column: 1 / -1; }
}

.tool-ai-panel { position: fixed; inset: auto; margin: 0; padding: 0; width: min(380px, calc(100vw - 24px)); max-width: none; max-height: calc(100dvh - 24px); border: 1px solid var(--ts-line-strong); border-radius: 16px; background: var(--ts-surface); color: var(--ts-ink); box-shadow: 0 22px 48px -18px var(--ts-shadow), 0 4px 12px -6px var(--ts-shadow); overflow: hidden; }
.tool-ai-panel[open] { display: flex; flex-direction: column; }
.tool-ai-panel::backdrop { background: rgba(20, 14, 10, .12); }
/* Shadows barely read on dark surfaces: separate the layer with a light edge and a deeper shade instead. */
html[data-theme="dark"] .tool-ai-panel { border-color: rgba(247, 240, 230, .24); box-shadow: 0 0 0 1px rgba(0, 0, 0, .45), 0 24px 56px -16px rgba(0, 0, 0, .72); }
html[data-theme="dark"] .tool-ai-panel::backdrop { background: rgba(0, 0, 0, .42); }
.tool-ai-panel__inner { display: grid; gap: 14px; min-height: 0; padding: 16px; overflow-y: auto; overscroll-behavior: contain; }
.tool-ai-panel__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tool-ai-panel__head h2 { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.35; }
.tool-ai-panel__close { flex: none; width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--ts-muted); font-size: 20px; line-height: 1; cursor: pointer; }
.tool-ai-panel__close:hover { background: var(--ts-surface-2); color: var(--ts-ink); }
.tool-ai-panel__close:focus-visible { outline: 2px solid var(--ts-accent); outline-offset: 1px; }
.tool-ai-panel__login { margin: 0; padding: 9px 11px; border: 1px solid var(--ts-line-strong); border-left: 3px solid var(--ts-accent); border-radius: 10px; background: var(--ts-surface-2); font-size: 13px; line-height: 1.55; }
.tool-ai-panel fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.tool-ai-panel legend, .tool-ai-panel__label { margin-bottom: 8px; padding: 0; color: var(--ts-muted); font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.tool-ai-panel__cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tool-ai-card { position: relative; display: grid; gap: 6px; min-width: 0; padding: 6px 6px 8px; border: 1px solid var(--ts-line-strong); border-radius: 12px; background: var(--ts-surface); cursor: pointer; }
.tool-ai-card input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.tool-ai-card__thumb { display: block; width: 100%; height: auto; aspect-ratio: 10 / 7; border-radius: 8px; background-color: var(--ts-surface-2); background-image: linear-gradient(45deg, var(--ts-line) 25%, transparent 25%, transparent 75%, var(--ts-line) 75%), linear-gradient(45deg, var(--ts-line) 25%, transparent 25%, transparent 75%, var(--ts-line) 75%); background-position: 0 0, 6px 6px; background-size: 12px 12px; }
.tool-ai-card__text { display: grid; gap: 1px; min-width: 0; padding: 0 2px; }
.tool-ai-card__text strong { font-size: 13px; line-height: 1.35; }
.tool-ai-card__text small { color: var(--ts-muted); font-size: 12px; line-height: 1.4; }
.tool-ai-card__mark { position: absolute; top: 10px; right: 10px; display: none; padding: 1px 7px; border-radius: 999px; background: var(--ts-accent); color: var(--ts-on-accent, #fff); font-size: 12px; font-weight: 700; line-height: 1.6; }
.tool-ai-card__mark::before { content: "✓ "; }
.tool-ai-card:has(input:checked) { border-color: var(--ts-accent); box-shadow: 0 0 0 1px var(--ts-accent); }
.tool-ai-card:has(input:checked) .tool-ai-card__mark { display: inline-block; }
.tool-ai-card:has(input:focus-visible) { outline: 2px solid var(--ts-accent); outline-offset: 2px; }
.tool-ai-card.is-disabled { cursor: not-allowed; border-style: dashed; }
.tool-ai-card.is-disabled .tool-ai-card__thumb { opacity: .45; }
.tool-ai-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tool-ai-chip { position: relative; display: inline-flex; align-items: center; min-height: 32px; padding: 5px 11px; border: 1px solid var(--ts-line-strong); border-radius: 999px; background: var(--ts-surface); color: var(--ts-ink); font-size: 12.5px; line-height: 1.35; cursor: pointer; }
.tool-ai-chip input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.tool-ai-chip:hover { border-color: var(--ts-accent); }
.tool-ai-chip:has(input:checked) { border-color: var(--ts-accent); background: var(--ts-accent-wash); color: var(--ts-accent-strong, var(--ts-ink)); font-weight: 600; }
.tool-ai-chip:has(input:checked)::before { content: "✓"; margin-right: 5px; }
.tool-ai-chip:has(input:focus-visible) { outline: 2px solid var(--ts-accent); outline-offset: 2px; }
.tool-ai-more { margin-top: 2px; }
.tool-ai-panel__hint, .tool-ai-panel__need, .tool-ai-panel__status { margin: 6px 0 0; color: var(--ts-muted); font-size: 12px; line-height: 1.55; }
.tool-ai-panel__hint:empty, .tool-ai-panel__status:empty { display: none; }
.tool-ai-panel__need.is-warn, .tool-ai-panel__status { color: var(--ts-danger, #b53e3e); }
.tool-ai-panel__settings { display: grid; gap: 4px; padding: 10px 12px; border: 1px solid var(--ts-line); border-radius: 12px; background: var(--ts-surface-2); }
.tool-ai-panel__settings-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tool-ai-panel__settings-head .tool-ai-panel__label { margin: 0; }
.tool-ai-panel__summary { margin: 0; font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.tool-ai-panel__text textarea { box-sizing: border-box; width: 100%; min-height: 88px; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--ts-line-strong); border-radius: 8px; background: var(--ts-surface); color: var(--ts-ink); font: inherit; font-size: 13px; line-height: 1.55; resize: vertical; }
.tool-ai-panel__text textarea:focus-visible { outline: 2px solid var(--ts-accent); outline-offset: 1px; }
.tool-ai-check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; line-height: 1.5; cursor: pointer; }
.tool-ai-check input { flex: none; width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--ts-accent); }
.tool-ai-panel__foot { position: sticky; bottom: -16px; display: grid; justify-items: center; gap: 4px; margin: 0 -16px -16px; padding: 12px 16px 14px; border-top: 1px solid var(--ts-line); background: var(--ts-surface); }
.tool-ai-go { width: 100%; min-height: 42px; padding: 8px 14px; border: 1px solid var(--ts-accent); border-radius: 10px; background: var(--ts-accent); color: var(--ts-on-accent, #fff); font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.tool-ai-go:hover:not(:disabled) { filter: brightness(1.06); }
.tool-ai-go:focus-visible { outline: 2px solid var(--ts-accent); outline-offset: 3px; }
.tool-ai-go:disabled { border-color: var(--ts-line-strong); background: var(--ts-surface-2); color: var(--ts-muted); cursor: not-allowed; }
.tool-ai-panel__cost { color: var(--ts-muted); font-size: 12px; line-height: 1.5; text-align: center; }
/* Phones and tablets: bottom sheet, primary action pinned above the safe area, page behind does not scroll. */
html.tool-ai-locked { overflow: hidden; }
.tool-ai-panel.is-sheet { inset: auto 0 0 0; width: 100%; max-width: 100%; max-height: 85dvh; border-width: 1px 0 0; border-radius: 18px 18px 0 0; }
.tool-ai-panel.is-sheet::before { content: ""; flex: none; align-self: center; width: 40px; height: 4px; margin-top: 8px; border-radius: 999px; background: var(--ts-line-strong); }
.tool-ai-panel.is-sheet .tool-ai-panel__foot { padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
.tool-ai-panel.is-sheet .tool-ai-panel__close { width: 44px; height: 44px; }
@media (pointer: coarse), (max-width: 1023px) {
  .material-segment .tool-control-strip--segment > .tool-ai-trigger { min-height: 44px; }
  .tool-ai-chip, .tool-ai-link, .tool-ai-more { min-height: 44px; }
  .tool-ai-go { min-height: 48px; }
  .tool-ai-panel__text textarea { font-size: 16px; }
}
@media (prefers-reduced-motion: no-preference) { .tool-ai-chip, .tool-ai-card { transition: border-color 140ms, background-color 140ms; } }
