/* Advantage RPC Portal: site-wide light and dark theme. */
/* Phase 10B / version 2.10.1.1001. */

:root {
  color-scheme: light;
  --theme-surface: #ffffff;
  --theme-surface-soft: #f7faff;
  --theme-surface-muted: #eef5fb;
  --theme-surface-raised: #ffffff;
  --theme-control: #ffffff;
  --theme-text: #172033;
  --theme-text-strong: #111827;
  --theme-muted: #64748b;
  --theme-border: #dbe4ef;
  --theme-border-strong: #c8d4e3;
  --theme-link: #003b6f;
  --theme-link-hover: #d96f16;
  --theme-row-hover: rgba(0, 59, 111, .055);
  --theme-shadow: 0 14px 36px rgba(0, 59, 111, .11);
  --theme-success-bg: #eaf8f0;
  --theme-success-border: #b7e0c8;
  --theme-success-text: #0f5132;
  --theme-warning-bg: #fff7ed;
  --theme-warning-border: #efc49e;
  --theme-warning-text: #8b4a13;
  --theme-danger-bg: #fff1f2;
  --theme-danger-border: #fecdd3;
  --theme-danger-text: #842029;
  --theme-info-bg: #eef5fb;
  --theme-info-border: #cbd8e2;
  --theme-info-text: #285f88;
  --theme-purple-bg: #f6f3ff;
  --theme-purple-border: #c9c1e8;
  --theme-purple-text: #57479c;
  --theme-code-bg: #0f172a;
  --theme-code-text: #f8fafc;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --adv-blue: #73b9f2;
  --adv-blue-dark: #071a2d;
  --adv-blue-soft: #8ac9fb;
  --adv-orange: #ff963d;
  --adv-orange-dark: #ffad66;
  --bg: #08111d;
  --panel: #101c2a;
  --text: #e6edf7;
  --muted: #9eafc3;
  --border: #2a3b50;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #fb7185;
  --shadow: 0 18px 45px rgba(0, 0, 0, .35);
  --theme-surface: #101c2a;
  --theme-surface-soft: #0d1825;
  --theme-surface-muted: #142337;
  --theme-surface-raised: #142235;
  --theme-control: #0c1724;
  --theme-text: #e6edf7;
  --theme-text-strong: #f7f9fc;
  --theme-muted: #9eafc3;
  --theme-border: #2a3b50;
  --theme-border-strong: #3a5068;
  --theme-link: #8ac9fb;
  --theme-link-hover: #ffad66;
  --theme-row-hover: rgba(115, 185, 242, .10);
  --theme-shadow: 0 14px 36px rgba(0, 0, 0, .30);
  --theme-success-bg: #102b20;
  --theme-success-border: #2f6d4b;
  --theme-success-text: #82e6ac;
  --theme-warning-bg: #33270d;
  --theme-warning-border: #7a5f16;
  --theme-warning-text: #ffd166;
  --theme-danger-bg: #35161b;
  --theme-danger-border: #7f2631;
  --theme-danger-text: #ff9aaa;
  --theme-info-bg: #0f2940;
  --theme-info-border: #2e648d;
  --theme-info-text: #8dccff;
  --theme-purple-bg: #251d3f;
  --theme-purple-border: #66539b;
  --theme-purple-text: #c9b8ff;
  --theme-code-bg: #050a11;
  --theme-code-text: #e6edf7;
}

html,
body,
.topbar,
.card,
.form-section,
input,
select,
textarea,
button,
table th,
table td {
  transition:
    background-color .18s ease,
    border-color .18s ease,
    color .18s ease,
    box-shadow .18s ease;
}

.theme-toggle {
  min-width: 88px;
  white-space: nowrap;
}

.theme-toggle-icon {
  width: 1.1em;
  font-size: 17px;
  line-height: 1;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at top left, rgba(255, 150, 61, .10), transparent 28rem),
    radial-gradient(circle at top right, rgba(63, 135, 196, .18), transparent 30rem),
    var(--bg);
  color: var(--theme-text);
}

html[data-theme="dark"] .topbar {
  background: linear-gradient(120deg, #061421, #0a2d4d 58%, #124c78);
  border-bottom-color: var(--adv-orange);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .38);
}

html[data-theme="dark"] body :where(.card, .form-section) {
  background: rgba(16, 28, 42, .97);
  border-color: var(--theme-border);
  box-shadow: var(--theme-shadow);
}

html[data-theme="dark"] body :where(.card h1, .card h2, .card h3, .form-section h1, .form-section h2, .form-section h3) {
  color: var(--theme-link);
}

html[data-theme="dark"] body :where(label, .executive-main, .cell-main, .strong) {
  color: var(--theme-text-strong);
}

html[data-theme="dark"] body :where(input, select, textarea) {
  background: var(--theme-control);
  border-color: var(--theme-border-strong);
  color: var(--theme-text);
}

html[data-theme="dark"] body :where(input, select, textarea)::placeholder {
  color: #74869c;
}

html[data-theme="dark"] body :where(input, select, textarea):focus {
  border-color: var(--adv-orange);
  box-shadow: 0 0 0 4px rgba(255, 150, 61, .18);
}

html[data-theme="dark"] option {
  background: var(--theme-control);
  color: var(--theme-text);
}

html[data-theme="dark"] .btn:not(.orange):not(.green):not(.red):not(.gray):not(.ghost) {
  background: #185f94;
  color: #ffffff;
}

html[data-theme="dark"] .btn.gray {
  background: #42546a;
  color: #ffffff;
}

html[data-theme="dark"] .btn.orange {
  color: #172033;
}

html[data-theme="dark"] .btn.ghost {
  background: rgba(255, 255, 255, .10);
  border-color: rgba(255, 255, 255, .28);
  color: #ffffff;
}

html[data-theme="dark"] body :where(.hero-card, .executive-cover) {
  background: linear-gradient(135deg, #071a2d, #0b3c64 64%, #125985);
}

html[data-theme="dark"] body :where(.notice, .diagnostic-success, .maintenance-clear, .backup-notice-success) {
  background: var(--theme-success-bg);
  border-color: var(--theme-success-border);
  color: var(--theme-success-text);
}

html[data-theme="dark"] body :where(.error, .schedule-error, .operation-error, .backup-notice-error) {
  background: var(--theme-danger-bg);
  border-color: var(--theme-danger-border);
  color: var(--theme-danger-text);
}

html[data-theme="dark"] body :where(.keybox, .diagnostic-log, pre) {
  background: var(--theme-code-bg);
  color: var(--theme-code-text);
  border-color: var(--theme-border-strong);
}

html[data-theme="dark"] body :where(.portal-footer, .portal-footer-copyright, .muted, .cell-sub, .section-note, .metric-label, .metric-note, .metric-sub, .executive-sub, .executive-time) {
  color: var(--theme-muted);
}

html[data-theme="dark"] .portal-footer {
  border-top-color: var(--theme-border);
}

html[data-theme="dark"] .portal-version-badge {
  background: #185f94;
  color: #ffffff;
}

html[data-theme="dark"] body :where(.metric-card, .metrics-grid .metric-card) {
  background: linear-gradient(145deg, var(--theme-surface-raised), var(--theme-surface-soft));
  border-color: var(--theme-border);
  box-shadow: var(--theme-shadow);
}

html[data-theme="dark"] body :where(.metric-value, .server-link, .detail-tab, .expiration-card h3) {
  color: var(--theme-link);
}

html[data-theme="dark"] .detail-tab {
  background: #185f94;
  color: #ffffff;
}

html[data-theme="dark"] body :where(.expiration-card, .partner-quick-link, .partner-lookup-form) {
  background: var(--theme-surface-raised);
  border-color: var(--theme-border);
  box-shadow: var(--theme-shadow);
}

html[data-theme="dark"] body :where(
  .summary-header,
  .partner-health-card .summary-header,
  .partner-quick-actions .summary-header,
  .recent-registrations-card .summary-header,
  .partner-activity-card .summary-header,
  .dashboard-card .summary-header
) {
  background: linear-gradient(135deg, rgba(115, 185, 242, .10), rgba(255, 150, 61, .07));
  border-color: var(--theme-border);
}

html[data-theme="dark"] table th {
  background: var(--theme-surface-muted);
  border-color: var(--theme-border);
  color: var(--theme-link);
}

html[data-theme="dark"] table td {
  background: transparent;
  border-color: var(--theme-border);
  color: var(--theme-text);
}

html[data-theme="dark"] table tbody tr:hover,
html[data-theme="dark"] table tbody tr:hover td,
html[data-theme="dark"] body :where(.partner-health-row, .partner-activity-row):hover {
  background: var(--theme-row-hover);
}

html[data-theme="dark"] body :where(.report-bar, .executive-chart-track, .operation-progress-track) {
  background: var(--theme-border);
}

html[data-theme="dark"] body :where(.pill.ok, .partner-health-badge.ok, .partner-health-clear-icon, .partner-activity-status.ok, .schedule-status, .backup-verified, .release-status-completed, .release-status-active) {
  background: var(--theme-success-bg);
  border-color: var(--theme-success-border);
  color: var(--theme-success-text);
}

html[data-theme="dark"] body :where(.pill.warn, .partner-health-badge.warn, .partner-health-status.warn, .backup-deletable, .release-status-installing) {
  background: var(--theme-warning-bg);
  border-color: var(--theme-warning-border);
  color: var(--theme-warning-text);
}

html[data-theme="dark"] body :where(.pill.danger, .partner-health-status.danger, .partner-activity-status.failed, .backup-invalid, .release-status-failed) {
  background: var(--theme-danger-bg);
  border-color: var(--theme-danger-border);
  color: var(--theme-danger-text);
}

html[data-theme="dark"] body :where(.pill.bill, .recent-registration-count, .backup-protected, .configuration-field-heading > span) {
  background: var(--theme-info-bg);
  border-color: var(--theme-info-border);
  color: var(--theme-info-text);
}

html[data-theme="dark"] body :where(.release-status-rolled_back) {
  background: var(--theme-purple-bg);
  border-color: var(--theme-purple-border);
  color: var(--theme-purple-text);
}

/* Dashboard and partner panels. */
html[data-theme="dark"] body :where(.partner-quick-title, .partner-activity-title, .partner-health-title, .recent-registration-server, .recent-registration-empty strong, .partner-activity-empty strong) {
  color: var(--theme-link);
}

html[data-theme="dark"] body :where(.partner-quick-copy, .partner-activity-target, .partner-activity-side time, .partner-health-target, .partner-health-detail, .partner-health-clear, .partner-health-more) {
  color: var(--theme-muted);
}

html[data-theme="dark"] body :where(.partner-health-more, .partner-lookup-form) {
  background: var(--theme-surface-soft);
}

html[data-theme="dark"] .recent-registration-table th {
  background: var(--theme-surface-muted);
  color: var(--theme-muted);
}

html[data-theme="dark"] .recent-registration-table td {
  color: var(--theme-text);
}

html[data-theme="dark"] .partner-health-clear strong {
  color: var(--theme-success-text);
}

/* Phones used a fixed dark table before Phase 10B; make both themes intentional. */
html[data-theme="light"] body :where(.phone-table td, .details-card) {
  background: var(--theme-surface);
  border-color: var(--theme-border);
}

html[data-theme="light"] body :where(.phone-table th, .details-table th, .phone-table .cell-sub) {
  color: var(--theme-muted);
}

html[data-theme="light"] body :where(.phone-table .strong, .details-table td) {
  color: var(--theme-text);
}

html[data-theme="light"] body :where(.phone-table .server-link, .details-table .server-link) {
  color: var(--theme-link);
}

html[data-theme="dark"] body :where(.phone-table td, .details-card) {
  background: var(--theme-surface-raised);
  border-color: var(--theme-border);
}

html[data-theme="dark"] body :where(.phone-table th, .details-table th, .phone-table .cell-sub) {
  color: var(--theme-muted);
}

html[data-theme="dark"] body :where(.phone-table .strong, .details-table td) {
  color: var(--theme-text);
}

html[data-theme="dark"] body :where(.phone-table .server-link, .details-table .server-link) {
  color: var(--theme-link);
}

/* Reports, exports, audit, scheduled reports, diagnostics, and security. */
html[data-theme="dark"] body :where(.date-note, .schedule-status.disabled) {
  color: var(--theme-muted);
}

html[data-theme="dark"] .schedule-status.disabled {
  background: var(--theme-surface-muted);
}

html[data-theme="dark"] .diagnostic-warning {
  background: var(--theme-warning-bg);
  border-color: var(--theme-warning-border);
  color: var(--theme-warning-text);
}

html[data-theme="dark"] .security-error-page {
  background: var(--bg);
  color: var(--theme-text);
}

html[data-theme="dark"] .security-error-card {
  background: var(--theme-surface);
  border-color: var(--theme-border);
}

html[data-theme="dark"] .security-error-link {
  background: #185f94;
  color: #ffffff;
}

/* Operations, backup, restore, configuration, and release management. */
html[data-theme="dark"] body :where(
  .operations-overall,
  .operation-count,
  .external-check-row,
  .maintenance-warning,
  .configuration-field
) {
  background: var(--theme-surface-raised);
  border-color: var(--theme-border);
}

html[data-theme="dark"] body :where(
  .operations-overall span,
  .operation-status-label,
  .operation-progress-detail,
  .operation-count span,
  .external-check-status small,
  .operations-section-heading p,
  .maintenance-warning span,
  .backup-delete-form label,
  .backup-action-note,
  .backup-safety-note span,
  .restore-validation-id,
  .configuration-field-description,
  .configuration-input-row > span,
  .configuration-range,
  .configuration-change-list span,
  .release-table th,
  .release-previous,
  .release-events li
) {
  color: var(--theme-muted);
}

html[data-theme="dark"] body :where(
  .operation-status-value,
  .operations-section-heading h2,
  .maintenance-warning strong,
  .configuration-field-heading strong,
  .release-events li strong
) {
  color: var(--theme-text-strong);
}

html[data-theme="dark"] .operation-status-icon {
  background: var(--theme-surface-muted);
  color: var(--theme-text);
}

html[data-theme="dark"] body .operation-healthy .operation-status-icon,
html[data-theme="dark"] body .backup-verified {
  background: var(--theme-success-bg);
  color: var(--theme-success-text);
}

html[data-theme="dark"] body .operation-warning .operation-status-icon,
html[data-theme="dark"] body .backup-deletable {
  background: var(--theme-warning-bg);
  color: var(--theme-warning-text);
}

html[data-theme="dark"] body .operation-critical .operation-status-icon,
html[data-theme="dark"] body .backup-invalid {
  background: var(--theme-danger-bg);
  color: var(--theme-danger-text);
}

html[data-theme="dark"] body .operation-info .operation-status-icon,
html[data-theme="dark"] body .backup-protected {
  background: var(--theme-info-bg);
  color: var(--theme-info-text);
}

/* Preserve Operations severity accents after the general dark card border. */
html[data-theme="dark"] body .operation-status-card.operation-healthy {
  border-top-color: var(--success);
}

html[data-theme="dark"] body .operation-status-card.operation-warning {
  border-top-color: var(--warning);
}

html[data-theme="dark"] body .operation-status-card.operation-critical {
  border-top-color: var(--danger);
}

html[data-theme="dark"] body .operation-status-card.operation-info {
  border-top-color: var(--theme-info-text);
}

html[data-theme="dark"] body .operation-healthy .operation-status-label {
  color: var(--theme-success-text);
}

html[data-theme="dark"] body .operation-warning .operation-status-label {
  color: var(--theme-warning-text);
}

html[data-theme="dark"] body .operation-critical .operation-status-label {
  color: var(--theme-danger-text);
}

html[data-theme="dark"] body .operation-info .operation-status-label {
  color: var(--theme-info-text);
}

html[data-theme="dark"] body .external-check-row.operation-healthy,
html[data-theme="dark"] body .maintenance-warning.operation-healthy {
  border-left-color: var(--success);
}

html[data-theme="dark"] body .external-check-row.operation-warning,
html[data-theme="dark"] body .maintenance-warning.operation-warning,
html[data-theme="dark"] body .maintenance-attention-card {
  border-left-color: var(--warning);
}

html[data-theme="dark"] body .external-check-row.operation-critical,
html[data-theme="dark"] body .maintenance-warning.operation-critical {
  border-left-color: var(--danger);
}

html[data-theme="dark"] body .external-check-row.operation-info,
html[data-theme="dark"] body .maintenance-warning.operation-info {
  border-left-color: var(--theme-info-text);
}

html[data-theme="dark"] .release-maintenance-state {
  background: var(--theme-success-bg);
  border-color: var(--theme-success-border);
  color: var(--theme-success-text);
}

html[data-theme="dark"] .release-maintenance-state.active {
  background: var(--theme-warning-bg);
  border-color: var(--theme-warning-border);
  color: var(--theme-warning-text);
}

html[data-theme="dark"] .backup-safety-note {
  background: var(--theme-info-bg);
  border-color: var(--theme-info-border);
}

html[data-theme="dark"] .backup-safety-note strong {
  color: var(--theme-info-text);
}

html[data-theme="dark"] body :where(
  .release-table th,
  .release-table td,
  .backup-table th,
  .backup-table td,
  .configuration-history-table th,
  .configuration-history-table td,
  .backup-card-action,
  .configuration-form-actions
) {
  border-color: var(--theme-border);
}

html[data-theme="dark"] .release-events summary {
  color: var(--theme-link);
}

html[data-theme="dark"] body :where(.release-failure, .restore-validation-error) {
  color: var(--theme-danger-text);
}

/* Executive HTML report follows the selected screen theme. */
html[data-theme="dark"] .executive-document {
  background: var(--theme-surface);
  border-color: var(--theme-border);
}

html[data-theme="dark"] body :where(.executive-content, .executive-section) {
  background: var(--theme-surface);
  color: var(--theme-text);
  border-color: var(--theme-border);
}

html[data-theme="dark"] .executive-metric {
  background: linear-gradient(145deg, var(--theme-surface-raised), var(--theme-surface-soft));
  border-color: var(--theme-border);
}

html[data-theme="dark"] .executive-insight {
  background: var(--theme-surface-soft);
}

html[data-theme="dark"] body :where(.executive-heading, .executive-metric-value, .executive-insight-value, .executive-section h2) {
  color: var(--theme-link);
}

html[data-theme="dark"] .executive-footer {
  border-color: var(--theme-border);
  color: var(--theme-muted);
}

@media (max-width: 900px) {
  .theme-toggle {
    order: -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  html,
  body,
  .topbar,
  .card,
  .form-section,
  input,
  select,
  textarea,
  button,
  table th,
  table td {
    transition: none;
  }
}

/* Printed pages and browser-created PDFs always use the light palette. */
@media print {
  html[data-theme="dark"] {
    color-scheme: light;
    --adv-blue: #003b6f;
    --adv-blue-dark: #00294d;
    --adv-blue-soft: #0b5f9f;
    --adv-orange: #f58220;
    --adv-orange-dark: #d96f16;
    --bg: #ffffff;
    --panel: #ffffff;
    --text: #111827;
    --muted: #475569;
    --border: #d5dbe3;
    --theme-surface: #ffffff;
    --theme-surface-soft: #f7faff;
    --theme-surface-muted: #eef5fb;
    --theme-surface-raised: #ffffff;
    --theme-control: #ffffff;
    --theme-text: #111827;
    --theme-text-strong: #111827;
    --theme-muted: #475569;
    --theme-border: #d5dbe3;
    --theme-border-strong: #c8d4e3;
    --theme-link: #003b6f;
    --theme-row-hover: transparent;
    --theme-shadow: none;
    --theme-success-bg: #eaf8f0;
    --theme-success-border: #b7e0c8;
    --theme-success-text: #0f5132;
    --theme-warning-bg: #fff7ed;
    --theme-warning-border: #efc49e;
    --theme-warning-text: #8b4a13;
    --theme-danger-bg: #fff1f2;
    --theme-danger-border: #fecdd3;
    --theme-danger-text: #842029;
    --theme-info-bg: #eef5fb;
    --theme-info-border: #cbd8e2;
    --theme-info-text: #285f88;
  }

  .theme-toggle {
    display: none !important;
  }

  html[data-theme="dark"] body,
  html[data-theme="dark"] body :where(
    .card,
    .form-section,
    .metric-card,
    .expiration-card,
    .partner-quick-link,
    .partner-lookup-form,
    .operations-overall,
    .operation-count,
    .external-check-row,
    .maintenance-warning,
    .configuration-field,
    .executive-document,
    .executive-content,
    .executive-section,
    .executive-metric,
    .executive-insight
  ) {
    background: #ffffff !important;
    color: #111827 !important;
    box-shadow: none !important;
  }
}
