* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --ink: #14233a;
    --teal: #0f766e;
    --teal-dark: #115e59;
    --teal-soft: #d9efec;
    --bg: #eaf0f1;
    --surface: #ffffff;
    --line: #d5dfe3;
    --muted: #5f6f7d;
    --folder: #b7791f;
    --folder-soft: #faecd0;
    --file-soft: #e6eef5;
    --radius: 14px;
}

html,
body {
    height: 100%;
}

body {
    font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
}

button,
input,
a {
    font-family: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.app {
    height: 100vh;
    height: 100dvh;
    padding: 20px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-icon {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 12px;
    background: var(--teal);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
}

.brand-info h1 {
    font-size: 21px;
    font-weight: 700;
    line-height: 1.2;
}

.brand-info p {
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
}

.search-input {
    width: 340px;
    max-width: 100%;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    padding: 0 16px;
    font-size: 15px;
    color: var(--ink);
}

.search-input:focus {
    border-color: var(--teal);
}

.menu {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    scrollbar-width: none;
}

.menu::-webkit-scrollbar {
    display: none;
}

.menu button {
    border: none;
    background: none;
    color: var(--muted);
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    transition: color .2s, border-color .2s;
}

.menu button:hover {
    color: var(--ink);
}

.menu button.active {
    color: var(--teal);
    border-bottom-color: var(--teal);
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 40px;
}

.btn-back {
    flex-shrink: 0;
    border: none;
    background: var(--teal);
    color: #fff;
    padding: 9px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}

.btn-back:hover:not(:disabled) {
    background: var(--teal-dark);
}

.btn-back:disabled {
    background: #c3d0d3;
    cursor: default;
}

.breadcrumb {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
}

.breadcrumb::-webkit-scrollbar {
    display: none;
}

.breadcrumb button {
    border: none;
    background: none;
    color: var(--teal);
    font-size: 14px;
    font-weight: 600;
    padding: 6px 4px;
    cursor: pointer;
    border-radius: 6px;
}

.breadcrumb button:hover {
    text-decoration: underline;
}

.breadcrumb button:last-child {
    color: var(--ink);
    cursor: default;
    text-decoration: none;
}

.breadcrumb .sep {
    color: var(--muted);
    font-size: 14px;
}

.total {
    flex-shrink: 0;
    color: var(--muted);
    font-size: 13px;
}

.main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
}

.explorer {
    position: relative;
    min-height: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.file-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.file-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    border: none;
    border-bottom: 1px solid var(--line);
    border-left: 3px solid transparent;
    background: none;
    text-align: left;
    color: inherit;
    cursor: pointer;
    transition: background .15s;
}

.file-row:hover {
    background: #f3f8f8;
}

.file-row.selected {
    background: var(--teal-soft);
    border-left-color: var(--teal);
}

.file-icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 10px;
    background: var(--file-soft);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
}

.file-row.folder .file-icon {
    background: var(--folder-soft);
}

.file-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-name {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    word-break: break-word;
}

.file-meta {
    font-size: 12px;
    color: var(--muted);
    word-break: break-word;
}

.file-row.folder .file-meta {
    color: var(--folder);
    font-weight: 600;
}

.state {
    min-height: 100%;
    padding: 40px 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    text-align: center;
    color: var(--muted);
}

.state .state-icon {
    font-size: 52px;
}

.state h3 {
    color: var(--ink);
    font-size: 17px;
}

.state p {
    font-size: 14px;
    max-width: 320px;
    line-height: 1.5;
}

.state button {
    margin-top: 6px;
    border: none;
    background: var(--teal);
    color: #fff;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
    visibility: hidden;
    opacity: 0;
    transition: opacity .2s ease, visibility 0s linear .2s;
}

.modal.open {
    visibility: visible;
    opacity: 1;
    transition: opacity .2s ease;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(20, 35, 58, .55);
}

.modal-dialog {
    position: relative;
    width: min(1000px, 100%);
    height: 88vh;
    height: 88dvh;
    max-height: 100%;
    background: var(--surface);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(20, 35, 58, .35);
    transform: scale(.97);
    transition: transform .2s ease;
}

.modal.open .modal-dialog {
    transform: none;
}

.modal.full {
    padding: 0;
}

.modal.full .modal-dialog {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
}

.preview-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.preview-header h2 {
    flex: 1;
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn-action {
    padding: 8px 14px;
    border-radius: 9px;
    background: var(--teal-soft);
    color: var(--teal-dark);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.btn-action:hover {
    background: #c3e4e0;
}

.btn-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 9px;
    background: #eef1f4;
    color: var(--ink);
    cursor: pointer;
}

.btn-close:hover {
    background: #e0e5ea;
}

.preview-content {
    position: relative;
    flex: 1;
    min-height: 0;
    background: #f1f5f8;
}

.preview-content iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

.preview-wait {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 14px;
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    padding: 24px;
}

.loading {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: rgba(255, 255, 255, .75);
    display: flex;
    justify-content: center;
    align-items: center;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid #d1dbe0;
    border-top-color: var(--teal);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-thumb {
    background: #c3ced5;
    border-radius: 10px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 900px) {
    .app {
        padding: 14px;
        padding-left: max(14px, env(safe-area-inset-left));
        padding-right: max(14px, env(safe-area-inset-right));
        gap: 10px;
    }

    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .brand-icon {
        width: 42px;
        height: 42px;
        font-size: 21px;
    }

    .brand-info h1 {
        font-size: 19px;
    }

    .search-input {
        width: 100%;
        font-size: 16px;
    }

    .main {
        grid-template-columns: minmax(0, 1fr);
    }

    .modal {
        padding: 12px;
    }

    .modal-dialog {
        height: 82vh;
        height: 82dvh;
    }

    .preview-header {
        padding: 10px 12px;
        gap: 8px;
    }

    .preview-actions {
        gap: 6px;
    }

    .btn-action {
        padding: 8px 10px;
    }

    .modal.full .preview-header {
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .modal.full .preview-content {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .total {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {

    .modal,
    .modal.open,
    .modal-dialog {
        transition: none;
    }

    .spinner {
        animation-duration: 1.6s;
    }
}