/* ============================================================
   Documents page — white + orange logo palette (see theme.css)
   ============================================================ */

/* ── Page layout ─────────────────────────────────────────── */
.documents-section {
    padding: 40px 0 70px;
    background: #FAFAF9;
    min-height: calc(100vh - 200px);
}

/* Bootstrap container stops at 1170px. From 1280px up, use more of the viewport
   so the document list is not boxed in by large side margins. */
@media (min-width: 1280px) {
    .documents-section > .container {
        width: calc(100% - 40px);
        max-width: 1800px;
    }
}

/* ── Page header ─────────────────────────────────────────── */
.documents-page-header {
    margin-bottom: 28px;
}
.documents-page-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: #0A0A0A;
    margin: 0 0 4px;
}
.documents-page-header p {
    font-size: 14px;
    color: #78716C;
    margin: 0;
}

/* ── Card ────────────────────────────────────────────────── */
.doc-card {
    background: var(--surface, #FFFFFF);
    border-radius: var(--radius-lg, 8px);
    border: 1px solid var(--border, #E8E4E1);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(28, 25, 23, 0.06));
    padding: 28px 28px 24px;
    margin-bottom: 24px;
}
.doc-card h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #1C1917);
    margin: 0 0 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border, #E8E4E1);
}
.doc-card h3 i {
    margin-right: 8px;
    color: #EF6C2F;
}

/* Collapsible card header (upload) */
.doc-card-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    margin: 0 0 20px;
    padding: 0 0 12px;
    border: none;
    border-bottom: 2px solid #E8E4E1;
    background: transparent;
    cursor: pointer;
    text-align: left;
}
.doc-card-toggle:hover .doc-card-toggle-icon {
    color: #EF6C2F;
}
.doc-card-toggle:focus {
    outline: none;
}
.doc-card-toggle:focus-visible {
    outline: 2px solid #EF6C2F;
    outline-offset: 4px;
    border-radius: 4px;
}
.doc-card-toggle h3 {
    margin: 0;
    padding: 0;
    border: none;
    flex: 1;
}
.doc-card-toggle-icon {
    flex-shrink: 0;
    font-size: 13px;
    color: #78716C;
    transition: transform .2s ease, color .2s;
}
.doc-card.is-collapsed .doc-card-toggle {
    margin-bottom: 0;
}
.doc-card.is-collapsed .doc-card-toggle-icon {
    transform: rotate(180deg);
}
.doc-card-body {
    overflow: hidden;
    transition: opacity .15s ease;
}
.doc-card.is-collapsed .doc-card-body {
    display: none;
}

/* ── Upload zone ─────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed #E8E4E1;
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
    background: #FAFAF9;
    position: relative;
}
.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary, #EF6C2F);
    background: var(--primary-light, #FFF4ED);
}
.upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}
.upload-zone-icon {
    font-size: 42px;
    color: #E8E4E1;
    margin-bottom: 12px;
    transition: color .2s;
}
.upload-zone:hover .upload-zone-icon,
.upload-zone.dragover .upload-zone-icon {
    color: #EF6C2F;
}
.upload-zone-text {
    font-size: 15px;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
}
.upload-zone-hint {
    font-size: 12px;
    color: #999;
}
.upload-zone-hint strong {
    color: #EF6C2F;
}

/* Selected file info */
.upload-selected-file {
    margin-top: 16px;
    display: none;
    align-items: center;
    gap: 10px;
    background: #FFF4ED;
    border: 1px solid #FDCAB0;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 13px;
    color: #EF6C2F;
}
.upload-selected-file i {
    font-size: 16px;
}
.upload-selected-file .file-name {
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.upload-selected-file .file-size {
    color: #78716C;
    white-space: nowrap;
}
.upload-clear-btn {
    background: none;
    border: none;
    color: #D4551A;
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
}
.upload-clear-btn:hover { color: #EF6C2F; }

/* Upload actions */
.upload-actions {
    margin-top: 16px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary-doc {
    background: var(--primary, #EF6C2F);
    color: #FFFFFF;
    border: 1px solid var(--primary, #EF6C2F);
    border-radius: var(--radius-md, 6px);
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, border-color .2s;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.btn-primary-doc:hover { background: var(--primary-dark, #D4551A); border-color: var(--primary-dark, #D4551A); }
.btn-primary-doc:disabled { opacity: .55; cursor: not-allowed; }

.btn-secondary-doc {
    background: var(--surface, #FFFFFF);
    color: var(--text-primary, #1C1917);
    border: 1px solid var(--border-strong, #D6D3D1);
    border-radius: var(--radius-md, 6px);
    padding: 9px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.btn-secondary-doc:hover {
    background: var(--primary-light, #FFF4ED);
    border-color: var(--primary, #EF6C2F);
    color: var(--primary, #EF6C2F);
}
.btn-secondary-doc:disabled { opacity: .55; cursor: not-allowed; }

.btn-icon-doc {
    background: none;
    border: 1px solid #E8E4E1;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    color: #555;
    transition: all .2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-icon-doc:hover { border-color: #EF6C2F; color: #EF6C2F; }
.btn-icon-doc.btn-danger:hover { border-color: #D4551A; color: #D4551A; }
.btn-icon-doc.btn-delete-doc:hover { border-color: #C0392B; color: #C0392B; background: #FDECEA; }

/* ── Alert / messages ────────────────────────────────────── */
.doc-alert {
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
    align-items: center;
    gap: 8px;
}
.doc-alert i { font-size: 15px; }
.doc-alert.error   { background: #FDECEA; border: 1px solid #F5C2C0; color: #C0392B; display: flex; }
.doc-alert.success { background: #E8F5E9; border: 1px solid #A7D7B0; color: #198754; display: flex; }
.doc-alert.info    { background: #FAFAF9; border: 1px solid #E8E4E1; color: #0A0A0A; display: flex; }

/* ── Upload progress ─────────────────────────────────────── */
.upload-progress-wrap {
    margin-top: 12px;
    display: none;
}
.upload-progress-label {
    font-size: 12px;
    color: #555;
    margin-bottom: 5px;
}
.progress {
    height: 8px;
    background: #E8E4E1;
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #EF6C2F, #F83838);
    border-radius: 4px;
    transition: width .3s ease;
    width: 0%;
}

/* ── Documents table ─────────────────────────────────────── */
.doc-table-wrap {
    overflow-x: auto;
}
.doc-table-wrap.has-open-menu {
    overflow: visible;
}
.doc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
/* Size, date and actions stay as wide as their content; the name column takes the rest. */
.doc-table th:nth-child(2),
.doc-table td:nth-child(2),
.doc-table th:nth-child(3),
.doc-table td:nth-child(3),
.doc-table th:nth-child(4),
.doc-table td:nth-child(4) {
    width: 1%;
    white-space: nowrap;
}
.doc-table th {
    background: var(--surface-muted, #F5F5F4);
    padding: 11px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary, #78716C);
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 1px solid var(--border, #E8E4E1);
    white-space: nowrap;
}
.doc-table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border, #E8E4E1);
    color: var(--text-primary, #1C1917);
    vertical-align: middle;
}
.doc-table tr:last-child td { border-bottom: none; }
.doc-table tr:hover td { background: var(--primary-light, #FFF4ED); }

/* File type icon cell */
.doc-type-icon {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    color: #FFFFFF;
    flex-shrink: 0;
}
.doc-type-icon.type-pdf  { background: #C0392B; }
.doc-type-icon.type-doc  { background: #2563EB; }
.doc-type-icon.type-docx { background: #2563EB; }
.doc-type-icon.type-json { background: #D97706; }
.doc-type-icon.type-xml  { background: #57534E; }
.doc-type-icon.type-txt  { background: #78716C; }
.doc-type-icon.type-img  { background: #198754; }
.doc-type-icon.type-other{ background: #78716C; }

/* File name cell */
.doc-name-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.doc-file-name {
    font-weight: 600;
    color: #0A0A0A;
    flex: 1;
    min-width: 0;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.doc-file-name small {
    display: block;
    font-weight: 400;
    color: #999;
    font-size: 11px;
}

/* Actions cell */
.doc-actions {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    align-items: center;
    position: relative;
}

/* Overflow menu (Premesti / Obriši) */
.doc-actions-more {
    position: relative;
    flex: 0 0 auto;
}
.doc-actions-more .btn-more-doc {
    min-width: 36px;
    justify-content: center;
    padding: 6px 10px;
}
.doc-actions-more .btn-more-doc .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}
.doc-actions-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 40;
    min-width: 160px;
    padding: 6px;
    background: #FFFFFF;
    border: 1px solid #E8E4E1;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    display: none;
    flex-direction: column;
    gap: 2px;
}
.doc-actions-more.is-open .doc-actions-menu {
    display: flex;
}
.doc-actions-menu[hidden] {
    display: none !important;
}
.doc-actions-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #555;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.doc-actions-menu-item:hover {
    background: #FAFAF9;
    color: #EF6C2F;
}
.doc-actions-menu-item.btn-delete-doc:hover {
    background: #FFF4ED;
    color: #c0392b;
}
.doc-actions-menu-item i {
    width: 14px;
    text-align: center;
}

/* ── Empty state ─────────────────────────────────────────── */
.doc-empty-state {
    text-align: center;
    padding: 48px 28px 52px;
    color: #78716C;
    max-width: 420px;
    margin: 0 auto;
}
.doc-empty-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 18px;
    border-radius: 50%;
    background: linear-gradient(160deg, #FFF4ED 0%, #FAFAF9 100%);
    border: 1px solid #E8E4E1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.doc-empty-icon i {
    font-size: 28px;
    color: #EF6C2F;
    opacity: .85;
    display: block;
    margin: 0;
}
.doc-empty-state.is-error .doc-empty-icon {
    background: #FFF4ED;
    border-color: #FDCAB0;
}
.doc-empty-state.is-error .doc-empty-icon i {
    color: #D4551A;
    opacity: 1;
}
.doc-empty-title {
    font-size: 16px;
    font-weight: 700;
    color: #0A0A0A;
    margin: 0 0 8px;
    line-height: 1.3;
}
.doc-empty-text {
    font-size: 14px;
    color: #78716C;
    margin: 0;
    line-height: 1.5;
}
.doc-empty-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 22px;
}
.doc-empty-actions .btn-primary-doc,
.doc-empty-actions .btn-secondary-doc {
    min-height: 38px;
    padding: 8px 16px;
    font-size: 13px;
}

/* Hide column headers when list is empty */
.doc-table-wrap.is-empty .doc-table thead {
    display: none;
}
.doc-table-wrap.is-empty .doc-table {
    border: none;
}
.doc-table tr.doc-table-message td {
    border: none !important;
    padding: 0;
}

/* ── Loader ──────────────────────────────────────────────── */
.doc-spinner {
    text-align: center;
    padding: 36px 20px;
    color: #999;
    font-size: 14px;
}
.doc-spinner i {
    font-size: 24px;
    display: block;
    margin-bottom: 8px;
    color: #EF6C2F;
}

/* ── Preview modal ───────────────────────────────────────── */
.doc-preview-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}
.doc-preview-overlay.open {
    display: flex;
}
.doc-preview-modal {
    background: #FFFFFF;
    border-radius: 8px;
    width: 92vw;
    max-width: 960px;
    height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,.25);
    overflow: hidden;
}
.doc-preview-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px 12px 20px;
    border-bottom: 1px solid #E8E4E1;
    background: #FFFFFF;
    flex-shrink: 0;
}
.doc-preview-header h4 {
    flex: 1;
    min-width: 0;
    font-size: 15px;
    font-weight: 700;
    color: #0A0A0A;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.doc-preview-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
}
.doc-preview-header .preview-download-btn,
.doc-preview-close {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    line-height: 1;
    transition: background .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.doc-preview-header .preview-download-btn {
    background: #EF6C2F;
    color: #FFFFFF;
    border: 1px solid #EF6C2F;
    box-shadow: 0 6px 16px rgba(239, 108, 47, .22);
    text-decoration: none;
}
.doc-preview-header .preview-download-btn:hover,
.doc-preview-header .preview-download-btn:focus {
    background: #D4551A;
    border-color: #D4551A;
    color: #FFFFFF;
    box-shadow: 0 8px 20px rgba(239, 108, 47, .28);
    transform: translateY(-1px);
}
.doc-preview-close {
    background: #FAFAF9;
    border: 1px solid #E8E4E1;
    color: #555;
}
.doc-preview-close:hover,
.doc-preview-close:focus {
    background: #FFFFFF;
    border-color: #EF6C2F;
    color: #EF6C2F;
    box-shadow: 0 6px 16px rgba(0, 0, 0, .10);
    transform: translateY(-1px);
}
.doc-preview-header .preview-download-btn:focus,
.doc-preview-close:focus {
    outline: none;
}
.doc-preview-header .preview-download-btn:focus-visible,
.doc-preview-close:focus-visible {
    outline: 2px solid rgba(239, 108, 47, .35);
    outline-offset: 2px;
}

/* Preview content area */
.doc-preview-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #FAFAF9;
}

/* PDF / iframe (desktop native viewer) */
.doc-preview-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* PDF.js canvas stack (mobile / no native inline PDF) */
.doc-preview-pdfjs {
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    background: #525252;
    padding: 8px;
    box-sizing: border-box;
}
.doc-preview-pdfjs .pdf-page {
    display: block;
    margin: 0 auto 8px;
    max-width: 100%;
    height: auto;
    background: #FFFFFF;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

/* Image preview (JPG / PNG / GIF / WEBP) */
.doc-preview-image-wrap {
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    box-sizing: border-box;
    background: #2a2a2a;
}
.doc-preview-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* Text / JSON / XML */
.doc-preview-body pre {
    margin: 0;
    padding: 20px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #1C1917;
    background: #FFFFFF;
    height: 100%;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    box-sizing: border-box;
}

/* Preview loading state */
.doc-preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #FAFAF9;
    color: #999;
    font-size: 14px;
    gap: 12px;
}
.doc-preview-loading i {
    font-size: 32px;
    color: #EF6C2F;
}

/* Preview error state */
.doc-preview-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #EF6C2F;
    font-size: 14px;
    gap: 12px;
    background: #FFFFFF;
    padding: 20px;
    text-align: center;
}
.doc-preview-error i {
    font-size: 40px;
    opacity: .6;
}

/* ── Content type badge ──────────────────────────────────── */
.doc-mime-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .3px;
    background: #FAFAF9;
    color: #555;
}

/* ── Pagination ──────────────────────────────────────────── */
.doc-pagination {
    margin-top: 16px;
    display: flex;
    justify-content: center;
    gap: 6px;
}
.doc-page-btn {
    width: 34px;
    height: 34px;
    border: 1px solid #E8E4E1;
    background: #FFFFFF;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all .15s;
}
.doc-page-btn:hover { border-color: #EF6C2F; color: #EF6C2F; }
.doc-page-btn.active { background: #EF6C2F; color: #FFFFFF; border-color: #EF6C2F; }
.doc-page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Upload zone — mobile/desktop copy swap */
.upload-text-mobile { display: none; }
.upload-text-desktop { display: inline; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 767px) {
    .documents-section {
        padding: 20px 0 48px;
    }

    .documents-page-header {
        margin-bottom: 18px;
    }
    .documents-page-header h2 {
        font-size: 18px;
        line-height: 1.3;
    }
    .documents-page-header p {
        font-size: 13px;
    }

    .doc-card {
        padding: 16px 14px;
        margin-bottom: 16px;
        border-radius: 10px;
    }
    .doc-card h3 {
        font-size: 15px;
        margin-bottom: 14px;
        padding-bottom: 10px;
    }
    .doc-card-toggle {
        margin-bottom: 14px;
        padding-bottom: 10px;
    }
    .doc-card-toggle h3 {
        margin-bottom: 0;
        padding-bottom: 0;
    }
    .doc-card.is-collapsed .doc-card-toggle {
        margin-bottom: 0;
    }

    /* Upload zone */
    .upload-zone {
        padding: 28px 16px;
        min-height: 140px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    .upload-zone-icon { font-size: 36px; }
    .upload-zone-text { font-size: 14px; }
    .upload-text-desktop { display: none; }
    .upload-text-mobile { display: inline; }
    .upload-zone-hint { font-size: 11px; line-height: 1.4; padding: 0 8px; }

    .upload-selected-file {
        flex-wrap: wrap;
        gap: 8px;
    }
    .upload-selected-file .file-name {
        flex: 1 1 100%;
        white-space: normal;
        word-break: break-word;
        order: 1;
    }
    .upload-clear-btn {
        padding: 8px;
        font-size: 16px;
        min-width: 36px;
        min-height: 36px;
    }

    .upload-actions { margin-top: 14px; }
    .upload-actions .btn-primary-doc {
        width: 100%;
        justify-content: center;
        padding: 14px 20px;
        font-size: 15px;
        min-height: 48px;
        border-radius: 6px;
    }

    /* ── Document list as cards (no horizontal scroll) ── */
    .doc-table-wrap {
        overflow: visible;
        margin: 0 -2px;
    }
    .doc-table,
    .doc-table tbody {
        display: block;
        width: 100%;
    }
    .doc-table thead {
        display: none;
    }
    .doc-table tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px 10px;
        background: #FFFFFF;
        border: 1px solid #E8E4E1;
        border-radius: 10px;
        padding: 14px;
        margin-bottom: 10px;
        box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    }
    .doc-table tr:last-child {
        margin-bottom: 0;
    }
    .doc-table tr:hover td {
        background: transparent;
    }
    .doc-table td {
        display: block;
        border: none;
        padding: 0;
        width: auto;
    }
    /* Name — full width */
    .doc-table td:nth-child(1) {
        flex: 1 1 100%;
        min-width: 0;
    }
    /* Size + date as compact meta */
    .doc-table td:nth-child(2),
    .doc-table td:nth-child(3) {
        flex: 0 0 auto;
        font-size: 12px;
        color: #78716C;
        line-height: 1.4;
    }
    .doc-table td:nth-child(2)::after {
        content: ' ·';
        color: #ccc;
        margin-left: 2px;
    }
    /* Message rows (loading / empty / error) */
    .doc-table tr.doc-table-message {
        display: block;
        border: none;
        box-shadow: none;
        padding: 8px 0;
        background: transparent;
    }
    .doc-table tr.doc-table-message td {
        width: 100%;
    }
    /* Actions — full width row */
    .doc-table td:nth-child(4) {
        flex: 1 1 100%;
        margin-top: 4px;
        padding-top: 10px;
        border-top: 1px solid #F5F5F4;
        overflow: visible;
        position: relative;
        z-index: 1;
    }
    .doc-table tr:has(.doc-actions-more.is-open) {
        z-index: 5;
        position: relative;
    }

    .doc-name-cell {
        gap: 12px;
        min-width: 0;
    }
    .doc-file-name {
        max-width: none;
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
        word-break: break-word;
        font-size: 14px;
        line-height: 1.35;
    }
    .doc-file-name small {
        margin-top: 2px;
        word-break: break-all;
    }
    .doc-type-icon {
        width: 40px;
        height: 40px;
        font-size: 13px;
    }

    .doc-actions {
        display: flex;
        gap: 8px;
        width: 100%;
        align-items: stretch;
    }
    .doc-actions > .btn-icon-doc {
        flex: 1;
        justify-content: center;
        min-height: 44px;
        padding: 10px 8px;
        font-size: 13px;
        border-radius: 6px;
        background: #FAFAF9;
        border-color: #E8E4E1;
    }
    .doc-actions-more {
        flex: 0 0 auto;
    }
    .doc-actions-more .btn-more-doc {
        flex: none;
        min-width: 44px;
        min-height: 44px;
        padding: 10px 12px;
        border-radius: 6px;
        background: #FAFAF9;
        border-color: #E8E4E1;
    }
    .doc-actions-menu {
        right: 0;
        left: auto;
        min-width: 180px;
    }
    .doc-actions .btn-icon-doc span {
        display: inline;
    }
    .doc-actions .btn-icon-doc i {
        font-size: 14px;
    }

    /* Very narrow phones — icon-only primary actions */
    @media (max-width: 360px) {
        .doc-actions > .btn-icon-doc span { display: none; }
        .doc-actions > .btn-icon-doc { min-width: 44px; }
    }

    .doc-empty-state {
        padding: 36px 16px 40px;
    }
    .doc-empty-icon {
        width: 64px;
        height: 64px;
        margin-bottom: 14px;
    }
    .doc-empty-icon i {
        font-size: 24px;
    }
    .doc-empty-title {
        font-size: 15px;
    }
    .doc-empty-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .doc-empty-actions .btn-primary-doc,
    .doc-empty-actions .btn-secondary-doc {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    /* Pagination — larger touch targets */
    .doc-pagination {
        gap: 8px;
        flex-wrap: wrap;
        margin-top: 14px;
    }
    .doc-page-btn {
        width: 40px;
        height: 40px;
        border-radius: 6px;
        font-size: 14px;
    }

    /* Preview modal */
    .doc-preview-modal {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        border-radius: 0;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .doc-preview-header {
        flex-wrap: nowrap;
        gap: 10px;
        padding: 10px 12px;
        min-height: 58px;
    }
    .doc-preview-header h4 {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 14px;
    }
    .doc-preview-header > i {
        display: none;
    }
    .doc-preview-actions {
        gap: 7px;
        margin-left: auto;
    }
    .doc-preview-header .preview-download-btn {
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
    }
    .doc-preview-close {
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
        font-size: 15px;
    }

    /* Dialog modals */
    .doc-modal {
        width: calc(100vw - 24px);
        max-width: none;
        border-radius: 10px;
    }
    .doc-modal-header {
        padding: 14px 16px 10px;
    }
    .doc-modal-body {
        padding: 14px 16px;
    }
    .doc-modal-body input,
    .doc-modal-body select {
        font-size: 16px; /* avoids iOS zoom on focus */
        min-height: 44px;
        padding: 10px 12px;
    }
    .doc-modal-footer {
        flex-direction: column-reverse;
        gap: 8px;
        padding: 12px 16px 16px;
    }
    .doc-modal-footer .btn-primary-doc,
    .doc-modal-footer .btn-secondary-doc {
        width: 100%;
        justify-content: center;
        min-height: 44px;
        padding: 12px 16px;
    }

    .doc-filter-bar {
        padding: 10px 12px;
    }
    .doc-filter-clear {
        margin-left: auto;
        padding: 8px 10px;
        min-height: 36px;
        font-size: 13px;
    }
}

/* ============================================================
   Folder sidebar & tree — FirstCode documents
   ============================================================ */

/* ── Main layout: sidebar + content ─────────────────────── */
.doc-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}
.doc-sidebar {
    width: 280px;
    flex-shrink: 0;
}
.doc-main {
    flex: 1;
    min-width: 0;
}

/* ── Folder sidebar card ─────────────────────────────────── */
.doc-sidebar-card {
    background: var(--surface, #FFFFFF);
    border-radius: var(--radius-lg, 8px);
    border: 1px solid var(--border, #E8E4E1);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(28, 25, 23, 0.06));
    overflow: hidden;
}
.doc-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--border, #E8E4E1);
    background: var(--surface-muted, #F5F5F4);
}
.doc-sidebar-header span {
    font-size: 13px;
    font-weight: 700;
    color: #0A0A0A;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.doc-sidebar-new-btn {
    background: none;
    border: 1px solid #E8E4E1;
    border-radius: 4px;
    color: #EF6C2F;
    cursor: pointer;
    font-size: 13px;
    padding: 3px 8px;
    line-height: 1.4;
    transition: all .15s;
}
.doc-sidebar-new-btn:hover {
    background: #FFF4ED;
    border-color: #EF6C2F;
}

/* ── Folder tree ─────────────────────────────────────────── */
.doc-folder-tree {
    list-style: none;
    margin: 0;
    padding: 8px 4px 12px;
    max-height: min(70vh, 640px);
    overflow-y: auto;
    overflow-x: hidden;
    background: #f4f7fb;
}
.doc-folder-tree ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.doc-folder-tree > li {
    margin: 0;
}
.doc-tree-node {
    position: relative;
}

/* Tree node row */
.doc-tree-row {
    display: flex;
    align-items: center;
    padding: 5px 8px 5px 2px;
    cursor: pointer;
    transition: background .12s, color .12s;
    border-radius: 6px;
    margin: 1px 4px;
    gap: 6px;
    position: relative;
    min-height: 30px;
}
.doc-tree-row:hover {
    background: rgba(255,255,255,0.7);
}
.doc-tree-row.active {
    background: #e8f3fc;
    color: #2f80ed;
}
.doc-tree-row.active .doc-tree-label {
    font-weight: 600;
    color: #2f80ed;
}

/* Collapse toggle */
.doc-tree-toggle {
    background: none;
    border: none;
    padding: 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
    color: #9aa3b2;
    font-size: 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: color .12s, background .12s, transform .15s;
}
.doc-tree-toggle:hover {
    color: #5c6778;
    background: rgba(255,255,255,0.8);
}
.doc-tree-toggle.open { transform: rotate(90deg); }
.doc-tree-toggle-spacer { width: 16px; flex-shrink: 0; }

/* Folder icon */
.doc-tree-icon {
    font-size: 15px;
    flex-shrink: 0;
    width: 16px;
    text-align: center;
    color: #8b95a7;
}
.doc-tree-row.active .doc-tree-icon { color: #2f80ed; }

/* Label */
.doc-tree-label {
    font-size: 13px;
    color: #4b5563;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

/* Folder actions (hover) */
.doc-tree-actions {
    display: none;
    gap: 1px;
    flex-shrink: 0;
}
.doc-tree-row:hover .doc-tree-actions,
.doc-tree-row:focus-within .doc-tree-actions { display: flex; }
.doc-tree-action-btn {
    background: none;
    border: none;
    padding: 3px 5px;
    cursor: pointer;
    font-size: 12px;
    color: #999;
    border-radius: 3px;
    line-height: 1;
    transition: all .12s;
}
.doc-tree-action-btn:hover { background: #ebebeb; color: #0A0A0A; }
.doc-tree-action-btn.danger:hover { background: #FDECEA; color: #C0392B; }

/* Children: nested list with a dotted guide */
.doc-tree-children {
    display: none;
    margin: 0 4px 2px 11px;
    padding: 1px 0 2px 10px;
    border-left: 1px dashed #c5ced9;
}
.doc-tree-children.open { display: block; }
.doc-tree-children .doc-tree-row {
    margin-left: 0;
    margin-right: 0;
}
.doc-tree-children .doc-tree-children {
    margin-left: 12px;
}

/* Special nodes (All / Root) stay in the existing red treatment */
.doc-tree-row.special .doc-tree-icon { color: #EF6C2F; }
.doc-tree-row.special.active {
    background: #fff0f0;
    color: #EF6C2F;
}
.doc-tree-row.special.active .doc-tree-icon,
.doc-tree-row.special.active .doc-tree-label {
    color: #EF6C2F;
    font-weight: 700;
}
.doc-folder-tree > li:nth-child(2) {
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid #F5F5F4;
}

/* Top-level folders that contain subfolders stay slightly larger and flush left */
.doc-folder-tree > li.has-children > .doc-tree-row {
    margin-left: 2px;
    padding: 7px 8px 7px 0;
    min-height: 36px;
    gap: 7px;
}
.doc-folder-tree > li.has-children > .doc-tree-row .doc-tree-icon {
    font-size: 17px;
    width: 18px;
    color: #6b7686;
}
.doc-folder-tree > li.has-children > .doc-tree-row .doc-tree-label {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}
.doc-folder-tree > li.has-children > .doc-tree-row.active .doc-tree-icon,
.doc-folder-tree > li.has-children > .doc-tree-row.active .doc-tree-label {
    color: #2f80ed;
}
.doc-folder-tree > li.has-children > .doc-tree-children {
    margin-left: 14px;
}

/* ── Folder filter breadcrumb ────────────────────────────── */
.doc-filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 10px 14px;
    font-size: 13px;
    color: #555;
    flex-wrap: wrap;
    background: #fff8f8;
    border: 1px solid #E8E4E1;
    border-radius: 8px;
}
.doc-filter-bar > i.fa-filter { color: #EF6C2F; flex-shrink: 0; }
.doc-filter-name {
    font-weight: 700;
    color: #0A0A0A;
}
.doc-filter-clear {
    background: none;
    border: none;
    color: #EF6C2F;
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    margin-left: auto;
    transition: all .12s;
    opacity: .85;
}
.doc-filter-clear:hover {
    background: #fff0f0;
    opacity: 1;
}

/* ── Modals (lightweight custom) ─────────────────────────── */
.doc-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 10500;
    align-items: center;
    justify-content: center;
}
.doc-modal-overlay.open { display: flex; }
.doc-modal {
    background: #FFFFFF;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
    width: 92vw;
    max-width: 420px;
    overflow: hidden;
}
.doc-modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px 12px;
    border-bottom: 1px solid #E8E4E1;
}
.doc-modal-header h4 {
    flex: 1;
    font-size: 15px;
    font-weight: 700;
    color: #0A0A0A;
    margin: 0;
}
.doc-modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #aaa;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}
.doc-modal-close:hover { color: #0A0A0A; }
.doc-modal-body {
    padding: 18px 20px;
}
.doc-modal-body label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: #666;
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-bottom: 6px;
}
.doc-modal-body input,
.doc-modal-body select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #E8E4E1;
    border-radius: 4px;
    font-size: 14px;
    color: #1C1917;
    transition: border-color .15s;
    box-sizing: border-box;
}
.doc-modal-body input:focus,
.doc-modal-body select:focus {
    outline: none;
    border-color: #EF6C2F;
}
.doc-modal-body input.is-invalid { border-color: #D4551A; }
.doc-modal-body .invalid-feedback {
    font-size: 12px;
    color: #D4551A;
    margin-top: 4px;
    display: none;
}
.doc-modal-body .invalid-feedback.show { display: block; }
.doc-modal-body p {
    font-size: 13px;
    color: #555;
    margin: 0 0 4px;
}
.doc-modal-body p strong { color: #0A0A0A; }
.doc-modal-hint {
    font-size: 12px;
    color: #999;
    margin-top: 6px !important;
}
.doc-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px 16px;
    border-top: 1px solid #E8E4E1;
}

/* ── My documents (account list) ─────────────────────────── */
.my-docs-card { margin-bottom: 0; }
.my-docs-card .doc-table td:first-child {
    width: 100%;
    max-width: 0;
}
.my-docs-card .doc-file-name small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.my-docs-lead {
    margin: -8px 0 18px;
    font-size: 13px;
    color: #78716C;
}
.my-docs-search {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.my-docs-search input {
    flex: 1 1 220px;
    max-width: 420px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid #E8E4E1;
    border-radius: 4px;
    font-size: 14px;
    color: #1C1917;
    background: #FFFFFF;
    box-sizing: border-box;
}
.my-docs-search input:focus {
    outline: none;
    border-color: #EF6C2F;
}
.doc-page-ellipsis {
    padding: 0 4px;
    line-height: 34px;
    color: #aaa;
}

/* ── Responsive sidebar ──────────────────────────────────── */
@media (max-width: 991px) {
    .doc-sidebar { width: 240px; }
}

@media (max-width: 767px) {
    .doc-layout {
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
    }
    .doc-sidebar,
    .doc-main { width: 100%; }
    .doc-sidebar-card {
        margin-bottom: 0;
        border-radius: 10px;
    }
    .doc-sidebar-header {
        padding: 12px 14px;
    }
    .doc-sidebar-new-btn {
        min-width: 36px;
        min-height: 36px;
        padding: 6px 10px;
        font-size: 14px;
    }

    /* Keep vertical tree on mobile so subfolders stay visible */
    .doc-folder-tree {
        max-height: min(50vh, 360px);
        padding: 6px 0 10px;
    }
    .doc-tree-row {
        min-height: 40px;
        padding: 8px 10px;
        margin: 1px 8px;
        border-radius: 8px;
    }
    .doc-folder-tree > li.has-children > .doc-tree-row {
        margin-left: 2px;
        padding-left: 0;
        min-height: 42px;
    }
    .doc-folder-tree > li.has-children > .doc-tree-children {
        margin-left: 16px;
    }
    .doc-tree-toggle,
    .doc-tree-toggle-spacer {
        width: 20px;
        height: 20px;
        font-size: 13px;
    }
    .doc-tree-children {
        margin-left: 14px;
        padding-left: 12px;
    }
    .doc-tree-label {
        font-size: 14px;
        max-width: none;
    }

    /* Keep rename/delete reachable on touch (no hover) */
    .doc-tree-actions {
        display: flex !important;
        gap: 2px;
    }
    .doc-tree-action-btn {
        min-width: 32px;
        min-height: 32px;
        padding: 6px;
        font-size: 13px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 767px) {
    .my-docs-search {
        flex-direction: column;
        align-items: stretch;
    }
    .my-docs-search input {
        flex: 0 0 auto;
        max-width: none;
        width: 100%;
        height: 44px;
        min-height: 44px;
        font-size: 16px;
    }
    .my-docs-card .doc-table td:first-child {
        max-width: none;
        width: auto;
    }
    .doc-table td:nth-child(2),
    .doc-table td:nth-child(3) {
        width: auto;
        max-width: 100%;
        white-space: nowrap;
    }
    .my-docs-search .btn-primary-doc {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }
}

/* ── Folder permissions (ADMIN) ───────────────────────────────────────── */

.doc-modal-wide {
    max-width: 560px;
    width: 94%;
    /* Native <select> popups mis-position when a rounded parent clips overflow
       (common in Chromium/Electron). Keep corners via header/footer only. */
    overflow: visible;
}

.doc-modal-wide .doc-modal-header {
    border-radius: 8px 8px 0 0;
}

.doc-modal-wide .doc-modal-footer {
    border-radius: 0 0 8px 8px;
}

.doc-modal-wide .perm-modal-body {
    overflow: visible;
}

.doc-tree-perm-badge {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1;
}

.doc-tree-perm-badge.perm-read {
    color: #2f80ed;
    background: rgba(47, 128, 237, 0.1);
}

.doc-tree-perm-badge.perm-write {
    color: #b7791f;
    background: rgba(183, 121, 31, 0.12);
}

.doc-tree-perm-badge.perm-delete {
    color: #EF6C2F;
    background: rgba(239, 108, 47, 0.1);
}

.perm-modal-body {
    padding-top: 16px;
    padding-bottom: 8px;
}

.perm-folder-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 10px;
}

.perm-folder-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: #999;
}

.perm-folder-name {
    font-size: 15px;
    color: #0A0A0A;
    word-break: break-word;
}

.perm-legend {
    list-style: none;
    margin: 0 0 4px;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
}

.perm-legend li {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #666;
    margin: 0;
}

.perm-chip {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .03em;
    color: #1A5C2A;
    background: rgba(26, 92, 42, 0.1);
    border-radius: 3px;
    padding: 2px 6px;
    line-height: 1.3;
}

.perm-legend-note {
    font-size: 12px !important;
    color: #999 !important;
    margin: 0 0 14px !important;
}

.perm-section {
    margin-bottom: 16px;
}

.perm-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: #666;
    margin-bottom: 8px;
}

.perm-grants-list {
    margin: 0;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #E8E4E1;
    border-radius: 6px;
    background: #FAFAFA;
}

.perm-empty {
    padding: 16px 14px;
    font-size: 13px;
    color: #888;
    text-align: center;
}

.perm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: #fff;
}

.perm-table th,
.perm-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #EFEFEF;
    text-align: left;
    vertical-align: middle;
}

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

.perm-table th {
    color: #999;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #F7F7F7;
    border-bottom: 1px solid #E8E4E1;
}

.perm-col-actions {
    width: 40px;
    text-align: right !important;
}

.perm-principal {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.perm-principal-kind {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #999;
}

.perm-principal strong {
    font-size: 13px;
    color: #0A0A0A;
    word-break: break-all;
}

.perm-modal-body .perm-level-select,
.perm-modal-body .perm-select {
    width: auto;
    max-width: 100%;
    height: 36px;
    min-height: 36px;
    padding: 0 10px;
    border: 1px solid #E8E4E1;
    border-radius: 4px;
    font-size: 13px;
    line-height: 34px;
    color: #1C1917;
    background: #fff;
    box-sizing: border-box;
    vertical-align: middle;
}

.perm-modal-body .perm-level-select {
    min-width: 108px;
}

.perm-remove-btn {
    border: none;
    background: transparent;
    color: #C0392B;
    cursor: pointer;
    padding: 6px 8px;
    font-size: 14px;
    line-height: 1;
    border-radius: 4px;
}

.perm-remove-btn:hover {
    color: #922B21;
    background: rgba(192, 57, 43, 0.08);
}

.perm-add-section {
    margin-bottom: 16px;
    position: relative;
    z-index: 2;
}

.perm-add-controls {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
    position: relative;
    z-index: 2;
}

.perm-select-wrap {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
}

.perm-modal-body .perm-select-type {
    flex: 0 0 110px;
    width: 110px;
}

.perm-modal-body .perm-select-target {
    flex: 1 1 auto;
    width: 100%;
    min-width: 120px;
}

.perm-modal-body .perm-select-level {
    flex: 0 0 108px;
    width: 108px;
}

.perm-add-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    height: 36px;
    padding: 0 14px;
}

@media (max-width: 575px) {
    .perm-add-controls {
        flex-wrap: wrap;
    }

    .perm-modal-body .perm-select-type,
    .perm-modal-body .perm-select-level,
    .perm-select-wrap,
    .perm-add-btn {
        flex: 1 1 100%;
        width: 100%;
    }

    .perm-modal-body .perm-select-type,
    .perm-modal-body .perm-select-level,
    .perm-modal-body .perm-select-target,
    .perm-modal-body .perm-level-select {
        width: 100%;
        min-height: 44px;
        height: 44px;
        line-height: 42px;
        font-size: 16px;
        padding: 0 12px;
    }

    .perm-add-btn {
        justify-content: center;
        min-height: 44px;
        height: 44px;
    }
}
