/**
 * Chakula Smart — Dark mode (html[data-theme="dark"])
 *
 * Load order: included last in head-assets.php.
 * Page-specific sheets (messages.css, food-scanner.css) load after this file
 * and must use design tokens (--surface-*, --text-*, --border-*) so themes stay in sync.
 */

html[data-theme="dark"] {
    color-scheme: dark;

    --surface-base: #0c1210;
    --surface-card: #161f1b;
    --surface-muted: #111916;
    --text-dark: #e6efe9;
    --text-primary: #e6efe9;
    --text-secondary: #94a89c;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-default: #2a3830;
    --glass-white: rgba(22, 31, 27, 0.92);
    --soft-green: #152820;
    --accent-light: #3d3420;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-card-hover: 0 12px 32px rgba(0, 0, 0, 0.5);
    --shadow-elevated: 0 20px 50px rgba(0, 0, 0, 0.55);
    --inner-glow: inset 0 0 15px rgba(255, 255, 255, 0.04);
}

html[data-theme="dark"] body {
    background-color: var(--surface-base);
    background-image:
        radial-gradient(at 0% 0%, rgba(45, 106, 79, 0.12) 0, transparent 50%),
        radial-gradient(at 100% 100%, rgba(212, 160, 23, 0.06) 0, transparent 50%);
    color: var(--text-primary);
}

html[data-theme="dark"] body:not(.landing-page) {
    background-color: var(--surface-base);
    background-image:
        radial-gradient(ellipse 80% 50% at 0% -10%, rgba(45, 106, 79, 0.15), transparent 55%),
        radial-gradient(ellipse 60% 40% at 100% 0%, rgba(212, 160, 23, 0.06), transparent 50%);
}

/* Bootstrap surfaces */
html[data-theme="dark"] .bg-light,
html[data-theme="dark"] .bg-white {
    background-color: var(--surface-muted) !important;
}

html[data-theme="dark"] .bg-body,
html[data-theme="dark"] body.bg-light {
    background-color: var(--surface-base) !important;
}

html[data-theme="dark"] .text-dark,
html[data-theme="dark"] .text-body {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .text-muted {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .border,
html[data-theme="dark"] .border-top,
html[data-theme="dark"] .border-bottom {
    border-color: var(--border-subtle) !important;
}

/* Cards & panels (app pages — avoid overriding landing marketing cards) */
html[data-theme="dark"] body:not(.landing-page) .card,
html[data-theme="dark"] body:not(.landing-page) .stat-card,
html[data-theme="dark"] body:not(.landing-page) .panel-card,
html[data-theme="dark"] body:not(.landing-page) .quick-link {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] body:not(.landing-page) .card-header {
    background: var(--surface-muted);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] body:not(.landing-page) .list-group-item {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] body:not(.landing-page) .list-group-item-action:hover {
    background: var(--surface-muted);
    color: var(--text-primary);
}

/* Forms */
html[data-theme="dark"] body:not(.landing-page) .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] textarea.form-control {
    background: var(--surface-muted);
    border-color: var(--border-default);
    color: var(--text-primary);
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    background: var(--surface-muted);
    border-color: var(--brand-500);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(64, 145, 108, 0.2);
}

html[data-theme="dark"] .form-control::placeholder {
    color: var(--text-secondary);
}

html[data-theme="dark"] .input-group-text {
    background: var(--surface-muted);
    border-color: var(--border-default);
    color: var(--text-secondary);
}

/* Dropdowns & modals */
html[data-theme="dark"] .dropdown-menu {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    box-shadow: var(--shadow-elevated);
}

html[data-theme="dark"] .dropdown-item {
    color: var(--text-primary);
}

html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .dropdown-item:focus {
    background: var(--surface-muted);
    color: var(--text-primary);
}

html[data-theme="dark"] .dropdown-item.active {
    background: rgba(45, 106, 79, 0.25);
    color: #b7e4c7;
}

html[data-theme="dark"] .modal-content {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Tables */
html[data-theme="dark"] .table {
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .table > :not(caption) > * > * {
    border-color: var(--border-subtle);
    background: transparent;
    color: inherit;
}

html[data-theme="dark"] .table-light {
    --bs-table-bg: var(--surface-muted);
    --bs-table-color: var(--text-primary);
}

/* Buttons */
html[data-theme="dark"] .btn-light {
    background: var(--surface-muted);
    border-color: var(--border-default);
    color: var(--text-primary);
}

html[data-theme="dark"] .btn-light:hover {
    background: #1f2b25;
    color: var(--text-primary);
}

html[data-theme="dark"] .btn-outline-secondary {
    color: var(--text-secondary);
    border-color: var(--border-default);
}

html[data-theme="dark"] .btn-outline-secondary:hover {
    background: var(--surface-muted);
    color: var(--text-primary);
}

html[data-theme="dark"] .btn-outline-dark {
    color: var(--text-primary);
    border-color: var(--border-default);
}

/* Alerts */
html[data-theme="dark"] .alert-success {
    background: rgba(25, 135, 84, 0.15);
    border-color: rgba(25, 135, 84, 0.35);
    color: #8fd4a8;
}

html[data-theme="dark"] .alert-warning {
    background: rgba(255, 193, 7, 0.12);
    border-color: rgba(255, 193, 7, 0.3);
    color: #f0d060;
}

html[data-theme="dark"] .alert-danger {
    background: rgba(220, 53, 69, 0.15);
    border-color: rgba(220, 53, 69, 0.35);
    color: #f5a5ad;
}

html[data-theme="dark"] .alert-info {
    background: rgba(13, 110, 253, 0.12);
    border-color: rgba(13, 110, 253, 0.3);
    color: #9ec5fe;
}

/* User dashboard */
html[data-theme="dark"] .dash-user-app {
    --dash-surface: #0c1210;
    --dash-card: #161f1b;
    --dash-border: rgba(255, 255, 255, 0.08);
    --dash-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
    background: var(--dash-surface) !important;
}

html[data-theme="dark"] .dash-topbar {
    background: rgba(12, 18, 16, 0.92);
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .dash-topbar-search input {
    background: var(--surface-muted);
    border-color: var(--border-default);
    color: var(--text-primary);
}

html[data-theme="dark"] .dash-icon-btn {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: #b7e4c7;
}

html[data-theme="dark"] .dash-icon-btn:hover {
    background: #1f2b25;
    color: #d8f3dc;
}

html[data-theme="dark"] .dash-notify-dot {
    border-color: var(--surface-card);
}

html[data-theme="dark"] .dash-stat-card,
html[data-theme="dark"] .dash-goal-card,
html[data-theme="dark"] .dash-feed-card,
html[data-theme="dark"] .dash-coach-card {
    background: var(--dash-card);
    border-color: var(--dash-border);
}

html[data-theme="dark"] .dash-greeting h1,
html[data-theme="dark"] .dash-goal-title {
    color: #b7e4c7;
}

html[data-theme="dark"] .dash-greeting p,
html[data-theme="dark"] .dash-goal-label,
html[data-theme="dark"] .dash-goal-meta {
    color: var(--text-secondary);
}

html[data-theme="dark"] .dash-goal-progress {
    background: #243029;
}

html[data-theme="dark"] .dash-fab-menu {
    background: var(--surface-card);
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .dash-fab-action {
    color: var(--text-primary);
}

html[data-theme="dark"] .dash-fab-action:hover {
    background: var(--surface-muted);
}

html[data-theme="dark"] .post-image-wrap,
html[data-theme="dark"] .post-media {
    --post-media-bg: #0a0e0c;
    background: var(--post-media-bg);
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .post-image-wrap--detail {
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .post-media__backdrop {
    filter: blur(32px) saturate(1.1) brightness(0.35);
}

/* Messages */
html[data-theme="dark"] .messages-page .contacts-panel,
html[data-theme="dark"] .messages-page .chat-header,
html[data-theme="dark"] .messages-page .composer,
html[data-theme="dark"] .messages-page .contacts-picker {
    background: var(--surface-card);
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .messages-page .chat-panel {
    background: var(--surface-base);
}

html[data-theme="dark"] .messages-page .contact-item {
    color: var(--text-primary);
}

html[data-theme="dark"] .messages-page .contact-item:hover {
    background: var(--surface-muted);
}

html[data-theme="dark"] .messages-page .contact-item.active {
    background: rgba(45, 106, 79, 0.22);
    border-left-color: var(--brand-500);
}

html[data-theme="dark"] .messages-page .bubble-received {
    background: var(--surface-card);
    border-color: var(--border-default);
    color: var(--text-primary);
}

html[data-theme="dark"] .messages-page .bubble-sent {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

html[data-theme="dark"] .messages-page .section-label {
    background: var(--surface-muted);
    color: var(--text-secondary);
}

html[data-theme="dark"] .messages-page .composer textarea.form-control {
    background: var(--surface-muted);
    border-color: var(--border-default);
    color: var(--text-primary);
}

html[data-theme="dark"] .messages-page .composer textarea.form-control:focus {
    background: var(--surface-card);
    border-color: var(--brand-500);
}

html[data-theme="dark"] .messages-page .msg-mobile-back {
    color: #b7e4c7 !important;
    background: rgba(45, 106, 79, 0.25);
}

html[data-theme="dark"] .messages-page .empty-state h4 {
    color: var(--text-primary);
}

/* Landing page */
html[data-theme="dark"] .landing-page .about .container {
    background: var(--glass-white);
    border-color: var(--border-subtle);
}

html[data-theme="dark"] .landing-page .feature-card,
html[data-theme="dark"] .landing-page .testimonial-card,
html[data-theme="dark"] .landing-page .step-card {
    background: var(--surface-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

html[data-theme="dark"] .landing-page section.bg-light,
html[data-theme="dark"] .landing-page .py-5.bg-light {
    background: var(--surface-muted) !important;
}

html[data-theme="dark"] .landing-page .auth-modal .modal-content,
html[data-theme="dark"] .landing-page .modal-content {
    background: var(--surface-card);
    color: var(--text-primary);
}

html[data-theme="dark"] .ui-icon-circle {
    background: rgba(45, 106, 79, 0.2);
}

html[data-theme="dark"] .ui-food-icon {
    background: linear-gradient(145deg, #1a2e24, var(--surface-card));
}

html[data-theme="dark"] .landing-page .section-subtitle,
html[data-theme="dark"] .landing-page .step-card p {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .landing-page .how-it-works-section {
    background: var(--surface-muted) !important;
}

html[data-theme="dark"] .landing-page .how-it-works-section .step-card {
    background: var(--surface-card) !important;
    border-color: var(--border-subtle) !important;
    box-shadow: var(--shadow-card) !important;
}

html[data-theme="dark"] .landing-page .testimonial-card {
    background: var(--surface-card) !important;
    color: var(--text-primary);
}

html[data-theme="dark"] .landing-page .testimonial-text {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .landing-page #features .section-title,
html[data-theme="dark"] .landing-page #testimonials .section-title,
html[data-theme="dark"] .landing-page .landing-section-visible .section-title {
    color: #b7e4c7 !important;
    -webkit-text-fill-color: #b7e4c7 !important;
}

html[data-theme="dark"] #signupModal .input-group-auth .form-control,
html[data-theme="dark"] #loginModal .input-group-auth .form-control,
html[data-theme="dark"] #signupModal .auth-modal-grid .form-control,
html[data-theme="dark"] #loginModal .auth-modal-grid .form-control {
    background: var(--surface-muted) !important;
    color: var(--text-primary) !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    border-color: var(--border-default) !important;
}

html[data-theme="dark"] #signupModal .input-group-auth .input-group-text,
html[data-theme="dark"] #loginModal .input-group-auth .input-group-text {
    background: var(--surface-card) !important;
    color: #b7e4c7 !important;
    border-color: var(--border-default) !important;
}

/* Theme toggle button */
.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.theme-toggle-btn .theme-icon-light,
.theme-toggle-btn .theme-icon-dark {
    font-size: 0.95rem;
    line-height: 1;
}

html:not([data-theme="dark"]) .theme-toggle-btn .theme-icon-dark,
html[data-theme="dark"] .theme-toggle-btn .theme-icon-light {
    display: none;
}

.theme-toggle-btn--dash {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--dash-border, var(--border-subtle));
    background: var(--dash-card, var(--surface-card));
    color: var(--dash-green-mid, var(--primary-green));
    padding: 0;
}

.theme-toggle-btn--dash:hover {
    box-shadow: var(--dash-shadow, var(--shadow-card));
}

.theme-toggle-btn--landing {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: #f0d78c;
    padding: 0;
}

.theme-toggle-btn--landing:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}
