:root {
    --bg: #eef4fb;
    --card: #ffffff;
    --text: #162033;
    --muted: #667085;
    --border: #d8e0ea;
    --primary: #0f70d7;
    --primary-dark: #0a58ad;
    --danger: #d92d20;
    --success-bg: #ecfdf3;
    --success-text: #027a48;
    --error-bg: #fef3f2;
    --error-text: #b42318;
    --shadow: 0 12px 30px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    min-height: 100vh;
    background: linear-gradient(145deg, #eaf3ff, var(--bg));
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
}
body.modal-open { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.app-shell { width: min(1280px, calc(100% - 28px)); margin: 18px auto 40px; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
h1 { margin: 0; font-size: clamp(24px, 4vw, 34px); }
h2 { margin: 0 0 10px; font-size: 18px; }
.muted { color: var(--muted); margin: 5px 0 0; }
.path-line { word-break: break-all; }
.panel, .login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}
.panel { padding: 16px; margin-bottom: 16px; }
.login-page {
    display: grid;
    place-items: center;
    padding: 20px;
}
.login-card {
    width: min(420px, 100%);
    padding: 24px;
}
.login-card label, .modal-card label { display: block; font-weight: 700; margin: 12px 0 6px; }
input[type="text"], input[type="password"], input[type="search"], input[type="file"] {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
    font: inherit;
}
input[type="file"] { padding: 8px; }
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.15;
}
.btn:hover { text-decoration: none; background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f2b8b5; }
.btn.small { min-height: 32px; padding: 6px 10px; border-radius: 10px; font-size: 13px; }
.btn.full { width: 100%; margin-top: 18px; }
.alert {
    padding: 12px 14px;
    border-radius: 14px;
    margin: 12px 0;
    font-weight: 650;
}
.alert.success { background: var(--success-bg); color: var(--success-text); }
.alert.error { background: var(--error-bg); color: var(--error-text); }
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    font-weight: 750;
    margin-bottom: 12px;
    word-break: break-all;
}
.go-path {
    display: flex;
    gap: 8px;
    align-items: center;
}
.go-path input { min-width: 0; flex: 1 1 auto; }
.go-path .btn { flex: 0 0 auto; }
.compact-row, .quick-links, .tool-buttons, .modal-actions, .top-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.quick-links { margin-top: 12px; }
.tools-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 12px;
}
.tool-buttons .btn { min-width: auto; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.file-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 14px;
}
.search { max-width: 320px; }
.table-wrap { overflow-x: auto; }
.file-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.file-table th, .file-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
.file-table th {
    color: #344054;
    background: #f8fafc;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .02em;
}
.file-name { font-weight: 750; color: var(--text); word-break: break-word; }
.file-name.folder { color: var(--primary); }
.select-col, .select-cell { width: 68px; text-align: center; }
.check-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    background: #fff;
}
.check-wrap input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.actions-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 260px;
}
.inline-form { display: inline-flex; }
.tag {
    display: inline-flex;
    align-items: center;
    padding: 5px 9px;
    border-radius: 999px;
    background: #f2f4f7;
    color: #475467;
    font-size: 12px;
    font-weight: 700;
}
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 1000;
}
.modal.is-open { display: flex; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .52);
}
.modal-card {
    position: relative;
    z-index: 1;
    width: min(520px, 100%);
    max-height: calc(100vh - 36px);
    overflow: auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 22px 70px rgba(15, 23, 42, .24);
    padding: 18px;
}
.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}
.modal-actions { margin-top: 14px; justify-content: flex-start; }
.editor-shell { width: min(1400px, calc(100% - 20px)); }
.editor-form { display: flex; flex-direction: column; gap: 12px; }
.editor-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}
.editor-meta span {
    padding: 6px 10px;
    border-radius: 999px;
    background: #f2f4f7;
}
#codeEditor {
    width: 100%;
    min-height: 68vh;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    background: #101828;
    color: #eef4ff;
    font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    tab-size: 4;
    outline: none;
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
    overflow-x: auto;
    overflow-y: auto;
}
.sticky-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 0;
    background: linear-gradient(180deg, rgba(238,244,251,0), var(--bg) 40%);
}
@media (max-width: 900px) {
    .app-shell { width: min(100% - 16px, 1280px); margin-top: 10px; }
    .panel { padding: 12px; border-radius: 15px; }
    .topbar, .file-toolbar { flex-direction: column; align-items: stretch; }
    .tools-head { flex-direction: column; }
    .search { max-width: none; }
    .go-path { flex-direction: row; align-items: center; gap: 7px; }
    .go-path .btn { padding-left: 12px; padding-right: 12px; }
    .quick-links .btn, .tool-buttons .btn, .actions-cell .btn, .actions-cell .inline-form .btn {
        min-height: 32px;
        padding: 6px 9px;
        border-radius: 10px;
        font-size: 13px;
    }
    .file-table, .file-table thead, .file-table tbody, .file-table tr, .file-table th, .file-table td { display: block; }
    .file-table thead { display: none; }
    .file-table tr {
        border: 1px solid var(--border);
        border-radius: 16px;
        margin-bottom: 10px;
        padding: 9px;
        background: #fff;
    }
    .file-table td {
        border-bottom: 0;
        padding: 6px 4px;
    }
    .file-table td::before {
        content: attr(data-label);
        display: block;
        color: var(--muted);
        font-size: 11px;
        font-weight: 800;
        margin-bottom: 3px;
        text-transform: uppercase;
    }
    .file-table td.select-cell {
        float: left;
        width: auto;
        padding-right: 8px;
    }
    .file-table td.select-cell::before { display: none; }
    .file-table td[data-label="Tên"] { min-height: 40px; padding-top: 8px; }
    .actions-cell { min-width: 0; clear: both; }
    .modal { padding: 10px; align-items: flex-end; }
    .modal-card { width: 100%; max-height: 88vh; border-radius: 18px 18px 0 0; }
    #codeEditor {
        min-height: 64vh;
        font-size: 13px;
        white-space: pre-wrap;
        overflow-wrap: anywhere;
        word-break: break-word;
        overflow-x: hidden;
    }
}

/* Danh sách file dạng 2 hàng: hàng 1 checkbox + tên + kích thước, hàng 2 thao tác */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
}
.file-list-item {
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: #fff;
    padding: 11px 10px;
}
.file-list-item:last-child { border-bottom: 0; }
.file-item-top {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) max-content;
    align-items: flex-start;
    column-gap: 8px;
    row-gap: 0;
    width: 100%;
}
.file-main {
    display: contents;
    min-width: 0;
}
.file-main .check-wrap,
.file-main .check-placeholder {
    grid-column: 1;
    grid-row: 1;
}
.file-main .file-name {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.35;
    padding-top: 4px;
}
.file-meta {
    grid-column: 2 / 4;
    grid-row: 2;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
    min-width: 0;
    margin-top: 1px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
    line-height: 1.15;
}
.file-meta time {
    white-space: nowrap;
}
.file-size {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    align-self: start;
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
    text-align: right;
    white-space: nowrap;
    padding-top: 5px;
}
.file-item-actions {
    margin-top: 9px;
    padding-left: 42px;
}
.file-item-actions.actions-cell {
    min-width: 0;
}
.check-placeholder {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
}
.empty-state {
    padding: 14px;
    border: 1px dashed var(--border);
    border-radius: 14px;
    color: var(--muted);
    background: #f8fafc;
}

@media (max-width: 900px) {
    .file-list { border-radius: 14px; }
    .file-list-item { padding: 10px 8px; }
    .file-item-top {
        grid-template-columns: 34px minmax(0, 1fr) max-content;
        column-gap: 7px;
    }
    .file-size { font-size: 12px; padding-top: 6px; }
    .file-item-actions { padding-left: 41px; gap: 6px; }
}

/* Cố định phần điều hướng/công cụ, chỉ cuộn danh sách file trên trang chính */
.filemanager-page {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
}
.filemanager-page .app-shell {
    height: calc(100dvh - 20px);
    margin-top: 10px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.filemanager-page .topbar,
.filemanager-page .path-panel,
.filemanager-page .tools-panel,
.filemanager-page .alert {
    flex: 0 0 auto;
}
.filemanager-page .panel {
    margin-bottom: 10px;
}
.filemanager-page .file-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 0;
}
.filemanager-page .file-toolbar {
    flex: 0 0 auto;
    margin-bottom: 10px;
}
.filemanager-page .file-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Công cụ nhanh: luôn nằm trên một hàng ngang, nhất là trên điện thoại */
.tools-panel .tools-head {
    margin-bottom: 8px;
}
.tools-panel .tool-buttons {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
}
.tools-panel .tool-buttons .btn {
    flex: 0 0 auto;
}

@media (max-width: 900px) {
    .filemanager-page .app-shell {
        width: calc(100% - 12px);
        height: calc(100dvh - 12px);
        margin-top: 6px;
        margin-bottom: 6px;
    }
    .filemanager-page .topbar {
        margin-bottom: 8px;
    }
    .filemanager-page .panel {
        padding: 9px;
        margin-bottom: 8px;
    }
    .filemanager-page .breadcrumb {
        margin-bottom: 8px;
        gap: 6px;
    }
    .filemanager-page .quick-links {
        margin-top: 8px;
    }
    .filemanager-page .tools-head h2,
    .filemanager-page .file-toolbar h2 {
        font-size: 16px;
        margin-bottom: 4px;
    }
    .filemanager-page .tool-buttons {
        gap: 5px;
    }
    .filemanager-page .tool-buttons .btn {
        min-height: 30px;
        padding: 5px 7px;
        border-radius: 9px;
        font-size: 12px;
    }
    .filemanager-page .file-toolbar {
        gap: 8px;
        margin-bottom: 8px;
    }
    .filemanager-page .search {
        min-height: 36px;
        padding: 7px 9px;
    }
    .filemanager-page .file-list-item {
        padding: 9px 8px;
    }
}

/* Đường dẫn dạng cuộn ngang và copy nhanh */
.breadcrumb {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    word-break: normal;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
}
.breadcrumb a,
.breadcrumb span {
    flex: 0 0 auto;
    white-space: nowrap;
}
.file-toolbar > div,
.topbar > div:first-child {
    min-width: 0;
}
.path-line {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    word-break: normal;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
}
.copy-path {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    font: inherit;
    color: var(--muted);
    cursor: copy;
    margin: 5px 0 0;
    padding-left: 0;
    padding-right: 0;
}
.copy-path:hover {
    color: var(--primary);
    text-decoration: none;
}

/* Modal đặt ở đầu trang/đầu màn hình thay vì bật từ dưới lên */
.modal {
    align-items: flex-start;
    padding-top: 18px;
}
@media (max-width: 900px) {
    .modal {
        align-items: flex-start;
        padding: 10px;
        padding-top: 12px;
    }
    .modal-card {
        width: 100%;
        max-height: calc(100dvh - 24px);
        border-radius: 18px;
    }
}

/* Thanh tiến trình upload thật */
.upload-progress {
    margin-top: 12px;
}
.upload-progress-head {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
    margin-bottom: 6px;
}
.progress-track {
    width: 100%;
    height: 11px;
    border-radius: 999px;
    overflow: hidden;
    background: #e4eaf2;
    border: 1px solid var(--border);
}
.progress-bar {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: var(--primary);
    transition: width .16s linear;
}
.btn:disabled {
    opacity: .65;
    cursor: not-allowed;
}

/* Công cụ trong trình sửa file */
.editor-tools {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
}
.editor-tools .btn {
    flex: 0 0 auto;
}
.fm-toast {
    position: fixed;
    left: 50%;
    top: 14px;
    transform: translateX(-50%) translateY(-16px);
    z-index: 2000;
    background: #101828;
    color: #fff;
    border-radius: 999px;
    padding: 9px 14px;
    font-weight: 750;
    box-shadow: 0 12px 35px rgba(16, 24, 40, .22);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
    max-width: calc(100% - 24px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fm-toast.is-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Cập nhật giao diện danh sách file: tiêu đề + tìm kiếm cùng hàng, thao tác nằm trong menu */
.file-toolbar {
    flex-direction: column;
    align-items: stretch;
}
.file-toolbar-main {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
}
.file-toolbar-main h2 {
    flex: 0 0 auto;
    margin: 0;
    white-space: nowrap;
}
.file-toolbar-main .search {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
}
.file-item-top {
    grid-template-columns: 34px minmax(0, 1fr) max-content 34px;
    align-items: flex-start;
}
.action-menu {
    grid-column: 4;
    grid-row: 1;
    position: relative;
    justify-self: end;
    align-self: start;
    z-index: 2;
}
.action-menu[open] {
    z-index: 30;
}
.action-menu summary {
    list-style: none;
}
.action-menu summary::-webkit-details-marker {
    display: none;
}
.action-menu-toggle {
    width: 32px;
    min-width: 32px;
    padding-left: 0;
    padding-right: 0;
    font-size: 18px;
    line-height: 1;
}
.action-menu-list {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 126px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 14px 35px rgba(16, 24, 40, .16);
}
.action-menu-list .btn,
.action-menu-list .inline-form,
.action-menu-list .inline-form .btn {
    width: 100%;
    justify-content: flex-start;
}
.action-menu-list .inline-form {
    display: flex;
}
.file-size {
    padding-right: 2px;
}
.file-item-actions {
    display: none;
}
.editor-main-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
}
.editor-main-actions .btn {
    flex: 0 0 auto;
}

@media (max-width: 900px) {
    .filemanager-page .file-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .file-toolbar-main {
        gap: 6px;
    }
    .file-toolbar-main h2 {
        font-size: 15px;
    }
    .file-toolbar-main .search {
        min-height: 34px;
        padding: 6px 8px;
        font-size: 13px;
    }
    .file-item-top {
        grid-template-columns: 34px minmax(0, 1fr) max-content 32px;
        column-gap: 6px;
    }
    .action-menu-toggle {
        width: 30px;
        min-width: 30px;
        min-height: 30px;
        border-radius: 9px;
    }
    .action-menu-list {
        min-width: 118px;
    }
    .editor-page .topbar {
        flex-direction: column;
        align-items: stretch;
    }
    .editor-main-actions {
        gap: 6px;
    }
    .editor-main-actions .btn {
        min-height: 34px;
        padding: 7px 10px;
    }
}

/* Thống kê thư mục/tệp tin trên cùng hàng với tiêu đề Công cụ nhanh */
.tools-head {
    align-items: center;
}
.item-stats {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 14px;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.file-name {
    text-decoration: none;
}
.file-name:hover {
    text-decoration: underline;
}

@media (max-width: 900px) {
    .filemanager-page .tools-head {
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        white-space: nowrap;
    }
    .filemanager-page .tools-head h2 {
        flex: 0 0 auto;
        margin: 0;
    }
    .filemanager-page .item-stats {
        flex: 0 0 auto;
        font-size: 13px;
    }
}

/* Tùy chọn giải nén trong modal Upload */
.checkbox-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}
.checkbox-stack label,
.modal-card .checkbox-stack label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-weight: 650;
    line-height: 1.35;
}
.checkbox-stack input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}
.upload-options {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
}

/* Công cụ nhanh chia thành 2 hàng theo thứ tự thao tác hàng loạt */
.tool-buttons-wrap {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}
.tools-panel .tool-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
}
.tools-panel .tool-row .btn {
    flex: 0 0 auto;
}
.update-tools-spacer {
    flex: 1 0 18px;
    min-width: 18px;
}
.btn-update-page {
    white-space: nowrap;
    text-decoration: none;
}
.hidden-form { display: none; }
.modal-card-wide {
    width: min(760px, 100%);
}
.bulk-rename-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}
.bulk-rename-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
}
.bulk-rename-row input[readonly] {
    background: #eef2f7;
    color: var(--muted);
}
.single-checkbox {
    margin-top: 10px;
}
@media (max-width: 900px) {
    .tool-buttons-wrap { gap: 5px; }
    .bulk-rename-row {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 6px;
        padding: 6px;
    }
    .bulk-rename-row input {
        min-height: 36px;
        padding: 7px 8px;
        font-size: 13px;
    }
}

/* Màu sắc + icon cho toàn bộ nút thao tác */
.btn {
    gap: 6px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.btn.primary,
.btn.btn-open,
.btn.btn-login,
.btn.btn-upload {
    background: #0f70d7;
    border-color: #0f70d7;
    color: #fff;
}
.btn.primary:hover,
.btn.btn-open:hover,
.btn.btn-login:hover,
.btn.btn-upload:hover {
    background: #0a58ad;
    border-color: #0a58ad;
}
.btn.success,
.btn.btn-save,
.btn.btn-create,
.btn.btn-download {
    background: #ecfdf3;
    border-color: #abefc6;
    color: #027a48;
}
.btn.success:hover,
.btn.btn-save:hover,
.btn.btn-create:hover,
.btn.btn-download:hover {
    background: #d1fadf;
}
.btn.info,
.btn.btn-copy,
.btn.btn-paste {
    background: #eff8ff;
    border-color: #b2ddff;
    color: #175cd3;
}
.btn.info:hover,
.btn.btn-copy:hover,
.btn.btn-paste:hover {
    background: #d1e9ff;
}
.btn.warning,
.btn.btn-zip,
.btn.btn-rename {
    background: #fffaeb;
    border-color: #fedf89;
    color: #b54708;
}
.btn.warning:hover,
.btn.btn-zip:hover,
.btn.btn-rename:hover {
    background: #fef0c7;
}
.btn.purple,
.btn.btn-move {
    background: #f4f3ff;
    border-color: #d9d6fe;
    color: #5925dc;
}
.btn.purple:hover,
.btn.btn-move:hover {
    background: #ebe9fe;
}
.btn.neutral,
.btn.btn-select,
.btn.btn-nav,
.btn.btn-close-action,
.btn.btn-menu {
    background: #f8fafc;
    border-color: #d0d5dd;
    color: #344054;
}
.btn.neutral:hover,
.btn.btn-select:hover,
.btn.btn-nav:hover,
.btn.btn-close-action:hover,
.btn.btn-menu:hover {
    background: #eef2f7;
}
.btn.danger,
.btn.btn-delete {
    background: #fef3f2;
    border-color: #fecdca;
    color: #b42318;
}
.btn.danger:hover,
.btn.btn-delete:hover {
    background: #fee4e2;
}
.action-menu-toggle.btn-menu {
    color: #344054;
    min-width: 34px;
    padding-left: 0;
    padding-right: 0;
}
.modal-close {
    color: #b42318;
    background: #fef3f2;
    border-color: #fecdca;
    font-weight: 800;
}
.modal-close:hover {
    background: #fee4e2;
}

/* Đổi tên hàng loạt: chỉ còn ô nhập tên mới, 2 ô mỗi hàng ngang */
.bulk-rename-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
}
.bulk-rename-row {
    display: block;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}
.bulk-rename-row .new-name-input {
    width: 100%;
}
@media (max-width: 360px) {
    .bulk-rename-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }
    .bulk-rename-row .new-name-input {
        padding-left: 8px;
        padding-right: 8px;
        font-size: 13px;
    }
}

/* Modal thông báo kết quả thao tác */
.result-modal .modal-card,
#messageModal .modal-card {
    width: min(560px, 100%);
}
.result-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}
.result-item {
    padding: 11px 12px;
    border-radius: 13px;
    border: 1px solid var(--border);
    font-weight: 700;
    line-height: 1.45;
    overflow-wrap: anywhere;
}
.result-item.success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: #abefc6;
}
.result-item.error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: #fecdca;
}
.result-item.info {
    background: #eff8ff;
    color: #175cd3;
    border-color: #b2ddff;
}

/* Công cụ nhanh mặc định ẩn, chỉ mở khi bấm nút */
.tools-head {
    cursor: default;
}
.tools-toggle-btn {
    flex: 0 0 auto;
}
.tools-body[hidden] {
    display: none !important;
}
.tools-body {
    display: flex;
    flex-direction: column;
    gap: 9px;
    min-width: 0;
}

/* Ghim đường dẫn thư mục hiện tại vào cookie */
.pinned-paths-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 2px;
    min-width: 0;
}
.pinned-title {
    color: var(--muted);
    font-weight: 800;
    font-size: 13px;
}
.pinned-paths {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
}
.pinned-empty {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}
.pinned-path-item {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    max-width: min(520px, 86vw);
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #f8fafc;
    overflow: hidden;
}
.pinned-path-link {
    display: block;
    padding: 7px 9px 7px 11px;
    color: var(--text);
    font-weight: 750;
    max-width: min(460px, 72vw);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pinned-path-link:hover {
    text-decoration: none;
    color: var(--primary);
}
.pinned-remove {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    margin-right: 3px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--danger);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.pinned-remove:hover {
    background: #fee4e2;
}

@media (max-width: 900px) {
    .tools-toggle-btn {
        min-height: 30px;
        padding: 5px 8px;
        border-radius: 9px;
        font-size: 12px;
    }
    .tools-body {
        gap: 6px;
    }
    .pinned-title,
    .pinned-empty {
        font-size: 12px;
    }
    .pinned-path-link {
        padding: 6px 8px 6px 10px;
        font-size: 12px;
        max-width: 68vw;
    }
    .pinned-remove {
        width: 26px;
        height: 26px;
        font-size: 18px;
    }
}

/* Khối điều hướng chính: tiêu đề và nút về thư mục filemanager cùng một hàng */
.navigation-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.navigation-toggle-btn,
.filemanager-home-btn {
    flex: 0 0 auto;
}
.navigation-body[hidden] {
    display: none !important;
}
.navigation-body {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
    padding-top: 10px;
}
.navigation-subtitle {
    margin: 0 0 10px;
}

/* Tiêu đề + thư mục cha + tìm kiếm luôn cùng một hàng ngang */
.file-toolbar-main {
    flex-wrap: nowrap;
    overflow: hidden;
}
.file-toolbar-main .parent-folder-btn {
    flex: 0 0 auto;
}

@media (max-width: 900px) {
    .navigation-toggle-btn,
    .filemanager-home-btn {
        min-height: 30px;
        padding: 5px 8px;
        border-radius: 9px;
        font-size: 12px;
    }
    .navigation-body {
        padding-top: 7px;
    }
    .file-toolbar-main .parent-folder-btn {
        min-height: 30px;
        padding: 5px 7px;
        border-radius: 9px;
        font-size: 12px;
    }
}


/* Quên mật khẩu và cấu hình Telegram */
.forgot-password-form {
    margin-top: 10px;
    text-align: center;
}
.forgot-password-btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--primary);
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    padding: 7px 10px;
}
.forgot-password-btn:hover {
    text-decoration: underline;
}
.telegram-setup-card {
    width: min(100% - 24px, 520px);
}
.telegram-setup-hint {
    margin: 12px 0 0;
}

/* Editor mở trong modal: khoảng nửa chiều rộng trên máy tính, toàn màn hình trên điện thoại */
.editor-host-modal {
    align-items: center;
    justify-content: center;
    padding: 18px;
}
.editor-host-card {
    width: clamp(640px, 54vw, 980px);
    height: min(88vh, 900px);
    max-height: calc(100dvh - 36px);
    padding: 0;
    overflow: hidden;
    border-radius: 18px;
}
.editor-host-close {
    z-index: 4;
    box-shadow: 0 5px 18px rgba(16, 24, 40, .18);
}
.editor-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: var(--bg);
}

body.editor-page {
    min-height: 100dvh;
}
body.editor-page:not(.editor-embedded) .editor-shell {
    padding: 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}
body.editor-embedded {
    min-height: 100dvh;
    overflow: hidden;
    background: var(--bg);
}
.editor-embedded .editor-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    padding: 14px;
}
.editor-embedded .editor-header {
    flex: 0 0 auto;
    margin-bottom: 10px;
    padding-right: 42px;
}
.editor-heading {
    min-width: 0;
}
.editor-heading h1 {
    font-size: clamp(20px, 3vw, 28px);
}
.editor-heading .path-line {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.editor-embedded .editor-form {
    flex: 1 1 auto;
    min-height: 0;
}
.editor-embedded #codeEditor {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    resize: none;
}
#editorUndoBtn:disabled,
#editorRedoBtn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

@media (max-width: 900px) {
    .editor-host-modal {
        align-items: stretch;
        justify-content: stretch;
        padding: 0;
    }
    .editor-host-card {
        width: 100vw;
        height: 100dvh;
        max-height: none;
        border: 0;
        border-radius: 0;
    }
    .editor-host-close {
        top: 6px;
        right: 6px;
    }
    .editor-embedded .editor-shell {
        height: 100dvh;
        padding: 8px;
    }
    .editor-embedded .editor-header {
        gap: 7px;
        margin-bottom: 7px;
        padding-right: 38px;
    }
    .editor-embedded .editor-heading h1 {
        font-size: 18px;
    }
    .editor-embedded .editor-heading .path-line {
        font-size: 11px;
    }
    .editor-embedded .editor-meta {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 1px;
    }
    .editor-embedded .editor-meta span {
        flex: 0 0 auto;
        padding: 5px 8px;
        font-size: 11px;
    }
    .editor-embedded .editor-tools {
        gap: 5px;
    }
    .editor-embedded .editor-tools .btn,
    .editor-embedded .editor-main-actions .btn {
        min-height: 32px;
        padding: 6px 8px;
        font-size: 12px;
    }
    .editor-embedded #codeEditor {
        border-radius: 10px;
        padding: 10px;
        font-size: 13px;
        white-space: pre-wrap;
        overflow-wrap: anywhere;
        word-break: break-word;
        overflow-x: hidden;
    }
}

/* Nút chọn toàn bộ đặt bên trái tiêu đề Danh sách file */
.file-toolbar-main .file-select-all-btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

@media (max-width: 900px) {
    .file-toolbar-main .file-select-all-btn {
        min-height: 30px;
        padding: 5px 8px;
        border-radius: 9px;
        font-size: 12px;
    }
}

/* Trình cập nhật phiên bản từ máy chủ chính */
.update-modal-card {
    width: min(620px, 100%);
}
.update-version-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 8px 0 10px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
}
.update-version-line span {
    color: var(--muted);
    font-weight: 750;
}
.update-version-line strong {
    white-space: nowrap;
}
.update-status {
    margin-top: 0;
}
.update-details {
    margin-top: 10px;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: #fff;
}
.update-detail-grid {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr);
    gap: 7px 12px;
    font-size: 13px;
}
.update-detail-grid span {
    color: var(--muted);
    font-weight: 700;
}
.update-detail-grid strong {
    overflow-wrap: anywhere;
}
.update-changelog-wrap {
    margin-top: 12px;
}
.update-changelog {
    margin: 7px 0 0;
    padding-left: 20px;
    max-height: 180px;
    overflow-y: auto;
}
.update-changelog li + li {
    margin-top: 5px;
}
.update-warning {
    margin-top: 10px;
}
.update-actions {
    flex-wrap: wrap;
}

@media (max-width: 600px) {
    .update-detail-grid {
        grid-template-columns: minmax(105px, auto) minmax(0, 1fr);
        gap: 6px 9px;
        font-size: 12px;
    }
    .update-version-line {
        font-size: 13px;
    }
    .update-actions .btn {
        flex: 1 1 auto;
    }
}
