/*
 * static/css/files.css — workspace pane and file previews (the viewers' own bodies).
 *
 * Owner: WP B-16. Spec: FR §5 (viewers), §3.4 (sizes), §10 (themes, mobile, a11y), §3.6 (file pane).
 * Every selector is defined once, in one file (I7; T-CSS checks the critical ones).
 * Prefixes: `.aiwv-*` = viewer bodies (inside B-15's `.aiw-card__viewer` / `.aiw-stage__body`, or the
 * pane's `.wsp-viewer`); `.wsp-*` = the workspace pane. The card chrome, the iframe element
 * (`.aiw-frame`) and the card background toggle (`.aiw-card__body[data-bg]`) live in artifacts.css.
 * No inline style attributes: the JS sets sizes through CSSOM (CSP).
 */

/* ---- shared viewer bits ------------------------------------------------------------------ */
.aiwv-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    padding: 6px var(--space-2);
    font: var(--t-body-s);
    color: var(--c-on-3);
}

.aiwv-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 32px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--c-surface-high);
    color: var(--c-on);
    font: var(--t-label-m);
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}

.aiwv-btn:hover { background: var(--c-surface-highest); }
.aiwv-btn:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.aiwv-btn[aria-pressed="true"] { color: var(--c-on-accent-container); background: var(--c-accent-container); }

.aiwv-mode-stage { height: 100%; min-height: 0; }

/* inline cards clamp tall text-like bodies at 480 px; the card's Expand removes the clamp (FR §3.4) */
.aiwv-clamped { max-height: 480px; overflow: auto; }

/* ---- fixed error state (FR §3.2; used when no card hosts the viewer) ---------------------- */
.aiwv-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 120px;
    padding: var(--space-4);
    text-align: center;
    color: var(--c-on-2);
}

.aiwv-error__text { margin: 0; font-size: 0.95rem; }
.aiwv-error__note { max-width: 100%; margin: 0; padding: var(--space-2); overflow-x: auto; background: var(--c-code); border: 1px solid var(--c-outline-variant); border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: 12px; color: var(--c-on-3); white-space: pre-wrap; }
.aiwv-error__actions { display: flex; gap: var(--space-2); }

/* ---- file card (binary, FR §5.7) ------------------------------------------------------------ */
.aiwv-filecard {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 72px;
    padding: var(--space-3) var(--space-4);
}

.aiwv-filecard__icon {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 40px;
    height: 48px;
    padding-bottom: 6px;
    border-radius: var(--radius-xs) var(--radius-md) var(--radius-xs) var(--radius-xs);
    background: var(--c-surface-high);
    box-shadow: inset 0 0 0 1px var(--c-outline-variant);
}

.aiwv-filecard__icon:is([data-family="image"], [data-family="video"]) { background: color-mix(in srgb, var(--c-brand) 18%, transparent); }
.aiwv-filecard__icon[data-family="archive"] { box-shadow: inset 0 0 0 1px var(--c-outline); }
.aiwv-filecard__ext { font: var(--t-label-s); font-size: 9.5px; letter-spacing: 0.04em; color: var(--c-accent-text); }
.aiwv-filecard__info { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; min-width: 0; }
.aiwv-filecard__name { overflow: hidden; color: var(--c-on); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.aiwv-filecard__meta, .aiwv-filecard__note { overflow: hidden; color: var(--c-on-3); font: var(--t-body-s); text-overflow: ellipsis; white-space: nowrap; }
.aiwv-filecard__gone { color: var(--c-danger); font: var(--t-body-s); }
.aiwv-filecard__download { flex: 0 0 auto; }

/* ---- image (FR §5.1) ------------------------------------------------------------------------ */
.aiwv-image { position: relative; display: flex; flex-direction: column; }
.aiwv-image__canvas { display: flex; align-items: center; justify-content: center; min-height: 40px; }

.aiwv-image__img {
    display: block;
    max-width: 100%;
    height: auto;
    max-height: 70vh;
    object-fit: contain;
    cursor: zoom-in;
}

.aiwv-image__img:focus-visible { outline: 2px solid var(--c-focus); outline-offset: -2px; }
.aiwv-mode-stage .aiwv-image__canvas { flex: 1 1 auto; min-height: 0; }
.aiwv-mode-stage .aiwv-image__img { max-height: 100%; }
.aiwv-mode-lightbox .aiwv-image__img { cursor: default; max-height: none; }
.aiwv-image__load { margin: var(--space-6) auto; }
.aiwv-image__bar { justify-content: flex-end; }

/* the pane's own background toggle (cards use .aiw-card__body[data-bg]) */
.aiwv-image[data-bg="light"] .aiwv-image__canvas { background: var(--canvas-light); }
.aiwv-image[data-bg="dark"] .aiwv-image__canvas { background: var(--canvas-dark); }
.aiwv-image[data-bg="checker"] .aiwv-image__canvas {
    background-color: var(--checker-b);
    background-image:
        linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
        linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
        linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* ---- pdf / office (FR §5.3): pages are always white --------------------------------------- */
.aiwv-pdf { position: relative; display: flex; flex-direction: column; min-height: 0; }
.aiwv-pdf--full { height: 100%; }
.aiwv-pdf__status { padding: 0 var(--space-3); color: var(--c-on-3); font-size: 12.5px; }
.aiwv-pdf__status:empty { display: none; }
.aiwv-pdf__scroller { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.aiwv-pdf--full .aiwv-pdf__scroller { overflow: auto; padding: var(--space-4); background: var(--c-surface-low); }
.aiwv-pdf__scroller:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--c-focus); }
.aiwv-pdf__pages { display: flex; flex-direction: column; align-items: center; gap: var(--space-4); }

.aiwv-pdf__page {
    position: relative;
    flex: 0 0 auto;
    max-width: none;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.18);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.aiwv-pdf--inline .aiwv-pdf__page { border-width: 0 0 1px; box-shadow: none; }
.aiwv-pdf__page--open { cursor: zoom-in; }
.aiwv-pdf__canvas { display: block; }
.aiwv-pdf__footer { justify-content: flex-start; border-top: 1px solid var(--c-outline-variant); }
.aiwv-pdf--full .aiwv-pdf__footer { justify-content: center; }
.aiwv-pdf__note { flex-basis: 100%; font-style: italic; }
.aiwv-pdf__pages-label { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.aiwv-pdf__pagebox { width: 4.4em; height: 32px; padding: 0 8px; border: 1px solid var(--c-outline); border-radius: var(--radius-sm); background: var(--c-surface); color: var(--c-on); font: inherit; text-align: right; font-variant-numeric: tabular-nums; }
.aiwv-pdf__zoom { height: 32px; padding: 0 30px 0 10px; border: 1px solid var(--c-outline); border-radius: var(--radius-sm); background: var(--c-surface) var(--chev) no-repeat right 8px center / 16px 16px; color: var(--c-on); font: inherit; appearance: none; -webkit-appearance: none; }
.aiwv-pdf__count { font-variant-numeric: tabular-nums; }
.aiwv-pdf__sep { opacity: 0.6; }
.aiwv-pdf__links { position: absolute; inset: 0; pointer-events: none; }
.aiwv-pdf__link { position: absolute; pointer-events: auto; }
.aiwv-pdf__link:hover, .aiwv-pdf__link:focus-visible { outline: 2px solid rgba(30, 90, 200, 0.55); outline-offset: 0; background: rgba(30, 90, 200, 0.08); }

/* pdf.js 4.x text layer (selection + screen readers); pdf.js sets --scale-factor via the page */
.aiwv-pdf .textLayer {
    position: absolute;
    inset: 0;
    overflow: clip;
    opacity: 1;
    line-height: 1;
    text-align: initial;
    text-size-adjust: none;
    -webkit-text-size-adjust: none;
    forced-color-adjust: none;
    transform-origin: 0 0;
    caret-color: CanvasText;
    z-index: 0;
}

.aiwv-pdf .textLayer :is(span, br) {
    position: absolute;
    color: transparent;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}

.aiwv-pdf .textLayer .markedContent { display: contents; }
.aiwv-pdf .textLayer span[role="img"] { user-select: none; cursor: default; }
.aiwv-pdf .textLayer ::selection { background: rgba(0, 90, 255, 0.28); }
.aiwv-pdf .textLayer br::selection { background: transparent; }
.hiddenCanvasElement { position: absolute; top: 0; left: 0; width: 0; height: 0; display: none; }

/* ---- sheet (FR §5.4) ------------------------------------------------------------------------ */
.aiwv-sheet { display: flex; flex-direction: column; min-height: 0; }
.aiwv-sheet.aiwv-mode-inline { height: 360px; }
.aiwv-sheet__loading { padding: var(--space-4); color: var(--c-on-3); font-size: 13px; }
.aiwv-sheet__banner { display: flex; flex-wrap: wrap; gap: var(--space-3); padding: 6px var(--space-3); border-bottom: 1px solid var(--c-outline-variant); background: var(--c-accent-container); color: var(--c-on-accent-container); font-size: 12.5px; }
.aiwv-sheet__scroller { position: relative; flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }

.aiwv-sheet__grid {
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    color: var(--c-on);
}

.aiwv-sheet__grid th, .aiwv-sheet__grid td {
    height: 28px;
    max-height: 28px;
    padding: 0 6px;
    overflow: hidden;
    border-right: 1px solid var(--c-outline-variant);
    border-bottom: 1px solid var(--c-outline-variant);
    background: var(--c-surface);
    line-height: 27px;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-sizing: border-box;
}

.aiwv-sheet__head th { position: sticky; top: 0; z-index: 3; background: var(--c-surface-low); color: var(--c-on-3); font-weight: 600; text-align: center; }
.aiwv-sheet__corner { left: 0; z-index: 5; }
.aiwv-sheet__head .aiwv-sheet__corner { z-index: 5; }
.aiwv-sheet__rownum { position: sticky; left: 0; z-index: 2; background: var(--c-surface-low); color: var(--c-on-3); font-weight: 500; text-align: right; }
.aiwv-sheet__cell { text-align: left; }
.aiwv-sheet__cell:focus { outline: 2px solid var(--c-accent); outline-offset: -2px; }
.aiwv-sheet__cell--b { font-weight: 700; }
.aiwv-sheet__cell--i { font-style: italic; }
.aiwv-sheet__cell--u { text-decoration: underline; }
.aiwv-sheet__cell--fx { color: var(--c-on-3); }
.aiwv-sheet__cell--err { color: var(--c-danger); }
.aiwv-sheet__cell--frozen-col { position: sticky; z-index: 1; }
.aiwv-sheet__cell--frozen-row { position: sticky; z-index: 2; box-shadow: inset 0 -1px 0 var(--c-outline); }
.aiwv-sheet__head .aiwv-sheet__cell--frozen-col { z-index: 4; }
.aiwv-sheet__row--frozen .aiwv-sheet__rownum { position: sticky; z-index: 4; }
.aiwv-sheet__row--frozen .aiwv-sheet__cell--frozen-col { z-index: 3; }
.aiwv-sheet__spacer { pointer-events: none; }
.aiwv-sheet__spacer td, .aiwv-sheet__spacer th { height: auto; border: 0; padding: 0; background: transparent; }
.aiwv-sheet__empty { margin: var(--space-4); color: var(--c-on-3); font-size: 13px; }
.aiwv-sheet[data-theme="light"] .aiwv-sheet__grid td { background: var(--canvas-light); }

.aiwv-sheet__tabs {
    display: flex;
    flex: 0 0 auto;
    gap: 2px;
    padding: 0 var(--space-2);
    overflow-x: auto;
    border-top: 1px solid var(--c-outline-variant);
    background: var(--c-surface-low);
    scrollbar-width: thin;
}

.aiwv-sheet__tab {
    flex: 0 0 auto;
    min-height: 30px;
    max-width: 220px;
    padding: 0 12px;
    overflow: hidden;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--c-on-2);
    font: var(--t-label-m);
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.aiwv-sheet__tab[aria-selected="true"] { border-bottom-color: var(--c-accent); color: var(--c-on); font-weight: 600; }
.aiwv-sheet__tab:hover { color: var(--c-on); background: var(--c-hover); }
.aiwv-sheet__tab:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--c-focus); }

/* ---- text, markdown, latex (FR §5.5) ------------------------------------------------------- */
.aiwv-text { display: flex; flex-direction: column; min-height: 0; }
.aiwv-text__bar { justify-content: flex-end; border-bottom: 1px solid var(--c-outline-variant); }
.aiwv-text__body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.aiwv-mode-stage .aiwv-text__body { overflow: auto; }
.aiwv-text__note { margin: 0; padding: 6px var(--space-3); color: var(--c-on-accent-container); background: var(--c-accent-container); font-size: 12.5px; }
.aiwv-text__status { padding: var(--space-4); color: var(--c-on-3); font-size: 13px; }
.aiwv-text__log { margin: 0 var(--space-3) var(--space-2); padding: var(--space-2); overflow-x: auto; background: var(--c-code); border: 1px solid var(--c-outline-variant); border-radius: var(--radius-sm); color: var(--c-danger); font-family: var(--font-mono); font-size: 12px; white-space: pre-wrap; }
.aiwv-text__block { display: flex; align-items: flex-start; min-width: 0; background: var(--c-code); }

.aiwv-text__gutter {
    position: sticky;
    left: 0;
    flex: 0 0 auto;
    min-width: 3em;
    margin: 0;
    padding: var(--space-3) var(--space-2) var(--space-3) var(--space-3);
    border-right: 1px solid var(--c-outline-variant);
    background: var(--c-code);
    color: var(--c-on-3);
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 20px;
    text-align: right;
    user-select: none;
}

.aiwv-text__code {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: var(--space-3);
    overflow: visible;
    color: var(--c-on);
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 20px;
    tab-size: 4;
}

.aiwv-text__code code { font: inherit; background: transparent; padding: 0; }
.aiwv-text__code code.hljs { padding: 0; background: transparent; overflow: visible; } /* the body scrolls (I3B-6) */
.aiwv-text__block--wrap .aiwv-text__gutter { display: none; }
.aiwv-text__block--wrap .aiwv-text__code { white-space: pre-wrap; overflow-wrap: anywhere; }
.aiwv-text__markdown { padding: var(--space-4); line-height: 1.65; overflow-wrap: anywhere; }
.aiwv-text__latex .katex-display { margin: var(--space-3) 0; }
.aiwv-text__pdf { min-height: 0; }

/* ---- notebook (FR §5.6) --------------------------------------------------------------------- */
.aiwv-nb { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-3) var(--space-4); }
.aiwv-mode-stage.aiwv-nb { overflow: auto; }
.aiwv-nb__cell { min-width: 0; }
.aiwv-nb__cell--code { display: grid; grid-template-columns: 4.5em minmax(0, 1fr); column-gap: var(--space-2); }
.aiwv-nb__prompt { grid-column: 1; padding-top: 8px; color: var(--c-accent); font-family: var(--font-mono); font-size: 12px; text-align: right; white-space: nowrap; }
.aiwv-nb__input { grid-column: 2; min-width: 0; }
.aiwv-nb__source { margin: 0; padding: 8px 10px; overflow-x: auto; border: 1px solid var(--c-outline-variant); border-radius: var(--radius-sm); background: var(--c-code); font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5; }
.aiwv-nb__source code { font: inherit; background: transparent; padding: 0; }
.aiwv-nb__outputs { display: flex; grid-column: 2; flex-direction: column; gap: var(--space-2); min-width: 0; margin-top: var(--space-2); }
.aiwv-nb__pre { margin: 0; padding: 6px 10px; overflow-x: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.aiwv-nb__stderr { background: var(--c-danger-container); }
.aiwv-nb__error { color: var(--c-danger); background: var(--c-danger-container); border-radius: var(--radius-sm); }
.aiwv-nb__img { display: block; max-width: 100%; height: auto; background: var(--canvas-light); }
.aiwv-nb__html { overflow-x: auto; }
.aiwv-nb__muted { margin: 0; color: var(--c-on-3); font-size: 12.5px; font-style: italic; }
.aiwv-nb__raw { color: var(--c-on-2); }

/* ---- media (FR §5.7) ------------------------------------------------------------------------ */
.aiwv-media { display: flex; align-items: center; justify-content: center; }
.aiwv-media--audio { min-height: 54px; padding: var(--space-2) var(--space-3); }
.aiwv-media__audio { width: 100%; }
.aiwv-media--video { background: #000; }
.aiwv-media__video { display: block; width: 100%; max-height: 70vh; aspect-ratio: var(--aiwv-media-aspect, 16 / 9); background: #000; }
.aiwv-mode-stage.aiwv-media--video .aiwv-media__video { height: 100%; max-height: none; }

/* ---- archive (FR §5.7) ---------------------------------------------------------------------- */
.aiwv-archive { display: flex; flex-direction: column; min-height: 0; }
.aiwv-archive.aiwv-mode-inline { max-height: 360px; }
.aiwv-archive__summary { padding: 6px var(--space-3); border-bottom: 1px solid var(--c-outline-variant); color: var(--c-on-3); font-size: 12.5px; }
.aiwv-archive__scroller { flex: 1 1 auto; min-height: 0; overflow: auto; }
.aiwv-archive__table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.aiwv-archive__table th { position: sticky; top: 0; z-index: 1; padding: 0; background: var(--c-surface-low); text-align: left; }
.aiwv-archive__table td { padding: 4px var(--space-3); border-bottom: 1px solid var(--c-outline-variant); }
.aiwv-archive__sort { width: 100%; padding: 6px var(--space-3); border: 0; background: transparent; color: var(--c-on-3); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.aiwv-archive__sort:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--c-focus); }
.aiwv-archive__table th[aria-sort="ascending"] .aiwv-archive__sort::after { content: " ▲"; }
.aiwv-archive__table th[aria-sort="descending"] .aiwv-archive__sort::after { content: " ▼"; }
.aiwv-archive__path { max-width: 0; overflow: hidden; font-family: var(--font-mono); text-overflow: ellipsis; white-space: nowrap; }
.aiwv-archive__size { width: 7em; color: var(--c-on-3); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.aiwv-archive__dir .aiwv-archive__path { color: var(--c-accent); }
.aiwv-archive__empty { color: var(--c-on-3); font-style: italic; }

/* ---- workspace pane (file manager; brief §6.11): a 24-radius dialog, two tonal columns, rows with kind tiles ---- */
.wsp-overlay {
    position: fixed;
    inset: 0;
    /* a modal overlay: above the stage pane and sheet (40), so its close button and the Workspace
       column are never covered (X36); lightbox and menus (45), notices (50) and dialogs (180) stay above */
    z-index: var(--z-files-pane);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: var(--c-scrim);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.wsp-panel {
    display: flex;
    flex-direction: column;
    width: min(1080px, 100%);
    height: min(760px, 100%);
    min-height: 0;
    overflow: hidden;
    border-radius: var(--radius-xl);
    background: var(--c-surface-low);
    box-shadow: var(--elev-3);
    color: var(--c-on);
    animation: panel-in var(--dur-3) var(--ease-enter);
}
[data-theme="light"] .wsp-panel { background: var(--c-surface); }

.wsp-head {
    display: flex;
    flex: 0 0 auto;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 24px 20px 16px 28px;
}

.wsp-head__titles { min-width: 0; }
.wsp-kicker { display: block; color: var(--c-accent-text); font: var(--t-label-m); }
.wsp-title { margin: 4px 0 0; font: var(--t-headline); letter-spacing: -0.015em; }
.wsp-subtitle { max-width: 470px; margin: 4px 0 0; color: var(--c-on-2); font: var(--t-body-m); }
.wsp-head__actions { display: flex; flex: 0 0 auto; align-items: center; gap: var(--space-2); }
.wsp-quota { color: var(--c-on-3); font: var(--t-body-s); font-variant-numeric: tabular-nums; }

/* × (kept in the DOM) drawn as an icon */
.wsp-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--c-on-2);
    font-size: 0;
    line-height: 0;
    cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}
.wsp-close::before {
    content: ''; width: 20px; height: 20px; background: currentColor;
    -webkit-mask: var(--icon-x) center / contain no-repeat; mask: var(--icon-x) center / contain no-repeat;
}

.wsp-close:hover { background: var(--c-hover); color: var(--c-on); }

.wsp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 32px;
    padding: 0 14px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--c-surface-high);
    color: var(--c-on);
    font: var(--t-label-m);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}

.wsp-btn:hover { background: var(--c-surface-highest); }
.wsp-btn--primary { background: var(--c-primary); color: var(--c-on-primary); box-shadow: inset 0 0 0 1px var(--c-primary-edge); }
.wsp-btn--primary:hover { background: var(--c-primary-hover); color: var(--c-on-primary); }
.wsp-btn--danger:hover { background: var(--c-danger-container); color: var(--c-on-danger-container); }
/* R-117: "Upload files" under a full network ban (workspace-pane.js syncNetwork; its title says why) */
.wsp-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.wsp-btn--primary:disabled:hover { background: var(--c-primary); }

.wsp-status { flex: 0 0 auto; margin: 0 16px 10px; padding: 8px 14px; border-radius: var(--radius-md); background: var(--c-surface-high); color: var(--c-on-2); font: var(--t-body-s); }
.wsp-status[data-level="error"] { background: var(--c-danger-container); color: var(--c-on-danger-container); }

.wsp-columns {
    display: grid;
    flex: 1 1 auto;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    min-height: 0;
    padding: 0 16px 16px;
}

.wsp-col {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--c-bg);
    transition: box-shadow var(--dur-2) var(--ease-standard);
}
[data-theme="light"] .wsp-col { background: var(--c-surface-low); }

.wsp-col--drop { box-shadow: inset 0 0 0 2px var(--c-accent); }
.wsp-col__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); padding: 14px 12px 10px 18px; }
.wsp-col__titles { min-width: 0; }
.wsp-col__title { margin: 0; font: var(--t-title-m); }
.wsp-col__subtitle { margin: 2px 0 0; color: var(--c-on-3); font: var(--t-body-s); }
.wsp-col__actions { display: flex; flex-wrap: wrap; gap: 6px; }
.wsp-col__actions > .wsp-btn:not(.wsp-btn--primary) { background: transparent; color: var(--c-accent-text); }
.wsp-col__actions > .wsp-btn:not(.wsp-btn--primary):hover { background: var(--c-hover); }
.wsp-list { flex: 1 1 auto; min-height: 0; margin: 0; padding: 4px 8px 8px; overflow-y: auto; list-style: none; }

.wsp-file {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 56px;
    padding: 6px 6px 6px 10px;
    border-radius: var(--radius-md);
    transition: background-color var(--dur-1) var(--ease-standard);
}

.wsp-file:hover, .wsp-file:focus-within { background: var(--c-hover); }

/* the kind: a 36 px tinted tile with a line icon (earth tones for categories, never states) */
.wsp-file__icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--c-surface-high);
    color: var(--c-on-2);
}
.wsp-file__icon::before {
    content: ''; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--icon-file) center / contain no-repeat; mask: var(--icon-file) center / contain no-repeat;
}

.wsp-file__icon:is([data-view="image"], [data-view="svg"]) { background: color-mix(in srgb, var(--c-brand) 18%, transparent); color: var(--c-accent-text); }
.wsp-file__icon:is([data-view="image"], [data-view="svg"])::before { -webkit-mask-image: var(--icon-image); mask-image: var(--icon-image); }
.wsp-file__icon[data-view="sheet"] { background: color-mix(in srgb, var(--c-sage) 18%, transparent); color: var(--c-sage); }
.wsp-file__icon[data-view="sheet"]::before { -webkit-mask-image: var(--icon-table); mask-image: var(--icon-table); }
.wsp-file__icon:is([data-view="markdown"], [data-view="latex"], [data-view="text"]) { background: color-mix(in srgb, var(--c-slate) 18%, transparent); color: var(--c-slate); }
.wsp-file__icon:is([data-view="markdown"], [data-view="latex"], [data-view="text"])::before { -webkit-mask-image: var(--icon-file-text); mask-image: var(--icon-file-text); }
.wsp-file__icon:is([data-view="html"], [data-view="deck"], [data-view="notebook"]) { background: var(--c-accent-container); color: var(--c-accent-text); }
.wsp-file__icon:is([data-view="html"], [data-view="notebook"])::before { -webkit-mask-image: var(--icon-code); mask-image: var(--icon-code); }
.wsp-file__icon[data-view="deck"]::before { -webkit-mask-image: var(--icon-slides); mask-image: var(--icon-slides); }
.wsp-file__icon:is([data-view="pdf"], [data-view="office"]) { background: color-mix(in srgb, var(--c-clay) 16%, transparent); color: var(--c-clay); }
.wsp-file__icon:is([data-view="pdf"], [data-view="office"])::before { -webkit-mask-image: var(--icon-file-text); mask-image: var(--icon-file-text); }
.wsp-file__icon[data-view="media"]::before { -webkit-mask-image: var(--icon-audio); mask-image: var(--icon-audio); }
.wsp-file__icon[data-view="archive"]::before { -webkit-mask-image: var(--icon-archive); mask-image: var(--icon-archive); }
.wsp-file__main { display: flex; flex: 1 1 auto; flex-direction: column; gap: 1px; min-width: 0; }

.wsp-file__name {
    display: block;
    max-width: 100%;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--c-on);
    font: var(--t-body-m);
    font-weight: 500;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.wsp-file__name:hover .wsp-file__base { color: var(--c-accent-text); }
.wsp-file__dir { color: var(--c-on-3); font-weight: 400; }
.wsp-file__meta { color: var(--c-on-3); font: var(--t-body-s); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.wsp-file__actions { display: flex; flex: 0 0 auto; gap: 2px; }

.wsp-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--c-on-2);
    font: var(--t-label-m);
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}

.wsp-icon-btn:hover { background: var(--c-hover); color: var(--c-on); }
/* the row's download (↓) and delete (×) keep their glyph text and draw line icons */
.wsp-file__actions > a.wsp-icon-btn, .wsp-file__delete { font-size: 0; line-height: 0; }
.wsp-file__actions > a.wsp-icon-btn::before {
    content: ''; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--icon-download) center / contain no-repeat; mask: var(--icon-download) center / contain no-repeat;
}
.wsp-file__delete::before {
    content: ''; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--icon-trash) center / contain no-repeat; mask: var(--icon-trash) center / contain no-repeat;
}
.wsp-file__delete:hover { color: var(--c-danger); }
.wsp-empty { padding: 48px var(--space-3); color: var(--c-on-3); font: var(--t-body-m); text-align: center; }
.wsp-empty--error { color: var(--c-danger); }

.wsp-preview { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; margin: 0 16px 16px; overflow: hidden; border-radius: var(--radius-lg); background: var(--c-bg); }
[data-theme="light"] .wsp-preview { background: var(--c-surface-low); }
.wsp-preview__bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: 10px 12px 10px 14px; border-bottom: 1px solid var(--c-outline-variant); }
.wsp-preview__titles { display: flex; flex: 1 1 200px; flex-direction: column; min-width: 0; }
.wsp-preview__title { margin: 0; overflow: hidden; font: var(--t-title-m); text-overflow: ellipsis; white-space: nowrap; }
.wsp-preview__meta { color: var(--c-on-3); font: var(--t-body-s); font-size: 0.75rem; }
.wsp-preview__actions { display: flex; flex-wrap: wrap; gap: 6px; }

.wsp-viewer {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    overflow: auto;
    background: var(--c-surface);
}

.wsp-viewer > * { flex: 1 1 auto; min-height: 0; }
.wsp-viewer[data-view="image"] > .aiwv-image, .wsp-viewer[data-view="svg"] > .aiwv-image { justify-content: center; padding: var(--space-4); }
.wsp-viewer[data-view="media"] > .aiwv-media, .wsp-viewer[data-view="binary"] > .aiwv-filecard { flex: 0 0 auto; margin: auto 0; }
.wsp-viewer:focus-visible { outline: none; }
.wsp-viewer > iframe { height: 100%; min-height: 360px; }

@media (max-width: 768px) {
    .wsp-overlay { padding: 0; }
    .wsp-panel { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; }
    .wsp-head { position: relative; flex-wrap: wrap; padding: 16px 56px 8px 20px; }
    .wsp-head__titles { flex: 1 1 60%; }
    .wsp-head__actions { flex: 1 0 100%; justify-content: flex-start; }
    .wsp-close { position: absolute; top: 10px; right: 8px; }
    .wsp-quota { display: none; }
    .wsp-subtitle { display: none; }
    .wsp-status { margin: 0 8px 8px; }
    .wsp-columns { grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(220px, auto); overflow-y: auto; padding: 0 8px 8px; }
    .wsp-col { overflow: visible; }
    .wsp-list { overflow: visible; padding: 4px 4px 8px; }
    .wsp-file { min-height: 56px; padding: 6px 4px 6px 8px; }
    .wsp-icon-btn { width: 40px; height: 40px; }
    .wsp-preview { margin: 0 8px 8px; }
    .wsp-preview__bar { padding: 8px 10px; }
    .aiwv-sheet.aiwv-mode-inline { height: 320px; }
}

/* Forced colours: the line icons are masks, which forced colours would paint in the Canvas colour. */
@media (forced-colors: active) {
    .wsp-close::before, .wsp-file__icon::before, .wsp-file__actions > a.wsp-icon-btn::before, .wsp-file__delete::before { forced-color-adjust: none; background: ButtonText; }
    /* keyboard focus drawn with a box-shadow, which forced colours drop (final review client-3) */
    .aiwv-pdf__scroller:focus-visible,
    .aiwv-sheet__tab:focus-visible,
    .aiwv-archive__sort:focus-visible { outline: 2px solid Highlight; outline-offset: -2px; }
}

@media (prefers-reduced-motion: reduce) {
    .wsp-overlay { backdrop-filter: none; -webkit-backdrop-filter: none; }
}
