/* ===== Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #222;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.hidden { display: none !important; }

/* ===== Panels ===== */
.panel {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 10;
}

.panel.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

#viewerPanel.active {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    background: #e8ecf4;
    color: #222;
    width: 100%;
    height: 100%;
}

/* ===== Desk window (login / connect shell) ===== */
.desk-window {
    width: min(920px, 96vw);
    height: min(560px, 92vh);
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: none;
}

.desk-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 16px 8px;
}

.desk-logo-img {
    width: 42px;
    height: 42px;
    object-fit: contain;
}

.desk-logo-text {
    font-size: 28px;
    font-weight: 700;
    color: #2f6fed;
    letter-spacing: 0.5px;
}

.desk-body {
    flex: 1;
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    gap: 14px;
    padding: 8px 16px 12px;
    min-height: 0;
}

.desk-left, .desk-right {
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.tab-pane { display: none; flex-direction: column; gap: 8px; flex: 1; }
.tab-pane.active { display: flex; }

.connect-form label {
    font-size: 13px;
    color: #555;
}

.connect-form input[type="text"],
.connect-form input[type="password"],
.contact-add input,
.book-search input,
.modal-card input {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #c8d0dc;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    color: #222;
}

.connect-form input:focus,
.book-search input:focus,
.modal-card input:focus {
    outline: none;
    border-color: #2f6fed;
    box-shadow: 0 0 0 2px rgba(47, 111, 237, 0.15);
}

.btn-connect {
    margin-top: 6px;
    width: 100%;
    padding: 11px 14px;
    background: #2f6fc0;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.btn-connect:hover { background: #1e5a9e; }

.router-status {
    margin-top: auto;
    font-size: 12px;
    color: #8a93a3;
    padding-top: 8px;
}

.status {
    font-size: 12px;
    color: #555;
    min-height: 1.2em;
}
.status.error { color: #c0392b; }
.status.connecting { color: #2f6fed; }
.status.connected { color: #2e8b57; }

.book-title {
    font-size: 15px;
    color: #6b7585;
    margin-bottom: 8px;
}

.book-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.book-search {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #c8d0dc;
    border-radius: 6px;
    padding: 0 8px;
    background: #fff;
}

.book-search input {
    border: none;
    padding: 8px 4px;
    box-shadow: none;
}

.book-search input:focus { box-shadow: none; }
.search-ico { font-size: 12px; opacity: 0.55; }

.tool-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #d0d7e2;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    color: #2f6fed;
    font-size: 14px;
}

.tool-btn:hover { background: #f3f6fb; }

.contact-list {
    flex: 1;
    overflow: auto;
    border: 1px solid #e6ebf2;
    border-radius: 8px;
    background: #fafbfd;
}

.contact-empty {
    padding: 24px 12px;
    text-align: center;
    color: #9aa3b2;
    font-size: 13px;
}

.contact-error {
    color: #b42318;
    background: #fff1f0;
    border: 1px solid #ffccc7;
    border-radius: 8px;
    margin: 12px;
}

.contact-row {
    width: 100%;
    display: grid;
    grid-template-columns: 28px 1fr auto 20px;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border: none;
    border-bottom: 1px solid #eef1f6;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.contact-row:hover { background: #eef4ff; }
.contact-row.selected { background: #e3ecff; }

.contact-row .presence {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #c5ccd8;
    justify-self: center;
}
.contact-row .presence.online { background: #2e8b57; }

.contact-row b { display: block; font-size: 13px; font-weight: 600; }
.contact-row small { color: #8a93a3; font-size: 11px; }
.contact-row em {
    font-style: normal;
    color: #6b7585;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.contact-row .star { color: #c5ccd8; font-size: 12px; }
.contact-row .star.on { color: #f0b429; }

.contact-add {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 8px;
}
.contact-add button { grid-column: 1 / -1; }

.desk-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px 12px;
    border-top: 1px solid #e6ebf2;
    font-size: 12px;
    color: #6b7585;
}

.footer-actions { display: flex; gap: 8px; }

.footer-btn {
    padding: 6px 14px;
    border: 1px solid #c8d0dc;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    color: #333;
}

.footer-btn:hover { background: #f3f6fb; }

.portal-message {
    padding: 0 16px 10px;
    font-size: 12px;
    color: #2f6fed;
    min-height: 1em;
}
.portal-message.error { color: #c0392b; }

/* Login modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
}

.modal-card {
    width: min(380px, 100%);
    background: #fff;
    border-radius: 14px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 18px 50px rgba(0,0,0,0.22);
}

.modal-card h3 { font-size: 16px; color: #333; margin: 0; }
.modal-hint {
    margin: 0;
    font-size: 13px;
    color: #66758a;
    line-height: 1.45;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* Пока нет сессии оператора — рабочая область недоступна */
body.auth-required #connectionPanel .desk-body,
body.auth-required #connectionPanel .desk-footer,
body.auth-required #contactsFab {
    pointer-events: none;
    user-select: none;
    filter: grayscale(0.15);
    opacity: 0.4;
}
body.auth-required #viewerPanel {
    display: none !important;
}

/* ===== Viewer chrome (light, как страница авторизации) ===== */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #fff;
    border-bottom: 1px solid #dce3ee;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(40, 60, 90, 0.06);
}

.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 6px 12px;
    background: #edf4fb;
    border: 1px solid #c8d0dc;
    border-radius: 8px;
    color: #31506d;
    cursor: pointer;
    font-size: 13px;
}

.btn:hover { background: #dceaf8; border-color: #2f6fc0; color: #1e5a9e; }
.btn-danger { background: #e74c3c; border: none; color: #fff; }
.btn-danger:hover { background: #c0392b; color: #fff; border: none; }
.btn-small { padding: 4px 10px; font-size: 11px; }

.fps-counter, .connection-info, .resolution-info, .bandwidth-info {
    font-size: 12px;
    color: #6b7585;
}

.screen-container {
    flex: 1 1 auto;
    position: relative;
    background: #000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

.screen-scroll {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 100% / зум больше окна — скролл только у screen-scroll */
.screen-scroll.is-panning {
    display: flex;
    align-items: safe center;
    justify-content: safe center;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.screen-viewport {
    position: relative;
    transform-origin: 0 0;
    max-width: 100%;
    max-height: 100%;
}

.screen-scroll.is-panning .screen-viewport {
    max-width: none;
    max-height: none;
    flex: 0 0 auto;
    margin: auto;
}

.screen-canvas, .cursor-canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
    pointer-events: none; /* ввод только через #inputCapture / drag-shield */
    -webkit-user-drag: none;
    user-drag: none;
    -webkit-user-select: none;
    user-select: none;
}

.screen-scroll.is-panning .screen-canvas,
.screen-scroll.is-panning .cursor-canvas {
    max-width: none;
    max-height: none;
}

.screen-viewport .cursor-canvas {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
}

.cursor-canvas {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none;
}

/* Перехват мыши/тача — не canvas (иначе Chrome открывает картинку в новой вкладке) */
.input-capture {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    cursor: inherit;
    outline: none;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    background: transparent;
}

/* Полноэкранный щит на время зажатой кнопки — жест «вынести картинку» не стартует */
.rd-drag-shield {
    position: fixed;
    inset: 0;
    z-index: 2147483646;
    cursor: inherit;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    background: transparent;
}

.cursor-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Мобильная плавающая панель */
.mobile-toolbar {
    position: absolute;
    left: 8px;
    top: 8px;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid #d5dbe6;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(40, 60, 90, 0.18);
    max-width: calc(100% - 16px);
    pointer-events: auto;
}

.mobile-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.mtool {
    min-width: 36px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid #c8d0dc;
    border-radius: 6px;
    background: #edf4fb;
    color: #31506d;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mtool:active { background: #dceaf8; }
.mtool.active { background: #2f6fc0; border-color: #2f6fc0; color: #fff; }
select.mtool {
    min-width: 88px;
    max-width: 120px;
    appearance: auto;
}

.mobile-status {
    position: absolute;
    right: 8px;
    top: 8px;
    left: auto;
    z-index: 35;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.9);
    color: #31506d;
    border: 1px solid #d5dbe6;
    font-size: 11px;
    border-radius: 4px;
    pointer-events: none;
}

.mobile-kbd-input {
    position: absolute;
    left: -9999px;
    top: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    border: 0;
    padding: 0;
    z-index: -1;
}

/* Встроенная компактная клавиатура */
.mobile-keyboard {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 55;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 4px 3px calc(4px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid #dce3ee;
    box-shadow: 0 -4px 16px rgba(40, 60, 90, 0.12);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.mkb-row {
    display: flex;
    gap: 3px;
    justify-content: center;
}

.mkey {
    flex: 1 1 0;
    min-width: 0;
    height: 34px;
    border: 1px solid #d0d7e2;
    border-radius: 5px;
    background: #f5f7fb;
    color: #222;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
}

.mkey:active { background: #e8eef8; }
.mkey.active { background: #2f6fc0; border-color: #2f6fc0; color: #fff; }
.mkey.wide { flex: 2 1 0; }
.mkey.space { flex: 4 1 0; }
.mkey.fn { background: #edf4fb; color: #31506d; font-size: 11px; }
.mkey.sm { font-size: 10px; letter-spacing: -0.3px; }
.mkey.mmod.active { background: #2f6fc0; border-color: #2f6fc0; color: #fff; }

.mobile-hide-chrome { display: none !important; }

@media (max-width: 900px) {
    #viewerPanel.active {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
    }
    #viewerPanel .topbar {
        display: none;
    }
}

.no-signal, .loading-overlay, .file-drop-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.55);
    color: #fff;
    text-align: center;
}

.quality-select, .scale-select {
    background: #fff;
    border: 1px solid #c8d0dc;
    color: #31506d;
    border-radius: 8px;
    padding: 4px 8px;
}

.side-panel {
    position: absolute;
    top: 48px;
    right: 12px;
    width: 320px;
    max-height: calc(100% - 100px);
    overflow: auto;
    background: #fff;
    border: 1px solid #dce3ee;
    border-radius: 12px;
    z-index: 20;
    color: #222;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.side-panel.file-panel {
    width: min(560px, calc(100vw - 24px));
    max-height: calc(100% - 64px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.side-panel.file-panel .panel-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
    min-height: 0;
    padding: 12px;
}

.side-panel .panel-content { padding: 16px; }
.side-panel label { display: block; margin: 8px 0; font-size: 13px; color: #555; }
.side-panel input[type="text"],
.side-panel input[type="number"],
.side-panel input[type="range"],
.side-panel select {
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid #c8d0dc;
    border-radius: 8px;
    background: #fff;
    color: #222;
    font: inherit;
}
.side-panel h2, .side-panel h3 { color: #333; font-weight: 600; }

.fm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.fm-header h2 { margin: 0; font-size: 16px; }

.fm-path-row, .fm-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.fm-path {
    flex: 1 1 140px;
    min-width: 0;
    background: #fff;
    border: 1px solid #c8d0dc;
    color: #222;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 13px;
}

.fm-cols {
    display: grid;
    grid-template-columns: 1fr 72px 120px;
    gap: 6px;
    padding: 4px 8px;
    font-size: 11px;
    color: #8a93a3;
    border-bottom: 1px solid #e6ebf2;
}

.fm-list, .file-list {
    flex: 1 1 auto;
    min-height: 220px;
    max-height: 52vh;
    overflow: auto;
    background: #fafbfd;
    border: 1px solid #e6ebf2;
    border-radius: 8px;
}

.fm-row {
    display: grid;
    grid-template-columns: 22px 1fr 72px 120px;
    gap: 6px;
    align-items: center;
    padding: 6px 8px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid #eef1f6;
}
.fm-row:hover { background: #eef4ff; }
.fm-row.selected { background: #e3ecff; }
.fm-row .fm-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.fm-row .fm-size, .fm-row .fm-mtime {
    font-size: 11px;
    color: #8a93a3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.fm-row.selected .fm-size,
.fm-row.selected .fm-mtime { color: #31506d; }
.fm-empty { padding: 24px; text-align: center; color: #9aa3b2; }
.fm-status { font-size: 12px; color: #6b7585; min-height: 1.2em; }
.fm-status.error { color: #c0392b; }
.fm-progress {
    font-size: 12px;
    color: #2f6fc0;
    background: #edf4fb;
    border-radius: 4px;
    padding: 4px 8px;
}

@media (max-width: 900px) {
    .side-panel.file-panel {
        left: 8px;
        right: 8px;
        width: auto;
        top: 8px;
        max-height: calc(100% - 16px);
    }
    .fm-cols { display: none; }
    .fm-row { grid-template-columns: 22px 1fr 64px; }
    .fm-row .fm-mtime { display: none; }
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #222;
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    z-index: 100;
    font-size: 13px;
}
.toast.success { background: #2e8b57; }
.toast.error { background: #c0392b; }

.sidebar { display: none; }

/* Floating contacts button + close button (mobile only; toggled via .hidden in JS) */
.contacts-fab { display: none; }
.book-close { display: none; }

@media (max-width: 760px) {
    .desk-body { grid-template-columns: 1fr; }
    .desk-window { height: auto; max-height: 96vh; overflow: auto; }

    /* Contact book becomes a floating bottom sheet, hidden by default */
    .desk-right {
        display: none;
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: 84px;
        max-height: 62vh;
        padding: 14px 14px 14px;
        background: #fff;
        border: 1px solid #d5dbe6;
        border-radius: 12px;
        box-shadow: 0 12px 32px rgba(20, 35, 70, 0.28);
        z-index: 60;
        overflow: auto;
    }
    .desk-right.open { display: flex; }

    .book-close:not(.hidden) {
        display: block;
        position: absolute;
        top: 8px;
        right: 10px;
        border: none;
        background: transparent;
        color: #6b7585;
        font-size: 16px;
        cursor: pointer;
        padding: 4px 6px;
        width: auto;
        line-height: 1;
    }

    .contacts-fab:not(.hidden) {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        right: 16px;
        bottom: 20px;
        width: 52px;
        height: 52px;
        border-radius: 50%;
        border: none;
        background: #2f6fed;
        color: #fff;
        font-size: 22px;
        cursor: pointer;
        box-shadow: 0 6px 18px rgba(47, 111, 237, 0.45);
        z-index: 61;
    }
}

/* ===== Тёмная тема (включается кнопкой; по умолчанию светлая) ===== */
html[data-theme="dark"] body {
    background: linear-gradient(135deg, #232544 0%, #3a2a4d 100%);
    color: #e6e8f0;
}

html[data-theme="dark"] #viewerPanel.active {
    background: #14162a;
    color: #e0e0e0;
}

html[data-theme="dark"] .desk-window {
    background: #1b1f36;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .desk-logo-text { color: #6f9bff; }
html[data-theme="dark"] .connect-form label,
html[data-theme="dark"] .contact-add label,
html[data-theme="dark"] .side-panel label { color: #a8b1c7; }

html[data-theme="dark"] .connect-form input[type="text"],
html[data-theme="dark"] .connect-form input[type="password"],
html[data-theme="dark"] .contact-add input,
html[data-theme="dark"] .book-search input,
html[data-theme="dark"] .modal-card input,
html[data-theme="dark"] .side-panel input[type="text"],
html[data-theme="dark"] .side-panel input[type="number"],
html[data-theme="dark"] .side-panel select,
html[data-theme="dark"] .fm-path,
html[data-theme="dark"] .chat-input input {
    background: #10142a;
    border-color: #313860;
    color: #e6e8f0;
}

html[data-theme="dark"] .book-search {
    background: #10142a;
    border-color: #313860;
}

html[data-theme="dark"] .btn-connect {
    background: #2f6fc0;
    color: #fff;
}
html[data-theme="dark"] .btn-connect:hover { background: #3b82d6; }

html[data-theme="dark"] .router-status,
html[data-theme="dark"] .status,
html[data-theme="dark"] .book-title,
html[data-theme="dark"] .desk-footer,
html[data-theme="dark"] .contact-row em { color: #98a2ba; }

html[data-theme="dark"] .tool-btn,
html[data-theme="dark"] .footer-btn {
    background: #232847;
    border-color: #343c66;
    color: #dfe3ef;
}
html[data-theme="dark"] .tool-btn:hover,
html[data-theme="dark"] .footer-btn:hover { background: #2c3357; }

html[data-theme="dark"] .contact-list {
    background: #161a30;
    border-color: #2b3157;
}
html[data-theme="dark"] .contact-empty { color: #7c86a0; }
html[data-theme="dark"] .contact-row { border-bottom-color: #262c4c; }
html[data-theme="dark"] .contact-row:hover { background: #232a49; }
html[data-theme="dark"] .contact-row.selected { background: #2b3a68; }
html[data-theme="dark"] .contact-row small { color: #8e98b0; }
html[data-theme="dark"] .desk-footer { border-top-color: #2b3157; }

html[data-theme="dark"] .modal-card {
    background: #1b1f36;
    color: #e6e8f0;
}
html[data-theme="dark"] .modal-card h3 { color: #e6e8f0; }
html[data-theme="dark"] .modal { background: rgba(6, 8, 18, 0.6); }

html[data-theme="dark"] .topbar {
    background: #171b31;
    border-bottom-color: #2a2f4e;
    box-shadow: none;
}

html[data-theme="dark"] .btn {
    background: #232847;
    border-color: #343c66;
    color: #dfe3ef;
}
html[data-theme="dark"] .btn:hover {
    background: #2f3866;
    border-color: #4a86f7;
    color: #fff;
}
html[data-theme="dark"] .btn-danger { background: #e74c3c; color: #fff; border: none; }
html[data-theme="dark"] .btn-danger:hover { background: #c0392b; }

html[data-theme="dark"] .quality-select,
html[data-theme="dark"] .scale-select {
    background: #10142a;
    border-color: #343c66;
    color: #dfe3ef;
}

html[data-theme="dark"] .fps-counter,
html[data-theme="dark"] .connection-info,
html[data-theme="dark"] .resolution-info,
html[data-theme="dark"] .bandwidth-info { color: #98a2ba; }

html[data-theme="dark"] .side-panel {
    background: #1b1f36;
    border-color: #2b3157;
    color: #e6e8f0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .side-panel h2,
html[data-theme="dark"] .side-panel h3 { color: #e6e8f0; }

html[data-theme="dark"] .fm-cols { color: #8e98b0; border-bottom-color: #2b3157; }
html[data-theme="dark"] .fm-list,
html[data-theme="dark"] .file-list {
    background: #10142a;
    border-color: #2b3157;
}
html[data-theme="dark"] .fm-row { border-bottom-color: #232946; }
html[data-theme="dark"] .fm-row:hover { background: #232a49; }
html[data-theme="dark"] .fm-row.selected { background: #2b3a68; }
html[data-theme="dark"] .fm-row .fm-size,
html[data-theme="dark"] .fm-row .fm-mtime { color: #8e98b0; }
html[data-theme="dark"] .fm-row.selected .fm-size,
html[data-theme="dark"] .fm-row.selected .fm-mtime { color: #cfe0ff; }
html[data-theme="dark"] .fm-empty { color: #7c86a0; }
html[data-theme="dark"] .fm-status { color: #98a2ba; }
html[data-theme="dark"] .fm-status.error { color: #ff8a80; }
html[data-theme="dark"] .fm-progress { background: #10142a; color: #8ab4ff; }

html[data-theme="dark"] .mobile-toolbar {
    background: rgba(23, 27, 49, 0.94);
    border-color: #343c66;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .mtool {
    background: #232847;
    border-color: #343c66;
    color: #dfe3ef;
}
html[data-theme="dark"] .mtool:active { background: #2f3866; }
html[data-theme="dark"] .mtool.active { background: #2f6fc0; border-color: #2f6fc0; color: #fff; }

html[data-theme="dark"] .mobile-status {
    background: rgba(10, 12, 24, 0.72);
    border-color: #343c66;
    color: #dfe3ef;
}

html[data-theme="dark"] .mobile-keyboard {
    background: rgba(20, 23, 42, 0.94);
    border-top-color: #2a2f4e;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .mkey {
    background: #262c4c;
    border-color: #343c66;
    color: #eceff7;
}
html[data-theme="dark"] .mkey:active { background: #31385e; }
html[data-theme="dark"] .mkey.active,
html[data-theme="dark"] .mkey.mmod.active { background: #2f6fc0; border-color: #2f6fc0; color: #fff; }
html[data-theme="dark"] .mkey.fn { background: #1e2340; color: #c3cade; }

html[data-theme="dark"] .portal-message { color: #8ab4ff; }
html[data-theme="dark"] .portal-message.error { color: #ff8a80; }

@media (max-width: 760px) {
    html[data-theme="dark"] .desk-right {
        background: #1b1f36;
        border-color: #2b3157;
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    }
    html[data-theme="dark"] .book-close:not(.hidden) { color: #98a2ba; }
}
