/**
 * Light / dark surfaces — fixes hardcoded #fff and gray text in admin + forms.
 * Load after portal.css and theme-dark.css.
 */

html[data-theme="light"] {
    color-scheme: light;
    --panel-card-bg: var(--color-surface);
}

html[data-theme="dark"] {
    --panel-card-bg: var(--color-surface-elevated);
}

/* ——— Shared: force readable text on main shells ——— */
html[data-theme="light"] body.has-panel-shell,
html[data-theme="light"] .panel-main,
html[data-theme="light"] .admin-mgmt-page,
html[data-theme="light"] .admin-page-legacy {
    color: var(--color-text);
}

html[data-theme="dark"] body.has-panel-shell,
html[data-theme="dark"] .panel-main,
html[data-theme="dark"] .admin-mgmt-page,
html[data-theme="dark"] .admin-page-legacy {
    color: var(--color-text);
}

html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] .panel-main__title,
html[data-theme="dark"] .admin-mgmt-block__title {
    color: var(--color-text-strong);
}

html[data-theme="light"] h1,
html[data-theme="light"] h2,
html[data-theme="light"] h3,
html[data-theme="light"] h4,
html[data-theme="light"] .panel-main__title {
    color: var(--color-text-strong);
}

/* ——— Admin home / directory chips ——— */
html[data-theme="light"] .admin-home-link,
html[data-theme="light"] .admin-home-page__foot,
html[data-theme="light"] .directory-tabs,
html[data-theme="light"] .employment-stage-summary__chip {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}

html[data-theme="dark"] .admin-home-link,
html[data-theme="dark"] .admin-home-page__foot,
html[data-theme="dark"] .directory-tabs,
html[data-theme="dark"] .employment-stage-summary__chip,
html[data-theme="dark"] .directory-table-wrap,
html[data-theme="dark"] .admin-table-filters,
html[data-theme="dark"] .admin-forms-index__card,
html[data-theme="dark"] .admin-evaluation-page .evaluation-card,
html[data-theme="dark"] .scoring-page .scoring-table-wrap,
html[data-theme="dark"] .job-ads-page .job-ads-card,
html[data-theme="dark"] .employment-hr-page .employment-panel,
html[data-theme="dark"] .sys-update-card,
html[data-theme="dark"] .panel-card {
    background: var(--color-surface-elevated) !important;
    color: var(--color-text) !important;
    border-color: var(--color-border) !important;
}

html[data-theme="dark"] .admin-home-link:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

html[data-theme="dark"] .directory-tabs {
    background: var(--color-surface-elevated);
}

html[data-theme="light"] .directory-tabs {
    background: var(--color-surface);
}

/* ——— Legacy pages with Tailwind grays ——— */
html[data-theme="dark"] .text-gray-800,
html[data-theme="dark"] .text-gray-700,
html[data-theme="dark"] .text-gray-600,
html[data-theme="dark"] .text-gray-500,
html[data-theme="dark"] .text-gray-400 {
    color: var(--color-text) !important;
}

html[data-theme="light"] .text-gray-800,
html[data-theme="light"] .text-gray-700 {
    color: var(--color-text-strong) !important;
}

html[data-theme="light"] .text-gray-600,
html[data-theme="light"] .text-gray-500,
html[data-theme="light"] .text-gray-400 {
    color: var(--color-muted) !important;
}

html[data-theme="dark"] .bg-white,
html[data-theme="dark"] .bg-gray-100,
html[data-theme="dark"] .bg-gray-50 {
    background-color: var(--color-surface-elevated) !important;
    color: var(--color-text);
}

html[data-theme="light"] .bg-white {
    background-color: var(--color-surface) !important;
    color: var(--color-text);
}

html[data-theme="light"] body.bg-gray-100 {
    background: var(--color-bg) !important;
    color: var(--color-text) !important;
}

/* ——— Form builder public forms ——— */
html[data-theme="light"] .formbuilder-page {
    --fb-bg: var(--color-bg);
    --fb-surface: #ffffff;
    --fb-border: var(--color-border);
    --fb-text: var(--color-text);
    --fb-muted: var(--color-muted);
    --fb-primary: var(--color-primary);
    --fb-primary-hover: var(--color-primary-hover);
    --fb-primary-soft: var(--color-primary-soft);
}

html[data-theme="dark"] .formbuilder-page {
    --fb-bg: var(--color-bg);
    --fb-surface: var(--color-surface-elevated);
    --fb-border: var(--color-border);
    --fb-text: var(--color-text);
    --fb-muted: var(--color-muted);
    --fb-primary: var(--color-primary);
    --fb-primary-hover: var(--color-primary-hover);
    --fb-primary-soft: var(--color-primary-soft);
    --fb-success-bg: var(--color-success-bg);
    --fb-success-text: var(--color-success-text);
    --fb-danger-bg: var(--color-danger-bg);
    --fb-danger-text: var(--color-danger-text);
}

html[data-theme="dark"] .formbuilder-page .form-control,
html[data-theme="dark"] .formbuilder-page input,
html[data-theme="dark"] .formbuilder-page select,
html[data-theme="dark"] .formbuilder-page textarea {
    background: var(--color-bg);
    color: var(--color-text);
    border-color: var(--color-border);
}

html[data-theme="dark"] .formbuilder-page .form-control::placeholder,
html[data-theme="dark"] .formbuilder-page input::placeholder {
    color: var(--color-muted);
}

html[data-theme="dark"] .formbuilder-page label,
html[data-theme="dark"] .formbuilder-page .text-muted {
    color: var(--color-muted);
}

html[data-theme="light"] .formbuilder-page label {
    color: var(--color-text);
}

/* ——— Inputs sit slightly inset ——— */
html[data-theme="dark"] .panel-main input:not([type="checkbox"]):not([type="radio"]),
html[data-theme="dark"] .panel-main select,
html[data-theme="dark"] .panel-main textarea,
html[data-theme="dark"] .admin-table-filters__control {
    background: var(--color-bg);
    color: var(--color-text);
    border-color: var(--color-border);
}

html[data-theme="light"] .panel-main input:not([type="checkbox"]):not([type="radio"]),
html[data-theme="light"] .panel-main select,
html[data-theme="light"] .panel-main textarea,
html[data-theme="light"] .admin-table-filters__control {
    background: #ffffff;
    color: var(--color-text);
    border-color: var(--color-border);
}

/* ——— Code / pre in admin ——— */
html[data-theme="dark"] code,
html[data-theme="dark"] .sys-update-files code {
    background: var(--color-bg);
    color: var(--color-text);
}

html[data-theme="light"] code {
    color: var(--color-text-strong);
}

/* Formbuilder theme toggle corner */
.formbuilder-page .formbuilder-theme-toggle {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 5;
}

.formbuilder-page .form-card {
    position: relative;
}

html[data-theme="dark"] .admin-mgmt-table th,
html[data-theme="dark"] .admin-mgmt-table td {
    color: var(--color-text);
    border-color: var(--color-border);
}

html[data-theme="dark"] .admin-mgmt-table thead th {
    background: var(--color-bg);
    color: var(--color-muted);
}

html[data-theme="light"] .admin-mgmt-table thead th {
    background: var(--color-surface-elevated);
    color: var(--color-muted);
}

html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .panel-main__lead,
html[data-theme="dark"] .admin-mgmt-page__lead,
html[data-theme="dark"] .sys-update-form .text-muted {
    color: var(--color-muted) !important;
}

html[data-theme="light"] .text-muted,
html[data-theme="light"] .panel-main__lead {
    color: var(--color-muted);
}
