/* One Dark / Light presentation layer shared by every authenticated role. */

.client-color-mode {
    display: inline-grid;
    flex: 0 0 auto;
    width: 40px;
    min-width: 40px;
    min-height: 38px;
    margin-left: auto;
    padding: 0;
    place-items: center;
    border: 1px solid var(--lc-line, #2a3340);
    border-radius: var(--lc-radius-small, 10px);
    background: var(--lc-panel, #121822);
    color: var(--lc-accent-hover, #fb7185);
    cursor: pointer;
    box-shadow: inset 0 1px rgba(255, 255, 255, .035);
}

.client-color-mode-icon {
    grid-area: 1 / 1;
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.client-color-mode-icon-moon,
.client-color-mode[data-mode="light"] .client-color-mode-icon-sun {
    display: none;
}

.client-color-mode[data-mode="light"] .client-color-mode-icon-moon {
    display: block;
}

.client-color-mode:hover:not(:disabled) {
    background: color-mix(in srgb, var(--lc-accent, #e11d48) 14%, var(--lc-panel-2, #171e29));
    color: var(--lc-text, #f4f4f5);
    box-shadow: inset 0 -2px var(--lc-accent, #e11d48);
}

.client-color-mode:focus-visible {
    outline: 2px solid var(--lc-accent, #e11d48);
    outline-offset: 2px;
}

.client-color-mode-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.billing-wallet-pill {
    margin-left: 0;
}

/* Palette aliases make every legacy and modular panel surface use one light system. */
body.legacy-clean[data-client-color-mode="light"] {
    color-scheme: light;
    --cs16-theme-bg: #edf2f7;
    --cs16-theme-bg-soft: #f8fafc;
    --cs16-theme-panel: #ffffff;
    --cs16-theme-panel-2: #f4f7fb;
    --cs16-theme-panel-3: #e8eef5;
    --cs16-theme-panel-glass: rgba(255, 255, 255, .97);
    --cs16-theme-line: #cbd5e1;
    --cs16-theme-line-soft: rgba(15, 23, 42, .09);
    --cs16-theme-text: #172033;
    --cs16-theme-muted: #58677c;
    --cs16-theme-dim: #718096;
    --cs16-theme-shadow: 0 14px 34px rgba(15, 23, 42, .11);

    --tpl-accent: var(--cs16-accent, #e11d48);
    --tpl-panel: var(--cs16-theme-panel);
    --tpl-panel-2: var(--cs16-theme-panel-2);
    --tpl-panel-3: var(--cs16-theme-panel-3);
    --tpl-line: var(--cs16-theme-line);
    --tpl-text: var(--cs16-theme-text);
    --tpl-muted: var(--cs16-theme-muted);
    --tpl-green: var(--cs16-positive, #15803d);
    --tpl-yellow: var(--cs16-warning, #b45309);
    --tpl-red: var(--cs16-danger, #dc2626);

    --accent: var(--cs16-accent, #e11d48);
    --surface: var(--cs16-theme-panel);
    --surface-2: var(--cs16-theme-panel-2);
    --border-color: var(--cs16-theme-line);
    --text-primary: var(--cs16-theme-text);
    --text-secondary: var(--cs16-theme-muted);

    background: var(--cs16-theme-bg) !important;
    color: var(--cs16-theme-text);
}

/* Application frame and shared controls */
body.legacy-clean[data-client-color-mode="light"] :is(
    #panelPage,
    .panel,
    .main,
    .sidebar,
    .topbar,
    .page,
    #genericPage
) {
    color: var(--lc-text);
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .sidebar,
    .topbar
) {
    background-color: var(--lc-bg-soft) !important;
    background-image: none !important;
    border-color: var(--lc-line) !important;
}

body.legacy-clean[data-client-color-mode="light"] .main {
    background: var(--lc-bg) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .nav-item,
    .logout,
    .account,
    .avatar,
    .billing-wallet-pill,
    .client-color-mode
) {
    border-color: var(--lc-line) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .nav-item:hover,
    .logout:hover,
    .billing-wallet-open:hover,
    .billing-wallet-add:hover
) {
    background-color: var(--lc-panel-2) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    h1, h2, h3, h4, h5, h6,
    .account strong,
    .billing-wallet-balance
) {
    color: var(--lc-text);
}

body.legacy-clean[data-client-color-mode="light"] :is(
    input, select, textarea
) {
    color-scheme: light;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .modal-card,
    .v5-module-panel,
    .v5-card,
    .v8-card,
    .v9-card,
    .v10-card,
    .api10-card,
    .cs-branding-preview-card,
    .cs-branding-item
) {
    border-color: var(--lc-line) !important;
    background-color: var(--lc-panel) !important;
    background-image: none !important;
    color: var(--lc-text) !important;
    box-shadow: var(--lc-shadow) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .modal,
    .v5-delete-overlay,
    .v8-overlay,
    .v9-modal,
    .v10-overlay,
    .api10-overlay
) {
    background: rgba(15, 23, 42, .48) !important;
}

/* Dashboard and service roster */
body.legacy-clean[data-client-color-mode="light"] :is(
    .dashboard-server-roster,
    .dashboard-server-roster-head,
    .dashboard-server-card,
    .dashboard-server-row,
    .dashboard-server-empty,
    .dashboard-roster-stat,
    .dashboard-roster-status,
    .dashboard-roster-auto-refresh
) {
    border-color: var(--lc-line) !important;
    color: var(--lc-text);
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .dashboard-server-roster,
    .dashboard-server-card,
    .dashboard-server-row,
    .dashboard-server-empty,
    .dashboard-roster-stat
) {
    background-color: var(--lc-panel) !important;
    background-image: none !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .dashboard-server-roster-head,
    .dashboard-roster-status,
    .dashboard-roster-auto-refresh
) {
    background-color: var(--lc-panel-2) !important;
    background-image: none !important;
}

body.legacy-clean[data-client-color-mode="light"] #commandDashboard .command-server-shell,
body.legacy-clean[data-client-color-mode="light"] #commandDashboard .command-server-header {
    border-color: var(--lc-line) !important;
    background: var(--lc-panel) !important;
    color: var(--lc-text) !important;
}

body.legacy-clean[data-client-color-mode="light"] #commandDashboard .command-server-tabs.cs16-server-header-controls,
body.legacy-clean[data-client-color-mode="light"] #cs16DashboardModuleHost {
    border-color: var(--lc-line) !important;
    background: var(--lc-bg-soft) !important;
    color: var(--lc-text) !important;
}

body.legacy-clean[data-client-color-mode="light"] #commandDashboard .server-picker select {
    border-color: var(--lc-line) !important;
    background: var(--lc-panel) !important;
    color: var(--lc-text) !important;
}

body.legacy-clean[data-client-color-mode="light"] #commandDashboard .cs16-server-nav-button {
    color: var(--lc-muted) !important;
}

body.legacy-clean[data-client-color-mode="light"] #commandDashboard .cs16-server-nav-button.active {
    background: var(--lc-panel) !important;
    color: var(--lc-text) !important;
}

body.legacy-clean[data-client-color-mode="light"] #commandDashboard .cs16-server-action:is(.is-copy, .is-refresh) {
    border-color: var(--lc-line) !important;
    background: var(--lc-panel) !important;
    color: var(--lc-text) !important;
}

body.legacy-clean[data-client-color-mode="light"] #commandDashboard .cs16-server-action:disabled {
    border-color: var(--lc-line) !important;
    background: var(--lc-panel-3) !important;
    color: var(--lc-dim) !important;
}

/* Server overview, players and activity */
body.legacy-clean[data-client-color-mode="light"] #serverDetailPage.cs16-inline-server-page .v5-module-panel,
body.legacy-clean[data-client-color-mode="light"] #serverDetailPage.cs16-inline-server-page :is(
    .cs16-server-information-card,
    .cs16-overview-chart-card,
    .cs16-live-players-card,
    .cs16-activity-card
) {
    border-color: var(--lc-line) !important;
    background: var(--lc-panel) !important;
    color: var(--lc-text) !important;
    box-shadow: none !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage :is(
    .cs16-server-info-grid > .v5-info-item,
    .cs16-server-info-grid > div,
    .cs16-player-table,
    .cs16-player-table-head,
    .cs16-player-table-row,
    .cs16-live-players-card .v5-player-row,
    .cs16-activity-item,
    .cs16-activity-meta span
) {
    border-color: var(--lc-line) !important;
    background-color: var(--lc-panel-2) !important;
    background-image: none !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage :is(
    .cs16-server-info-grid span,
    .cs16-player-table-head,
    .cs16-player-index,
    .cs16-player-time,
    .cs16-activity-sub,
    .cs16-activity-count,
    .cs16-activity-meta span,
    .cs16-activity-item > code
) {
    color: var(--lc-muted) !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage :is(
    .cs16-server-info-grid strong,
    .cs16-player-name,
    .cs16-player-score,
    .cs16-activity-main > strong,
    .cs16-activity-user,
    .cs16-activity-meta b
) {
    color: var(--lc-text) !important;
}

/* Configuration workspace: keep only the code editor itself dark. */
body.legacy-clean[data-client-color-mode="light"] #serverDetailPage [data-v5-module-panel="config"] {
    --cfg-panel: var(--lc-panel);
    --cfg-panel-2: var(--lc-panel-2);
    --cfg-line: var(--lc-line);
    --cfg-text: var(--lc-text);
    --cfg-muted: var(--lc-muted);
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage .v5-server-config-hero {
    background:
        radial-gradient(circle at 100% 0, color-mix(in srgb, var(--cfg-accent) 9%, transparent), transparent 27rem),
        var(--lc-panel) !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage :is(
    .v5-server-config-sidebar,
    .v5-server-config-editor,
    .v5-server-config-editor-head,
    .v5-server-config-code-bar,
    .v5-server-config-editor-footer,
    .v5-server-config-dialog,
    .v5-server-config-file-search,
    .v5-server-config-file,
    .v5-server-config-file-icon,
    .v5-server-config-message
) {
    border-color: var(--cfg-line) !important;
    background-color: var(--cfg-panel-2) !important;
    background-image: none !important;
    color: var(--cfg-text) !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage .v5-server-config-info {
    background: #eaf7fc !important;
    color: #164e63 !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage .v5-server-config-info p {
    color: #285d70 !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage :is(
    .v5-server-config-title code,
    .v5-server-config-info code,
    .v5-server-config-protected code,
    .v5-server-config-editor-name code,
    .v5-server-config-editor-footer code
) {
    border-color: var(--cfg-line) !important;
    background: var(--lc-panel-3) !important;
    color: var(--lc-text) !important;
}

/* Billing and purchase */
body.legacy-clean[data-client-color-mode="light"] :is(
    .billing-stat-card,
    .billing-card,
    .billing-service-row,
    .billing-table-wrap,
    .billing-modal-card,
    .billing-money-input,
    .server-purchase-dialog,
    .server-purchase-offer-strip,
    .server-purchase-preview,
    .server-purchase-success dl
) {
    border-color: var(--lc-line) !important;
    background-color: var(--lc-panel) !important;
    background-image: none !important;
    color: var(--lc-text) !important;
    box-shadow: var(--lc-shadow) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .billing-table th,
    .billing-table td,
    .billing-service-row,
    .server-purchase-head,
    .server-purchase-success dl > div
) {
    border-color: var(--lc-line) !important;
}

body.legacy-clean[data-client-color-mode="light"] .billing-table th {
    background: var(--lc-panel-2) !important;
    color: var(--lc-muted) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .billing-alert.is-success,
    .billing-status-badge.is-positive,
    .billing-service-badge.is-positive,
    .billing-amount.is-positive
) {
    color: #166534 !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .billing-alert.is-warning,
    .billing-status-badge.is-warning,
    .billing-service-badge.is-warning,
    .billing-paypal-message.is-unconfigured,
    .server-purchase-alert[data-kind="warning"],
    .server-purchase-funds
) {
    color: #92400e !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .billing-alert.is-error,
    .billing-inline-error,
    .billing-amount.is-negative,
    .server-purchase-alert
) {
    color: #b91c1c !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .billing-alert,
    .billing-status-badge,
    .billing-service-badge,
    .server-purchase-alert,
    .server-purchase-funds,
    .server-purchase-retry,
    .server-purchase-notice
) {
    background-color: color-mix(in srgb, currentColor 8%, var(--lc-panel)) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .billing-alert:not(.is-success):not(.is-warning):not(.is-error),
    .billing-status-badge.is-info,
    .billing-service-badge.is-info,
    .server-purchase-alert[data-kind="info"],
    .server-purchase-retry,
    .server-purchase-notice
) {
    color: #075985 !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .server-purchase-alert[data-kind="warning"],
    .server-purchase-funds
) {
    color: #92400e !important;
}

body.legacy-clean[data-client-color-mode="light"] .server-purchase-field :is(input, select) {
    background: var(--lc-panel-2) !important;
    color: var(--lc-text) !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage :is(
    .cs16-player-count-pill,
    .v5-server-config-status.synced,
    .v5-server-config-message.success
) {
    color: #166534 !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage :is(
    .v5-server-config-status.dirty,
    .v5-server-config-message.warning,
    .v5-server-config-message.working
) {
    color: #92400e !important;
}

body.legacy-clean[data-client-color-mode="light"] #serverDetailPage :is(
    .v5-server-config-status.conflict,
    .v5-server-config-message.error
) {
    color: #b91c1c !important;
}

/* Addons / plugins catalog */
body.legacy-clean[data-client-color-mode="light"] :is(
    .catalog-hero,
    .catalog-toolbar,
    .catalog-stat,
    .catalog-card,
    .catalog-empty,
    .catalog-modal-card,
    .catalog-file
) {
    border-color: var(--lc-line) !important;
    background-color: var(--lc-panel) !important;
    background-image: none !important;
    color: var(--lc-text) !important;
    box-shadow: var(--lc-shadow) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .catalog-button,
    .catalog-tab,
    .catalog-meta > div,
    .catalog-install-state,
    .catalog-modal-head,
    .catalog-modal-footer,
    .catalog-modal-close
) {
    border-color: var(--lc-line) !important;
    background-color: var(--lc-panel-2) !important;
    background-image: none !important;
    color: var(--lc-text) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .catalog-hero p,
    .catalog-description,
    .catalog-meta span,
    .catalog-field small
) {
    color: var(--lc-muted) !important;
}

body.legacy-clean[data-client-color-mode="light"] .catalog-button.primary,
body.legacy-clean[data-client-color-mode="light"] .catalog-tab.active {
    border-color: var(--catalog-accent) !important;
    background: var(--catalog-accent) !important;
    color: var(--cs16-accent-contrast, #fff) !important;
}

body.legacy-clean[data-client-color-mode="light"] .catalog-alert.error {
    color: #b91c1c !important;
    background: #fef2f2 !important;
}

body.legacy-clean[data-client-color-mode="light"] .catalog-alert.warning {
    color: #92400e !important;
    background: #fffbeb !important;
}

/* Profile and management settings surfaces */
body.legacy-clean[data-client-color-mode="light"] :is(
    .v10-settings-page,
    .v10-modal
) {
    --v10-bg: var(--lc-bg);
    --v10-card: var(--lc-panel);
    --v10-card-alt: var(--lc-panel-2);
    --v10-line: var(--lc-line);
    --v10-line-strong: #b8c4d3;
    --v10-text: var(--lc-text);
    --v10-muted: var(--lc-muted);
    color: var(--lc-text);
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .v10-settings-tabs-shell,
    .v10-card,
    .v10-modal-card,
    .v10-paypal-status-grid article,
    .v10-paypal-identity,
    .v10-paypal-enable-row,
    .v10-security-action
) {
    border-color: var(--v10-line) !important;
    background-color: var(--v10-card) !important;
    background-image: none !important;
    color: var(--v10-text) !important;
    box-shadow: var(--lc-shadow) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .v10-settings-tabs,
    .v10-settings-tab:hover,
    .v10-paypal-status-grid article,
    .v10-paypal-enable-row
) {
    background-color: var(--v10-card-alt) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .v10-settings-tab,
    .v10-field small,
    .v10-paypal-status-grid span,
    .v10-paypal-identity span,
    .v10-paypal-identity p
) {
    color: var(--v10-muted) !important;
}

body.legacy-clean[data-client-color-mode="light"] :is(
    .v10-settings-tab.active,
    .v10-field > span,
    .v10-paypal-status-grid strong,
    .v10-paypal-identity strong,
    .v10-paypal-enable-row strong
) {
    color: var(--v10-text) !important;
}

body.legacy-clean[data-client-color-mode="light"] .v10-switch > span {
    border-color: var(--v10-line-strong);
    background: var(--v10-card-alt);
}

/* Consent follows the selected appearance. */
body.legacy-clean[data-client-color-mode="light"] .cs16-cookie-consent {
    border-color: var(--lc-line) !important;
    background: var(--lc-panel) !important;
    color: var(--lc-text) !important;
    box-shadow: var(--lc-shadow) !important;
}

/* Consoles and code editors intentionally retain a dark, high-contrast canvas. */
body.legacy-clean[data-client-color-mode="light"] :is(
    .v5-console,
    .v5-console-output,
    .command-console,
    .v5-editor-textarea,
    .v5-server-config-editor textarea,
    .v5-server-config-template-preview,
    .v5-server-config-preview-frame
) {
    color-scheme: dark;
    border-color: #293547 !important;
    background: #08101b !important;
    color: #e8eef7 !important;
    box-shadow: none !important;
}

@media (max-width: 820px) {
    body.legacy-clean .topbar > .client-color-mode {
        flex: 0 0 38px;
        width: 38px;
        min-width: 38px;
    }
}

@media (max-width: 560px) {
    .client-color-mode {
        width: 36px;
        min-width: 36px;
        min-height: 36px;
    }

    .client-color-mode-icon {
        width: 14px;
        height: 14px;
    }
}

@media (max-width: 420px) {
    .client-color-mode {
        width: 34px;
        min-width: 34px;
        min-height: 34px;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .client-color-mode {
        transition: background-color .16s ease, color .16s ease, box-shadow .16s ease;
    }
}
