/* documents.css */

/* =======================================
   Documents Page Styles
   ======================================= */
.subgroup-content .doc-row {
    padding-left: 40px;
}

.custom-dropdown {
    position: relative;
    width: 15%;
}

.dropdown-toggle {
    background-color: var(--bg-primary);
    border: 2px solid var(--accent-primary);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1em;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dropdown-toggle svg {
    margin-left: 10px;
    transition: transform 0.3s ease;
}

.dropdown-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    background-color: var(--bg-primary);
    position: absolute;
    z-index: 1;
    width: 100% !important;
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease;
    top: 100%;
    left: 0;
    box-sizing: border-box;
}

.custom-dropdown.open .dropdown-menu {
    border: 2px solid var(--accent-primary);
    border-top: none;
    border-bottom-left-radius: 25px;
    border-bottom-right-radius: 25px;
}

.dropdown-menu li {
    list-style: none;
    width: 100%;
    margin: 0;
}

.dropdown-menu li button {
    width: 100%;
    padding: 10px;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    text-align: center;
    border: none;
    border-top: none;
    font-size: medium;
}

.dropdown-menu li button:hover {
    background-color: var(--hover-bg);
}

.dropdown-menu li:first-child button {
    border-top: none;
}

.custom-dropdown.open .dropdown-toggle {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
}

.collapse-toggle {
    background: none;
    border: none;
    cursor: pointer;
    margin-right: 10px;
    color: var(--accent-primary);
}

.collapse-toggle svg {
    transition: transform 0.3s ease;
}

.doc-name {
    margin-left: 15px;
}

.documents-box .doc-row .doc-symbol + .doc-name {
    margin-left: 15px;
}

.home-selector .dropdown-toggle span {
    flex: 1;
    text-align: left;
}

.home-selector .dropdown-menu {
    border-radius: 0 0 30px 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    top: calc(100% + 6px);
}

.home-selector .dropdown-menu button:last-child {
    border-top: 3px solid var(--accent-primary);
    padding: 20px;
    color: var(--accent-primary);
    font-weight: 600;
    text-align: center;
}

/* =======================================
   Dynamic document list / grouping
   ======================================= */
.docs-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.doc-group-header {
    display: flex;
    align-items: center;
    margin-bottom: 14px;
}

.doc-group + .doc-group {
    margin-top: 44px;
}

.doc-group .collapse-toggle svg {
    transition: transform 0.25s ease;
    transform: rotate(90deg);
}

.doc-group.collapsed .collapse-toggle svg {
    transform: rotate(0deg);
}

.doc-group .subgroup-content {
    overflow: hidden;
    transition: max-height 0.35s ease;
}

.doc-group-header h4 {
    margin: 0;
}

.doc-empty {
    color: var(--text-secondary);
    text-align: center;
    padding: 20px 0;
    margin: 0;
}

.doc-privacy-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 2px;
}

.doc-privacy-options {
    display: flex;
    gap: 20px;
}

.doc-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.95em;
    color: var(--text-primary);
    margin-top: 0 !important;
}

.doc-check input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    padding: 0;
    margin: 0;
    border: 2px solid var(--accent-primary);
    border-radius: 6px;
    background: var(--bg-secondary);
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    transition: background 0.2s ease, border-color 0.2s ease;
    box-sizing: border-box;
}

.doc-check input[type="checkbox"]:hover {
    background: var(--hover-bg);
}

.doc-check input[type="checkbox"]:checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.doc-check input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid #FFFFFF;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.doc-field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.doc-info-wrap {
    position: relative;
    margin-left: auto;
}

.doc-info-btn {
    flex: none;
    background: none;
    border: none;
    color: var(--accent-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.doc-info-btn svg {
    width: 26px;
    height: 26px;
    display: block;
}

.doc-info-btn:hover svg {
    transform: scale(1.12);
}

.doc-info-btn:active svg {
    transform: scale(0.96);
}

.doc-tooltip {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    width: 320px;
    max-width: 82vw;
    background: var(--bg-primary);
    border: 2px solid var(--accent-primary);
    border-radius: 14px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.3);
    padding: 16px 18px;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    text-align: left;
    pointer-events: none;
}

.doc-info-wrap.show .doc-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* The "File" (format) info button sits at the top of the popup, so its
   tooltip should open downward (and inward, via right:0) over the popup. */
.doc-format-info-wrap .doc-tooltip {
    bottom: auto;
    top: calc(100% + 10px);
}

.doc-tooltip h4 {
    margin: 0 0 8px;
    color: var(--accent-primary);
    font-size: 1.1em;
}

.doc-tooltip p {
    margin: 0 0 10px;
    font-size: 1.05em;
    line-height: 1.55;
    color: var(--text-primary);
}

.doc-tooltip p:last-child {
    margin-bottom: 0;
}

.doc-tooltip strong {
    color: var(--accent-primary);
}

.doc-privacy-tag {
    display: inline-block;
    font-size: 0.68em;
    font-weight: 600;
    border-radius: 12px;
    padding: 3px 10px;
    white-space: nowrap;
    vertical-align: middle;
}

.doc-privacy-tag.house {
    color: #fff;
    background: var(--accent-secondary);
    border: 1px solid var(--accent-secondary);
}

.doc-privacy-tag.private {
    color: var(--text-secondary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
}

.doc-cell-privacy {
    width: 88px;
    text-align: center;
}

.doc-search-header {
    text-align: left;
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 12px;
}

.doc-mark {
    background: rgba(32, 178, 170, 0.25);
    color: inherit;
    border-radius: 3px;
    padding: 0 1px;
}

.doc-row-open {
    cursor: pointer;
    transition: background 0.2s ease;
    border-radius: 8px;
    padding: 6px 8px;
    margin-bottom: 6px;
}

.doc-row-open:hover {
    background: var(--hover-bg);
}

.doc-row-left {
    display: flex;
    align-items: center;
    gap: 22px;
    min-width: 0;
    flex: 1 1 auto;
}

.doc-row-right {
    display: flex;
    align-items: center;
    gap: 26px;
    flex-shrink: 0;
    margin-left: auto;
}

.doc-cell {
    flex: none;
    white-space: normal;
}

.doc-cell-icon { width: 22px; }

.doc-row-left .doc-symbol {
    flex: none;
}

.doc-cell-asset {
    width: 190px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.doc-cell-name {
    min-width: 200px;
    flex: 0 1 auto;
    text-align: left;
    font-weight: 500;
}

.doc-cell-performed { width: 132px; text-align: center; font-size: 0.82rem; color: var(--text-secondary); white-space: nowrap; }
.doc-cell-uploaded  { width: 132px; text-align: center; font-size: 0.82rem; color: var(--text-secondary); white-space: nowrap; }
.doc-cell-type      { width: 104px; text-align: center; font-size: 0.8rem;  font-weight: 600; color: var(--accent-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-cell-size      { width: 80px;  text-align: center; font-size: 0.82rem; color: var(--text-secondary); white-space: nowrap; }
.doc-cell-edit      { width: 46px;  text-align: center; }

.doc-edit-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    transition: color 0.2s ease, background 0.2s ease;
}

.doc-edit-btn:hover {
    color: var(--accent-primary);
    background: var(--hover-bg);
}

.doc-header-row {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 8px;
    padding: 6px 8px;
    cursor: default;
}

.doc-col-label {
    color: var(--text-secondary);
}

.doc-header-row .doc-cell-name {
    font-weight: 600;
}

.doc-sort-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

#doc-sort-dropdown {
    width: auto;
    min-width: 240px;
}

#doc-sort-dropdown .dropdown-toggle {
    height: 46px;
    box-sizing: border-box;
    padding: 0 20px;
    justify-content: space-between;
}

#doc-sort-dropdown .dropdown-toggle span {
    text-align: left;
    margin-right: 12px;
}

#doc-sort-dropdown .dropdown-toggle svg {
    transition: transform 0.25s ease;
}

#doc-sort-dropdown.inverted .dropdown-toggle svg {
    transform: rotate(180deg);
}

#doc-sort-dropdown.open .dropdown-toggle svg {
    transform: rotate(180deg);
}

#doc-sort-dropdown.open.inverted .dropdown-toggle svg {
    transform: rotate(0deg);
}

.doc-sort-invert {
    background-color: var(--bg-primary);
    border: 2px solid var(--accent-primary);
    color: var(--text-primary);
    border-radius: 50%;
    width: 42px;
    height: 42px;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
    transition: background 0.2s ease, color 0.2s ease;
}

.doc-sort-invert:hover {
    background: var(--accent-primary);
    color: #fff;
}

.doc-invert-icon {
    display: block;
}

/* ---- Preview modal ---- */
#doc-preview-overlay.preview-max {
    padding: 0;
}

#doc-preview-overlay.preview-max .preview-card {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    box-sizing: border-box;
}

#doc-preview-overlay.preview-max .preview-body {
    flex: 1;
    min-height: 0;
}

#doc-preview-overlay.preview-max .preview-media {
    max-height: none;
    max-width: 100%;
    width: auto;
    height: auto;
}

#doc-preview-overlay.preview-max .preview-frame {
    width: 100%;
    height: 100%;
    flex: 1;
}
#doc-preview-overlay {
    z-index: 30000;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 20px;
}

.preview-card {
    background: var(--bg-secondary);
    border: 4px solid var(--accent-primary);
    border-radius: 18px;
    padding: 18px 20px;
    width: 92%;
    max-width: 820px;
    height: 90vh;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 14px 40px rgba(0,0,0,0.4);
    box-sizing: border-box;
}

.preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.preview-title {
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-close {
    flex: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1.6rem;
    line-height: 1;
    padding: 0 6px;
}

.preview-close:hover {
    color: var(--text-primary);
}

.preview-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: #000;
    border-radius: 10px;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
}

.preview-img-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-media {
    max-width: 100%;
    max-height: 65vh;
    object-fit: contain;
}

.preview-frame-wrap {
    width: 100%;
    height: 100%;
}

.preview-frame {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: block;
    border: none;
    background: #fff;
    overscroll-behavior: contain;
}

.preview-note {
    color: var(--text-secondary);
    text-align: center;
    padding: 30px;
    max-width: 420px;
    margin: auto;
}

.preview-actions {
    margin-top: 14px;
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.preview-actions .popup-btn {
    flex: 1 1 0;
    min-width: 150px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.preview-actions a.popup-btn,
.preview-actions button.popup-btn:not(.confirm) {
    background: transparent;
    border: 2px solid var(--accent-primary);
    color: var(--text-primary);
    cursor: pointer;
}

.preview-actions a.popup-btn:hover,
.preview-actions button.popup-btn:not(.confirm):hover {
    background: var(--accent-primary);
    color: #fff;
}

/* =======================================
   Custom PDF viewer
   ======================================= */
.preview-frame-wrap, .preview-frame {
    width: 100%;
    height: 100%;
}

.pdfv {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #3a3f44;
    overflow: hidden;
}

.preview-body > .pdfv {
    border-radius: 10px;
    overflow: hidden;
}

/* =======================================
   3D model viewer
   ======================================= */
.viewer3d-wrap {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    border-radius: 10px;
}

.viewer3d-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* =======================================
   Office document viewer
   ======================================= */
.office-spreadsheet {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.office-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 10px 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.office-tab {
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 10px 10px 0 0;
    border-bottom: none;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s ease, color 0.2s ease;
}

.office-tab:hover {
    color: var(--text-primary);
}

.office-tab.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
    font-weight: 600;
}

.office-sheets {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: #fff;
}

.office-sheet {
    display: none;
    padding: 10px;
}

.office-sheet.active {
    display: block;
}

.office-sheet table {
    border-collapse: collapse;
    font-size: 0.85rem;
}

.office-sheet table td,
.office-sheet table th {
    border: 1px solid #c8cdd2;
    padding: 4px 8px;
    color: #14171a;
    text-align: left;
    white-space: nowrap;
}

.office-sheet table th {
    background: #eef1f4;
    font-weight: 600;
}

.office-word {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #3a3f44;
    overflow: hidden;
}

.office-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    flex: none;
}

.office-doc-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
}

.office-page-input {
    width: 3ch;
    min-width: 40px;
    height: 34px;
    box-sizing: border-box;
    padding: 0 8px;
    text-align: center;
    border: 2px solid var(--accent-primary);
    border-radius: 999px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.office-page-input::-webkit-inner-spin-button,
.office-page-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.office-page-input {
    -moz-appearance: textfield;
    appearance: textfield;
}

.office-page-total,
.office-zoom-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: nowrap;
}

.office-zoom-label {
    min-width: 44px;
    text-align: center;
    cursor: pointer;
}

.pdfv-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.pdfv-btn {
    background-color: var(--bg-primary);
    border: 2px solid var(--accent-primary);
    color: var(--text-primary);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.pdfv-btn:hover {
    background: var(--accent-primary);
    color: #fff;
}

.pdfv-page-input {
    width: 3ch;
    min-width: 40px;
    height: 34px;
    box-sizing: border-box;
    padding: 0 8px;
    text-align: center;
    border: 2px solid var(--accent-primary);
    border-radius: 999px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.pdfv-page-input::-webkit-inner-spin-button,
.pdfv-page-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.pdfv-page-input {
    -moz-appearance: textfield;
    appearance: textfield;
}

.pdfv-page-total,
.pdfv-zoom-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: nowrap;
}

.pdfv-zoom-label {
    min-width: 44px;
    text-align: center;
}

.pdfv-divider {
    width: 1px;
    height: 22px;
    background: var(--border-color);
    margin: 0 4px;
    flex: none;
}

.pdfv-pages {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    background: #3a3f44;
    overscroll-behavior: contain;
}

.pdfv-page {
    background: #fff;
    box-shadow: 0 4px 14px rgba(0,0,0,0.4);
    flex: none;
    line-height: 0;
}

.pdfv-page canvas {
    display: block;
}

/* =======================================
   Responsive: Dashboard "Latest Documents" rows
   Keeps the row on one line and progressively
   drops the least important columns.
   ======================================= */
.documents-box .doc-cell-name,
.documents-box .doc-cell-asset {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The dashboard box is narrow, so keep every row fluid: the name
   truncates and the right side compresses instead of being clipped. */
.documents-box .doc-cell-name { min-width: 0; flex: 1 1 auto; }
.documents-box .doc-row-right { flex-shrink: 1; }
.documents-box .doc-row-right .doc-cell { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.documents-box .doc-row-right .doc-cell-privacy,
.documents-box .doc-row-right .doc-cell-edit { flex: none; }

@media (max-width: 1100px) {
    .documents-box .doc-row-left,
    .documents-box .doc-row-right {
        gap: 12px;
    }
    .documents-box .doc-cell-size { display: none; }
    .documents-box .doc-cell-performed { width: 110px; }
    .documents-box .doc-cell-asset { width: 160px; }
}

@media (max-width: 1000px) {
    .documents-box .doc-cell-type { display: none; }
}

@media (max-width: 850px) {
    .documents-box .doc-cell-uploaded { display: none; }
    .documents-box .doc-cell-asset { width: 120px; }
    .documents-box .doc-cell-performed { width: 92px; }
}

@media (max-width: 745px) {
    .documents-box .doc-cell-asset { width: 110px; }
    .documents-box .doc-cell-performed { width: 86px; }
    .documents-box .doc-row-left,
    .documents-box .doc-row-right { gap: 8px; }
}

@media (max-width: 560px) {
    .documents-box .doc-cell-performed { display: none; }
    .documents-box .doc-cell-asset { width: 110px; }
}

@media (max-width: 475px) {
    .documents-box .doc-cell-asset { display: none; }
    .documents-box .doc-cell-name { min-width: 0; }
}

/* =======================================
   Responsive: My Documents page rows
   (name/asset truncate; symbol, size and
   uploaded date removed only on narrow screens)
   ======================================= */
#doc-groups .doc-cell-name,
#doc-groups .doc-cell-asset {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Keep every row fluid so the name truncates and the right side
   compresses instead of being clipped on narrow screens. */
#doc-groups .doc-cell-name { min-width: 0; flex: 1 1 auto; }
#doc-groups .doc-row-right { flex-shrink: 1; }
#doc-groups .doc-row-right .doc-cell { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#doc-groups .doc-row-right .doc-cell-privacy,
#doc-groups .doc-row-right .doc-cell-edit { flex: none; }

@media (max-width: 1100px) {
    #doc-groups .doc-row-left,
    #doc-groups .doc-row-right {
        gap: 12px;
    }
    #doc-groups .doc-cell-size { display: none; }
    #doc-groups .doc-cell-asset { width: 160px; min-width: 0; text-align: left; }
}

@media (max-width: 1000px) {
    #doc-groups .doc-cell-type { display: none; }
}

@media (max-width: 850px) {
    #doc-groups .doc-cell-uploaded { display: none; }
    #doc-groups .doc-cell-icon,
    #doc-groups .doc-symbol { display: none; }
    #doc-groups .doc-cell-asset { width: 120px; }
    #doc-groups .doc-cell-performed { width: 92px; }
}

@media (max-width: 745px) {
    #doc-groups .doc-cell-asset { width: 110px; }
    #doc-groups .doc-cell-performed { width: 86px; }
    #doc-groups .doc-row-left,
    #doc-groups .doc-row-right { gap: 8px; }
}

@media (max-width: 560px) {
    #doc-groups .doc-cell-performed { display: none; }
    #doc-groups .doc-cell-asset { width: 110px; }
}

@media (max-width: 475px) {
    #doc-groups .doc-cell-asset { display: none; }
    #doc-groups .doc-cell-name { min-width: 0; }
}

/* My Documents page: edge spacing + tidy rows (like the dashboard) */
main:has(#doc-groups) .grid-container {
    padding: 0 16px;
    box-sizing: border-box;
    /* Constrain the column to the container width so long document names
       cannot stretch the row/grid beyond the screen (auto tracks size to
       max-content, which clips the sort button and row right side). */
    grid-template-columns: minmax(0, 1fr);
}
main:has(#doc-groups) .grid-container > * {
    min-width: 0;
}

/* Keep the sort header on screen: title on the left, sort controls on
   the right at their natural width. If they no longer fit side by side,
   wrap the controls onto their own line (still right-aligned) instead
   of letting them spill past the right edge. */
#doc-list-head { flex-wrap: wrap; row-gap: 12px; }
.doc-sort-controls { margin-left: auto; min-width: 0; }

@media (max-width: 850px) {
    main:has(#doc-groups) .grid-container {
        padding: 0 12px;
    }
    #doc-groups .subgroup-content .doc-row {
        padding-left: 12px;
    }
    #doc-sort-dropdown { min-width: 0; }
    #doc-sort-dropdown .dropdown-toggle { padding: 0 14px; }
}

@media (max-width: 560px) {
    main:has(#doc-groups) .grid-container {
        padding: 0 10px;
    }
    #doc-groups .subgroup-content .doc-row {
        padding-left: 6px;
    }
    #doc-sort-dropdown { min-width: 0; }
}

/* Document popups (add/edit, old-date confirm, delete confirm):
   keep a comfortable gap from the screen edges on narrow screens
   so the popup never touches the sides. */
@media (max-width: 500px) {
    #doc-add-popup .popup-content,
    #doc-old-date-popup .popup-content,
    #doc-confirm-overlay .popup-content {
        box-sizing: border-box;
        width: calc(100% - 32px);
        padding: 24px 18px;
    }
}

/* =======================================
   Document scanning
   ======================================= */
.button-group > #doc-add-btn,
.button-group > #doc-scan-btn {
    margin-top: 0;
}

/* Dashboard document actions share the same dimensions and alignment. */
.dashboard-grid .documents-box .button-group > #doc-add-btn,
.dashboard-grid .documents-box .button-group > .view-button {
    flex: 1 1 0;
    min-width: 0;
    height: 44px;
    box-sizing: border-box;
}

.dashboard-grid .documents-box .button-group > #doc-add-btn {
    margin-top: 10px;
}

.doc-scan-status {
    font-size: 0.9em;
    line-height: 1.4;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 25px;
    padding: 10px 14px;
    margin-top: 4px;
    text-align: center;
}

.doc-scan-status.scanning {
    color: var(--accent-primary);
    font-weight: 600;
}

.doc-scan-status.ok {
    color: var(--accent-secondary);
}

.doc-scan-status.error {
    color: var(--delete-red);
}

/* On phones, anchored tooltips can be clipped by a scrolling popup. Use a
   bottom sheet instead so each help text is fully visible and tap-friendly. */
@media (max-width: 700px) {
    .doc-tooltip,
    .doc-format-info-wrap .doc-tooltip {
        position: fixed;
        inset: auto 16px 16px;
        width: auto;
        max-width: none;
        max-height: min(60dvh, 460px);
        overflow-y: auto;
        z-index: 3000;
    }
}


#doc-name.invalid {
    border-color: #e74c3c;
    color: #e74c3c;
}

#doc-name.shake {
    animation: doc-shake 0.4s ease;
}
