body.modal-open {
    overflow: hidden;
}

[hidden],
.file-card[hidden] {
    display: none !important;
}

.filters {
    grid-template-columns: minmax(260px, 2fr) repeat(3, minmax(130px, 1fr)) auto;
}

.viewer-dialog {
    width: 90vw;
    max-width: none;
    height: 90vh;
    height: 90dvh;
    max-height: none;
    padding: 0;
    overflow: hidden;
    background: #fff;
}

.viewer-dialog[open] {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.viewer-head {
    min-height: 62px;
    padding: 12px 16px 12px 20px;
    background: #fff;
    border-bottom: 1px solid #dfe5e1;
}

.viewer-head h2 {
    max-width: calc(100% - 60px);
    overflow: hidden;
    font-size: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer-close {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    color: #17211b;
    background: #e8ede9;
    font-size: 28px;
}

.viewer-body {
    min-height: 0;
    max-height: none;
    margin: 0;
    border-radius: 0;
    background: #252b27;
    overscroll-behavior: contain;
}

.image-viewer-body,
.video-viewer-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: auto;
    touch-action: pinch-zoom;
}

.image-viewer-body img,
.video-viewer-body video {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 100%;
    object-fit: contain;
}

.pdf-viewer-body {
    display: block;
    overflow: hidden;
    background: #e3e6e4;
}

.pdf-stage {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    padding: 12px;
    overflow: hidden;
    touch-action: pan-y;
}

.pdf-stage canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    background: #fff;
    box-shadow: 0 10px 34px rgba(0, 0, 0, .18);
}

.viewer-loading,
.viewer-error,
.unavailable-viewer-body p {
    max-width: 460px;
    margin: auto;
    padding: 24px;
    color: #425048;
    text-align: center;
}

.viewer-loading {
    color: #637068;
}

.viewer-footer {
    min-height: 64px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: #fff;
    border-top: 1px solid #dfe5e1;
}

.pdf-controls {
    grid-column: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: #34423a;
    font-size: 14px;
    font-weight: 750;
}

.page-button {
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid #d8e0db;
    border-radius: 50%;
    color: #2f7130;
    background: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.page-button:disabled {
    color: #aeb7b1;
    background: #f1f3f2;
    cursor: default;
}

.viewer-actions {
    grid-column: 3;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.share-button::before {
    content: "↗";
    margin-right: 6px;
    font-weight: 900;
}

.share-button:disabled {
    opacity: .7;
    cursor: wait;
}

.share-link-dialog {
    width: min(520px, calc(100% - 32px));
    max-height: 88vh;
    max-height: 88dvh;
    padding: 0;
    overflow: hidden;
    background: #fff;
}

.share-link-dialog[open] {
    display: flex;
    flex-direction: column;
}

.share-dialog-header {
    flex: 0 0 auto;
    align-items: flex-start;
    padding: 18px 20px 16px;
    border-bottom: 1px solid #e2e9e4;
}

.share-dialog-heading {
    min-width: 0;
    flex: 1;
}

.share-dialog-header h2 {
    margin: 0;
    font-size: 19px;
    letter-spacing: -.2px;
}

.share-dialog-filename {
    display: -webkit-box;
    max-width: 100%;
    margin: 8px 0 0;
    overflow: hidden;
    overflow-wrap: anywhere;
    color: #26332b;
    font-size: 15px;
    font-weight: 750;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.share-dialog-meta {
    min-height: 17px;
    margin: 3px 0 0;
    color: #748078;
    font-size: 12px;
    line-height: 1.4;
}

.share-dialog-close {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    color: #4d5a52;
    background: #f4f6f4;
    font-size: 22px;
    line-height: 1;
}

.share-dialog-close:focus-visible,
.share-duration-options input:focus-visible + span,
.share-revoke-link:focus-visible,
.share-row-revoke:focus-visible {
    outline: 3px solid rgba(87, 182, 81, .28);
    outline-offset: 2px;
}

.share-link-content {
    min-height: 0;
    flex: 1 1 auto;
    padding: 18px 20px 20px;
    overflow: auto;
    overscroll-behavior: contain;
}

.share-create-form {
    display: block;
}

.share-duration-fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.share-duration-fieldset legend {
    margin-bottom: 8px;
    color: #34423a;
    font-size: 13px;
    font-weight: 750;
}

.share-duration-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.share-duration-options label {
    position: relative;
    min-width: 0;
    margin: 0;
}

.share-duration-options input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

.share-duration-options span {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 6px;
    border: 1px solid #dbe2dd;
    border-radius: 12px;
    color: #4a5950;
    background: #fff;
    font-size: 13px;
    font-weight: 750;
    text-align: center;
    cursor: pointer;
}

.share-duration-options input:checked + span {
    border-color: #57b651;
    color: #347431;
    background: #ebf7ea;
    box-shadow: inset 0 0 0 1px rgba(87, 182, 81, .2);
}

.share-duration-fieldset:disabled {
    opacity: .62;
}

.share-duration-fieldset:disabled span {
    cursor: wait;
}

.share-create-form > .button {
    width: 100%;
    min-height: 50px;
    margin-top: 14px;
}

.share-create-form > .button:disabled {
    opacity: .68;
    cursor: wait;
}

.share-created {
    margin-top: 16px;
    padding: 16px;
    border: 1px solid #c5e2c2;
    border-radius: 14px;
    background: #f2faf1;
}

.share-success-label {
    margin: 0;
    color: #438f3e;
    font-size: 15px;
    font-weight: 800;
}

.share-created-expiry {
    margin: 4px 0 0;
    color: #4f5f55;
    font-size: 13px;
}

.share-created-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}

.share-created-actions .button {
    min-height: 44px;
}

.share-revoke-link,
.share-row-revoke {
    min-height: 44px;
    padding: 8px 10px;
    border: 0;
    border-radius: 10px;
    color: #a43a31;
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 750;
    cursor: pointer;
}

.share-revoke-link {
    width: 100%;
    margin-top: 4px;
}

.share-revoke-link:hover,
.share-row-revoke:hover {
    background: #fff0f0;
}

.share-modal-status {
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: 11px;
    color: #53645a;
    background: #f1f5f2;
    font-size: 13px;
}

.share-modal-status.error {
    color: #9d2e25;
    background: #fff0f0;
}

.active-shares {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid #e2e9e4;
}

.active-shares-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.active-shares-heading h3 {
    margin: 0;
    font-size: 15px;
}

.active-shares-heading span {
    min-width: 24px;
    padding: 3px 7px;
    border-radius: 99px;
    color: #637068;
    background: #eef2ef;
    font-size: 12px;
    text-align: center;
}

.active-shares-list {
    display: grid;
    gap: 8px;
}

.active-share-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 10px 11px 12px;
    border: 1px solid #e2e9e4;
    border-radius: 12px;
    background: #fbfcfb;
}

.active-share-row > div {
    min-width: 0;
}

.active-share-row p {
    margin: 0;
    color: #4a5950;
    font-size: 12px;
    line-height: 1.45;
}

.active-share-row strong {
    display: block;
    color: #243128;
    font-size: 13px;
    line-height: 1.45;
}

.share-row-revoke {
    flex: 0 0 auto;
}

.share-links-empty {
    margin: 0;
    padding: 12px;
    border-radius: 11px;
    color: #748078;
    background: #f6f8f6;
    font-size: 13px;
    text-align: center;
}

.share-note {
    margin: -12px 0 24px;
    color: #6d7b72;
    font-size: 13px;
}

.share-note strong {
    color: #3f5f43;
}

@media (max-width: 900px) {
    .filters {
        grid-template-columns: 1fr 1fr;
    }

    .viewer-dialog {
        width: calc(100vw - 20px);
        height: calc(100vh - 20px);
        height: calc(100dvh - 20px);
    }
}

@media (max-width: 620px) {
    .topbar {
        gap: 8px;
        padding: 0 12px;
    }

    .topbar .brand {
        min-width: 0;
        font-size: 18px;
        white-space: nowrap;
    }

    .topbar nav {
        flex: 0 0 auto;
        gap: 5px;
    }

    .topbar .button {
        min-height: 40px;
        padding: 7px 9px;
        font-size: 12px;
    }

    .hero {
        gap: 12px;
    }

    .filters {
        grid-template-columns: 1fr;
        margin: 22px 0;
    }

    .file-card {
        gap: 11px;
        padding: 14px;
    }

    .file-info h3 {
        margin-bottom: 3px;
    }

    .file-info p {
        margin-bottom: 7px;
    }

    .meta {
        gap: 7px 11px;
    }

    .file-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .file-actions .button {
        width: 100%;
    }

    .file-actions .download-action {
        grid-column: 1 / -1;
        min-height: 38px;
        color: #526158;
        background: #f6f8f6;
    }

    .file-actions .admin-action {
        grid-column: auto;
    }

    .viewer-dialog {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        margin: 0;
        border-radius: 0;
    }

    .viewer-head {
        min-height: 58px;
        padding: 8px 10px 8px 14px;
    }

    .viewer-body {
        padding: 8px;
    }

    .pdf-viewer-body {
        padding: 0;
    }

    .pdf-stage {
        padding: 8px;
    }

    .viewer-footer {
        min-height: 60px;
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 8px 12px max(8px, env(safe-area-inset-bottom));
    }

    .viewer-actions {
        grid-column: 1;
        grid-row: 1;
        justify-content: stretch;
    }

    .viewer-dialog[data-preview-type="pdf"] .viewer-footer {
        min-height: 116px;
        grid-template-rows: auto auto;
    }

    .viewer-dialog[data-preview-type="pdf"] .pdf-controls {
        grid-column: 1;
        grid-row: 1;
    }

    .viewer-dialog[data-preview-type="pdf"] .viewer-actions {
        grid-row: 2;
    }

    .viewer-actions .button {
        flex: 1;
    }

    .share-link-dialog {
        width: calc(100% - 24px);
        max-width: none;
        max-height: 88vh;
        max-height: 88dvh;
        margin: auto 12px max(12px, env(safe-area-inset-bottom));
        border-radius: 22px 22px 18px 18px;
    }

    .share-dialog-header {
        padding: 16px 16px 13px;
    }

    .share-link-content {
        padding: 16px 16px max(16px, env(safe-area-inset-bottom));
    }

    .share-duration-options {
        gap: 6px;
    }
}

@media (max-width: 410px) {
    .topbar .brand {
        font-size: 17px;
    }

    .topbar .button {
        padding-inline: 7px;
    }

    .hero h1 {
        font-size: 28px;
    }
}
