/* Documents page — migrated from Documents.razor.css; scoped under .page-documents. */
.page-documents { display: flex; flex-direction: column; gap: 34px; }

/* ── Component kit (scoped to this page): buttons, split layout,
   list rows, fields, modal — ported from the old global portal.css.
   Colour tokens (--surface, --line, --accent…) inherit from .shell on
   the layout. Scoped here so they can't collide with Bootstrap globals. ── */

/* Buttons */
.page-documents .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px; border: 1px solid var(--line); border-radius: 0;
    background: var(--surface); color: var(--text); text-decoration: none;
    font: 600 13px var(--font-body); cursor: pointer;
    transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.page-documents .btn:hover:not(:disabled) { border-color: var(--accent-line); background: var(--surface-2); transform: translateY(-1px); }
.page-documents .btn:disabled { opacity: .5; cursor: not-allowed; }
.page-documents .btn-primary { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-2); }
.page-documents .btn-primary:hover:not(:disabled) { background: rgba(45,212,191,.22); }

/* Two-column split (browser + preview). Both tracks are fluid with a zero floor (§26): the panel clips,
   so a pixel minimum on either side pushes the other's content past the edge instead of shrinking it. */
.page-documents .split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 22px; align-items: start; }
@media (max-width: 960px) { .page-documents .split { grid-template-columns: minmax(0, 1fr); } }

/* On a wide display the extra width goes to the preview: the browser pane holds a name and two lines of
   meta whatever the display, and the thing being read is on the right. */
@media (min-width: 1600px) { .page-documents .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.9fr); } }

/* Expanded: the preview takes the whole column and the browser pane is hidden. A spreadsheet is why this
   exists, since a workbook is wider than either half of a split at any resolution. The pane is hidden in
   CSS rather than dropped from the markup so this stays one layout with one set of rows, and display:none
   keeps the hidden buttons out of the tab order. */
.page-documents .split.is-wide { grid-template-columns: minmax(0, 1fr); }
.page-documents .split.is-wide > .panel:first-child { display: none; }

/* Download, and the expand toggle when there is something on screen to expand. */
.page-documents .preview-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

/* Panel head row + count chip */
.page-documents .panel-head-row { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.page-documents .panel-head-row h3 { margin: 0; font-size: 14px; font-weight: 600; }
/* The chip says what it counts ("7 items"), so it holds one line and is never squeezed by the crumbs. */
.page-documents .count-chip { flex: none; display: inline-flex; min-width: 18px; height: 18px; padding: 0 6px; align-items: center; justify-content: center; white-space: nowrap; background: var(--surface-2); border: 1px solid var(--line); font-size: 11px; color: var(--muted); }

/* Breadcrumb, the panel's heading, because where the reader is standing is what a folder browser
   has to say. Each crumb is a button: pressing an ancestor goes back up to it. */
.page-documents .crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; }
.page-documents .crumb {
    max-width: 220px; padding: 2px 4px; border: 0; background: none;
    font: 600 13.5px var(--font-body); color: var(--muted); cursor: pointer;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    transition: color .14s ease;
}
.page-documents .crumb:hover { color: var(--accent-2); }
.page-documents .crumb.here { color: var(--text); cursor: default; }
.page-documents .crumb-sep { color: var(--faint); font-size: 12px; }

/* Rows. Folders and files are the same control (a button, since each one navigates or selects), so the
   whole row is the target rather than a click handler on a div. */
.page-documents .list-row {
    display: flex; width: 100%; align-items: center; gap: 10px;
    padding: 11px 16px; border: 0; border-bottom: 1px solid var(--line-soft);
    background: transparent; color: inherit; font: inherit; text-align: left;
    cursor: pointer; transition: background .14s ease;
}
.page-documents .list-row:last-child { border-bottom: none; }
.page-documents .list-row:hover { background: var(--surface-2); }
.page-documents .list-row.sel { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }

/* Every cell clamps and the name ellipsises: .content .panel is overflow:hidden, so a long file name
   would be cut off rather than scrolled (§26). */
.page-documents .row-main { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.page-documents .list-row-name { display: block; font-size: 13.5px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-documents .list-row-meta { display: block; font-size: 12px; color: var(--faint); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.page-documents .row-icon { flex: none; display: inline-flex; width: 20px; height: 20px; color: var(--accent); }
.page-documents .row-icon svg { width: 20px; height: 20px; }
.page-documents .row-icon.is-file { color: var(--faint); }
.page-documents .row-chevron { flex: none; color: var(--faint); font-size: 16px; line-height: 1; }
.page-documents .icon-btn { flex: none; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; background: transparent; color: var(--faint); cursor: pointer; font-size: 13px; }
.page-documents .icon-btn:hover { color: var(--bad); border-color: rgba(255,107,107,.3); }

/* Empty / loading / error */
.page-documents .empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.page-documents .empty-title { font-size: 14.5px; font-weight: 600; color: var(--text); margin: 0 0 6px; }
.page-documents .empty-detail { font-size: 13px; color: var(--faint); margin: 0; }
.page-documents .loading { padding: 28px 24px; text-align: center; color: var(--muted); font-size: 13px; }
.page-documents .error-box { margin: 0 0 12px; padding: 11px 14px; border: 1px solid rgba(255,107,107,.3); background: rgba(255,107,107,.08); color: #ffb3b3; font-size: 12.5px; }

/* Forms */
.page-documents .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.page-documents .field-label { font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--faint); }
.page-documents .field-input, .page-documents .field-select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 0;
    background: var(--bg); color: var(--text); font: 400 13.5px var(--font-body);
    transition: border-color .15s ease;
}
.page-documents .field-input:focus, .page-documents .field-select:focus { outline: none; border-color: var(--accent-line); }
.page-documents .field-input::placeholder { color: var(--faint); }
.page-documents .field-input:disabled, .page-documents .field-select:disabled { opacity: .55; }
.page-documents .field-hint { font-size: 12px; color: var(--faint); }

/* Section label inside preview */
.page-documents .block-label { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); margin: 18px 0 8px; display: flex; align-items: center; gap: 8px; }

/* Modal overlay + card (centred, faded backdrop) */
.page-documents .modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center; padding: 24px;
    background: rgba(7,9,10,.66); backdrop-filter: blur(3px);
    animation: modal-fade .18s ease both;
}
.page-documents .modal {
    display: block; position: relative; inset: auto; height: auto; overflow-x: hidden;
    width: 100%; max-width: 560px; max-height: calc(100vh - 64px); overflow-y: auto;
    background: var(--surface); border: 1px solid var(--line);
    box-shadow: 0 24px 60px rgba(0,0,0,.5); padding: 22px 24px 26px;
    animation: modal-rise .22s cubic-bezier(.22,.9,.3,1) both;
}
.page-documents .modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.page-documents .modal-title { margin: 0; font-family: var(--font-display); font-size: 18px; font-weight: 600; }
.page-documents .modal-eyebrow { margin: 0 0 3px; font-size: 11.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--accent); }
.page-documents .modal-close {
    flex: none; width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line); background: transparent; color: var(--muted);
    font-size: 15px; cursor: pointer; transition: border-color .15s, color .15s;
}
.page-documents .modal-close:hover { border-color: var(--accent-line); color: var(--text); }

/* ── Page-specific ── */

/* File type and order, side by side under the search box. Two equal columns rather than a popover: this
   pane is half a split, and a menu opening over it would cover the rows it is filtering. */
.page-documents .doc-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 0 16px 12px;
}

/* Why the folders have gone, said where the folders were. */
.page-documents .doc-filter-note {
    padding: 0 16px 12px;
    font-size: 12px;
    color: var(--faint);
}

/* Document list scroll. Sized off the viewport rather than a flat 560px so a tall display shows more rows
   before scrolling, with a floor for a short one. Viewport units only, never the content's own height: the
   box must not resize because of what is in it (§28). */
.page-documents .doc-list {
    max-height: clamp(360px, 52vh, 720px);
    overflow-y: auto;
}

/* Inline preview sizing */
.page-documents .doc-img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--line);
    background: var(--bg);
}

.page-documents .doc-frame {
    width: 100%;
    height: clamp(420px, 68vh, 1000px);
    border: 1px solid var(--line);
    background: var(--bg);
}

.page-documents .split.is-wide .doc-frame { height: clamp(420px, 80vh, 1400px); }

/* An image shows at its natural size, so expanded it is centred for the same reason as .doc-word below. */
.page-documents .split.is-wide .doc-img { display: block; margin-inline: auto; }

/* ── Spreadsheet preview (§47) ──
   The sheet is drawn as a table from parsed rows, so it is chrome the portal styles rather than a file the
   browser renders. It scrolls inside .sheet-wrap: .content .panel is overflow:hidden, so a sheet wider or
   taller than the pane would be clipped rather than reachable (§26). */
.page-documents .sheet-tabs {
    display: flex; flex-wrap: wrap; gap: 4px;
    margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
}

.page-documents .sheet-tab {
    max-width: 180px; padding: 5px 11px;
    border: 1px solid var(--line); background: var(--surface); color: var(--muted);
    font: 600 12px var(--font-body); cursor: pointer;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.page-documents .sheet-tab:hover { border-color: var(--accent-line); color: var(--text); }
.page-documents .sheet-tab.here {
    background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-2); cursor: default;
}

/* A single sheet is named, not tabbed. */
.page-documents .sheet-single {
    margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
    font: 600 12px var(--font-body); color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.page-documents .sheet-wrap {
    max-height: clamp(360px, 66vh, 1000px); overflow: auto;
    border: 1px solid var(--line); background: var(--bg);
}

/* Expanded, the sheet gets the height as well as the width: this is the closest the portal comes to
   opening the workbook, so it is worth the whole screen. */
.page-documents .split.is-wide .sheet-wrap { max-height: clamp(420px, 80vh, 1400px); }
.page-documents .split.is-wide .sheet-table td { max-width: 360px; }

.page-documents .sheet-table { border-collapse: separate; border-spacing: 0; font-size: 12.5px; }

/* Column letters and row numbers, both sticky, so the reader keeps their bearings while scrolling a sheet
   in either direction. The header sits above the gutter where they cross. */
.page-documents .sheet-table th,
.page-documents .sheet-table td {
    max-width: 220px; padding: 6px 10px;
    border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft);
    text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.page-documents .sheet-table thead th {
    position: sticky; top: 0; z-index: 2;
    background: var(--surface-2); color: var(--faint);
    font-weight: 600; letter-spacing: .04em;
}

.page-documents .sheet-table .sheet-gutter {
    position: sticky; left: 0; z-index: 1;
    min-width: 40px; background: var(--surface-2); color: var(--faint);
    font-variant-numeric: tabular-nums; text-align: right; font-weight: 600;
}

.page-documents .sheet-table thead .sheet-gutter { z-index: 3; }
.page-documents .sheet-table tbody td { color: var(--text); }
.page-documents .sheet-table tbody tr:hover td:not(.sheet-gutter) { background: var(--surface-2); }

.page-documents .sheet-note { margin: 10px 0 0; font-size: 12px; color: var(--faint); }

/* ── Text preview (§47) ──
   The same box as a sheet, for the same reason: the pane must scroll rather than clip (§26). Lines are
   NOT wrapped. These files are logs, queries, JSON and CSV, where a wrapped line reads as two records and
   an indent that no longer lines up is a changed meaning, so the box scrolls sideways instead. */
.page-documents .doc-text-wrap {
    max-height: clamp(360px, 66vh, 1000px); overflow: auto;
    border: 1px solid var(--line); background: var(--bg);
}

.page-documents .split.is-wide .doc-text-wrap { max-height: clamp(420px, 80vh, 1400px); }

.page-documents .doc-text {
    margin: 0; padding: 12px 14px;
    font: 400 12.5px/1.65 ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
    color: var(--text); white-space: pre; tab-size: 4;
}

/* ── Word preview (§47) ──
   Blocks the API read out of a .docx, drawn as the portal's own chrome. Fidelity is text, not layout: no
   pages, no columns, no fonts of the document's own choosing. The measure is capped because this is the
   one preview made of prose, and a paragraph run across a 2100px column (§28) is unreadable. */
.page-documents .doc-word {
    max-width: 78ch;
    max-height: clamp(360px, 66vh, 1000px); overflow: auto;
    padding: 18px 20px;
    border: 1px solid var(--line); background: var(--bg);
    font: 400 13.5px/1.7 var(--font-body); color: var(--text);
}

/* Expanded, the measure stays capped but the page is centred: left-aligned, the capped box kept its width
   and slid into the space the hidden browser pane left, so Expand read as "move it left". */
.page-documents .split.is-wide .doc-word { max-height: clamp(420px, 80vh, 1400px); margin-inline: auto; }

.page-documents .doc-word .wd-p { margin: 0 0 11px; }
.page-documents .doc-word > :last-child { margin-bottom: 0; }

/* The document's own heading depth, drawn as sizes rather than as h1..h6: this is somebody else's
   document sitting inside our page, and its headings are not sections of ours (§14). Plain ink, never
   the accent. */
.page-documents .doc-word .wd-h {
    margin: 20px 0 8px; font-family: var(--font-display); font-weight: 600;
    line-height: 1.3; color: var(--text);
}

.page-documents .doc-word .wd-h:first-child { margin-top: 0; }
.page-documents .doc-word .wd-h1 { font-size: 20px; }
.page-documents .doc-word .wd-h2 { font-size: 17px; }
.page-documents .doc-word .wd-h3 { font-size: 15px; }
.page-documents .doc-word .wd-h4,
.page-documents .doc-word .wd-h5,
.page-documents .doc-word .wd-h6 { font-size: 13.5px; color: var(--muted); }

.page-documents .doc-word .wd-list { margin: 0 0 11px; padding-left: 22px; }
.page-documents .doc-word .wd-list li { margin: 0 0 4px; }

/* A list level indents rather than nesting: the blocks arrive flat, each carrying its own depth, which
   is the shape the file has too. */
.page-documents .doc-word .wd-l1 { margin-left: 18px; }
.page-documents .doc-word .wd-l2 { margin-left: 36px; }
.page-documents .doc-word .wd-l3 { margin-left: 54px; }
.page-documents .doc-word .wd-l4 { margin-left: 72px; }

.page-documents .doc-word .wd-table-wrap { margin: 0 0 14px; overflow-x: auto; }

.page-documents .doc-word .wd-table {
    border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px;
}

.page-documents .doc-word .wd-table th,
.page-documents .doc-word .wd-table td {
    padding: 6px 10px; text-align: left; vertical-align: top;
    border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft);
    /* A cell may hold several paragraphs, joined with newlines by the parse (§41). */
    white-space: pre-wrap;
}

.page-documents .doc-word .wd-table th {
    background: var(--surface-2); color: var(--faint); font-weight: 600;
}

.page-documents .doc-word .wd-note { margin: 0 0 12px; font-size: 12px; color: var(--faint); }

/* File input */
.page-documents .field-file {
    width: 100%;
    font: 400 13px var(--font-body);
    color: var(--muted);
}

.page-documents .field-file::file-selector-button {
    margin-right: 12px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text);
    font: 600 12.5px var(--font-body);
    cursor: pointer;
    transition: border-color .15s ease;
}

.page-documents .field-file::file-selector-button:hover {
    border-color: var(--accent-line);
}
