/**
 * Chakula Smart — Dark mode overrides (load LAST after page CSS)
 * Resolves hardcoded light colors in page-specific stylesheets.
 */

html[data-theme="dark"] {
    --soft-green: #152820;
    --accent-light: #3d3420;
    --glass-white: rgba(22, 31, 27, 0.92);
    --dash-text: var(--text-primary);
    --dash-text-muted: var(--text-secondary);
}

/* ── Global readability ── */
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6,
html[data-theme="dark"] .h1,
html[data-theme="dark"] .h2,
html[data-theme="dark"] .h3,
html[data-theme="dark"] .h4,
html[data-theme="dark"] .h5,
html[data-theme="dark"] .h6 {
    color: var(--text-primary);
}

html[data-theme="dark"] a:not(.btn):not(.nav-link):not(.dash-nav-link):not(.chakula-nav__link):not(.dropdown-item) {
    color: #8fd4a8;
}

html[data-theme="dark"] a.text-dark,
html[data-theme="dark"] .text-dark.text-decoration-none,
html[data-theme="dark"] .card-title a.text-dark,
html[data-theme="dark"] .dash-content a.text-dark {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] a.text-dark:hover,
html[data-theme="dark"] .card-title a.text-dark:hover {
    color: #b7e4c7 !important;
}

html[data-theme="dark"] hr {
    border-color: var(--border-subtle);
    opacity: 1;
}

html[data-theme="dark"] .card-footer {
    background: var(--surface-muted);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .badge.bg-light {
    background: var(--surface-muted) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .badge.bg-secondary {
    background: #3a4a42 !important;
    color: #e6efe9 !important;
}

/* ── User dashboard ── */
html[data-theme="dark"] .dash-user-app {
    --dash-text: var(--text-primary);
    --dash-text-muted: var(--text-secondary);
    color: var(--text-primary);
}

html[data-theme="dark"] .dash-main {
    background: var(--dash-surface, var(--surface-base));
}

html[data-theme="dark"] .dash-content .border,
html[data-theme="dark"] .dash-content .border-top,
html[data-theme="dark"] .dash-content .border-bottom,
html[data-theme="dark"] .dash-content .rounded-3 {
    border-color: var(--border-subtle) !important;
}

html[data-theme="dark"] .dash-content .bg-light,
html[data-theme="dark"] .dash-content .border.rounded-3 .bg-light,
html[data-theme="dark"] .dash-content .border.rounded-3 > .p-3.bg-light,
html[data-theme="dark"] .dash-content .border.rounded-3 > .p-2.border-top.bg-light {
    background: var(--surface-muted) !important;
    color: var(--text-primary);
}

html[data-theme="dark"] .dash-greeting h1 {
    color: #b7e4c7;
}

html[data-theme="dark"] .dash-greeting p,
html[data-theme="dark"] .dash-topbar-search i {
    color: var(--text-secondary);
}

html[data-theme="dark"] .dash-topbar-search input {
    background: var(--surface-muted) !important;
    border-color: var(--border-default) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .dash-icon-btn {
    background: var(--surface-card) !important;
    border-color: var(--border-subtle) !important;
    color: #b7e4c7 !important;
}

html[data-theme="dark"] .dash-icon-btn:hover {
    background: #1f2b25 !important;
}

html[data-theme="dark"] .dash-notify-dot {
    border-color: var(--surface-card) !important;
}

html[data-theme="dark"] .dash-stat-card .stat-value,
html[data-theme="dark"] .dash-stat-value {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .dash-stat-label {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .dash-stat-trend.up {
    color: #8fd4a8;
}

html[data-theme="dark"] .dash-user-app .chart-container,
html[data-theme="dark"] .dash-user-app .dash-chart-wrap {
    background: transparent;
}

html[data-theme="dark"] .dash-stat-card,
html[data-theme="dark"] .dash-stat-card .stat-value,
html[data-theme="dark"] .dash-stat-card .stat-label,
html[data-theme="dark"] .dash-motivation,
html[data-theme="dark"] .dash-coach-card,
html[data-theme="dark"] .dash-feed-card {
    color: var(--text-primary);
}

html[data-theme="dark"] .dash-stat-card .stat-label,
html[data-theme="dark"] .dash-goal-meta,
html[data-theme="dark"] .dash-coach-card .text-muted {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .dash-sidebar-promo {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.88);
}

html[data-theme="dark"] .dash-sidebar-promo p {
    color: rgba(255, 255, 255, 0.72);
}

html[data-theme="dark"] .feed-post-card,
html[data-theme="dark"] .dash-content .border.rounded-3 {
    background: var(--surface-card);
}

html[data-theme="dark"] .like-btn {
    color: var(--text-secondary);
}

html[data-theme="dark"] .like-btn:hover {
    background: var(--surface-muted);
    color: var(--text-primary);
}

html[data-theme="dark"] .like-btn.liked {
    color: #f5a5ad;
}

html[data-theme="dark"] .dash-fab-action,
html[data-theme="dark"] .dash-quick-card {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .dash-content .text-muted,
html[data-theme="dark"] .dash-content .small.text-muted {
    color: var(--text-secondary) !important;
}

/* ── Health feed & posts ── */
html[data-theme="dark"] .post-card,
html[data-theme="dark"] .post-card .card-body {
    background: var(--surface-card);
    color: var(--text-primary);
}

html[data-theme="dark"] .post-card .card-text,
html[data-theme="dark"] .post-view-hero .post-content {
    color: var(--text-secondary);
}

html[data-theme="dark"] .post-view-hero,
html[data-theme="dark"] .comments-panel {
    background: var(--surface-card);
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .comments-panel .comments-panel-head {
    background: linear-gradient(135deg, #0f2e22, var(--brand-800));
}

html[data-theme="dark"] .comment-composer {
    background: var(--surface-muted);
}

html[data-theme="dark"] .like-btn-large {
    background: var(--surface-muted);
    border-color: var(--border-default);
    color: var(--text-primary);
}

html[data-theme="dark"] .like-btn-large.liked {
    background: rgba(220, 53, 69, 0.18);
    border-color: rgba(220, 53, 69, 0.35);
    color: #f5a5ad;
}

/* ── AI Concierge chatbot ── */
html[data-theme="dark"] .chakula-ai-window {
    background: var(--surface-card);
    border-color: rgba(212, 175, 55, 0.22) !important;
}

html[data-theme="dark"] .chakula-ai-body {
    background:
        radial-gradient(circle at 85% 15%, rgba(212, 175, 55, 0.05), transparent 40%),
        radial-gradient(circle at 10% 80%, rgba(45, 106, 79, 0.08), transparent 35%),
        var(--surface-muted);
}

html[data-theme="dark"] .chakula-ai-bubble--bot {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .chakula-ai-bubble--user {
    background: linear-gradient(135deg, rgba(45, 106, 79, 0.45), rgba(64, 145, 108, 0.35));
    color: #e6efe9;
}

html[data-theme="dark"] .chakula-ai-time {
    color: var(--text-secondary);
}

html[data-theme="dark"] .chakula-ai-suggestions-title {
    color: #b7e4c7;
}

html[data-theme="dark"] .chakula-ai-chip {
    --bs-btn-color: var(--text-primary);
    --bs-btn-border-color: rgba(64, 145, 108, 0.35);
    --bs-btn-hover-bg: rgba(45, 106, 79, 0.2);
    --bs-btn-hover-border-color: rgba(64, 145, 108, 0.5);
    --bs-btn-hover-color: #b7e4c7;
    background: var(--surface-card);
}

html[data-theme="dark"] .chakula-ai-window .chakula-ai-footer {
    background: var(--surface-card) !important;
    border-color: var(--border-subtle) !important;
}

html[data-theme="dark"] .chakula-ai-window .chakula-ai-input-group {
    background: var(--surface-muted) !important;
    border-color: var(--border-default) !important;
}

html[data-theme="dark"] .chakula-ai-window .chakula-ai-input-group .form-control {
    background: transparent !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .chakula-ai-window .chakula-ai-input-group .form-control::placeholder {
    color: var(--text-secondary);
}

html[data-theme="dark"] .chakula-ai-window .chakula-ai-tool-btn {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .chakula-ai-window .chakula-ai-tool-btn:hover:not(:disabled) {
    background: rgba(45, 106, 79, 0.18) !important;
    color: #b7e4c7 !important;
}

html[data-theme="dark"] .chakula-ai-wrapper .chakula-ai-avatar,
html[data-theme="dark"] .chakula-ai-window .chakula-ai-avatar {
    background: linear-gradient(160deg, #1a2e24 0%, var(--surface-card) 55%, #152820 100%);
    color: #b7e4c7;
}

html[data-theme="dark"] .chakula-ai-dropdown {
    background: var(--surface-card) !important;
}

html[data-theme="dark"] .chakula-ai-dropdown .dropdown-item {
    color: var(--text-primary);
}

html[data-theme="dark"] .chakula-ai-toggle-chevron {
    background: var(--surface-card);
    color: #b7e4c7;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

html[data-theme="dark"] .chakula-ai-window .chakula-ai-privacy {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .chakula-ai-system {
    background: rgba(255, 193, 7, 0.12) !important;
    border-color: rgba(255, 193, 7, 0.28) !important;
    color: #f0d060 !important;
}

/* ── Landing page sections ── */
html[data-theme="dark"] .landing-page .feature-card h5,
html[data-theme="dark"] .landing-page .step-card h5 {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .landing-page .step-card p,
html[data-theme="dark"] .landing-page .testimonial-text,
html[data-theme="dark"] .landing-page .testimonial-role {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .landing-page .testimonial-name {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .landing-page .testimonial-card {
    background: var(--surface-card) !important;
}

html[data-theme="dark"] .landing-page .cta-section .btn-light {
    background: rgba(255, 255, 255, 0.95);
    color: var(--brand-800) !important;
}

html[data-theme="dark"] .landing-page footer {
    background: #080f0c !important;
}

html[data-theme="dark"] .landing-page .back-to-top {
    background: linear-gradient(135deg, var(--brand-600), var(--brand-800));
    color: #fff;
}

html[data-theme="dark"] .chakula-nav__lang-menu {
    background: rgba(22, 31, 27, 0.98) !important;
    border-color: var(--border-subtle) !important;
}

html[data-theme="dark"] .chakula-nav__lang-menu .dropdown-item {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .chakula-nav__lang-menu .dropdown-item:hover {
    background: rgba(45, 106, 79, 0.22) !important;
    color: #b7e4c7 !important;
}

html[data-theme="dark"] .chakula-nav__lang-menu .dropdown-item.active {
    background: linear-gradient(135deg, #2d6a4f, #40916c) !important;
    color: #fff !important;
}

/* ── Auth modals (landing) ── */
html[data-theme="dark"] .auth-modal .modal-body,
html[data-theme="dark"] .auth-modal .auth-modal-body {
    background: var(--surface-card);
    color: var(--text-primary);
}

html[data-theme="dark"] .auth-modal .form-label,
html[data-theme="dark"] .auth-modal .auth-modal-subtitle,
html[data-theme="dark"] .auth-modal .auth-switch-text {
    color: var(--text-secondary);
}

html[data-theme="dark"] .auth-modal .auth-switch-link {
    color: #8fd4a8;
}

html[data-theme="dark"] .auth-modal .input-group-auth .form-control,
html[data-theme="dark"] .auth-modal .auth-modal-grid .form-control {
    background: var(--surface-muted) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-default) !important;
}

html[data-theme="dark"] .auth-modal .input-group-auth .input-group-text {
    background: var(--surface-card) !important;
    color: #b7e4c7 !important;
    border-color: var(--border-default) !important;
}

html[data-theme="dark"] .auth-modal .auth-modal-footer-note {
    color: var(--text-secondary);
}

/* ── Admin pages ── */
html[data-theme="dark"] .admin-page .stat-card,
html[data-theme="dark"] .admin-page .quick-link,
html[data-theme="dark"] .admin-page .card {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .admin-page .card-header.bg-white {
    background: var(--surface-muted) !important;
    color: var(--text-primary);
}

html[data-theme="dark"] .admin-users-table tbody tr {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .admin-users-table tbody td::before {
    color: var(--text-secondary);
}

html[data-theme="dark"] .admin-logo-preview {
    background: var(--surface-muted);
    border-color: var(--border-default);
}

html[data-theme="dark"] .admin-chart-wrap {
    background: var(--surface-muted);
    border-radius: 12px;
}

/* ── App navbar (header.php pages) ── */
html[data-theme="dark"] .navbar-app.fx-glass-nav {
    background: rgba(12, 18, 16, 0.94) !important;
    border-bottom: 1px solid var(--border-subtle);
}

html[data-theme="dark"] .navbar-app .navbar-user {
    color: var(--text-secondary);
}

/* ── Messages (extra beyond dark-mode.css) ── */
html[data-theme="dark"] .messages-page {
    --msg-surface: var(--surface-card);
    --msg-muted: var(--surface-muted);
    --msg-base: var(--surface-base);
    --msg-border: var(--border-subtle);
    --msg-border-strong: var(--border-default);
    --msg-text: var(--text-primary);
    --msg-text-muted: var(--text-secondary);
}

html[data-theme="dark"] .messages-page .contact-item .contact-name,
html[data-theme="dark"] .messages-page .contact-item .contact-preview {
    color: var(--text-primary);
}

html[data-theme="dark"] .messages-page .contact-item .contact-time,
html[data-theme="dark"] .messages-page .contact-item .text-muted {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .messages-page .chat-header .chat-peer-name {
    color: #fff;
}

html[data-theme="dark"] .messages-page .empty-state p {
    color: var(--text-secondary);
}

/* ── Post images shimmer ── */
html[data-theme="dark"] .post-image-wrap--loading::before {
    background: linear-gradient(
        110deg,
        rgba(255, 255, 255, 0.02) 8%,
        rgba(255, 255, 255, 0.08) 18%,
        rgba(255, 255, 255, 0.02) 33%
    );
}

/* ── FX / misc ── */
html[data-theme="dark"] .fx-app:not(.landing-page):not(.dash-user-app) .container,
html[data-theme="dark"] .fx-app:not(.landing-page) main {
    color: var(--text-primary);
}

html[data-theme="dark"] .pagination .page-link {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .pagination .page-link:hover {
    background: var(--surface-muted);
    color: #b7e4c7;
}

html[data-theme="dark"] .pagination .page-item.active .page-link {
    background: var(--brand-600);
    border-color: var(--brand-600);
    color: #fff;
}

html[data-theme="dark"] .dropdown-divider {
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .form-check-label {
    color: var(--text-primary);
}

html[data-theme="dark"] .form-text {
    color: var(--text-secondary);
}

html[data-theme="dark"] .dash-goal-title,
html[data-theme="dark"] .dash-stat-card .stat-value,
html[data-theme="dark"] .dash-quick-card h6,
html[data-theme="dark"] .dash-coach-card h5 {
    color: var(--text-primary);
}

html[data-theme="dark"] .dash-content .fw-bold.text-dark,
html[data-theme="dark"] .dash-content .fw-semibold.text-dark {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .stat-card {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .stat-card .stat-label {
    color: var(--text-secondary);
}

html[data-theme="dark"] .quick-link {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .quick-link:hover {
    background: var(--surface-muted);
    color: #b7e4c7;
}

html[data-theme="dark"] .navbar-app .nav-link {
    color: rgba(255, 255, 255, 0.82);
}

html[data-theme="dark"] .navbar-app .nav-link:hover,
html[data-theme="dark"] .navbar-app .nav-link.active {
    color: #fff;
}

html[data-theme="dark"] .landing-page .about .container,
html[data-theme="dark"] .landing-page #features {
    color: var(--text-primary);
}

html[data-theme="dark"] .landing-page .feature-card p {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .auth-pages-wrap,
html[data-theme="dark"] .auth-card {
    background: var(--surface-card);
    color: var(--text-primary);
}

html[data-theme="dark"] .app-page-header h1,
html[data-theme="dark"] .app-page-header .h4 {
    color: var(--text-primary);
}

html[data-theme="dark"] .panel-card,
html[data-theme="dark"] .empty-state {
    color: var(--text-primary);
}

html[data-theme="dark"] .profile-photo-preview {
    background: linear-gradient(135deg, #1a2e24, #2d6a4f);
}

html[data-theme="dark"] .user-avatar {
    background: linear-gradient(135deg, #2d6a4f, #40916c);
    color: #e6efe9;
}

html[data-theme="dark"] .dash-sidebar-avatar.user-avatar {
    background: linear-gradient(135deg, #2d6a4f, #40916c);
}

html[data-theme="dark"] .empty-state .text-muted {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] ::selection {
    background: rgba(64, 145, 108, 0.35);
    color: #fff;
}

/* ── Food scanner ── */
html[data-theme="dark"] .scanner-page .concierge-scan-shell {
    background: var(--surface-card);
    border-color: var(--border-subtle) !important;
}

html[data-theme="dark"] .scanner-page .concierge-scan-body,
html[data-theme="dark"] .scanner-page .concierge-upload-zone,
html[data-theme="dark"] .scanner-page .concierge-result-card,
html[data-theme="dark"] .scanner-page .concierge-history-item,
html[data-theme="dark"] .scanner-page .concierge-hydration-card {
    background: var(--surface-card);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .scanner-page .concierge-scan-body {
    background: linear-gradient(160deg, var(--surface-muted) 0%, var(--surface-card) 55%, var(--surface-base) 100%);
}

html[data-theme="dark"] .scanner-page .concierge-nutrition-label,
html[data-theme="dark"] .scanner-page .concierge-disclaimer,
html[data-theme="dark"] .scanner-page .concierge-muted {
    color: var(--text-secondary);
}

html[data-theme="dark"] .scanner-page .concierge-nutrition-value,
html[data-theme="dark"] .scanner-page .concierge-result-title {
    color: var(--text-primary);
}

html[data-theme="dark"] .scanner-page .concierge-mobile-bar {
    background: var(--surface-card);
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .scanner-page .concierge-mobile-tab {
    color: var(--text-secondary);
}

html[data-theme="dark"] .scanner-page .concierge-mobile-tab.active {
    color: var(--brand-500);
    background: rgba(64, 145, 108, 0.12);
}
