/* KENCore theme tokens — Bootstrap 5.3 data-bs-theme + app surfaces */

[data-bs-theme="light"] {
    --kencore-page-bg: #f5f6f8;
    --kencore-surface: #ffffff;
    --kencore-surface-elevated: #ffffff;
    --kencore-border: #dee2e6;
    --kencore-border-subtle: #ecf0f1;
    --kencore-text: #212529;
    --kencore-text-muted: #6c757d;
    --kencore-heading: #2c3e50;
    --kencore-code-bg: #f1f3f5;
    --kencore-shadow: rgba(0, 0, 0, 0.1);
    --kencore-success-fg: #155724;
    --kencore-success-bg: #d4edda;
    --kencore-danger-fg: #721c24;
    --kencore-danger-bg: #f8d7da;
    --kencore-warning-fg: #856404;
    --kencore-warning-bg: #fff3cd;
    --kencore-warning-border: #ffc107;
    --kencore-label: #495057;
    --kencore-hover-bg: #f8f9fa;
    --kencore-input-border: #ced4da;
    --kencore-highlight-bg: #f8fbff;
    --kencore-success-surface: #f8fff9;
    --kencore-link: #006bb7;
}

[data-bs-theme="dark"] {
    --kencore-page-bg: #121212;
    --kencore-surface: #1e1e1e;
    --kencore-surface-elevated: #2a2a2a;
    --kencore-border: #404040;
    --kencore-border-subtle: #333333;
    --kencore-text: #e8e8e8;
    --kencore-text-muted: #adb5bd;
    --kencore-heading: #f1f3f5;
    --kencore-code-bg: #2d3339;
    --kencore-shadow: rgba(0, 0, 0, 0.35);
    --kencore-success-fg: #8ce99a;
    --kencore-success-bg: #1a3d2a;
    --kencore-danger-fg: #ffa8a8;
    --kencore-danger-bg: #3d1a1a;
    --kencore-warning-fg: #ffd43b;
    --kencore-warning-bg: #3d3200;
    --kencore-warning-border: #b8860b;
    --kencore-label: #ced4da;
    --kencore-hover-bg: #333333;
    --kencore-input-border: #505050;
    --kencore-highlight-bg: #1a2838;
    --kencore-success-surface: #152a1c;
    --kencore-link: #74c0fc;
    color: var(--kencore-text);
}

body {
    background-color: var(--kencore-page-bg, inherit);
    color: var(--kencore-text, inherit);
}

.main-content,
.kencore-main-region {
    background-color: var(--kencore-page-bg, inherit);
    color: var(--kencore-text, inherit);
    min-height: calc(100vh - var(--kencore-topbar-height, 3.5rem));
}

/* Bootstrap text utilities — dark mode contrast */
[data-bs-theme="dark"] .text-muted {
    color: var(--kencore-text-muted) !important;
}

[data-bs-theme="dark"] .text-success {
    color: var(--kencore-success-fg) !important;
}

[data-bs-theme="dark"] .text-secondary {
    color: #ced4da !important;
}

[data-bs-theme="dark"] code {
    color: #f8f9fa;
    background-color: var(--kencore-code-bg);
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background-color: var(--kencore-surface-elevated);
    border-color: var(--kencore-border);
    color: var(--kencore-text);
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
    background-color: var(--kencore-surface-elevated);
    color: var(--kencore-text);
    border-color: #6c757d;
}

[data-bs-theme="dark"] .table {
    --bs-table-bg: var(--kencore-surface);
    --bs-table-color: var(--kencore-text);
    --bs-table-border-color: var(--kencore-border);
    --bs-table-striped-bg: var(--kencore-surface-elevated);
    --bs-table-hover-bg: var(--kencore-surface-elevated);
}

[data-bs-theme="dark"] .card {
    background-color: var(--kencore-surface);
    border-color: var(--kencore-border);
    color: var(--kencore-text);
}

[data-bs-theme="dark"] .alert-info {
    background-color: #1a2d3d;
    border-color: #2d4a63;
    color: #b6d4fe;
}

[data-bs-theme="dark"] .alert-secondary {
    background-color: var(--kencore-surface-elevated);
    border-color: var(--kencore-border);
    color: var(--kencore-text);
}

[data-bs-theme="dark"] .alert-success {
    background-color: var(--kencore-success-bg);
    border-color: #2d5a3d;
    color: var(--kencore-success-fg);
}

[data-bs-theme="dark"] .alert-warning {
    background-color: var(--kencore-warning-bg);
    border-color: var(--kencore-warning-border);
    color: var(--kencore-warning-fg);
}

[data-bs-theme="dark"] .alert-danger {
    background-color: var(--kencore-danger-bg);
    border-color: #5a2d2d;
    color: var(--kencore-danger-fg);
}

[data-bs-theme="dark"] .alert-link {
    color: var(--kencore-link);
}

[data-bs-theme="dark"] .badge.bg-warning.text-dark {
    background-color: var(--kencore-warning-border) !important;
    color: #1a1a1a !important;
}

[data-bs-theme="dark"] a:not(.btn):not(.nav-link):not(.dropdown-item) {
    color: var(--kencore-link);
}

[data-bs-theme="dark"] .form-control[readonly],
[data-bs-theme="dark"] .form-control:disabled,
[data-bs-theme="dark"] .form-select:disabled {
    background-color: var(--kencore-border-subtle);
    color: var(--kencore-text-muted);
}

/* Scoped page CSS overrides — higher specificity than Blazor [b-xxx] attributes */
html[data-bs-theme="dark"] .modal-content,
html[data-bs-theme="dark"] .config-modal-content,
html[data-bs-theme="dark"] .config-modal-content .modal-header,
html[data-bs-theme="dark"] .config-modal-content .modal-footer,
html[data-bs-theme="dark"] .controller-card,
html[data-bs-theme="dark"] .network-card,
html[data-bs-theme="dark"] .person-card,
html[data-bs-theme="dark"] .account-card,
html[data-bs-theme="dark"] .group-card,
html[data-bs-theme="dark"] .hotel-card,
html[data-bs-theme="dark"] .config-section,
html[data-bs-theme="dark"] .controller-type-card,
html[data-bs-theme="dark"] .detail-panel,
html[data-bs-theme="dark"] .members-panel,
html[data-bs-theme="dark"] .view-panel {
    background: var(--kencore-surface);
    color: var(--kencore-text);
    border-color: var(--kencore-border);
}

html[data-bs-theme="dark"] .modal-header,
html[data-bs-theme="dark"] .modal-footer,
html[data-bs-theme="dark"] .modal-actions {
    border-color: var(--kencore-border);
    background: var(--kencore-surface-elevated);
}

html[data-bs-theme="dark"] .modal-header h2,
html[data-bs-theme="dark"] .modal-header h5,
html[data-bs-theme="dark"] .modal-header .modal-title,
html[data-bs-theme="dark"] .header-content h1,
html[data-bs-theme="dark"] .section-header h2,
html[data-bs-theme="dark"] .card-title,
html[data-bs-theme="dark"] .detail-label {
    color: var(--kencore-heading);
}

html[data-bs-theme="dark"] .header-content p,
html[data-bs-theme="dark"] .section-header p,
html[data-bs-theme="dark"] .form-text,
html[data-bs-theme="dark"] .form-group label,
html[data-bs-theme="dark"] .detail-value,
html[data-bs-theme="dark"] .loading {
    color: var(--kencore-text-muted);
}

html[data-bs-theme="dark"] .modal-close:hover,
html[data-bs-theme="dark"] .modal-header .btn-close:hover {
    background: var(--kencore-hover-bg);
    color: var(--kencore-text);
}

html[data-bs-theme="dark"] .btn-outline {
    color: var(--kencore-text);
    border-color: var(--kencore-border);
}

html[data-bs-theme="dark"] .btn-outline:hover {
    background-color: var(--kencore-hover-bg);
    color: var(--kencore-text);
}

html[data-bs-theme="dark"] .page-header {
    border-bottom-color: var(--kencore-border);
}

html[data-bs-theme="dark"] .connection-status.connected {
    background: var(--kencore-success-bg);
    color: var(--kencore-success-fg);
    border-color: #2d5a3d;
}

html[data-bs-theme="dark"] .connection-status.disconnected {
    background: var(--kencore-danger-bg);
    color: var(--kencore-danger-fg);
    border-color: #5a2d2d;
}

html[data-bs-theme="dark"] .config-section.highlighted {
    background: var(--kencore-highlight-bg);
    border-color: #4dabf7;
}

html[data-bs-theme="dark"] .config-section.success {
    background: var(--kencore-success-surface);
    border-color: #51cf66;
}

html[data-bs-theme="dark"] .status-badge.warning,
html[data-bs-theme="dark"] .warning-banner {
    background: var(--kencore-warning-bg);
    color: var(--kencore-warning-fg);
    border-color: var(--kencore-warning-border);
}

/* Organizations / shared page chrome */
.companies-container,
.dashboard-container {
    color: var(--kencore-text);
}

.companies-container h1,
.companies-container h2,
.dashboard-container h1,
.dashboard-container h2,
.page-header h1 {
    color: var(--kencore-heading);
}

.company-card,
.modal-content {
    background: var(--kencore-surface);
    border-color: var(--kencore-border);
    color: var(--kencore-text);
}

.code-badge {
    background: var(--kencore-code-bg);
    color: var(--kencore-text);
}

.modal-header {
    border-bottom-color: var(--kencore-border);
}

.modal-overlay {
    background: rgba(0, 0, 0, 0.55);
}

[data-bs-theme="dark"] .btn-outline {
    color: var(--kencore-text);
    border-color: var(--kencore-border);
}

[data-bs-theme="dark"] .btn-outline:hover {
    background-color: var(--kencore-surface-elevated);
    color: var(--kencore-text);
}

/* Dashboard status cards */
.status-card,
.system-status,
.recent-activity {
    background: var(--kencore-surface);
    color: var(--kencore-text);
    box-shadow: 0 4px 6px var(--kencore-shadow);
}

.dashboard-header h1,
.status-content h3,
.status-value,
.system-status h2,
.recent-activity h2,
.activity-text,
.status-item .status-label {
    color: var(--kencore-heading);
}

.subtitle,
.status-content h3,
.status-label,
.activity-time,
.no-activity {
    color: var(--kencore-text-muted);
}

.status-item {
    border-bottom-color: var(--kencore-border-subtle);
}

.activity-item {
    border-bottom-color: var(--kencore-border-subtle);
}

.status-indicator.online {
    background: var(--kencore-success-bg);
    color: var(--kencore-success-fg);
}

.status-indicator.offline {
    background: var(--kencore-danger-bg);
    color: var(--kencore-danger-fg);
}

/* Bootstrap utility overrides — dark theme readability */
html[data-bs-theme="dark"] .bg-light {
    background-color: var(--kencore-surface-elevated) !important;
    color: var(--kencore-text);
}

html[data-bs-theme="dark"] .table-light {
    --bs-table-bg: var(--kencore-surface-elevated);
    --bs-table-color: var(--kencore-text);
    --bs-table-border-color: var(--kencore-border);
}

html[data-bs-theme="dark"] .card-header.bg-light,
html[data-bs-theme="dark"] .card-header {
    background-color: var(--kencore-surface-elevated);
    color: var(--kencore-text);
    border-bottom-color: var(--kencore-border);
}

html[data-bs-theme="dark"] pre.bg-light,
html[data-bs-theme="dark"] pre {
    background-color: var(--kencore-code-bg) !important;
    color: var(--kencore-text);
    border: 1px solid var(--kencore-border);
}

html[data-bs-theme="dark"] .list-group-item {
    background-color: var(--kencore-surface);
    color: var(--kencore-text);
    border-color: var(--kencore-border);
}

html[data-bs-theme="dark"] .list-group-item.active {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

html[data-bs-theme="dark"] .input-group-text {
    background-color: var(--kencore-surface-elevated);
    border-color: var(--kencore-border);
    color: var(--kencore-text-muted);
}

html[data-bs-theme="dark"] .border,
html[data-bs-theme="dark"] .border.rounded {
    border-color: var(--kencore-border) !important;
}

html[data-bs-theme="dark"] .dropdown-menu {
    background-color: var(--kencore-surface-elevated);
    border-color: var(--kencore-border);
    color: var(--kencore-text);
}

html[data-bs-theme="dark"] .dropdown-item {
    color: var(--kencore-text);
}

html[data-bs-theme="dark"] .dropdown-item:hover,
html[data-bs-theme="dark"] .dropdown-item:focus {
    background-color: var(--kencore-hover-bg);
    color: var(--kencore-text);
}

html[data-bs-theme="dark"] h1,
html[data-bs-theme="dark"] h2,
html[data-bs-theme="dark"] h3,
html[data-bs-theme="dark"] h4,
html[data-bs-theme="dark"] h5,
html[data-bs-theme="dark"] h6 {
    color: var(--kencore-heading);
}

html[data-bs-theme="dark"] .container-fluid {
    color: var(--kencore-text);
}
