:root {
    --bg: #f3ede2;
    --bg-strong: #eadfce;
    --surface: #fffdfa;
    --surface-strong: #fff7eb;
    --line: rgba(22, 51, 63, 0.12);
    --line-strong: rgba(22, 51, 63, 0.22);
    --ink: #16333f;
    --ink-soft: #5b6e78;
    --accent: #0f7c6d;
    --accent-strong: #0b5e53;
    --warning: #b74d29;
    --shadow: 0 20px 60px rgba(18, 40, 47, 0.12);
    --radius-xl: 30px;
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;
}

[data-theme="dark"] {
    --bg: #0f1923;
    --bg-strong: #1a2530;
    --surface: #1e2d3a;
    --surface-strong: #243545;
    --line: rgba(255, 255, 255, 0.10);
    --line-strong: rgba(255, 255, 255, 0.18);
    --ink: #e8edf0;
    --ink-soft: #8fa3b0;
    --accent: #1ab8a6;
    --accent-strong: #0f9484;
    --warning: #e06840;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.40);
}

[data-theme="dark"] body {
    background: linear-gradient(180deg, #0f1923 0%, #1a2530 100%);
}

html[data-theme="dark"]::before,
html[data-theme="iv"]::before {
    display: none;
}

[data-theme="iv"] {
    --bg: #162018;
    --bg-strong: #1c2a1e;
    --surface: #1e2e20;
    --surface-strong: #243626;
    --line: rgba(185, 145, 30, 0.20);
    --line-strong: rgba(185, 145, 30, 0.35);
    --ink: #f0e8d0;
    --ink-soft: rgba(240, 232, 208, 0.55);
    --accent: #c9a227;
    --accent-strong: #a88520;
    --warning: #e06840;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.50);
}

[data-theme="iv"] body {
    background: linear-gradient(180deg, #162018 0%, #1c2a1e 100%);
}

html {
    scroll-behavior: smooth;
    touch-action: pan-y pinch-zoom;
}

* {
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

[x-cloak] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "IBM Plex Sans", sans-serif;
    color: var(--ink);
    /* Solid base colour — the decorative gradient lives on html::before (fixed/GPU layer) */
    background: linear-gradient(180deg, #f5f0e8 0%, #efe6d8 100%);
}

/* Decorative corner gradients promoted to their own composited layer so they
   never repaint during scroll. */
html::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at top left,  rgba(15, 124, 109, 0.14), transparent 30%),
        radial-gradient(circle at top right, rgba(183, 77, 41,  0.12), transparent 28%);
    pointer-events: none;
    z-index: -1;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
.ghost-button,
.primary-button,
.accent-button {
    border: none;
    border-radius: 999px;
    padding: 0.8rem 1.2rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

button:hover,
.ghost-button:hover,
.primary-button:hover,
.accent-button:hover {
    transform: translateY(-1px);
}

button[disabled],
.ghost-button[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.primary-button {
    background: linear-gradient(135deg, #0f7c6d, #14615c);
    color: #fff;
    box-shadow: 0 14px 28px rgba(15, 124, 109, 0.28);
}

.accent-button {
    background: linear-gradient(135deg, #cc6a3d, #b74d29);
    color: #fff;
    box-shadow: 0 14px 28px rgba(183, 77, 41, 0.22);
}

.ghost-button,
.icon-button {
    background: rgba(255, 255, 255, 0.7);
    color: var(--ink);
    border: 1px solid var(--line);
}

.ghost-button.is-active {
    background: rgba(15, 124, 109, 0.14);
    border-color: rgba(15, 124, 109, 0.4);
    color: var(--teal, #0f7c6d);
}

.icon-button {
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.35rem;
}

.page-shell {
    padding: 24px;
}

.site-header,
.toolbar-card,
.card,
.auth-panel {
    backdrop-filter: blur(16px);
}

.site-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    padding: 22px 24px;
    margin-bottom: 22px;
    background: rgba(255, 252, 247, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.site-header h1,
.panel-header h2,
.panel-header h3,
.auth-panel h2 {
    margin: 0;
    font-family: "Space Grotesk", sans-serif;
    letter-spacing: -0.03em;
}

.eyebrow {
    margin: 0 0 8px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--ink-soft);
}

.site-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-links {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.nav-links a {
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    background: rgba(15, 124, 109, 0.08);
    color: var(--accent-strong);
}

.nav-link-with-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

.user-badge {
    display: grid;
    gap: 0.15rem;
    padding: 0.5rem 0.85rem;
    border-radius: 18px;
    background: rgba(22, 51, 63, 0.06);
}

.flash {
    margin-bottom: 18px;
    padding: 16px 18px;
    border-radius: 18px;
    box-shadow: 0 10px 24px rgba(22, 51, 63, 0.08);
}

.flash-success {
    background: rgba(15, 124, 109, 0.12);
    color: var(--accent-strong);
}

.flash-error {
    background: rgba(183, 77, 41, 0.12);
    color: var(--warning);
}

.card,
.toolbar-card {
    background: rgba(255, 252, 247, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.toolbar-card {
    padding: 20px;
    margin-bottom: 20px;
}

.toolbar-grid {
    display: grid;
    grid-template-columns: minmax(250px, 2fr) minmax(340px, 2fr) auto;
    gap: 14px;
    align-items: start;
}

.toolbar-filters-collapsible {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.toolbar-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.search-active-filters {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 4px;
    align-items: center;
}

.strict-mode-label {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-direction: row;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--ink-soft);
    grid-column: 1 / -1;
}

.strict-mode-label input[type="checkbox"] {
    width: 1em;
    height: 1em;
    cursor: pointer;
    pointer-events: auto;
    accent-color: var(--accent);
}

.strict-sep {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--ink-soft);
    padding: 0 1px;
}

.strict-hint {
    font-size: 0.75rem;
    color: var(--ink-soft);
    font-style: italic;
}

.workspace-grid {
    display: grid;
    grid-template-columns: 280px minmax(0, 1.4fr) minmax(320px, 0.9fr);
    gap: 20px;
    align-items: start;
}

.card {
    padding: 18px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: start;
    margin-bottom: 16px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    border-radius: 999px;
    background: rgba(15, 124, 109, 0.1);
    color: var(--accent-strong);
    font-size: 0.82rem;
}

.chip.muted {
    background: rgba(22, 51, 63, 0.08);
    color: var(--ink-soft);
}

.chip.chip--dim {
    background: rgba(22, 51, 63, 0.06);
    color: var(--ink-soft);
}

button.chip {
    appearance: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.12s;
}

button.chip:hover {
    opacity: 0.75;
}

.tag-cloud-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 20px 0;
}

.tag-cloud-group {
    padding-bottom: 14px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--line);
}

.tag-cloud-group:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.tag-cloud-group-header {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin: 14px 0 0;
}

.tag-cloud-group .tag-cloud-chips {
    margin: 10px 0 0;
}

.tag-cloud-modal {
    overflow-x: hidden;
}

.tag-cloud-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 16px;
}

@media (max-width: 760px) {
    .tag-cloud-modal {
        padding: 20px 16px;
    }

    .tag-cloud-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .tag-cloud-footer > div {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .tag-cloud-footer button {
        width: 100%;
        justify-content: center;
    }
}

.system-chip {
    background: rgba(183, 77, 41, 0.12);
    color: var(--warning);
}

.folder-panel,
.list-panel,
.detail-panel {
    min-height: 640px;
}

.folder-tree,
.folder-subtree {
    list-style: none;
    margin: 0;
    padding: 0;
}

.folder-node {
    list-style: none;
    margin: 2px 0;
}

.folder-subtree {
    margin-left: 16px;
}

.folder-link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 0.85rem;
    margin-bottom: 6px;
    border-radius: 16px;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.folder-link:hover {
    background: rgba(15, 124, 109, 0.08);
}

.folder-row:hover > .folder-link {
    background: rgba(15, 124, 109, 0.08);
}

.folder-link.is-active {
    background: linear-gradient(135deg, rgba(15, 124, 109, 0.16), rgba(15, 124, 109, 0.08));
    color: var(--accent-strong);
}

.folder-glyph {
    color: var(--ink-soft);
}

.table-wrap {
    overflow: auto;
    border-radius: 20px;
    border: 1px solid var(--line);
}

.document-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
    background: rgba(255, 255, 255, 0.56);
}

.document-table th,
.document-table td {
    padding: 0.95rem 1rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.document-table th {
    position: sticky;
    top: 0;
    background: rgba(234, 223, 206, 0.92);
    z-index: 1;
    font-size: 0.84rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-soft);
}

.document-table tr.is-selected {
    background: rgba(15, 124, 109, 0.08);
}

.document-link {
    display: inline-block;
    font-weight: 600;
    margin-bottom: 4px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.document-table .col-name {
    width: 99%;
}

.document-table .col-compact {
    white-space: nowrap;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.document-table .chip {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
}

.document-table a.chip:hover {
    opacity: 0.8;
}

.document-table a.chip.is-active-tag {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.document-table .tag-strip {
    max-width: 160px;
}

.tag-strip {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

textarea.auto-resize {
    resize: none;
    overflow: hidden;
    min-height: 2.4em;
}

.doc-extra-details {
    margin-top: 8px;
}

.doc-extra-summary {
    cursor: pointer;
    font-size: 1rem;
    color: var(--ink-soft, #6b7280);
    padding: 6px 0;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.doc-extra-summary::before {
    content: '▸';
    font-size: 0.85rem;
    transition: transform 0.15s ease;
}

.doc-extra-details[open] .doc-extra-summary::before {
    transform: rotate(90deg);
}

.preview-surface {
    margin-bottom: 16px;
    min-height: 360px;
    border-radius: 22px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, #fbf6ee, #efe1d0);
}

.preview-surface.is-fullscreen {
    border-radius: 0 !important;
    background: #0a1920 !important;
    margin-bottom: 0 !important;
}

.preview-surface.is-fullscreen .img-zoom-wrap {
    position: absolute !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
}

.preview-surface.is-fullscreen .image-preview {
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    max-width: 100% !important;
    min-height: 0 !important;
    object-fit: contain !important;
}

.preview-surface.is-fullscreen .pdf-preview {
    position: absolute !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
}

.preview-fs-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0 10px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--surface-strong);
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.8rem;
    white-space: nowrap;
}

.preview-fs-btn:hover {
    background: var(--surface-hover, var(--line));
}

.pdf-preview,
.image-preview {
    width: 100%;
    min-height: 360px;
    border: 0;
    display: block;
}

@media (min-width: 761px) {
    .pdf-preview {
        height: 700px;
    }
}

.pdf-preview-mobile {
    display: none;
}

.pdf-canvas {
    display: block;
}

.pdf-pages-zoom {
    width: 100%;
}

.pdf-pages-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    min-width: 320px;
}

.pdf-mobile-controls {
    display: none;
}

.pdf-mobile-controls--overlay {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    padding: 0;
    gap: 0;
}

.pdf-mobile-zoom-bar {
    position: static !important;
    transform: none !important;
    left: auto !important;
    bottom: auto !important;
}

.pdf-page-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--ink-soft);
    font-size: 0.9rem;
}

.img-zoom-wrap:has(.pdf-preview) {
    overflow: auto;
    max-height: 700px;
    align-items: flex-start;
}

.img-zoom-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 360px;
    max-height: 700px;
    overflow: hidden;
}

.image-preview {
    object-fit: contain;
    max-height: 700px;
    transform-origin: center center;
    transition: transform 0.08s ease;
    user-select: none;
    -webkit-user-drag: none;
}

.stack-form,
.detail-form,
.inline-form {
    display: grid;
    gap: 14px;
}

.split-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

label,
fieldset {
    display: grid;
    gap: 0.4rem;
}

label span,
fieldset legend {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--ink-soft);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="date"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.85);
    color: var(--ink);
}

textarea {
    resize: vertical;
}

input[readonly],
textarea[readonly] {
    background: rgba(22, 51, 63, 0.05);
    cursor: default;
    pointer-events: none;
}

.tag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    padding: 0;
    border: 0;
}

.tag-checkbox {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    padding: 0.75rem 0.85rem;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.7);
}

.tag-checkbox input {
    width: auto;
}

.preview-card {
    padding: 16px;
    margin-bottom: 18px;
    border-radius: 22px;
    background: linear-gradient(135deg, rgba(15, 124, 109, 0.08), rgba(255, 255, 255, 0.74));
    border: 1px solid rgba(15, 124, 109, 0.18);
}

.preview-table {
    display: grid;
    gap: 10px;
    margin: 14px 0;
}

.preview-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.72);
}

.preview-row.has-warning {
    background: rgba(183, 77, 41, 0.1);
}

.preview-row span,
.preview-warning,
.activity-item small,
.empty-state p,
.auth-copy,
.empty-detail p {
    color: var(--ink-soft);
}

.button-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.activity-panel {
    margin-top: 20px;
}

.activity-feed {
    display: grid;
    gap: 12px;
}

.activity-item {
    display: flex;
    gap: 0.8rem;
    padding: 0.9rem 0.95rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(22, 51, 63, 0.06);
}

.activity-dot {
    width: 10px;
    height: 10px;
    margin-top: 0.55rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #cc6a3d, #0f7c6d);
}

.empty-state,
.empty-detail {
    padding: 2rem;
    text-align: center;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

@media (max-width: 760px) {
    .empty-state {
        padding: 1.5rem 1rem;
    }
}

.auth-shell {
    min-height: calc(100vh - 48px);
    display: grid;
    place-items: center;
}

.auth-panel {
    width: min(680px, 100%);
    padding: 40px 48px;
    background: rgba(255, 251, 245, 0.88);
    border-radius: 34px;
    border: 1px solid rgba(255, 255, 255, 0.74);
    box-shadow: var(--shadow);
}

.admin-shell {
    display: grid;
    gap: 20px;
}

.admin-grid {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 20px;
}

.admin-list {
    display: grid;
    gap: 12px;
}

.admin-row {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) auto auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.72);
}

.admin-row.is-wide {
    grid-template-columns: minmax(120px, 1fr) minmax(150px, 1fr) 120px minmax(120px, 1fr) auto;
}

.admin-row-group {
    border-radius: 18px;
    overflow: hidden;
}

.admin-row-group.is-disabled {
    opacity: 0.55;
}

.admin-row-group.is-disabled:hover {
    opacity: 1;
}

.user-disabled-banner {
    padding: 4px 12px;
    background: var(--danger, #c0392b);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
}

.admin-row-actions {
    display: flex;
    gap: 8px;
    padding: 6px 12px 10px;
    background: rgba(255, 255, 255, 0.72);
}

.btn-warn {
    color: var(--warning, #e67e22) !important;
    border-color: var(--warning, #e67e22) !important;
}

.btn-enable {
    color: var(--success, #27ae60) !important;
    border-color: var(--success, #27ae60) !important;
}

.btn-danger {
    color: var(--danger, #c0392b) !important;
    border-color: var(--danger, #c0392b) !important;
}

.inline-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(15, 32, 38, 0.48);
    z-index: 50;
}

.modal-card {
    width: min(760px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    padding: 24px;
    border-radius: 28px;
    background: rgba(255, 250, 244, 0.97);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.22);
}

.mobile-helper-card {
    display: none;
}

@media (max-width: 1180px) {
    .workspace-grid,
    .admin-grid,
    .toolbar-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .toolbar-buttons {
        justify-content: flex-start;
    }

    /* No file selected: helper card first, then folder tree and list */
    .workspace-grid:not(.has-selection) .folder-panel { order: 1; }
    .workspace-grid:not(.has-selection) .list-panel   { order: 2; }
    .workspace-grid:not(.has-selection) .detail-panel { order: 3; }
    .mobile-helper-card                               { display: block; order: 0; }

    /* File selected: preview first, then list, then folder tree */
    .workspace-grid.has-selection .detail-panel { order: 1; }
    .workspace-grid.has-selection .list-panel   { order: 2; }
    .workspace-grid.has-selection .folder-panel { order: 3; }

    .search-active-filters {
        display: flex;
    }
}

@media (max-width: 760px) {
    .page-shell {
        padding: 14px;
    }

    .site-header,
    .card,
    .toolbar-card,
    .auth-panel,
    .modal-card {
        border-radius: 22px;
    }

    .folder-panel,
    .list-panel,
    .detail-panel {
        min-height: unset;
    }

    .split-fields,
    .admin-row,
    .admin-row.is-wide {
        grid-template-columns: 1fr;
    }
}

.lang-toggle {
    display: flex;
    gap: 4px;
}
.view-toggle {
    display: none;
    gap: 4px;
}
@media (max-width: 760px) {
    .view-toggle { display: flex; }
}
@media (pointer: coarse) {
    .view-toggle { display: flex; }
}
.lang-toggle form {
    margin: 0;
}
.lang-toggle .primary-button,
.lang-toggle .ghost-button,
.view-toggle .primary-button,
.view-toggle .ghost-button {
    padding: 4px 10px;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   Download Stats
═══════════════════════════════════════════════════════════════ */

.stats-shell {
    max-width: 900px;
}

/* ── Range tabs ── */

.stats-ranges {
    display: flex;
    gap: 6px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.stats-range-tab {
    padding: 0.45rem 1.1rem;
    border-radius: 999px;
    background: rgba(15, 124, 109, 0.07);
    color: var(--accent-strong);
    font-size: 0.88rem;
    transition: background 0.15s, color 0.15s;
}

.stats-range-tab:hover {
    background: rgba(15, 124, 109, 0.14);
}

.stats-range-tab.is-active {
    background: linear-gradient(135deg, #0f7c6d, #14615c);
    color: #fff;
}

/* ── Summary strip ── */

.stats-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 18px;
}

.stats-summary-box {
    background: rgba(255, 252, 247, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stats-summary-value {
    font-family: "Space Grotesk", sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--ink);
    line-height: 1;
}

.stats-summary-value small {
    font-size: 1rem;
    color: var(--ink-soft);
    font-weight: 400;
}

.stats-summary-label {
    font-size: 0.78rem;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* ── Chart table ── */

.stats-card {
    overflow: hidden;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table th,
.stats-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.stats-table thead th {
    font-size: 0.76rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
    border-bottom: 2px solid var(--line);
    padding-top: 0;
}

.stats-table tbody tr:last-child td {
    border-bottom: none;
}

.stats-table tbody tr:hover td {
    background: rgba(15, 124, 109, 0.03);
}

.stats-th-rank  { width: 38px; text-align: center; }
.stats-th-count { width: 110px; text-align: right; }
.stats-th-chart { width: 46%; }

.stats-rank {
    text-align: center;
    font-size: 0.8rem;
    color: var(--ink-soft);
    font-weight: 600;
}

.stats-name {
    font-size: 0.88rem;
    max-width: 220px;
}

.stats-name a {
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.stats-name a:hover {
    color: var(--accent);
}

/* ── Stacked bar ── */

.stats-bar-cell {
    padding-right: 18px;
}

.stat-bar-track {
    display: flex;
    height: 10px;
    border-radius: 5px;
    background: var(--bg-strong);
    overflow: hidden;
}

.stat-bar-staff {
    height: 100%;
    width: var(--pct);
    background: var(--accent);
    border-radius: 5px 0 0 5px;
    transition: width 0.35s ease;
    min-width: 0;
}

.stat-bar-guest {
    height: 100%;
    width: var(--pct);
    background: rgba(183, 77, 41, 0.72);
    border-radius: 0 5px 5px 0;
    transition: width 0.35s ease;
    min-width: 0;
}

/* ── Count column ── */

.stats-count {
    text-align: right;
    font-size: 0.9rem;
    white-space: nowrap;
}

.stats-split {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
    margin-top: 2px;
}

.stats-split-staff,
.stats-split-guest {
    font-size: 0.72rem;
    padding: 1px 6px;
    border-radius: 99px;
}

.stats-split-staff {
    background: rgba(15, 124, 109, 0.12);
    color: var(--accent-strong);
}

.stats-split-guest {
    background: rgba(183, 77, 41, 0.12);
    color: var(--warning);
}

/* ── Legend ── */

.stats-legend {
    display: flex;
    gap: 18px;
    padding: 12px 12px 0;
    font-size: 0.78rem;
    color: var(--ink-soft);
}

.stats-legend-staff::before,
.stats-legend-guest::before {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
}

.stats-legend-staff::before { background: var(--accent); }
.stats-legend-guest::before  { background: rgba(183, 77, 41, 0.72); }

/* ── Timeline legend ── */

.stats-legend-added::before,
.stats-legend-removed::before {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
}
.stats-legend-added::before   { background: var(--accent); }
.stats-legend-removed::before { background: rgba(183, 77, 41, 0.72); }

/* ── Section title ── */

.stats-section-title {
    margin: 28px 0 12px;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink);
}

/* ── Timeline chart ── */

.stats-timeline-wrap {
    display: flex;
    padding: 12px 12px 0;
    min-height: 140px;
}

.stats-y-axis {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    padding-left: 8px;
    height: 110px;
    flex-shrink: 0;
    order: 1;
}

.stats-y-axis span {
    font-size: 0.65rem;
    color: var(--ink-soft);
    line-height: 1;
}

.stats-timeline {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
}

.stats-timeline-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.stats-timeline-bars {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 110px;
    width: 100%;
    justify-content: center;
}

.stats-timeline-bar {
    width: 42%;
    max-width: 22px;
    border-radius: 3px 3px 0 0;
    height: var(--pct);
    transition: height 0.3s ease;
}

.stats-timeline-bar--added {
    background: var(--accent);
}

.stats-timeline-bar--removed {
    background: rgba(183, 77, 41, 0.72);
}

.stats-timeline-label {
    font-size: 0.68rem;
    color: var(--ink-soft);
    white-space: nowrap;
}

/* ── Per-user bars ── */

.stats-user-grid {
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    margin-bottom: 0;
}

.stats-user-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 4px 8px;
}

.stats-user-row {
    display: grid;
    grid-template-columns: 120px 1fr 52px;
    gap: 10px;
    align-items: center;
}

.stats-user-name {
    font-size: 0.85rem;
    color: var(--ink);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-user-bar-track {
    height: 10px;
    border-radius: 5px;
    background: var(--bg-strong);
    overflow: hidden;
}

.stats-user-bar {
    height: 100%;
    width: var(--pct);
    border-radius: 5px;
    transition: width 0.35s ease;
    min-width: 2px;
}

.stats-user-bar--uploads {
    background: var(--accent);
}

.stats-user-bar--changes {
    background: rgba(70, 130, 180, 0.8);
}

.stats-user-bar--reviews {
    background: rgba(130, 90, 180, 0.75);
}

.stats-timeline-bar--submissions {
    background: rgba(130, 90, 180, 0.75);
}

.stats-user-count {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink);
    text-align: right;
}

/* ── Responsive ── */

@media (max-width: 760px) {
    .stats-summary {
        grid-template-columns: 1fr 1fr;
    }

    .stats-summary-box:last-child {
        grid-column: 1 / -1;
    }

    .stats-th-chart,
    .stats-bar-cell {
        display: none;
    }

    .stats-th-count { width: auto; }

    .stats-user-grid {
        grid-template-columns: 1fr;
    }

    .stats-user-row {
        grid-template-columns: 90px 1fr 44px;
    }

    .stats-timeline-label {
        font-size: 0.6rem;
    }
}

/* ─── Animations ─────────────────────────────────────── */

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.site-header {
    animation: slideUp 380ms ease-out both;
    animation-delay: 0ms;
}

.toolbar-card {
    animation: slideUp 380ms ease-out both;
    animation-delay: 80ms;
}

.folder-panel {
    animation: slideUp 380ms ease-out both;
    animation-delay: 160ms;
}

.list-panel {
    animation: slideUp 380ms ease-out both;
    animation-delay: 200ms;
}

.detail-panel {
    animation: slideUp 380ms ease-out both;
    animation-delay: 240ms;
}

.activity-panel {
    animation: slideUp 380ms ease-out both;
    animation-delay: 300ms;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.flash {
    animation: slideDown 280ms ease-out both;
}

@keyframes rowIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.document-table tbody tr {
    animation: rowIn 280ms ease-out both;
    border-left: 3px solid transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.document-table tbody tr:nth-child(1)  { animation-delay: 0ms; }
.document-table tbody tr:nth-child(2)  { animation-delay: 25ms; }
.document-table tbody tr:nth-child(3)  { animation-delay: 50ms; }
.document-table tbody tr:nth-child(4)  { animation-delay: 75ms; }
.document-table tbody tr:nth-child(5)  { animation-delay: 100ms; }
.document-table tbody tr:nth-child(6)  { animation-delay: 125ms; }
.document-table tbody tr:nth-child(7)  { animation-delay: 150ms; }
.document-table tbody tr:nth-child(8)  { animation-delay: 175ms; }
.document-table tbody tr:nth-child(n+9) { animation-delay: 175ms; }

.document-table tbody tr:hover,
.document-table tbody tr:active {
    background: rgba(15, 124, 109, 0.06);
    border-left-color: rgba(15, 124, 109, 0.4);
}

/* Modal transition helpers (used by Alpine x-transition) */
.transition-fade-in  { transition: opacity 180ms ease-out; }
.transition-fade-out { transition: opacity 180ms ease-in; }
.opacity-0 { opacity: 0; }
.opacity-1 { opacity: 1; }

.transition-modal-in  { transition: opacity 200ms ease-out, transform 200ms ease-out; }
.transition-modal-out { transition: opacity 150ms ease-in,  transform 150ms ease-in; }
.modal-enter-start { opacity: 0; transform: scale(0.95); }
.modal-enter-end   { opacity: 1; transform: scale(1); }
.modal-leave-start { opacity: 1; transform: scale(1); }
.modal-leave-end   { opacity: 0; transform: scale(0.97); }

@media (max-width: 760px) {
    .modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }

    .modal-card {
        width: 100%;
        border-radius: 28px 28px 0 0;
        max-height: 90vh;
    }

    .modal-enter-start { opacity: 0; transform: translateY(100%); }
    .modal-enter-end   { opacity: 1; transform: translateY(0); }
    .modal-leave-start { opacity: 1; transform: translateY(0); }
    .modal-leave-end   { opacity: 0; transform: translateY(100%); }

    .transition-modal-in  { transition: opacity 220ms ease-out, transform 220ms ease-out; }
    .transition-modal-out { transition: opacity 160ms ease-in,  transform 160ms ease-in; }
}

/* ─── Pagination ─────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 16px 14px;
    border-top: 1px solid var(--border);
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    padding: 0 6px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--ink-soft);
    text-decoration: none;
    border: 1px solid transparent;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    line-height: 1;
}

.page-btn:hover {
    background: rgba(18, 40, 47, 0.06);
    color: var(--ink);
}

.page-btn.is-active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
    pointer-events: none;
}

.page-btn--nav {
    font-size: 1rem;
}

.per-page-label {
    font-size: 0.78rem;
    color: var(--ink-soft);
    white-space: nowrap;
}

.page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 30px;
    font-size: 0.82rem;
    color: var(--ink-soft);
    pointer-events: none;
}

/* ─── Soft navigation (folder change) ────────────────── */
/* Only the list panel animates; chrome + detail stay put */
html.soft-nav .site-header,
html.soft-nav .toolbar-card,
html.soft-nav .folder-panel,
html.soft-nav .detail-panel,
html.soft-nav .activity-panel {
    animation: none;
}

/* ─── Document navigation (same folder, different file) ── */
/* Handled via fetch in JS — no full page reload. These rules
   cover the rare fallback where the browser lands on a doc-nav
   URL directly (e.g. popstate reload).                          */
html.doc-nav .site-header,
html.doc-nav .toolbar-card,
html.doc-nav .folder-panel,
html.doc-nav .list-panel,
html.doc-nav .activity-panel {
    animation: none;
}

html.doc-nav .document-table tbody tr {
    animation: none;
}

html.doc-nav .detail-panel {
    animation-delay: 0ms;
}

/* ─── Accessibility & performance safeguards ─────────── */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ─── Mobile scroll performance ──────────────────────── */
/* On mobile the 60px box-shadow blur on every card is very expensive for the
   GPU. Swap it for a lighter shadow so the compositor isn't overwhelmed. */
@media (max-width: 760px) {
    .card,
    .toolbar-card,
    .modal-card,
    .preview-card {
        box-shadow: 0 2px 10px rgba(18, 40, 47, 0.10);
    }

    /* Entrance animations use opacity, which forces a compositor layer per
       element. With 20+ rows animating simultaneously the GPU runs out of
       layer budget and scroll stalls. Disable them on mobile. */
    .document-table tbody tr,
    .document-table tbody tr:nth-child(n) {
        animation: none;
        animation-delay: 0ms;
    }
}

@media (hover: none) {
    .site-header,
    .toolbar-card,
    .folder-panel,
    .list-panel,
    .detail-panel,
    .activity-panel {
        animation-duration: 260ms;
    }

    .document-table tbody tr {
        animation-duration: 195ms;
        transition-duration: 0.1s;
    }
}

/* ─── Firefox: disable backdrop-filter for scroll performance ── */
/* Firefox's backdrop-filter compositor is significantly slower than Chrome's,
   causing scroll jank on mobile. Remove the blur and use a more opaque
   background instead. @supports (-moz-appearance: none) targets Gecko only. */
@supports (-moz-appearance: none) {
    .site-header,
    .toolbar-card,
    .card,
    .auth-panel {
        backdrop-filter: none;
    }
    .site-header {
        background: rgba(255, 252, 247, 0.97);
    }
    .card,
    .toolbar-card {
        background: rgba(255, 252, 247, 0.97);
    }
}

/* ═══════════════════════════════════════════════════════════════
   Gallery
═══════════════════════════════════════════════════════════════ */

.gallery-layout {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 20px;
    align-items: start;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

.gallery-card {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(255, 252, 247, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 2px 8px rgba(18, 40, 47, 0.07);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.gallery-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(18, 40, 47, 0.12);
}

.gallery-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.gallery-name {
    font-size: 0.73rem;
    padding: 5px 8px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink-soft);
}

.eliminate-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(183, 77, 41, 0.82);
    color: #fff;
    border: none;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.12s ease, background 0.1s ease;
    backdrop-filter: blur(4px);
    padding: 0;
}

.gallery-card:hover .eliminate-btn {
    opacity: 1;
}

.eliminate-btn:hover {
    background: var(--warning);
}

@media (hover: none) {
    .eliminate-btn {
        opacity: 1;
    }
}

.gallery-card--loading {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    font-size: 0.8rem;
    color: var(--ink-soft);
    background: rgba(255, 252, 247, 0.5);
}

.gallery-exhausted {
    grid-column: 1 / -1;
    font-size: 0.82rem;
    color: var(--ink-soft);
    text-align: center;
    padding: 12px 0 0;
    margin: 0;
}

.gallery-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 40px 0;
    color: var(--ink-soft);
}

.eliminated-sidebar {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.eliminated-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0 0 12px;
    font-size: 0.88rem;
}

.count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(15, 124, 109, 0.13);
    color: var(--accent-strong);
    font-size: 0.75rem;
    font-weight: 600;
}

.eliminated-empty {
    font-size: 0.8rem;
    color: var(--ink-soft);
    margin: 0;
}

.eliminated-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--line);
}

.eliminated-item:last-of-type {
    border-bottom: none;
}

.eliminated-thumb {
    width: 38px;
    height: 38px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.eliminated-name {
    font-size: 0.78rem;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink);
}

.undo-btn {
    background: none;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 0.73rem;
    cursor: pointer;
    flex-shrink: 0;
    color: var(--ink-soft);
    transition: background 0.1s, border-color 0.1s;
}

.undo-btn:hover {
    background: var(--bg-strong);
    border-color: var(--line-strong);
}

.gallery-reset-btn {
    width: 100%;
    margin-top: 10px;
    border-radius: var(--radius-md) !important;
    font-size: 0.8rem !important;
    padding: 0.5rem 0.8rem !important;
    text-align: center;
}

/* Gallery thumb button (replaces the <a> wrapper) */
.gallery-thumb-btn {
    display: block;
    width: 100%;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

/* ─── Gallery lightbox ─────────────────────────────────────── */

.gallery-lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 25, 32, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    padding: 20px;
    backdrop-filter: blur(3px);
}

.gallery-lightbox {
    background: var(--bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
    max-width: min(960px, 100%);
    max-height: calc(100vh - 40px);
    width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.gallery-lightbox-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(18, 40, 47, 0.08);
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-soft);
    z-index: 1;
    transition: background 0.12s;
}

.gallery-lightbox-close:hover {
    background: rgba(18, 40, 47, 0.15);
    color: var(--ink);
}

.gallery-lightbox-body {
    display: flex;
    gap: 0;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.gallery-lightbox-img-wrap {
    flex: 1 1 60%;
    background: #1a2830;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    overflow: hidden;
}

.gallery-lightbox-img {
    max-width: 100%;
    max-height: calc(100vh - 80px);
    object-fit: contain;
    display: block;
    transform-origin: center center;
    transition: transform 0.08s ease;
    user-select: none;
    -webkit-user-drag: none;
}

.gallery-zoom-bar {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(10, 25, 32, 0.7);
    backdrop-filter: blur(6px);
    border-radius: 999px;
    padding: 4px 10px;
}

.gallery-zoom-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s;
}

.gallery-zoom-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
}

.gallery-zoom-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.gallery-zoom-btn--active {
    background: rgba(15, 124, 109, 0.7);
    color: #fff;
}

.gallery-zoom-level {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.85);
    min-width: 38px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.gallery-lightbox-meta {
    flex: 0 0 280px;
    padding: 52px 24px 24px;
    overflow-y: auto;
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.gallery-lightbox-name {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    word-break: break-word;
    color: var(--ink);
    line-height: 1.35;
}

.gallery-lightbox-dl {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.gallery-lightbox-dl > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.gallery-lightbox-dl dt {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
    font-weight: 600;
}

.gallery-lightbox-dl dd {
    font-size: 0.88rem;
    color: var(--ink);
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.gallery-lightbox-link {
    align-self: flex-start;
    font-size: 0.82rem !important;
    padding: 0.4rem 0.9rem !important;
}

@media (max-width: 640px) {
    .gallery-lightbox-body {
        flex-direction: column;
        overflow-y: auto;
    }
    .gallery-lightbox-img-wrap {
        flex: 0 0 auto;
        max-height: 50vh;
    }
    .gallery-lightbox-meta {
        flex: 1;
        border-left: none;
        border-top: 1px solid var(--line);
        padding-top: 16px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Quiz
═══════════════════════════════════════════════════════════════ */

.quiz-shell {
    max-width: 560px;
    margin: 0 auto;
}

.quiz-card {
    background: rgba(255, 252, 247, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    padding: 32px;
}

.quiz-eyebrow {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--ink-soft);
    margin: 0 0 8px;
}

.quiz-image {
    width: 100%;
    max-height: 380px;
    object-fit: contain;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    background: var(--bg-strong);
}

.quiz-answers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px;
}

.quiz-answer-btn {
    padding: 14px 16px;
    border: 2px solid var(--line);
    border-radius: var(--radius-md);
    background: rgba(255, 252, 247, 0.7);
    font-size: 0.88rem;
    cursor: pointer;
    text-align: left;
    color: var(--ink);
    transition: border-color 0.14s, background 0.14s, transform 0.14s;
    line-height: 1.3;
}

.quiz-answer-btn:hover {
    border-color: rgba(15, 124, 109, 0.5);
    background: rgba(15, 124, 109, 0.06);
    transform: translateY(-1px);
}

.quiz-progress {
    display: flex;
    gap: 6px;
    margin-bottom: 20px;
}

.quiz-progress-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--line-strong);
}

.quiz-progress-dot.is-done   { background: var(--accent); }
.quiz-progress-dot.is-active { background: var(--accent-strong); }

.quiz-score {
    font-size: 2.8rem;
    font-weight: 700;
    font-family: "Space Grotesk", sans-serif;
    color: var(--accent-strong);
    line-height: 1;
    margin: 12px 0 6px;
}

.quiz-result-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    font-size: 0.84rem;
}

.quiz-result-table th,
.quiz-result-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.quiz-result-table th {
    font-weight: 600;
    color: var(--ink-soft);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.quiz-result-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    vertical-align: middle;
}

.quiz-correct { color: #15803d; font-weight: 600; }
.quiz-wrong   { color: var(--warning); }

.quiz-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
}

@media (max-width: 1180px) {
    .gallery-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .gallery-layout {
        grid-template-columns: 1fr;
    }
    .eliminated-sidebar {
        position: static;
        max-height: none;
    }
}

@media (max-width: 760px) {
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .quiz-answers {
        grid-template-columns: 1fr;
    }
}

body {
    background:
        radial-gradient(circle at top left, rgba(15, 124, 109, 0.14), transparent 30%),
        radial-gradient(circle at top right, rgba(183, 77, 41, 0.12), transparent 28%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-strong) 100%);
}

.theme-toggle,
.login-theme-toggle {
    display: flex;
    gap: 4px;
    align-items: center;
}

.theme-toggle button,
.login-theme-toggle button {
    padding: 0.45rem 0.7rem;
    font-size: 0.78rem;
    min-width: 0;
}

.login-theme-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 100;
}

.site-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.site-logo {
    height: 100%;
    max-height: 64px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.login-logo {
    max-height: 80px;
    width: auto;
    display: block;
    margin: 0 auto 24px;
    object-fit: contain;
}

.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 24px;
    background: var(--surface);
    border-top: 1px solid var(--line-strong);
    font-size: 0.82rem;
    color: var(--ink-soft);
    z-index: 200;
    box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.12);
}

.cookie-banner-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
}

.cookie-banner-text strong {
    color: var(--ink);
    font-size: 0.88rem;
}

.cookie-banner-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.cookie-banner button {
    padding: 0.35rem 0.9rem;
    font-size: 0.78rem;
    flex-shrink: 0;
}

.cookie-opted-out {
    font-size: 0.75rem;
    color: var(--ink-soft);
    font-style: italic;
}

.text-muted {
    color: var(--ink-soft);
}

.divider {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 24px 0;
}

.branding-slot {
    display: grid;
    gap: 14px;
}

.branding-slot h3 {
    margin: 0;
}

.branding-preview {
    max-height: 96px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    padding: 12px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: var(--surface-strong);
}

.folder-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 6px;
}

.folder-row > .folder-link {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.folder-row.is-active > .folder-link {
    font-weight: 600;
    color: var(--accent-strong);
    background: linear-gradient(135deg, rgba(15, 124, 109, 0.16), rgba(15, 124, 109, 0.08));
}

.folder-chevron-btn {
    background: none;
    border: none;
    padding: 2px 4px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--ink-soft);
    box-shadow: none;
}

.folder-chevron-btn:hover {
    background: var(--line);
    transform: none;
}

.folder-chevron {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    transition: transform 0.15s ease, background-color 0.15s ease;
    opacity: 0.8;
    cursor: pointer;
    flex-shrink: 0;
}

.folder-chevron::after {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 9px solid currentColor;
    transition: transform 0.15s ease;
}

.folder-chevron:hover {
    background: var(--line);
    opacity: 1;
}

.folder-chevron.is-open::after {
    transform: rotate(90deg);
}

.folder-chevron-spacer {
    display: inline-block;
    width: 28px;
    flex-shrink: 0;
}

.folder-action-btn {
    background: none;
    border: none;
    padding: 2px 5px;
    cursor: pointer;
    color: var(--ink-soft);
    font-size: 0.85rem;
    border-radius: 4px;
    opacity: 0.5;
    transition: opacity 0.1s ease, background-color 0.1s ease, color 0.1s ease;
    flex-shrink: 0;
    box-shadow: none;
}

.folder-row:hover .folder-action-btn,
.folder-row.is-active .folder-action-btn,
.folder-reorder-controls .folder-action-btn {
    opacity: 1;
}

.folder-reorder-toggle {
    background: none;
    border: 1px solid var(--line);
    padding: 4px 8px;
    cursor: pointer;
    color: var(--ink-soft);
    font-size: 1rem;
    border-radius: 6px;
    flex-shrink: 0;
    line-height: 1;
    box-shadow: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.folder-reorder-toggle:hover {
    background: var(--line);
    color: var(--accent);
}

.folder-action-btn:hover {
    background: var(--line);
    color: var(--accent);
    transform: none;
}

.folder-delete-btn {
    color: var(--warning);
    font-size: 1rem;
    line-height: 1;
}

.folder-delete-btn:hover {
    color: var(--warning);
    background: rgba(183, 77, 41, 0.12);
}

.folder-rename-input {
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 6px 8px;
    font: inherit;
    font-size: 0.85rem;
    background: var(--surface);
    color: var(--ink);
    min-width: 120px;
    flex: 1;
    outline: none;
}

.site-header,
.toolbar-card,
.card,
.auth-panel,
.modal-card,
.stats-summary-box,
.gallery-card,
.quiz-card,
.ghost-button,
.icon-button,
.document-table,
.activity-item,
.admin-row,
.tag-checkbox,
.preview-row,
.preview-card,
.branding-preview,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="date"],
input[type="file"],
select,
textarea {
    color: var(--ink);
}

.site-header,
.toolbar-card,
.card,
.auth-panel,
.modal-card,
.stats-summary-box,
.gallery-card,
.quiz-card {
    background: var(--surface);
    border-color: var(--line);
}

.ghost-button,
.icon-button,
.activity-item,
.admin-row,
.tag-checkbox,
.preview-row,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="date"],
input[type="file"],
select,
textarea {
    background: var(--surface);
    border-color: var(--line);
}

.preview-card,
.preview-surface {
    background: linear-gradient(180deg, var(--surface-strong), var(--surface));
    border-color: var(--line);
}

.document-table {
    background: var(--surface);
}

.document-table th {
    background: var(--bg-strong);
}

.nav-links a,
.user-badge {
    background: var(--surface-strong);
}

.nav-links a {
    color: var(--accent-strong);
}

.user-badge,
.preview-row span,
.preview-warning,
.activity-item small,
.empty-state p,
.auth-copy,
.empty-detail p,
.per-page-label,
.page-ellipsis {
    color: var(--ink-soft);
}

.primary-button {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    box-shadow: 0 14px 28px rgba(15, 124, 109, 0.28);
}

[data-theme="dark"] .primary-button,
[data-theme="iv"] .primary-button {
    box-shadow: none;
}

/* ═══════════════════════════════════════════════════════════════
   Hamburger menu button — hidden on desktop, visible on mobile
═══════════════════════════════════════════════════════════════ */

.hamburger-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 12px;
    background: rgba(15, 124, 109, 0.08);
    border: 1px solid var(--line);
    color: var(--ink);
    cursor: pointer;
    flex-shrink: 0;
}

.site-header-top {
    display: contents;
}

/* ═══════════════════════════════════════════════════════════════
   Mobile collapsible <details> — transparent on desktop
═══════════════════════════════════════════════════════════════ */

.mobile-collapse {
    display: contents;
}

.mobile-collapse-toggle {
    cursor: default;
    list-style: none;
}

.mobile-collapse-toggle::-webkit-details-marker,
.mobile-collapse-toggle::marker {
    display: none;
    content: '';
}

/* ═══════════════════════════════════════════════════════════════
   Mobile responsive — max 760px
═══════════════════════════════════════════════════════════════ */

@media (max-width: 760px) {
    .cookie-banner {
        flex-direction: column;
        align-items: stretch;
        padding: 12px 14px;
    }

    /* ── Header: hamburger + collapsible nav ── */

    .site-header {
        flex-direction: column;
        padding: 14px 16px;
        gap: 0;
        margin-bottom: 12px;
    }

    .site-header-top {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: center;
    }

    .hamburger-btn {
        display: flex;
    }

    .site-header h1 {
        font-size: 1.15rem;
    }

    .site-header .eyebrow {
        font-size: 0.7rem;
        margin-bottom: 4px;
    }

    .site-actions {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        width: 100%;
        padding-top: 14px;
        margin-top: 14px;
        border-top: 1px solid var(--line);
    }

    .site-actions.is-open {
        display: flex;
    }

    .nav-links {
        flex-direction: column;
        gap: 4px;
    }

    .nav-links a {
        padding: 0.55rem 0.85rem;
        text-align: left;
    }

    .theme-toggle {
        align-self: flex-start;
    }

    .lang-toggle {
        align-self: flex-start;
    }

    .user-badge {
        padding: 0.4rem 0;
    }

    .site-logo {
        max-height: 32px;
    }

    /* ── Toolbar: compact layout ── */

    .toolbar-card {
        padding: 12px;
        margin-bottom: 12px;
    }

    .toolbar-grid {
        gap: 10px;
    }

    .toolbar-filters-collapsible {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .toolbar-buttons {
        gap: 6px;
    }

    .toolbar-buttons .ghost-button,
    .toolbar-buttons .primary-button,
    .toolbar-buttons .accent-button {
        padding: 0.55rem 0.85rem;
        font-size: 0.82rem;
    }

    /* ── Panels: no forced min-height, tighter padding ── */

    .folder-panel,
    .list-panel,
    .detail-panel {
        min-height: 0;
    }

    .card {
        padding: 14px;
        border-radius: 18px;
    }

    .panel-header {
        margin-bottom: 10px;
    }

    .panel-header h2 {
        font-size: 1.1rem;
    }

    /* ── Collapsible sections on mobile ── */

    .mobile-collapse {
        display: block;
    }

    .mobile-collapse-toggle {
        cursor: pointer;
        position: relative;
        padding-right: 28px;
    }

    .mobile-collapse-toggle::after {
        content: '';
        position: absolute;
        right: 4px;
        top: 50%;
        transform: translateY(-50%) rotate(45deg);
        width: 8px;
        height: 8px;
        border-right: 2px solid var(--ink-soft);
        border-bottom: 2px solid var(--ink-soft);
        transition: transform 0.2s ease;
    }

    details.mobile-collapse[open] > .mobile-collapse-toggle::after {
        transform: translateY(-30%) rotate(-135deg);
    }

    /* Folder panel collapsed = just the summary visible */
    .folder-panel .mobile-collapse > .folder-tree,
    .folder-panel .mobile-collapse > .folder-link {
        /* shown only when <details> is open — handled natively */
    }

    /* ── Workspace grid: single column ── */

    .workspace-grid {
        gap: 12px;
    }

    /* ── Document table: compact ── */

    .document-table th,
    .document-table td {
        padding: 0.65rem 0.7rem;
        font-size: 0.85rem;
    }

    /* ── Detail panel: compact form ── */

    .stack-form,
    .detail-form,
    .inline-form {
        gap: 10px;
    }

    .preview-surface {
        min-height: 300px;
        border-radius: 16px;
    }

    .pdf-preview,
    .image-preview {
        min-height: 300px;
    }

    .pdf-preview-desktop {
        display: none !important;
    }

    .pdf-preview-mobile {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        padding: 0.5rem 0;
        gap: 0.75rem;
    }

    .pdf-mobile-controls {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
        padding: 0.5rem 0;
    }

    /* ── Activity panel: starts collapsed ── */

    .activity-panel {
        margin-top: 4px;
    }

    .activity-panel .panel-header {
        margin-bottom: 0;
    }

    .activity-panel details.mobile-collapse[open] .panel-header {
        margin-bottom: 10px;
    }

    /* ── Chips and eyebrows: smaller ── */

    .chip {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }

    .eyebrow {
        font-size: 0.7rem;
        margin-bottom: 4px;
    }

    /* ── Buttons: prevent hover lift on touch ── */

    button:hover,
    .ghost-button:hover,
    .primary-button:hover,
    .accent-button:hover {
        transform: none;
    }

    /* ── Flash messages ── */

    .flash {
        margin-bottom: 12px;
        padding: 12px 14px;
        border-radius: 14px;
        font-size: 0.88rem;
    }

    /* ── Modal: full width bottom sheet ── */

    .modal-card {
        border-radius: 22px 22px 0 0;
        max-height: 85vh;
        overflow-y: auto;
    }
}
