/* documents.css
 *
 * Device Documents styles (the per-device Documents modal: list, upload,
 * preview, download, version history, deletion), extracted from
 * styles.css as part of Stage 2 of the frontend modularization plan
 * (docs/planning/frontend-modularization-and-csp-hardening-plan.md).
 *
 * Scope matches js/modules/documents.js exactly. Does NOT include the
 * Admin tab's Document Storage quota settings panel (a Stage 5 concern,
 * and confirmed to use no documents-*/doc-* classes of its own), or the
 * plain-text preview modal's content styling (.logcat-view-meta /
 * .logcat-view-content), which is shared with the Service tab's logcat
 * viewer and stays in styles.css until that's migrated.
 *
 * Load order: linked in index.html after core.css and automation.css,
 * before styles.css.
 */

.documents-modal-body {
    max-height: 340px;
    overflow-y: auto;
    overflow-x: visible;
    margin-bottom: 1rem;
}

.documents-modal-body.menu-open {
    overflow-y: visible;
}

.documents-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    table-layout: fixed;
}

.documents-table th {
    text-align: left;
    padding: 0.4rem 0.5rem;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
}

.documents-table td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.documents-table th:nth-child(1),
.documents-table td:nth-child(1) { width: 23%; }

.documents-table th:nth-child(2),
.documents-table td:nth-child(2) { width: 28%; }

.documents-table th:nth-child(3),
.documents-table td:nth-child(3) {
    width: 9%;
    white-space: nowrap;
}

.documents-table th:nth-child(4),
.documents-table td:nth-child(4) {
    width: 21%;
    white-space: nowrap;
}

.documents-table th:nth-child(5),
.documents-table td:nth-child(5) {
    width: 19%;
    white-space: nowrap;
}

.documents-table th:nth-child(5) {
    padding-right: 0.2rem;
}

.documents-table td:nth-child(5) {
    padding-left: 0.3rem;
    padding-right: 0.2rem;
    text-align: right;
    overflow: visible;
}

.documents-table td:nth-child(1),
.documents-table td:nth-child(2) {
    overflow: hidden;
}

.documents-description-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.documents-file-text {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.documents-file-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    width: 100%;
    min-width: 0;
    white-space: nowrap;
}

.documents-uploaded-text {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.documents-row-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
    width: 100%;
}

@media (pointer: coarse) {
    .documents-row-actions {
        gap: 0.5rem;
    }
}

.documents-row-actions .btn-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
}

@media (pointer: coarse) {
    .documents-row-actions .btn-icon {
        width: 44px;
        height: 44px;
        min-width: 44px;
    }
}

.doc-row-menu-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.doc-row-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 180px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
    padding: 0.3rem;
    z-index: 90;
    display: none;
    flex-direction: column;
}

.doc-row-menu.open {
    display: flex;
}

.doc-row-menu.open-up {
    top: auto;
    bottom: calc(100% + 6px);
}

.doc-row-menu-item {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    font-size: 0.83rem;
    line-height: 1.2;
    padding: 0.45rem 0.55rem;
    border-radius: 6px;
    cursor: pointer;
}

.doc-row-menu-item:hover {
    background: var(--bg-color);
}

.doc-row-menu-item.danger {
    color: var(--danger-color);
}

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

.documents-upload-section {
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
    margin-bottom: 0.5rem;
}

.documents-upload-heading {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.documents-drop-hint {
    margin: -0.15rem 0 0.55rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.documents-upload-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.documents-upload-input {
    flex: 0 1 260px;
    min-width: 180px;
    max-width: 280px;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    background: var(--input-bg, var(--card-bg));
    color: var(--text-primary);
}

.documents-upload-filename {
    flex: 1 1 260px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 220px;
    max-width: none;
}

.documents-upload-error {
    margin-top: 0.4rem;
    font-size: 0.82rem;
    color: var(--danger-color);
}

.documents-modal .btn {
    height: 32px;
    padding: 0 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-sizing: border-box;
    vertical-align: middle;
}

.documents-modal .modal-actions {
    margin-top: 1.2rem;
    padding-top: 0.35rem;
}

.documents-modal .modal-actions .btn {
    height: auto;
    min-height: 0;
    padding: 0.75rem 1.5rem;
}

.documents-modal .btn-primary {
    border: 2px solid var(--primary-color);
}

.documents-modal .btn-danger {
    border: 2px solid var(--danger-color);
}

.documents-modal .documents-row-actions .btn-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
    padding: 0;
}

@media (pointer: coarse) {
    .documents-modal .documents-row-actions .btn-icon {
        width: 44px;
        height: 44px;
        min-width: 44px;
    }
}

.documents-modal .modal-box.modal-box-wide {
    max-width: 820px;
    width: min(94vw, 820px);
}

#documents-modal-box {
    transition: box-shadow 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

#documents-modal-box.drag-active {
    border-color: var(--primary-color);
    background: #f8fbff;
    box-shadow: 0 0 0 3px rgba(0, 78, 154, 0.16), 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* Document version tag shown inline in File cell when versionNumber > 1 */
.doc-version-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    background: var(--info-bg);
    color: var(--info-text);
    border: 1px solid var(--info-color);
    margin-left: 0.3rem;
    vertical-align: middle;
    line-height: 1.2;
    white-space: nowrap;
}

.doc-version-history-btn.active {
    background: color-mix(in srgb, var(--info-color) 15%, var(--info-bg));
    border-color: var(--info-color);
    color: var(--info-text);
}

/* Shared expand/collapse animation for sub-rows */
.doc-version-history-row > td,
.doc-version-upload-row > td {
    padding: 0;
    background: var(--bg-color);
}

.doc-expansion-wrapper {
    overflow: hidden;
    height: 0;
    transition: height 0.3s ease;
}

.doc-expansion-inner {
    padding: 0.5rem 0.5rem 0.5rem 2rem;
}

/* Version history expansion row */

.doc-version-history-panel {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.doc-version-history-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.3rem 0.6rem;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.doc-version-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.25rem 0.35rem 0.25rem 0;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.doc-version-history-header .doc-version-history-label {
    border-bottom: none;
    background: transparent;
    padding-right: 0.35rem;
}

.doc-version-history-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.doc-version-delete-all-btn {
    white-space: nowrap;
}

.doc-version-history-table {
    width: 100%;
    border-collapse: collapse;
}

.doc-version-history-table td {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.doc-version-history-table tr:last-child td {
    border-bottom: none;
}

.doc-vh-version {
    width: 3.5rem;
    font-weight: 600;
    color: var(--info-text);
    white-space: nowrap;
}

.doc-vh-file {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

.doc-vh-size {
    width: 5rem;
    white-space: nowrap;
    color: var(--text-secondary);
}

.doc-vh-date {
    white-space: nowrap;
    color: var(--text-secondary);
}

.doc-vh-by {
    font-size: 0.72rem;
    color: var(--text-secondary);
    opacity: 0.9;
}

.doc-vh-actions {
    width: 5.5rem;
    text-align: right;
}

.doc-version-upload-panel {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.doc-version-upload-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.3rem 0.6rem;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.doc-version-upload-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.25rem 0.35rem 0.25rem 0;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.doc-version-upload-header .doc-version-upload-label {
    border-bottom: none;
    background: transparent;
    padding-right: 0.35rem;
}

.doc-version-upload-form {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
}

.doc-version-upload-panel .doc-vu-error {
    margin: 0 0.6rem 0.5rem;
}

/* ── Stage 2 hidden-convention support classes ──────────────────────────
 * Replace what used to be inline style="..." attributes -- see
 * automation.css's equivalent section from Stage 1 for the same pattern. */

.documents-empty-message {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.documents-error-message {
    color: var(--danger-color);
}

.documents-history-error-message {
    margin: 0.6rem;
}
