/* ==========================================================================
   xDocket Matter Documents File Manager
   Phase I - UI Foundation Refactor
   ========================================================================== */

:root {
    --docfm-bg-page: linear-gradient(180deg, #f5f8fc 0%, #eef3f8 100%);
    --docfm-bg-panel: #ffffff;
    --docfm-bg-muted: #f3f6fb;
    --docfm-bg-hover: #eef5ff;
    --docfm-bg-selected: #e7f0ff;
    --docfm-border: #d6dfeb;
    --docfm-border-strong: #c2cddd;
    --docfm-text: #17212f;
    --docfm-text-muted: #5a687b;
    --docfm-text-soft: #7a8899;
    --docfm-primary: #0b57d0;
    --docfm-primary-strong: #0a4db8;
    --docfm-danger: #c53a3a;
    --docfm-shadow-sm: 0 1px 2px rgba(14, 30, 53, 0.08);
    --docfm-shadow-md: 0 8px 24px rgba(15, 35, 64, 0.08);
    --docfm-shadow-lg: 0 14px 30px rgba(18, 42, 74, 0.14);
    --docfm-radius-sm: 8px;
    --docfm-radius-md: 12px;
    --docfm-radius-lg: 16px;
}

.documents-content.docfm-shell {
    background: var(--docfm-bg-page);
    border-radius: var(--docfm-radius-lg);
    border: 1px solid #d9e2ef;
    overflow: hidden;
    box-shadow: var(--docfm-shadow-sm);
    --docfm-grid-col-width: 128px;
    --docfm-grid-gap-x: 0.5rem;
    --docfm-grid-gap-y: 0.75rem;
}

.documents-content.docfm-shell[data-density="comfortable"] {
    --docfm-grid-col-width: 148px;
    --docfm-grid-gap-x: 0.85rem;
}

.file-manager-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.875rem;
    padding: 0.85rem 1rem;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: saturate(140%) blur(5px);
    border-bottom: 1px solid var(--docfm-border);
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.docfm-discovery-controls {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.docfm-search-input,
.docfm-sort-select {
    height: 34px;
    border: 1px solid var(--docfm-border);
    border-radius: 9px;
    background: #fff;
    color: var(--docfm-text);
    font-size: 12.5px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.docfm-search-input {
    min-width: 220px;
    padding: 0 0.75rem;
}

.docfm-sort-select {
    padding: 0 0.6rem;
}

.docfm-search-input:focus,
.docfm-sort-select:focus {
    outline: none;
    border-color: #a9c3ea;
    box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.12);
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-width: 34px;
    height: 34px;
    padding: 0 0.6rem;
    border: 1px solid var(--docfm-border);
    border-radius: 9px;
    background: var(--docfm-bg-panel);
    color: var(--docfm-text-muted);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.toolbar-btn:hover:not(:disabled) {
    background: var(--docfm-bg-hover);
    border-color: #b8c9e2;
    color: var(--docfm-text);
    transform: translateY(-1px);
}

.toolbar-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.toolbar-btn:focus-visible,
.action-btn:focus-visible,
.action-btn-sm:focus-visible,
.path-segment:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.2);
}

.toolbar-btn-primary {
    background: linear-gradient(180deg, #2f73de 0%, #0b57d0 100%);
    border-color: #0b57d0;
    color: #fff;
}

.toolbar-btn-primary:hover:not(:disabled) {
    background: linear-gradient(180deg, #2367d1 0%, #0a4db8 100%);
    border-color: #0a4db8;
    color: #fff;
}

.toolbar-btn i {
    font-size: 17px;
}

.toolbar-separator {
    width: 1px;
    height: 22px;
    background: var(--docfm-border);
    margin: 0 0.1rem;
}

.folder-path-bar {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    min-width: 260px;
    max-width: 560px;
    padding: 0.3rem;
    border-radius: 10px;
    border: 1px solid var(--docfm-border);
    background: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
    overflow-x: auto;
    white-space: nowrap;
}

.folder-path-bar::-webkit-scrollbar {
    height: 4px;
}

.folder-path-bar::-webkit-scrollbar-thumb {
    background: #ccd6e6;
    border-radius: 999px;
}

.path-segment {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.34rem 0.55rem;
    border-radius: 7px;
    font-size: 12.5px;
    line-height: 1;
    color: var(--docfm-text-muted);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

.path-segment:hover {
    background: var(--docfm-bg-hover);
    color: var(--docfm-text);
}

.path-segment.drag-over {
    background: var(--docfm-bg-selected);
    box-shadow: inset 0 0 0 2px var(--docfm-primary);
}

.path-segment.root {
    color: var(--docfm-text);
    font-weight: 600;
}

.path-segment i {
    font-size: 14px;
}

.path-separator {
    color: #8d99aa;
    font-size: 11px;
    margin: 0 0.05rem;
}

.view-toggle-group {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.density-toggle-group {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.view-toggle-group .btn-check {
    display: none;
}

.toolbar-btn-view span {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.view-toggle-group .btn-check:checked + .toolbar-btn {
    background: #e9f1ff;
    border-color: #b8cff7;
    color: #103b8c;
}

.density-btn.is-active {
    background: #e9f1ff;
    border-color: #b8cff7;
    color: #103b8c;
}

.bulk-actions-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.22rem 0.75rem;
    border-bottom: 1px solid var(--docfm-border);
    background: linear-gradient(180deg, #eef4ff 0%, #e7f0ff 100%);
}

.bulk-actions-left,
.bulk-actions-right {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.bulk-actions-count {
    font-size: 11.5px;
    font-weight: 700;
    color: #1f3d7a;
}

.bulk-actions-bar .toolbar-btn {
    height: 28px;
    min-width: 28px;
    padding: 0 0.42rem;
    border-radius: 7px;
    font-size: 12.5px;
}

.bulk-actions-bar .toolbar-btn i {
    font-size: 14px;
}

.operation-feedback-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    padding: 0.5rem 0.95rem;
    border-bottom: 1px solid var(--docfm-border);
    background: #f8fbff;
}

.operation-feedback-left,
.operation-feedback-right {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.operation-feedback-text {
    font-size: 12px;
    color: var(--docfm-text-muted);
    font-weight: 600;
}

.file-manager-content {
    background: var(--docfm-bg-panel);
    min-height: 430px;
    max-height: 620px;
    overflow: auto;
    padding: 1rem;
}

.documents-grid.drag-over-root {
    box-shadow: inset 0 0 0 2px rgba(11, 87, 208, 0.35);
    border-radius: var(--docfm-radius-md);
    background-image: linear-gradient(180deg, rgba(231, 240, 255, 0.55) 0%, rgba(231, 240, 255, 0.15) 100%);
}

.documents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 0.75rem;
}

/* Keep icon columns tight and left-aligned (Finder/Explorer-like) */
.documents-content.docfm-shell .documents-grid {
    grid-template-columns: repeat(auto-fill, minmax(var(--docfm-grid-col-width), var(--docfm-grid-col-width)));
    justify-content: start;
    gap: var(--docfm-grid-gap-y) var(--docfm-grid-gap-x);
}

/* Prevent legacy matter-documents card spacing from leaking into file manager items */
.documents-content.docfm-shell .document-item {
    justify-content: flex-start;
    min-height: 0;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
}

.document-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    min-height: 138px;
    padding: 0.8rem 0.75rem;
    border: 1px solid transparent;
    border-radius: var(--docfm-radius-md);
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.document-item.folder-item {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
}

.document-item:not(.folder-item) {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

.document-item:hover {
    background: #f8fbff;
    border-color: #d8e5f5;
    box-shadow: inset 0 0 0 1px rgba(11, 87, 208, 0.08);
    transform: none;
}

.document-item:focus-visible,
.folder-row:focus-visible,
.document-row:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px rgba(11, 87, 208, 0.4), var(--docfm-shadow-md);
}

.document-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.document-item.drag-over {
    background: var(--docfm-bg-selected);
    border: 2px dashed var(--docfm-primary);
    outline: 2px solid rgba(11, 87, 208, 0.45);
    outline-offset: -2px;
    box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.18), var(--docfm-shadow-lg);
}

.document-item.is-selected {
    border-color: #7ea6e2;
    background: linear-gradient(180deg, #f8fbff 0%, #eff5ff 100%);
    box-shadow: inset 0 0 0 2px rgba(11, 87, 208, 0.14), var(--docfm-shadow-md);
}

/* Ensure selected document cards remain visibly selected even with base !important resets */
.document-item.is-selected:not(.folder-item) {
    border: 1px solid #7ea6e2 !important;
    background: linear-gradient(180deg, #f8fbff 0%, #eff5ff 100%) !important;
    box-shadow: inset 0 0 0 2px rgba(11, 87, 208, 0.2), var(--docfm-shadow-md) !important;
}

/* Folder cards are baseline borderless; restore a clear selected state in grid view. */
.document-item.folder-item.is-selected {
    border: 1px solid #7ea6e2 !important;
    background: linear-gradient(180deg, #f8fbff 0%, #eff5ff 100%) !important;
    box-shadow: inset 0 0 0 2px rgba(11, 87, 208, 0.2), var(--docfm-shadow-md) !important;
}

.document-item.drag-over .folder-icon {
    color: var(--docfm-primary);
    animation: docfm-pulse 0.65s ease-in-out infinite;
}

.document-item:not(.folder-item).drag-over {
    background: #fff;
    border: 1px solid var(--docfm-border) !important;
    outline: none;
    box-shadow: 0 1px 0 rgba(21, 33, 49, 0.04);
}

.docfm-drag-ghost {
    position: fixed;
    top: -9999px;
    left: -9999px;
    pointer-events: none;
    z-index: -1;
    padding: 0.3rem 0.55rem;
    border-radius: 999px;
    border: 1px solid rgba(11, 87, 208, 0.35);
    background: rgba(236, 244, 255, 0.98);
    color: #0c3e84;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.01em;
    box-shadow: 0 4px 10px rgba(11, 87, 208, 0.2);
}

@keyframes docfm-pulse {
    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.08);
    }
}

.document-icon-wrapper {
    position: relative;
    margin-bottom: 0.35rem;
}

.documents-content.docfm-shell .document-icon-wrapper {
    margin-bottom: 0.18rem;
}

.folder-icon,
.file-icon {
    font-size: 42px;
}

.folder-icon {
    color: #1b76d1;
}

.file-icon {
    color: #6a7686;
}

.file-type-pdf {
    color: #cc3344;
}

.file-type-doc {
    color: #235abf;
}

.file-type-sheet {
    color: #1f8a4c;
}

.file-type-slide {
    color: #dd6b20;
}

.file-type-image {
    color: #7a3cc7;
}

.file-type-archive {
    color: #9c6f12;
}

.file-type-video {
    color: #8a2f7e;
}

.file-type-audio {
    color: #0f7f9d;
}

.file-type-mail {
    color: #2f7b9c;
}

.file-type-code {
    color: #4d5db3;
}

.file-type-generic {
    color: #6a7686;
}

.document-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    text-align: center;
    width: 100%;
}

.documents-content.docfm-shell .document-info {
    gap: 0.12rem;
}

.document-name {
    display: block;
    width: 100%;
    font-size: 12.8px;
    font-weight: 600;
    color: var(--docfm-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.documents-content.docfm-shell .document-name {
    margin-bottom: 0;
    line-height: 1.2;
}

.document-name-with-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.28rem;
}

.document-name-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.document-shared-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 999px;
    color: #2563eb;
    background: #eaf2ff;
    border: 1px solid #c7dafc;
    flex: 0 0 auto;
}

.document-shared-indicator i {
    font-size: 9px;
    line-height: 1;
}

.document-shared-indicator-list {
    margin-left: 0.35rem;
    vertical-align: middle;
}

.document-size {
    font-size: 11.5px;
    color: var(--docfm-text-soft);
}

.documents-content.docfm-shell .document-size {
    margin-bottom: 0;
    padding-bottom: 0;
}

.document-type-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    line-height: 1;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #476182;
    border: 1px solid #d7e5f7;
    background: #f4f8ff;
    border-radius: 999px;
    padding: 0.2rem 0.42rem;
    margin-top: 0.08rem;
}

.file-icon-type-tag {
    position: absolute;
    right: -0.75rem;
    bottom: -0.2rem;
    min-width: 28px;
    padding: 0.1rem 0.26rem;
    border-radius: 6px;
    border: 1px solid #d5e2f4;
    background: #ffffff;
    color: #475f80;
    font-size: 8.5px;
    font-weight: 800;
    letter-spacing: 0.04em;
    line-height: 1.1;
    text-transform: uppercase;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}

.document-actions {
    position: absolute;
    top: 0.45rem;
    right: 0.45rem;
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.document-item:hover .document-actions,
.document-item:focus-within .document-actions {
    opacity: 1;
}

.folder-item .document-actions {
    opacity: 1;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 27px;
    height: 27px;
    border: 1px solid var(--docfm-border);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.95);
    color: #4e5f74;
    cursor: pointer;
    transition: all 0.15s ease;
}

.action-btn:hover {
    color: var(--docfm-primary);
    border-color: #9eb8df;
    background: #f6f9ff;
}

.action-btn i {
    font-size: 14px;
}

.documents-list {
    width: 100%;
}

.documents-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
    border: 1px solid var(--docfm-border);
    border-radius: var(--docfm-radius-md);
    overflow: hidden;
}

.documents-table thead {
    background: #f4f7fc;
}

.documents-table th {
    padding: 0.58rem 0.8rem;
    text-align: left;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #5b6a7e;
    text-transform: uppercase;
    border-bottom: 1px solid var(--docfm-border);
}

.documents-table td {
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid #edf2f8;
}

.documents-table tbody tr {
    transition: background 0.15s ease;
}

.documents-table tbody tr:hover {
    background: #f8fbff;
}

.documents-table tbody tr.drag-over {
    background: var(--docfm-bg-selected);
    box-shadow: inset 0 0 0 2px var(--docfm-primary);
}

.documents-table tbody tr.folder-row.drag-over {
    background: transparent;
    box-shadow: none;
}

.documents-table tbody tr.folder-row.drag-over .col-name {
    background: var(--docfm-bg-selected);
    box-shadow: inset 0 0 0 2px var(--docfm-primary);
    border-radius: 8px;
}

.documents-table tbody tr.folder-row.drag-over .folder-icon-sm {
    color: var(--docfm-primary);
}

.documents-table tbody tr.is-selected {
    background: #eff5ff;
    box-shadow: inset 0 0 0 2px rgba(11, 87, 208, 0.18);
}

.documents-table tbody tr.is-selected td:first-child {
    box-shadow: inset 3px 0 0 0 #0b57d0;
}

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

.col-name {
    width: 62%;
}

.col-size {
    width: 16%;
}

.col-date {
    width: 22%;
}

.folder-icon-sm,
.file-icon-sm {
    font-size: 18px;
    margin-right: 0.45rem;
    vertical-align: text-bottom;
}

.file-type-pill {
    display: inline-flex;
    align-items: center;
    margin-left: 0.55rem;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #4a5f7e;
    border: 1px solid #d8e4f5;
    border-radius: 999px;
    padding: 0.08rem 0.38rem;
    background: #f5f8fd;
    vertical-align: middle;
}

.sortable-header {
    cursor: pointer;
    user-select: none;
}

.sortable-header:hover {
    color: #2e4f82;
    background: #f7faff;
}

.action-btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #63748a;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-left: 0.25rem;
}

.action-btn-sm:hover {
    border-color: #bdd0eb;
    color: var(--docfm-primary);
    background: #eff5ff;
}

.inline-rename-input {
    width: 100%;
    min-width: 120px;
    height: 28px;
    border: 1px solid #8db1e8;
    border-radius: 7px;
    padding: 0 0.45rem;
    font-size: 12.5px;
    color: var(--docfm-text);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.1);
}

.inline-rename-input:focus {
    outline: none;
    border-color: #4f84d8;
}

.file-manager-statusbar {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.95rem;
    background: #f7f9fc;
    border-top: 1px solid var(--docfm-border);
    font-size: 12px;
    color: var(--docfm-text-muted);
}

.statusbar-text {
    font-weight: 600;
}

.statusbar-separator {
    color: #b2becc;
}

.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 330px;
    padding: 2.2rem 1rem;
    border: 1px dashed var(--docfm-border-strong);
    border-radius: var(--docfm-radius-md);
    background: #fbfcff;
}

.empty-state i {
    font-size: 54px;
    color: #b4c0d0;
    margin-bottom: 0.8rem;
}

.empty-state p {
    color: var(--docfm-text-muted);
    font-size: 14px;
    margin-bottom: 1.25rem;
}

@media (max-width: 900px) {
    .file-manager-toolbar {
        flex-wrap: wrap;
    }

    .folder-path-bar {
        order: 3;
        width: 100%;
        max-width: none;
    }

    .documents-grid {
        grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    }

    .docfm-discovery-controls {
        width: 100%;
    }

    .docfm-search-input {
        flex: 1;
        min-width: 0;
    }

    .bulk-actions-bar {
        flex-wrap: wrap;
    }

    .operation-feedback-bar {
        flex-wrap: wrap;
    }
}

@media (max-width: 640px) {
    .file-manager-content {
        padding: 0.75rem;
        min-height: 380px;
    }

    .toolbar-btn-view span {
        display: none;
    }

    .docfm-sort-select {
        max-width: 140px;
    }

    .documents-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 0.7rem;
    }

    .document-item {
        min-height: 154px;
        padding: 0.8rem 0.6rem;
    }
}
