/**
 * تطبيق الثيم على كل الشاشات المحمّلة داخل #moduleContent و .sigma-module-host
 * يعتمد على متغيرات CSS من sigma-themes-opera-gx.css / home.css على html/body
 */

:root {
    --text-on-accent: #ffffff;
    --sigma-chip-success-bg: #dcfce7;
    --sigma-chip-success-fg: #166534;
    --sigma-chip-danger-bg: #fee2e2;
    --sigma-chip-danger-fg: #991b1b;
    --sigma-chip-warning-bg: #feebc8;
    --sigma-chip-warning-fg: #7c2d12;
    --sigma-chip-cancel-bg: #fed7d7;
    --sigma-chip-cancel-fg: #742a2a;
    --sigma-chip-neutral-bg: #e2e8f0;
    --sigma-chip-neutral-fg: #334155;
    --sigma-chip-info-bg: #dbeafe;
    --sigma-chip-info-fg: #1e40af;
}

/* ——— نطاق الثيم: وراثة لون النص الأساسي ——— */
html[class*="sigma-theme-base"],
body[class*="sigma-theme-base"],
#moduleContent,
.sigma-module-host,
.sigma-fullscreen-module-overlay {
    color: var(--text-primary);
}

#moduleContent,
.sigma-module-host {
    color: var(--text-primary);
}

/* ——— محددات مشتركة للوضع الداكن والفاتح ——— */
html.dark-mode #moduleContent,
html.dark-mode .sigma-module-host,
html.dark-mode .sigma-fullscreen-module-overlay,
body.dark-mode #moduleContent,
body.dark-mode .sigma-module-host,
body.dark-mode .sigma-fullscreen-module-overlay,
#moduleContent.dark-mode,
.sigma-module-host.dark-mode,
.sigma-fullscreen-module-overlay.dark-mode,
[data-sigma-theme-mode="dark"] #moduleContent,
[data-sigma-theme-mode="dark"] .sigma-module-host {
    color: var(--text-primary);
}

html:not(.dark-mode) #moduleContent,
html:not(.dark-mode) .sigma-module-host,
body:not(.dark-mode) #moduleContent,
body:not(.dark-mode) .sigma-module-host,
#moduleContent:not(.dark-mode),
.sigma-module-host:not(.dark-mode) {
    color: var(--text-primary);
}

/* ——— حاويات النماذج ——— */
.sigma-module-host .form-container,
.sigma-module-host .form-body,
.sigma-module-host .fields-section,
.sigma-module-host .image-section,
#moduleContent .form-container,
#moduleContent .form-body,
#moduleContent .fields-section,
#moduleContent .image-section {
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host .form-container,
html.dark-mode #moduleContent .form-container,
body.dark-mode .sigma-module-host .form-container,
body.dark-mode #moduleContent .form-container,
.sigma-module-host.dark-mode .form-container,
#moduleContent.dark-mode .form-container {
    background-color: var(--card-bg);
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host .fields-section,
html.dark-mode .sigma-module-host .image-section,
html.dark-mode #moduleContent .fields-section,
html.dark-mode #moduleContent .image-section,
body.dark-mode .sigma-module-host .fields-section,
body.dark-mode .sigma-module-host .image-section,
body.dark-mode #moduleContent .fields-section,
body.dark-mode #moduleContent .image-section,
.sigma-module-host.dark-mode .fields-section,
.sigma-module-host.dark-mode .image-section {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* ——— حقول ونماذج ——— */
html.dark-mode .sigma-module-host .form-row label,
html.dark-mode #moduleContent .form-row label,
body.dark-mode .sigma-module-host .form-row label,
body.dark-mode #moduleContent .form-row label,
.sigma-module-host.dark-mode .form-row label,
#moduleContent.dark-mode .form-row label,
body[data-sigma-theme] .sigma-module-host .form-row label,
body[data-sigma-theme] .sigma-module-host label,
html:not(.dark-mode) .sigma-module-host .form-row label,
html:not(.dark-mode) #moduleContent .form-row label {
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
html.dark-mode .sigma-module-host select,
html.dark-mode .sigma-module-host textarea,
html.dark-mode #moduleContent input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
html.dark-mode #moduleContent select,
html.dark-mode #moduleContent textarea,
body.dark-mode .sigma-module-host input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
body.dark-mode .sigma-module-host select,
body.dark-mode .sigma-module-host textarea,
body.dark-mode #moduleContent input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
body.dark-mode #moduleContent select,
body.dark-mode #moduleContent textarea,
.sigma-module-host.dark-mode input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
.sigma-module-host.dark-mode select,
.sigma-module-host.dark-mode textarea,
body[data-sigma-theme] .sigma-module-host input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
body[data-sigma-theme] .sigma-module-host select,
body[data-sigma-theme] .sigma-module-host textarea {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html:not(.dark-mode) .sigma-module-host input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
html:not(.dark-mode) .sigma-module-host select,
html:not(.dark-mode) .sigma-module-host textarea,
html:not(.dark-mode) #moduleContent input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
html:not(.dark-mode) #moduleContent select,
html:not(.dark-mode) #moduleContent textarea {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html.dark-mode .sigma-module-host .station-toolbar-btn,
html.dark-mode .sigma-module-host button.station-toolbar-btn,
body.dark-mode .sigma-module-host .station-toolbar-btn,
body.dark-mode .sigma-module-host button.station-toolbar-btn,
body[data-sigma-theme] .sigma-module-host .station-toolbar-btn,
body[data-sigma-theme] .sigma-module-host button.station-toolbar-btn {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html:not(.dark-mode) .sigma-module-host .station-toolbar-btn:hover,
body[data-sigma-theme="light"] .sigma-module-host .station-toolbar-btn:hover,
body[data-sigma-theme-mode="light"] .sigma-module-host .station-toolbar-btn:hover {
    background-color: color-mix(in srgb, var(--input-bg) 85%, var(--text-primary));
}

/* ——— جداول view-all ——— */
html.dark-mode .sigma-module-host .view-all-table tbody td,
html.dark-mode #moduleContent .view-all-table tbody td,
body.dark-mode .sigma-module-host .view-all-table tbody td,
body.dark-mode #moduleContent .view-all-table tbody td,
.sigma-module-host.dark-mode .view-all-table tbody td,
#moduleContent.dark-mode .view-all-table tbody td,
.sigma-fullscreen-module-overlay.dark-mode .view-all-table tbody td {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html:not(.dark-mode) .sigma-module-host .view-all-table tbody td,
html:not(.dark-mode) #moduleContent .view-all-table tbody td,
.sigma-module-host:not(.dark-mode) .view-all-table tbody td {
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host .view-all-table tbody tr:hover td,
html.dark-mode #moduleContent .view-all-table tbody tr:hover td,
body.dark-mode .sigma-module-host .view-all-table tbody tr:hover td,
body.dark-mode #moduleContent .view-all-table tbody tr:hover td,
.sigma-module-host.dark-mode .view-all-table tbody tr:hover td {
    background-color: var(--sidebar-hover);
}

html.dark-mode .sigma-module-host .view-all-table thead > tr:first-child th,
html.dark-mode #moduleContent .view-all-table thead > tr:first-child th,
body.dark-mode .sigma-module-host .view-all-table thead > tr:first-child th,
body.dark-mode #moduleContent .view-all-table thead > tr:first-child th,
body[data-sigma-theme] .sigma-module-host .view-all-table thead > tr:first-child th {
    background-color: var(--accent-color);
    color: var(--text-on-accent);
    border-color: var(--border-color);
}

html.dark-mode .sigma-module-host .view-all-table tr.sumorder-station-filter-row th,
html.dark-mode .sigma-module-host .view-all-table tr.filter-row th,
html.dark-mode #moduleContent .view-all-table tr.sumorder-station-filter-row th,
html.dark-mode #moduleContent .view-all-table tr.filter-row th,
body.dark-mode .sigma-module-host .view-all-table tr.sumorder-station-filter-row th,
body.dark-mode .sigma-module-host .view-all-table tr.filter-row th,
body.dark-mode #moduleContent .view-all-table tr.sumorder-station-filter-row th,
body.dark-mode #moduleContent .view-all-table tr.filter-row th,
.sigma-module-host.dark-mode .view-all-table tr.sumorder-station-filter-row th,
.sigma-module-host.dark-mode .view-all-table tr.filter-row th,
body[data-sigma-theme] .sigma-module-host .view-all-table tr.sumorder-station-filter-row th,
body[data-sigma-theme] .sigma-module-host .view-all-table tr.filter-row th {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html.dark-mode .sigma-module-host .view-all-table .filter-menu .filter-dropdown,
html.dark-mode #moduleContent .view-all-table .filter-menu .filter-dropdown,
body.dark-mode .sigma-module-host .view-all-table .filter-menu .filter-dropdown,
body.dark-mode #moduleContent .view-all-table .filter-menu .filter-dropdown,
.sigma-module-host.dark-mode .view-all-table .filter-menu .filter-dropdown,
#moduleContent .filter-menu .filter-dropdown,
.sigma-fullscreen-module-overlay .filter-menu .filter-dropdown {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html.dark-mode .sigma-module-host .view-all-table .filter-search,
html.dark-mode #moduleContent .filter-search,
body.dark-mode .sigma-module-host .view-all-table .filter-search,
body.dark-mode #moduleContent .filter-search,
.sigma-module-host.dark-mode .view-all-table .filter-search {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html.dark-mode .sigma-module-host .view-all-table .filter-select-all-wrap,
html.dark-mode .sigma-module-host .view-all-table .filter-option label,
html.dark-mode #moduleContent .filter-select-all-wrap,
html.dark-mode #moduleContent .filter-option label,
body.dark-mode .sigma-module-host .view-all-table .filter-select-all-wrap,
body.dark-mode .sigma-module-host .view-all-table .filter-option label,
body.dark-mode #moduleContent .filter-select-all-wrap,
body.dark-mode #moduleContent .filter-option label,
.sigma-module-host.dark-mode .view-all-table .filter-select-all-wrap,
.sigma-module-host.dark-mode .view-all-table .filter-option label {
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host .view-all-table .filter-toggle,
html.dark-mode #moduleContent .view-all-table .filter-toggle,
body.dark-mode .sigma-module-host .view-all-table .filter-toggle,
body.dark-mode #moduleContent .view-all-table .filter-toggle,
.sigma-module-host.dark-mode .view-all-table .filter-toggle,
body[data-sigma-theme] .sigma-module-host .view-all-table .filter-toggle {
    color: var(--text-on-accent);
    border-color: var(--border-color);
}

html.dark-mode .sigma-module-host .view-all-actions,
html.dark-mode #moduleContent .view-all-actions,
body.dark-mode .sigma-module-host .view-all-actions,
body.dark-mode #moduleContent .view-all-actions,
.sigma-module-host.dark-mode .view-all-actions {
    background-color: var(--header-bg);
    border-bottom-color: var(--border-color);
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host .view-all-container,
html.dark-mode #moduleContent .view-all-container,
body.dark-mode .sigma-module-host .view-all-container,
body.dark-mode #moduleContent .view-all-container,
.sigma-module-host.dark-mode .view-all-container {
    background-color: var(--card-bg);
    color: var(--text-primary);
}

/* ——— نماذج الحسابات (financial) ——— */
html.dark-mode .sigma-module-host .fin-form-container,
html.dark-mode #moduleContent .fin-form-container,
body.dark-mode .sigma-module-host .fin-form-container,
body.dark-mode #moduleContent .fin-form-container {
    background-color: var(--bg-body);
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host .fin-panel,
html.dark-mode .sigma-module-host .fin-form-toolbar,
html.dark-mode #moduleContent .fin-panel,
html.dark-mode #moduleContent .fin-form-toolbar,
body.dark-mode .sigma-module-host .fin-panel,
body.dark-mode .sigma-module-host .fin-form-toolbar,
body.dark-mode #moduleContent .fin-panel,
body.dark-mode #moduleContent .fin-form-toolbar {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host .fin-form-row label,
html.dark-mode #moduleContent .fin-form-row label,
body.dark-mode .sigma-module-host .fin-form-row label,
body.dark-mode #moduleContent .fin-form-row label {
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host .fin-form-row input,
html.dark-mode .sigma-module-host .fin-form-row select,
html.dark-mode .sigma-module-host .fin-form-row textarea,
html.dark-mode #moduleContent .fin-form-row input,
html.dark-mode #moduleContent .fin-form-row select,
html.dark-mode #moduleContent .fin-form-row textarea,
body.dark-mode .sigma-module-host .fin-form-row input,
body.dark-mode .sigma-module-host .fin-form-row select,
body.dark-mode .sigma-module-host .fin-form-row textarea {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html.dark-mode .sigma-module-host .fin-form-toolbar button:not(.fin-btn-primary),
body.dark-mode .sigma-module-host .fin-form-toolbar button:not(.fin-btn-primary) {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* ——— شارات الحالة والأزرار الملونة — لا ترث لون نص الخلية ——— */
#moduleContent .view-all-table tbody td .badge,
#moduleContent .view-all-table tbody td .status-badge,
.sigma-module-host .view-all-table tbody td .badge,
.sigma-module-host .view-all-table tbody td .status-badge,
.sigma-fullscreen-module-overlay .view-all-table tbody td .badge,
.sigma-fullscreen-module-overlay .view-all-table tbody td .status-badge,
.badge,
.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    white-space: nowrap;
    border: 1px solid transparent;
}

.badge-on,
.status-completed,
.status-active,
.status-success {
    background-color: var(--sigma-chip-success-bg) !important;
    color: var(--sigma-chip-success-fg) !important;
}

.badge-off,
.status-cancelled,
.status-danger,
.status-error {
    background-color: var(--sigma-chip-danger-bg) !important;
    color: var(--sigma-chip-danger-fg) !important;
}

.badge-neutral,
.status-neutral,
.status-default {
    background-color: var(--sigma-chip-neutral-bg) !important;
    color: var(--sigma-chip-neutral-fg) !important;
}

.status-pending,
.status-warning {
    background-color: var(--sigma-chip-warning-bg) !important;
    color: var(--sigma-chip-warning-fg) !important;
}

.status-cancelled-alt {
    background-color: var(--sigma-chip-cancel-bg) !important;
    color: var(--sigma-chip-cancel-fg) !important;
}

.status-info {
    background-color: var(--sigma-chip-info-bg) !important;
    color: var(--sigma-chip-info-fg) !important;
}

/* أزرار إجراءات ملونة داخل الجداول */
#moduleContent .view-all-table tbody td .btn-act-activate,
#moduleContent .view-all-table tbody td .view-all-btn-success,
#moduleContent .view-all-table tbody td .view-all-btn-primary,
#moduleContent .view-all-table tbody td .action-btn,
.sigma-module-host .view-all-table tbody td .btn-act-activate,
.sigma-module-host .view-all-table tbody td .view-all-btn-success,
.sigma-module-host .view-all-table tbody td .view-all-btn-primary,
.sigma-module-host .view-all-table tbody td .action-btn,
.btn-act-activate,
.view-all-btn-success,
.view-all-btn-primary,
.action-btn {
    color: var(--text-on-accent) !important;
}

#moduleContent .view-all-table tbody td .btn-act-deactivate,
#moduleContent .view-all-table tbody td .view-all-btn-danger,
.sigma-module-host .view-all-table tbody td .btn-act-deactivate,
.sigma-module-host .view-all-table tbody td .view-all-btn-danger,
.btn-act-deactivate,
.view-all-btn-danger {
    color: var(--text-on-accent) !important;
}

/* رسائل الحالة — ألوان ثابتة واضحة */
.status-message.success,
.message.success,
.fin-status-message.success {
    color: var(--sigma-chip-success-fg) !important;
}

.status-message.error,
.message.error,
.fin-status-message.error {
    color: var(--sigma-chip-danger-fg) !important;
}

html.dark-mode .status-message.success,
html.dark-mode .message.success,
body.dark-mode .status-message.success,
body.dark-mode .message.success {
    color: #bbf7d0 !important;
}

html.dark-mode .status-message.error,
html.dark-mode .message.error,
body.dark-mode .status-message.error,
body.dark-mode .message.error {
    color: #fecaca !important;
}

/* ——— Opera GX (كل الإصدارات) ——— */
body.sigma-theme-opera-gx .sigma-module-host .view-all-table thead > tr:first-child th,
body.sigma-theme-opera-gx-neon .sigma-module-host .view-all-table thead > tr:first-child th,
body.sigma-theme-opera-gx-void .sigma-module-host .view-all-table thead > tr:first-child th,
body.sigma-theme-opera-gx-purple .sigma-module-host .view-all-table thead > tr:first-child th {
    background: linear-gradient(180deg, #3d1828 0%, #2a1520 100%);
    border-color: rgba(255, 41, 72, 0.4);
    box-shadow: 0 2px 8px rgba(255, 27, 45, 0.15);
    color: var(--text-on-accent);
}

body.sigma-theme-opera-gx .sigma-module-host .view-all-table tbody tr:hover td,
body.sigma-theme-opera-gx-neon .sigma-module-host .view-all-table tbody tr:hover td,
body.sigma-theme-opera-gx-void .sigma-module-host .view-all-table tbody tr:hover td,
body.sigma-theme-opera-gx-purple .sigma-module-host .view-all-table tbody tr:hover td {
    background-color: rgba(255, 27, 45, 0.1);
}

body.sigma-theme-opera-gx .sigma-module-host .form-container,
body.sigma-theme-opera-gx-neon .sigma-module-host .form-container,
body.sigma-theme-opera-gx-void .sigma-module-host .form-container,
body.sigma-theme-opera-gx-purple .sigma-module-host .form-container {
    background: var(--card-bg);
    border-color: rgba(255, 41, 72, 0.18);
}

body.sigma-theme-opera-gx-neon .sigma-module-host .view-all-table thead > tr:first-child th {
    box-shadow: 0 0 12px rgba(255, 41, 72, 0.35);
}

body.sigma-theme-opera-gx-purple .sigma-module-host .view-all-table thead > tr:first-child th {
    background: linear-gradient(180deg, #3d1848 0%, #2a1528 100%);
    border-color: rgba(180, 80, 255, 0.35);
}

/* ——— جارفيس ——— */
body.sigma-theme-jarvis .sigma-module-host .view-all-table thead > tr:first-child th {
    background: linear-gradient(180deg, #1a4a6e 0%, #0d3048 100%);
    border-color: rgba(0, 212, 255, 0.4);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.2);
    color: var(--text-on-accent);
}

body.sigma-theme-jarvis .sigma-module-host .view-all-table tbody tr:hover td {
    background-color: rgba(0, 212, 255, 0.08);
}

/* ——— محيط / زمردي / عنبري ——— */
body.sigma-theme-ocean .sigma-module-host .view-all-table thead > tr:first-child th {
    background: linear-gradient(180deg, #1e5a8a 0%, #0c3d5c 100%);
    color: var(--text-on-accent);
}

body.sigma-theme-emerald .sigma-module-host .view-all-table thead > tr:first-child th {
    background: linear-gradient(180deg, #1a5c48 0%, #0d3d32 100%);
    color: var(--text-on-accent);
}

body.sigma-theme-amber .sigma-module-host .view-all-table thead > tr:first-child th {
    background: linear-gradient(180deg, #8b5a12 0%, #5c3d08 100%);
    color: var(--text-on-accent);
}

/* تبويبات */
html.dark-mode .sigma-module-host .tab-btn,
html.dark-mode .sigma-module-host .tab-button,
body.dark-mode .sigma-module-host .tab-btn,
body.dark-mode .sigma-module-host .tab-button,
body[data-sigma-theme] .sigma-module-host .tab-btn,
body[data-sigma-theme] .sigma-module-host .tab-button {
    color: var(--text-secondary);
    border-color: var(--border-color);
}

html.dark-mode .sigma-module-host .tab-btn.active,
html.dark-mode .sigma-module-host .tab-button.active,
body.dark-mode .sigma-module-host .tab-btn.active,
body.dark-mode .sigma-module-host .tab-button.active,
body[data-sigma-theme] .sigma-module-host .tab-btn.active,
body[data-sigma-theme] .sigma-module-host .tab-button.active {
    color: var(--accent-color);
    border-color: var(--accent-color);
}

/* شاشة ملء كاملة */
.sigma-module-host--fullscreen-overlay {
    background: var(--bg-body);
    color: var(--text-primary);
}

/* شريط الأدوات */
html.dark-mode .sigma-module-host .form-toolbar,
body.dark-mode .sigma-module-host .form-toolbar,
.sigma-module-host.dark-mode .form-toolbar {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

html.dark-mode .sigma-module-host .form-toolbar button,
body.dark-mode .sigma-module-host .form-toolbar button,
.sigma-module-host.dark-mode .form-toolbar button {
    background-color: var(--input-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* ——— وراثة متغيرات الثيم على html (للشاشات المحمّلة) ——— */
html[class*="sigma-theme-base"].dark-mode #moduleContent,
html[class*="sigma-theme-base"].dark-mode .sigma-module-host,
html[class*="sigma-theme-base"].dark-mode .sigma-fullscreen-module-overlay,
html.dark-mode #moduleContent,
html.dark-mode .sigma-module-host,
html.dark-mode .sigma-fullscreen-module-overlay {
    color: var(--text-primary);
}
