.portal-preferences {
    display: flex;
    align-items: center;
    gap: 10px;
}

@media (max-width: 650px) {
    .portal-preferences { gap: 6px; }
}

.header-dropdown {
    position: relative;
    display: block;
    flex-shrink: 0;
}

.header-dropdown[hidden], .appearance-choice[hidden] { display: none; }

.header-dropdown > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 110px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface, #fff);
    color: var(--text, #263b45);
    font-size: 12px;
    line-height: 1.6;
    list-style: none;
    white-space: nowrap;
    cursor: pointer;
}

.header-dropdown > summary::-webkit-details-marker { display: none; }

.header-dropdown > summary:focus-visible,
.header-dropdown-options button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.header-dropdown-options {
    position: absolute;
    top: calc(100% + 5px);
    inset-inline-end: 0;
    min-width: 155px;
    padding: 5px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface, #fff);
    box-shadow: 0 8px 25px #203b4826;
    z-index: 40;
}

.header-dropdown-options :is(a, button) {
    padding: 9px 11px;
    font-size: 12px;
    border-radius: 4px;
    white-space: nowrap;
}

.header-dropdown-options :is(a, button):hover { background: var(--soft); }

.header-dropdown-options button,
.appearance-choice {
    display: flex;
    align-items: center;
    gap: 7px;
}

.header-dropdown-options button {
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 12px;
    text-align: start;
    cursor: pointer;
}

.header-dropdown-options button[aria-pressed="true"] {
    background: var(--soft);
    border-color: var(--line);
    color: var(--accent-dark);
}

.appearance-icon, .appearance-check { display: inline-flex; }
.appearance-icon svg, .appearance-check svg { width: 15px; height: 15px; flex-shrink: 0; }
.appearance-icon--auto { color: #356d81; }
.appearance-icon--light { color: #9c5f12; }
.appearance-icon--dark { color: #6150a1; }
.appearance-check { margin-inline-start: auto; visibility: hidden; }
[aria-pressed="true"] > .appearance-check { visibility: visible; }

@media (max-width: 650px) {
    .header-dropdown > summary { min-width: 92px; padding: 6px 8px; }
}

@media print {
    .portal-appearance { display: none; }
}

@media screen {
    html[data-portal-theme="light"] { color-scheme: light; }

    html[data-portal-theme="dark"] {
        color-scheme: dark;
        background: #11181e;
    }

    html[data-portal-theme="dark"] body {
        --surface: #11181e;
        --paper: #19232a;
        --inset: #202d35;
        --field: #131d24;
        --field-line: #647985;
        --line: #344750;
        --ink: #e4edf1;
        --muted: #b3c2ca;
        --text: var(--ink);
        --accent: #8dca73;
        --accent-dark: #a6df91;
        --action: #96ce7c;
        --action-ink: #102019;
        --soft: #23352e;
        --dark: #233a32;
        --positive: #99dfa9;
        --positive-panel: #1c352d;
        --positive-line: #467659;
        --warning: #ffd18a;
        --warning-panel: #3b2b21;
        --warning-line: #88623b;
        --danger: #ffabb1;
        --danger-panel: #3b242d;
        --danger-line: #945662;
        --info: #a5d2ff;
        --info-panel: #1e3147;
        --info-line: #50759a;
        --reply: #d6bfff;
        --reply-panel: #312642;
        --reply-line: #78639a;
        background: var(--surface);
        color: var(--ink);
    }

    /* Keep the identity hue for navigation and primary actions on every portal. */
    html[data-portal-theme="dark"] body.brand-servts {
        --accent: #58d1bd;
        --accent-dark: #82e1d0;
        --soft: #193833;
        --dark: #19383c;
        --action: #efd479;
    }

    html[data-portal-theme="dark"] body.brand-simplevm {
        --accent: #5ad2c6;
        --accent-dark: #8be2d6;
        --soft: #1c3637;
        --dark: #24314a;
        --action: #ff9e8d;
    }

    html[data-portal-theme="dark"] body.brand-tinyvds {
        --accent: #ff936f;
        --accent-dark: #ffb199;
        --soft: #392b26;
        --dark: #30372e;
        --action: #ff9a77;
    }

    html[data-portal-theme="dark"] body.brand-vdsplanet {
        --accent: #80baff;
        --accent-dark: #a5d3ff;
        --soft: #22354b;
        --dark: #1e354e;
        --action: #80baff;
    }

    html[data-portal-theme="dark"] body.brand-vds6 {
        --accent: #a0b4ff;
        --accent-dark: #bbc8ff;
        --soft: #293450;
        --dark: #343550;
        --action: #a0b4ff;
    }

    html[data-portal-theme="dark"] body.brand-vmium {
        --accent: #78bbfa;
        --accent-dark: #a5d4ff;
        --soft: #20344a;
        --dark: #20354d;
        --action: #ffd24a;
    }

    /* Navigation, cards, and form controls. */
    html[data-portal-theme="dark"] :is(.topbar, .sidebar, .panel, .auth-card, .stat-card,
        .account-tabs, .vps-tabs, .kb-feed, .kb-categories, .kb-category-intro,
        .announcement-feed, .announcement-months, .skip-link, .cart-summary,
        .brand-option.current, .auth-brand-tabs a, .plan-category-link) {
        background-color: var(--paper);
        border-color: var(--line);
    }

    html[data-portal-theme="dark"] :is(.help-box, .payment-method-tab, .message.staff-message,
        .kb-categories h2, .announcement-months h2, .mass-detail-summary dl > div,
        th, .mini-row:hover, tbody tr:hover) {
        background-color: var(--inset);
    }

    html[data-portal-theme="dark"] :is(.topbar .public-support-nav, .settings-detail,
        .kb-categories a, .announcement-months nav a, .announcement-summary, .kb-summary,
        .announcement-article > time, .kb-article .markdown-body :is(td, th, h2),
        .customer-invoice-workspace .invoice-retention-offer, .invoice-method-selector,
        .invoice-identity, .vps-readonly-frame) {
        border-color: var(--line);
    }

    html[data-portal-theme="dark"] :is(.portal-name, .workspace-label, .nav-item,
        .eyebrow, .stat-label, .stat-note, .stat-card strong small,
        .brand-option, .brand-option-arrow, .portal-footer, .portal-footer a,
        .service-identity span, .service-plan span, .service-renewal :is(span, small),
        .small-symbol, .table-secondary, .mini-identity small, .message-header div > span,
        .message-header time, .customer-conversation .message-header time,
        .sender-notice, .empty-state, th, dt, label, legend, .priority, .subtle-note,
        .settings-detail span, .section-title span, .period-tabs a, .demo-entry > span,
        .invoice-identity, .customer-invoice-workspace .invoice-identity, .invoice-line-label,
        .customer-invoice-table th, .public-plan-countries, .kb-count, .announcement-article > time,
        .announcement-summary-footer time, .kb-summary-footer,
        .dashboard-recent-records .mini-identity small, .service-card .service-reference,
        .service-identity > .service-reference, .page-heading .service-reference) {
        color: var(--muted);
    }

    html[data-portal-theme="dark"] :is(.nav-item:hover, .nav-item.selected, .payment-method-tab:hover,
        .payment-method-tab.is-active, .account-tab.is-active, .account-tab:hover,
        .kb-categories a[aria-current], .announcement-months nav a[aria-current],
        .checkout-payment-choice:has(input:checked)) {
        background: var(--soft);
        color: var(--accent-dark);
    }

    html[data-portal-theme="dark"] :is(.public-support-nav a, .back-link, .panel-heading > a,
        .announcement-summary h2 a, .announcement-summary-footer a, .kb-summary h2 a,
        .kb-summary-footer a, .kb-category-intro h2, .announcement-article .markdown-body :is(h2, h3),
        .markdown-body a, .service-reference > span, .invoice-number-link) {
        color: var(--accent-dark);
    }

    html[data-portal-theme="dark"] :is(.public-support-nav .public-contact-link:hover,
        .public-support-nav .public-contact-link[aria-current="page"]) {
        color: var(--action-ink);
    }

    html[data-portal-theme="dark"] :is(.header-dropdown > summary, .header-dropdown-options) {
        background: var(--paper);
        color: var(--ink);
        border-color: var(--field-line);
    }

    html[data-portal-theme="dark"] .appearance-icon--auto { color: var(--info); }
    html[data-portal-theme="dark"] .appearance-icon--light { color: var(--warning); }
    html[data-portal-theme="dark"] .appearance-icon--dark { color: var(--reply); }

    html[data-portal-theme="dark"] :is(.button-outline, .customer-invoice-table .invoice-view-button,
        .dashboard-os-banner .button, .service-summary .service-ip-copy,
        .vps-address button.service-ip-copy:not([hidden]), .public-plan-fields .configuration-os-family,
        .checkout-page .checkout-payment-choice, input, select, textarea) {
        background-color: var(--field);
        border-color: var(--field-line);
        color: var(--ink);
    }

    html[data-portal-theme="dark"] :is(.button-outline, input, select, textarea):is(:hover, :focus-visible) {
        border-color: var(--accent);
    }

    html[data-portal-theme="dark"] :is(input, textarea)::placeholder { color: var(--muted); }

    html[data-portal-theme="dark"] select:not([multiple]):not([size]) {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23b3c2ca' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
    }

    /* A neutral backing keeps dark letters on supplied logos legible. */
    html[data-portal-theme="dark"] body:not(.brand-vds6) .brand-logo img,
    html[data-portal-theme="dark"] :is(.brand-logo--gray img,
        .invoice-identity img:not(.vds6-invoice-logo:not(.vds6-invoice-logo--gray))) {
        background: #c8d2d8;
        border-radius: 5px;
        padding: 4px 7px;
    }

    html[data-portal-theme="dark"] :is(.service-symbol, .brand-square) {
        background: var(--soft);
        color: var(--accent-dark);
        border-color: var(--line);
    }

    html[data-portal-theme="dark"] .dashboard-os-banner {
        background: linear-gradient(145deg, var(--soft), var(--paper) 82%);
        border-color: var(--line);
    }

    html[data-portal-theme="dark"] .dashboard-stat-grid .stat-card {
        background: linear-gradient(145deg, var(--soft), var(--paper) 82%);
        border-color: var(--line);
        border-top-color: var(--accent);
    }

    html[data-portal-theme="dark"] .dashboard-stat-grid .stat-unpaid {
        background: linear-gradient(145deg, var(--warning-panel), var(--paper) 82%);
        border-top-color: var(--warning-line);
    }

    html[data-portal-theme="dark"] .dashboard-stat-grid .stat-paid {
        background: linear-gradient(145deg, var(--positive-panel), var(--paper) 82%);
        border-top-color: var(--positive-line);
    }

    html[data-portal-theme="dark"] .dashboard-stat-grid .stat-tickets {
        background: linear-gradient(145deg, var(--info-panel), var(--paper) 82%);
        border-top-color: var(--info-line);
    }

    html[data-portal-theme="dark"] :is(.dashboard-os-logo, .service-symbol-glyph) {
        background: #acbbc4;
        border-color: #acbbc4;
        color: #18242d;
    }

    /* Positive, pending, informational, answered and error states keep distinct hues. */
    html[data-portal-theme="dark"] :is(.badge, .customer-invoice-table .badge,
        .service-status-badge, .record-status, .vps-power-chip) {
        color: var(--status-ink, var(--muted));
        background: var(--status-panel, var(--inset));
        border-color: var(--status-line, var(--line));
    }

    html[data-portal-theme="dark"] :is(.badge-active, .badge-paid, .record-status-paid,
        .public-plan-stock, .notice.success, .vps-power-chip.is-running) {
        --status-ink: var(--positive);
        --status-panel: var(--positive-panel);
        --status-line: var(--positive-line);
    }

    html[data-portal-theme="dark"] :is(.badge-pending, .badge-suspended, .badge-unpaid,
        .badge-new, .record-status-new, .record-status-unpaid, .demo-label, .notice:not(.success, .error),
        .public-plan-unavailable, .public-plan-stock.sold-out, .service-suspension-guidance,
        .stat-icon.amber, .vps-power-chip.is-paused, .traffic-review) {
        --status-ink: var(--warning);
        --status-panel: var(--warning-panel);
        --status-line: var(--warning-line);
    }

    html[data-portal-theme="dark"] :is(.badge-open, .badge-customer_reply, .badge-refunded,
        .record-status-open, .record-status-customer_reply, .service-pending-guidance, .stat-icon.blue) {
        --status-ink: var(--info);
        --status-panel: var(--info-panel);
        --status-line: var(--info-line);
    }

    html[data-portal-theme="dark"] :is(.badge-answered, .record-status-answered) {
        --status-ink: var(--reply);
        --status-panel: var(--reply-panel);
        --status-line: var(--reply-line);
    }

    html[data-portal-theme="dark"] :is(.badge-cancelled, .badge-canceled, .badge-fraud, .record-status-fraud,
        .badge-disabled, .badge-terminated, .notice.error, .header-logout, .sidebar .logout, .cart-remove) {
        --status-ink: var(--danger);
        --status-panel: var(--danger-panel);
        --status-line: var(--danger-line);
    }

    html[data-portal-theme="dark"] :is(.notice, .demo-label, .public-plan-stock, .public-plan-unavailable,
        .service-suspension-guidance, .service-pending-guidance, .stat-icon.amber, .stat-icon.blue,
        .header-logout, .sidebar .logout, .cart-remove, .traffic-review,
        .invoice-actions .invoice-status .badge, .service-history-card .badge) {
        color: var(--status-ink, var(--muted));
        background: var(--status-panel, var(--inset));
        border-color: var(--status-line, var(--line));
    }

    html[data-portal-theme="dark"] :is(.notice, .service-suspension-guidance, .service-pending-guidance) p {
        color: inherit;
    }

    html[data-portal-theme="dark"] :is(.header-logout, .sidebar .logout, .cart-remove):hover {
        background: color-mix(in srgb, var(--danger-panel), var(--danger) 13%);
    }

    html[data-portal-theme="dark"] :is(.priority-high, .invoice-amount small, .dashboard-recent-records .mini-value > small) {
        color: var(--warning);
    }

    html[data-portal-theme="dark"] :is(.priority-urgent, .registration-field-error, .configuration-field-error,
        .cancellation-reversible, .cancellation-reversible a, .mass-detail-actions .mass-cancel-button) {
        color: var(--danger);
    }

    html[data-portal-theme="dark"] :is(.priority-medium, .promo-saving) { color: var(--positive); }

    html[data-portal-theme="dark"] body :is(input, select, textarea)[aria-invalid="true"],
    html[data-portal-theme="dark"] .registration-fields :is(input, select)[aria-invalid="true"] {
        background: var(--danger-panel);
        border-color: var(--danger);
        box-shadow: 0 0 0 1px var(--danger);
    }

    /* Commerce, documentation and support. */
    html[data-portal-theme="dark"] :is(.dashboard-stat-grid .stat-label,
        .payment-method-intro > strong, .cart-summary h2, .cart-summary .cart-subtotal,
        .checkout-signin summary, .public-plan-purchase > strong, .checkout-payment-options legend,
        .checkout-payment-choice strong, .customer-invoice-table .invoice-amount > strong,
        .customer-invoice-table .invoice-due-date, .public-contact-intro strong, .kb-summary p,
        .announcement-summary p, .announcement-article .markdown-body, .kb-categories h2,
        .announcement-months h2, .vps-fact strong, .vps-backup-table th) {
        color: var(--ink);
    }

    html[data-portal-theme="dark"] :is(.invoice-payment, .checkout-promo, .checkout-signin) {
        background: var(--soft);
        border-color: var(--line);
    }

    html[data-portal-theme="dark"] :is(.markdown-body pre, .markdown-body code, .kb-article .markdown-body th,
        .markdown-editor-status, div.markdown-editor-shell .markdown-toolbar-unified) {
        background: var(--inset);
        border-color: var(--line);
        color: var(--ink);
    }

    html[data-portal-theme="dark"] :is(.markdown-preview, .markdown-editor-shell,
        div.markdown-editor-shell > textarea, div.markdown-editor-shell .markdown-toolbar .button,
        .vps-readonly-frame, .vps-guest-agent-help, .vps-access-step) {
        background: var(--field);
        border-color: var(--line);
        color: var(--ink);
    }

    html[data-portal-theme="dark"] div.markdown-editor-shell .markdown-toolbar [data-markdown-preview] {
        background: var(--info-panel);
        border-color: var(--info-line);
        color: var(--info);
    }

    html[data-portal-theme="dark"] div.markdown-editor-shell .markdown-toolbar .button:hover,
    html[data-portal-theme="dark"] div.markdown-editor-shell .markdown-toolbar [aria-pressed="true"] {
        background: var(--soft);
        border-color: var(--accent);
        color: var(--accent-dark);
    }

    html[data-portal-theme="dark"] :is(.markdown-body img, .markdown-body blockquote) {
        border-color: var(--line);
    }

    html[data-portal-theme="dark"] .customer-conversation .customer-message { background: var(--info-panel); }

    html[data-portal-theme="dark"] .customer-conversation .customer-message :is(.avatar, .message-role) {
        background: var(--paper);
        color: var(--info);
    }

    html[data-portal-theme="dark"] .customer-conversation .staff-message :is(.avatar, .message-role) {
        background: var(--soft);
        color: var(--accent-dark);
    }

    /* Service actions retain independent status and command colors. */
    html[data-portal-theme="dark"] .vps-customer {
        --vps-warning: var(--warning);
        --vps-warning-bg: var(--warning-panel);
        --vps-danger: var(--danger);
        --vps-danger-bg: var(--danger-panel);
        --vps-blue: var(--info);
        --vps-blue-bg: var(--info-panel);
    }

    html[data-portal-theme="dark"] .vps-command {
        background: color-mix(in srgb, var(--command-tint), var(--paper));
        border-color: color-mix(in srgb, var(--command-ink) 45%, var(--line));
        border-bottom-color: var(--command-ink);
    }

    html[data-portal-theme="dark"] :is(.vps-command-stop, .vps-command-reset) {
        --command-ink: var(--danger);
        --command-tint: var(--danger-panel);
    }

    html[data-portal-theme="dark"] .vps-customer :is(.vps-refresh-button, .vps-danger):not(:disabled) {
        color: var(--action-ink);
    }

    html[data-portal-theme="dark"] .vps-customer .vps-refresh-button:hover {
        background: #ffe0aa;
        border-color: #ffe0aa;
    }

    html[data-portal-theme="dark"] .vps-customer .vps-danger:hover {
        background: #ffc2c6;
        border-color: #ffc2c6;
    }

    html[data-portal-theme="dark"] :is(.vps-os-family:has(option:checked:not([value=""])),
        .mass-detail-actions .mass-cancel-button:hover) {
        background: var(--soft);
        border-color: var(--accent);
    }

    html[data-portal-theme="dark"] .checkout-page .checkout-payment-choice:has(input:checked) {
        background: var(--soft);
        border-color: var(--accent);
    }

    html[data-portal-theme="dark"] .support-view-banner {
        background: var(--warning-panel);
        color: var(--warning);
        border-color: var(--warning-line);
    }

    html[data-portal-theme="dark"] .support-view-banner a { color: inherit; }
}

@media (forced-colors: active) {
    html[data-portal-theme="dark"] select:not([multiple]):not([size]) { background-image: none; }
}
