/* Final dark-theme layer. It is loaded after page styles so local light-only
   surfaces cannot override the shared night palette. */
html[data-theme="dark"] body.redesign-shell {
    color-scheme: dark;
    background: var(--ops-bg);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell .app-layout,
html[data-theme="dark"] body.redesign-shell .app-main {
    background: var(--ops-bg);
}

html[data-theme="dark"] body.redesign-shell .app-sidebar {
    background: var(--ops-sidebar);
    border-color: var(--ops-border);
}

html[data-theme="dark"] body.redesign-shell .card-panel,
html[data-theme="dark"] body.redesign-shell .card,
html[data-theme="dark"] body.redesign-shell .list-group-item,
html[data-theme="dark"] body.redesign-shell .accordion-item,
html[data-theme="dark"] body.redesign-shell .dropdown-menu,
html[data-theme="dark"] body.redesign-shell .modal-content {
    background-color: var(--ops-surface);
    border-color: var(--ops-border-soft);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell .card-panel-header,
html[data-theme="dark"] body.redesign-shell .card-header,
html[data-theme="dark"] body.redesign-shell .accordion-button {
    background-color: var(--ops-surface);
    border-color: var(--ops-border-soft);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell .accordion-button {
    color: var(--ops-text) !important;
}

html[data-theme="dark"] body.redesign-shell .form-control,
html[data-theme="dark"] body.redesign-shell .form-select,
html[data-theme="dark"] body.redesign-shell textarea,
html[data-theme="dark"] body.redesign-shell input[type="text"],
html[data-theme="dark"] body.redesign-shell input[type="search"],
html[data-theme="dark"] body.redesign-shell input[type="number"],
html[data-theme="dark"] body.redesign-shell input[type="password"],
html[data-theme="dark"] body.redesign-shell input[type="date"],
html[data-theme="dark"] body.redesign-shell input[type="file"] {
    background-color: var(--ops-surface);
    border-color: var(--ops-border);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell .form-select option {
    background: var(--ops-surface);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell .form-control::file-selector-button {
    background: var(--ops-surface-muted);
    border-color: var(--ops-border);
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell .form-control:hover::file-selector-button {
    background: var(--ops-surface-soft);
}

html[data-theme="dark"] body.redesign-shell .btn-outline-secondary {
    background: transparent;
    border-color: var(--ops-border);
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell .btn-outline-secondary:hover,
html[data-theme="dark"] body.redesign-shell .btn-outline-secondary:focus-visible,
html[data-theme="dark"] body.redesign-shell .btn-outline-secondary.active {
    background: var(--ops-surface-muted);
    border-color: rgba(var(--ops-primary-rgb), .42);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell .btn-outline-primary {
    background: transparent;
    border-color: rgba(var(--ops-primary-rgb), .42);
    color: var(--ops-primary-strong);
}

html[data-theme="dark"] body.redesign-shell .btn-outline-primary:hover,
html[data-theme="dark"] body.redesign-shell .btn-outline-primary:focus-visible {
    background: var(--ops-surface-soft);
    color: var(--ops-primary-strong);
}

html[data-theme="dark"] body.redesign-shell .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--ops-text-soft);
    --bs-table-border-color: var(--ops-border-soft);
    --bs-table-hover-bg: var(--ops-surface-muted);
    --bs-table-hover-color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell .table thead th {
    background: var(--ops-surface-muted);
    color: var(--ops-text-muted);
}

html[data-theme="dark"] body.redesign-shell .table-light,
html[data-theme="dark"] body.redesign-shell .table-light > tr,
html[data-theme="dark"] body.redesign-shell .table-light > tr > th {
    --bs-table-bg: var(--ops-surface-muted);
    --bs-table-color: var(--ops-text-muted);
    background: var(--ops-surface-muted);
    color: var(--ops-text-muted);
}

html[data-theme="dark"] body.redesign-shell .bg-light {
    background-color: var(--ops-surface-muted) !important;
}

html[data-theme="dark"] body.redesign-shell .text-dark {
    color: var(--ops-text) !important;
}

html[data-theme="dark"] body.redesign-shell .shell-theme-toggle-icon,
html[data-theme="dark"] body.redesign-shell .lang-pill {
    background: var(--ops-surface-muted);
    border-color: var(--ops-border);
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell .lang-pill.is-active {
    background: var(--ops-primary);
    border-color: var(--ops-primary);
    color: #fff;
}

/* Dialogs */
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-shell,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-pane,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-pane-header,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-chat-body,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-compose-panel {
    background: var(--ops-surface);
    border-color: var(--ops-border-soft);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-pane-accounts,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-pane-dialogs {
    border-right-color: var(--ops-border);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-account-search,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-compose-textarea {
    background: var(--ops-surface-muted);
    border-color: var(--ops-border);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .chat-history,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-chat-stage {
    background: var(--ops-bg);
    border-color: var(--ops-border-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-pane-kicker,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-pane-header h5,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-chat-headline-copy h5,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-chat-headline-copy strong {
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-tab-row .btn,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-filter-modes .btn {
    background: transparent;
    border-color: transparent;
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-tab-row .btn.active,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-filter-modes .btn.active {
    background: var(--ops-surface-soft);
    color: var(--ops-primary-strong);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-tabs .btn {
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-tabs .btn.active {
    color: var(--ops-primary-strong);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] #wrapAnsweredFilters .btn,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] #wrapAllFilters .btn {
    background: var(--ops-surface-muted);
    border-color: var(--ops-border);
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] #wrapAnsweredFilters .btn.active,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] #wrapAllFilters .btn.active {
    background: var(--ops-surface-soft);
    border-color: rgba(var(--ops-primary-rgb), .42);
    color: var(--ops-primary-strong);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-chat-actions .btn,
html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-template-action {
    border-color: var(--ops-border);
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-chat-actions .btn.disabled {
    color: var(--ops-text-muted);
    opacity: .56;
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="messages"] .msg-chat-actions .btn.disabled span {
    color: inherit;
}

/* VK accounts */
html[data-theme="dark"] body.redesign-shell[data-active-tab="accounts"] .accounts-list-panel {
    background: var(--ops-surface);
    border-color: var(--ops-border-soft);
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="accounts"] .account-tools-head h2 {
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="accounts"] .account-tools-grid label {
    color: var(--ops-text-soft);
}

/* Search tokens */
html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-search-field,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-search-field,
html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-bulk-panel,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-bulk-panel {
    background: var(--ops-surface);
    border-color: var(--ops-border);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-capacity-note.is-warning,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-capacity-note.is-warning {
    background: rgba(247, 144, 9, .12);
    border-color: rgba(247, 144, 9, .34);
    color: #fedf89;
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-capacity-note.is-danger,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-capacity-note.is-danger {
    background: rgba(240, 68, 56, .12);
    border-color: rgba(240, 68, 56, .34);
    color: #fecdca;
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-table thead th,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-table thead th {
    background: var(--ops-surface-muted);
    border-color: var(--ops-border-soft);
    color: var(--ops-text-muted);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-table tbody tr,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-table tbody tr {
    background: var(--ops-surface);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-table tbody tr:hover,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-table tbody tr:hover,
html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-table tbody tr.is-selected,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-table tbody tr.is-selected {
    background: var(--ops-surface-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-inline-input:hover,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-inline-input:hover,
html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-inline-input:focus,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-inline-input:focus {
    background: var(--ops-surface-muted);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-icon-button:hover,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-icon-button:hover,
html[data-theme="dark"] body.redesign-shell[data-active-tab="my_tokens"] .tokens-check-button:hover,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_user_tokens"] .tokens-check-button:hover {
    background: var(--ops-surface-soft);
}

/* Token getter */
html[data-theme="dark"] body.redesign-shell[data-active-tab="token_getter"] .token-field input,
html[data-theme="dark"] body.redesign-shell[data-active-tab="token_getter"] .token-field select,
html[data-theme="dark"] body.redesign-shell[data-active-tab="token_getter"] .token-field textarea {
    background: var(--ops-surface);
    border-color: var(--ops-border);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="token_getter"] .token-field select option {
    background: var(--ops-surface);
    color: var(--ops-text);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="token_getter"] .token-icon-button {
    background: var(--ops-surface-muted);
    border-color: var(--ops-border);
    color: var(--ops-text-muted);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="token_getter"] .token-icon-button:not(:disabled):hover {
    background: var(--ops-surface-soft);
    color: var(--ops-primary-strong);
}

/* New-group operators */
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-admin-page {
    --ng-text: var(--ops-text);
    --ng-muted: var(--ops-text-muted);
    --ng-border: var(--ops-border);
    --ng-blue: var(--ops-primary);
    --ng-blue-soft: var(--ops-surface-soft);
    --ng-green: #32d583;
    --ng-red: #f97066;
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-date-filter input,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-icon-button,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-create-panel,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-operators-section,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-history-drawer,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-modal-panel {
    background: var(--ops-surface);
    border-color: var(--ng-border);
    color: var(--ng-text);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-field > span,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-active-switch,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-operator-login,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-operator-name,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-group-type,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-connection,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-number,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-empty-operators strong,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-history-title,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-history-summary strong,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-history-grid h3,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-assignments-history h3 {
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-operator-head,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-operator-editor {
    background: var(--ops-surface-muted);
    border-color: var(--ng-border);
    color: var(--ops-text-muted);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-operator-row:hover,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-operator-record[open] > .ng-operator-row {
    background: var(--ops-surface-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-avatar,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-day-badge {
    background: var(--ops-surface-soft);
    color: var(--ops-primary-strong);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-row-actions,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_new_group_operators"] .ng-operator-record[open] .ng-row-actions {
    background: transparent;
    border-color: var(--ng-border);
    color: var(--ops-text-muted);
}

/* Full statistics */
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-page {
    --as-text: var(--ops-text);
    --as-muted: var(--ops-text-muted);
    --as-border: var(--ops-border);
    --as-blue: var(--ops-primary);
    --as-blue-soft: var(--ops-surface-soft);
    --as-green: #32d583;
    --as-red: #f97066;
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-date-form label,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-icon-button,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-range-tabs a,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-summary,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-managers,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-advanced,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-modal-panel {
    background: var(--ops-surface);
    border-color: var(--as-border);
    color: var(--as-text);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-date-form input,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-metric-label,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-summary strong,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-managers-head h2,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-table-overview,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-table-overview strong,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-table,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-table strong,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-advanced > summary span,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-modal-panel h2,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-modal-summary strong {
    color: var(--ops-text-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-table-actions,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-table thead th,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-table tfoot th {
    background: var(--ops-surface-muted);
    border-color: var(--as-border);
    color: var(--ops-text-muted);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-table tbody tr:hover {
    background: var(--ops-surface-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-delivery-track {
    background: var(--ops-border-soft);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-metric-icon--blue,
html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-avatar {
    background: var(--ops-surface-soft);
    color: var(--ops-primary-strong);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-metric-icon--green {
    background: rgba(18, 183, 106, .14);
}

html[data-theme="dark"] body.redesign-shell[data-active-tab="admin_stats"] .astats-metric-icon--red {
    background: rgba(240, 68, 56, .14);
}
