/*
 * deep_study.css - THEME COLLISION FIX
 */

/* =========================================
   1. THEME DEFINITIONS (VARIABLES)
   ========================================= */

/* DEFAULT (LIGHT) */
:root {
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-main: #334155;
    --text-heading: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --bot-bubble-bg: #ffffff;
    --bot-bubble-text: #334155;
    --settings-bg: #ffffff;
}

/* DARK MODE - Fixed Selector */
body[data-theme="dark"] {
    --bg-body: #020617;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text-main: #e2e8f0;
    --text-heading: #ffffff;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --shadow-soft: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --bot-bubble-bg: #1e293b;
    --bot-bubble-text: #e2e8f0;
    --settings-bg: #1e293b;
}

/* COLOUR POP - Fixed Selector */
body[data-theme="colourpop"] {
    --bg-body: linear-gradient(120deg, #5c6bc0, #ab47bc);
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-input: #ffffff;
    --text-main: #404040;
    --text-heading: #1f2937;
    --text-muted: #4b5563;
    --border-color: rgba(255, 255, 255, 0.5);
    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.1);
    --bot-bubble-bg: #ffffff;
    --bot-bubble-text: #404040;
    --settings-bg: #ffffff;
}

/* NIGHT GLASS (iOS) - Fixed Selector */
body[data-theme="ios"] {
    --bg-body: url('https://images.unsplash.com/photo-1485470733090-0aae1788d5af?q=80&w=2117&auto=format&fit=crop');
    --bg-card: rgba(20, 20, 20, 0.6);
    --bg-input: rgba(255, 255, 255, 0.1);
    --text-main: #e2e8f0;
    --text-heading: #ffffff;
    --text-muted: #cbd5e1;
    --border-color: rgba(255, 255, 255, 0.15);
    --shadow-soft: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --bot-bubble-bg: rgba(20, 20, 20, 0.8);
    --bot-bubble-text: #e2e8f0;
    --settings-bg: rgba(20, 20, 20, 0.9);
}

/* =========================================
   2. GLOBAL LAYOUT & SCROLLBARS
   ========================================= */

body {
    background: var(--bg-body);
    background-size: cover;
    background-attachment: fixed;
    background-position: center;
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background 0.3s ease, color 0.3s ease;
    overscroll-behavior-y: none;
    overflow: hidden; /* Fix double scrollbars */
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1; /* We keep this neutral */
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Header & Main Cards */
header, .bg-white {
    background-color: var(--bg-card) !important;
    border-color: var(--border-color) !important;
}

/* Force Text Colors */
h1, h2, h3, h4, .font-bold, .font-semibold { color: var(--text-heading) !important; }
p, .text-slate-500, .text-slate-400 { color: var(--text-muted) !important; }

/* Apply Night Glass Blur to containers */
[data-theme="ios"] header, 
[data-theme="ios"] #view-form > div,
[data-theme="ios"] #chat-input-area > div,
[data-theme="ios"] #settings-menu {
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
}

/* =========================================
   3. FORM ELEMENTS
   ========================================= */

.input-field {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-input);
    color: var(--text-heading);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.input-field:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    transform: translateY(-1px);
}

.input-field::placeholder {
    color: var(--text-muted);
}

.btn-submit {
    width: 100%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    padding: 0.875rem;
    border-radius: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.025em;
    transition: transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.btn-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
}

.btn-submit:active {
    transform: translateY(0);
}

/* =========================================
   4. CHAT BUBBLES & CANVAS
   ========================================= */

.user-bubble {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white !important;
    padding: 0.75rem 1.25rem;
    border-radius: 1.25rem;
    border-bottom-right-radius: 0.25rem;
    max-width: 85%;
    width: fit-content;
    margin-left: auto;
    margin-bottom: 1.5rem;
    font-weight: 500;
    line-height: 1.5;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
    
    /* Layout Fixes */
    overflow-wrap: break-word;
    opacity: 0;
    animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* AI Canvas (The Response Box) */
.ai-canvas {
    background-color: var(--bot-bubble-bg) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 1rem;
    border-top-left-radius: 0.25rem;
    width: 100%;
    max-width: 100%;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-soft);
    overflow: hidden;
    position: relative;
    
    /* Animation */
    opacity: 0;
    animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* The Text Content */
.ai-content {
    padding: 1.5rem;
    color: var(--bot-bubble-text) !important;
    font-size: 1rem;
    line-height: 1.7;
    
    /* CRITICAL LAYOUT FIXES */
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* =========================================
   5. MARKDOWN & PROSE STYLING
   ========================================= */

.prose h1, .prose h2, .prose h3 {
    color: var(--text-heading) !important;
    font-weight: 700;
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    line-height: 1.3;
}

.prose h1 { font-size: 1.5rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.prose h2 { font-size: 1.25rem; }
.prose h3 { font-size: 1.1rem; }

.prose p, .prose li { 
    margin-bottom: 0.5em; 
    color: var(--bot-bubble-text) !important; 
}

.prose ul, .prose ol {
    margin-bottom: 1em;
    padding-left: 1.5em;
}
.prose ul { list-style-type: disc; }
.prose ol { list-style-type: decimal; }

.prose strong {
    color: var(--text-heading) !important;
    font-weight: 700;
}

/* CRITICAL FIX: PREVENT MECHANICAL FONTS */
.prose pre, .prose code {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    background-color: transparent !important;
    border: none !important;
    padding: 0 !important;
    color: inherit !important;
    white-space: pre-wrap !important;
}

/* =========================================
   6. FOOTER & INPUTS (Chat Island)
   ========================================= */

#chat-input-area > div {
    background-color: var(--bg-card); /* Theme aware background */
    border-color: var(--border-color);
}

#chat-input {
    background: transparent !important;
    color: var(--text-heading) !important;
}

#chat-input::placeholder {
    color: var(--text-muted);
}

.canvas-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background-color: var(--bg-body); /* Slightly distinct from card */
    border-top: 1px solid var(--border-color);
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: 0.5rem;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.action-btn:hover {
    background-color: var(--bg-input);
    color: #3b82f6;
    border-color: var(--border-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* =========================================
   7. SETTINGS WIDGET STYLES
   ========================================= */

#settings-btn {
    background-color: var(--settings-bg) !important;
    border-color: var(--border-color) !important;
    color: var(--text-heading) !important;
}

#settings-menu {
    background-color: var(--settings-bg) !important;
    border-color: var(--border-color) !important;
}

#settings-menu h4 {
    color: var(--text-muted) !important;
}

.theme-option {
    color: var(--text-heading) !important;
}
.theme-option:hover {
    background-color: var(--bg-body) !important;
}

/* Icon Rotation Animation */
#settings-btn svg {
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#settings-btn:hover svg {
    transform: rotate(90deg);
}
#settings-btn.rotate-active svg {
    transform: rotate(180deg);
}

/* Animations */
@keyframes slideUpFade { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.animate-fade-in-up { animation: fadeUp 0.6s ease-out forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.animate-fade-in { animation: fadeIn 0.4s ease-out forwards; }
@keyframes bounceIn {
    0% { transform: translate(-50%, -100%); opacity: 0; }
    60% { transform: translate(-50%, 10%); opacity: 1; }
    100% { transform: translate(-50%, 0); }
}
.animate-bounce-in { animation: bounceIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }

.typing-indicator {
    padding: 1rem;
    background: var(--bg-input); /* Theme aware */
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    border-top-left-radius: 0;
    width: fit-content;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 4px;
    animation: slideUpFade 0.3s ease-out forwards;
}
.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.5); } }



/* =========================================
   6. AI QUIZ MASTER STYLES (THEME AWARE)
   ========================================= */

/* --- 1. SELECTION MODAL (The Card with 5/10/15 options) --- */

.quiz-modal-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-heading);
    transition: all 0.3s ease;
}

/* Modal Text Styling */
.quiz-modal-card h3 { color: var(--text-heading); }
.quiz-modal-card p { color: var(--text-muted); }

/* Icon Container */
.quiz-icon-container {
    background-color: rgba(99, 102, 241, 0.1); /* Indigo-50 */
    color: #6366f1; /* Indigo-500 */
}

/* Selection Buttons (5, 10, 15 Questions) */
.quiz-selection-btn {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    background-color: transparent; /* Let card bg show through */
    color: var(--text-heading);
    font-weight: 600;
    transition: all 0.2s ease;
}

.quiz-selection-btn:hover {
    border-color: #6366f1;
    background-color: rgba(99, 102, 241, 0.05);
    color: #6366f1;
}

/* Badges (Quick, Standard, Deep Dive) */
.quiz-badge {
    background-color: var(--bg-input);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    transition: all 0.2s;
}

.quiz-selection-btn:hover .quiz-badge {
    background-color: #6366f1;
    color: #ffffff;
}

/* --- 2. ACTIVE QUIZ INTERFACE (The Game) --- */

/* Option Buttons (A, B, C, D) */
.quiz-option-btn {
    width: 100%;
    text-align: left;
    padding: 1rem 1.25rem;
    border-radius: 0.75rem;
    border: 2px solid var(--border-color);
    background-color: var(--bg-card);
    color: var(--text-heading);
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.quiz-option-btn:hover:not(:disabled) {
    border-color: #6366f1;
    background-color: rgba(99, 102, 241, 0.05);
    color: #6366f1;
}

/* Option Letter Circle (A, B, C, D) */
.option-letter {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--bg-input);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
}

.quiz-option-btn:hover .option-letter {
    background-color: #6366f1;
    color: white;
    border-color: #6366f1;
}

/* Correct/Wrong States (Always colorful) */
.quiz-option-correct {
    border-color: #22c55e !important;
    background-color: rgba(34, 197, 94, 0.1) !important;
    color: #15803d !important; /* Green-700 */
}
/* Ensure text is readable in Dark Mode for correct/wrong */
[data-theme="dark"] .quiz-option-correct, 
[data-theme="ios"] .quiz-option-correct {
    color: #4ade80 !important; /* Brighter Green */
}

.quiz-option-wrong {
    border-color: #ef4444 !important;
    background-color: rgba(239, 68, 68, 0.1) !important;
    color: #b91c1c !important; /* Red-700 */
}
[data-theme="dark"] .quiz-option-wrong,
[data-theme="ios"] .quiz-option-wrong {
    color: #f87171 !important; /* Brighter Red */
}

.quiz-option-btn:disabled {
    cursor: default;
    opacity: 0.7;
}

/* --- 3. NIGHT GLASS SPECIFIC OVERRIDES --- */
/* This makes the card blurry and transparent only in Night Glass mode */

[data-theme="ios"] .quiz-modal-card,
[data-theme="ios"] #quiz-interface > div.max-w-2xl,
[data-theme="ios"] #quiz-scorecard > div {
    background-color: rgba(30, 30, 30, 0.65) !important; /* Semi-transparent Dark */
    backdrop-filter: blur(20px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3) !important;
}

/* Force bright text for legibility on glass */
[data-theme="ios"] .quiz-modal-card h3,
[data-theme="ios"] .quiz-selection-btn,
[data-theme="ios"] .quiz-option-btn,
[data-theme="ios"] #quiz-question,
[data-theme="ios"] #quiz-current-num,
[data-theme="ios"] #quiz-total-num,
[data-theme="ios"] #score-final {
    color: #ffffff !important;
}

[data-theme="ios"] .quiz-modal-card p,
[data-theme="ios"] .quiz-badge,
[data-theme="ios"] .option-letter,
[data-theme="ios"] #score-total {
    color: #cbd5e1 !important; /* Slate-300 */
}

/* Adjust borders for glass theme */
[data-theme="ios"] .quiz-selection-btn,
[data-theme="ios"] .quiz-option-btn {
    border-color: rgba(255, 255, 255, 0.2);
    background-color: rgba(255, 255, 255, 0.05);
}

[data-theme="ios"] .quiz-selection-btn:hover,
[data-theme="ios"] .quiz-option-btn:hover:not(:disabled) {
    background-color: rgba(99, 102, 241, 0.2);
    border-color: #818cf8;
}

/* =========================================
   FIX: QUIZ SCORECARD ALIGNMENT
   ========================================= */

/* 1. Reset the container (Stop it from shifting left) */
#quiz-scorecard {
    animation: fadeIn 0.3s ease-out forwards !important; /* Just fade in background */
    transform: none !important; /* Force remove the -50% shift */
}

/* 2. Animate the Inner Card instead (Scale up) */
#quiz-scorecard > div {
    animation: modalPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    opacity: 0;
}

/* 3. New Pop Animation (No shifting) */
@keyframes modalPop {
    0% { 
        transform: scale(0.8); 
        opacity: 0; 
    }
    100% { 
        transform: scale(1); 
        opacity: 1; 
    }
}

/* =========================================
   FIX: SCORECARD BUTTON (Psychology & Visibility)
   ========================================= */

/* Target the "Back to Study" button specifically */
#quiz-scorecard button {
    /* 1. VISIBILITY FIX: Force text to be White */
    color: #ffffff !important;
    
    /* 2. PSYCHOLOGY FIX: Calming Indigo Gradient */
    /* Indigo promotes deep concentration and focus, unlike aggressive red or black */
    background: linear-gradient(135deg, #6366f1, #4f46e5) !important; /* Indigo-500 -> Indigo-600 */
    
    /* 3. Polish */
    border: none !important;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4); /* Soft glowing shadow */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Hover Effect: Slightly lift and glow brighter */
#quiz-scorecard button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
    background: linear-gradient(135deg, #818cf8, #6366f1) !important; /* Lighter Indigo */
}

/* Active Click Effect */
#quiz-scorecard button:active {
    transform: translateY(0);
}


/* =========================================
   FIX: TOAST VISIBILITY (Always on Top)
   ========================================= */
#toast {
    z-index: 1000 !important; /* Force it above all modals (which are usually z-50 to z-90) */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4); /* Stronger shadow for visibility */
}


/* =========================================
   7. TEST HISTORY PAGE STYLES
   ========================================= */

/* The Main History Page/Modal */
#test-history-modal {
    /* FIX: Use 'background' instead of 'background-color' to support Gradients & Images */
    background: var(--bg-body) !important; 
    
    /* Ensure images/gradients cover the whole screen properly */
    background-size: cover !important;
    background-attachment: fixed !important;
    background-position: center !important;
    
    color: var(--text-main);
    z-index: 100 !important; /* Ensure it sits on top of everything */
}

#test-history-modal header {
    background-color: var(--bg-card) !important;
    border-color: var(--border-color) !important;
}

#test-history-modal h2 {
    color: var(--text-heading) !important;
}

/* Date Group Label (e.g., "Today", "Dec 8") */
.history-date-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    margin-top: 1.5rem;
    padding-left: 0.5rem;
    border-left: 3px solid #6366f1; /* Indigo accent */
}

/* Individual Test Result Card */
.history-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem;
    position: relative;
    box-shadow: var(--shadow-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.2s;
    overflow: hidden; /* For the serial number decoration */
}

.history-card:hover {
    transform: translateY(-2px);
    border-color: #6366f1; /* Highlight on hover */
}

/* Serial Number Decoration (Big faded number in background) */
.history-serial {
    position: absolute;
    left: -10px;
    bottom: -15px;
    font-size: 4rem;
    font-weight: 900;
    color: var(--text-main);
    opacity: 0.05; /* Very subtle watermark */
    pointer-events: none;
    line-height: 1;
}

/* Left Side: Topic & Time */
.history-info h4 {
    color: var(--text-heading);
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.history-info p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Right Side: Score Badge */
.history-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-input); /* Slight contrast */
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.5rem 1rem;
    min-width: 70px;
}

.score-val {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-heading);
}

.score-total {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* High Score Accent (Green text if they got 100%) */
.score-perfect .score-val {
    color: #22c55e !important;
}

/* Loading State */
#history-list-container .fa-circle-notch {
    color: #6366f1;
}

/* =========================================
   FIX: TAKE QUIZ BUTTON (Universal Style)
   ========================================= */

/* Force a consistent, high-quality look across ALL themes */
#btn-take-quiz {
    /* 1. Force White Background & Indigo Text */
    background: #ffffff !important;
    color: #4f46e5 !important; /* Indigo-600 */
    border: 2px solid #eef2ff !important; /* Indigo-50 border */
    
    /* 2. Force Shadow for depth */
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.1), 0 2px 4px -1px rgba(79, 70, 229, 0.06) !important;
    
    /* 3. Standard styling */
    padding: 0.6rem 1.2rem;
    border-radius: 9999px;
    font-weight: 700;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transition: all 0.2s ease;
    letter-spacing: 0.025em;
}

/* Hover State: Slightly darker indigo & bigger shadow */
#btn-take-quiz:hover {
    border-color: #c7d2fe !important; /* Indigo-200 */
    background: #f8fafc !important; /* Slate-50 */
    color: #4338ca !important; /* Indigo-700 */
    box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.15), 0 4px 6px -2px rgba(79, 70, 229, 0.1) !important;
    transform: translateY(-1px);
}

/* Active State: Click effect */
#btn-take-quiz:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px -1px rgba(79, 70, 229, 0.1) !important;
}

/* --- Night Glass Fix --- */
/* Remove any glass effect from this specific button */
[data-theme="ios"] #btn-take-quiz {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* =========================================
   FIX: SETTINGS MENU (Universal Theme Support)
   ========================================= */

/* 1. Base Menu Styling (Defaults for Light Mode) */
#settings-menu {
    background-color: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-heading) !important;
}

/* Ensure Text Colors follow variables */
#settings-menu h4, 
.theme-option {
    color: var(--text-heading) !important;
}

/* 2. Theme Option Buttons */
.theme-option {
    background-color: transparent;
    border: 1px solid transparent; /* Invisible border by default */
}

/* Hover State (Light/Dark Safe) */
.theme-option:hover {
    background-color: var(--bg-input) !important;
    transform: translateX(2px);
}

/* 3. "Selected" State (Indigo Outline) */
.theme-option.active-theme {
    border-color: #6366f1 !important;
    background-color: rgba(99, 102, 241, 0.08) !important;
}

/* --- DARK MODE SPECIFIC FIXES --- */
/* When body is dark, ensure menu background is dark */
[data-theme="dark"] #settings-menu {
    background-color: #1e293b !important; /* Slate-800 */
    border-color: #334155 !important;
}

[data-theme="dark"] #settings-menu h4,
[data-theme="dark"] .theme-option {
    color: #ffffff !important; /* Force White Text */
}

[data-theme="dark"] .theme-option:hover {
    background-color: #334155 !important; /* Lighter Slate for hover */
}

/* --- NIGHT GLASS SPECIFIC FIXES --- */
[data-theme="ios"] #settings-menu {
    background-color: rgba(30, 30, 30, 0.7) !important; /* Semi-transparent black */
    backdrop-filter: blur(20px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
}

[data-theme="ios"] #settings-menu h4,
[data-theme="ios"] .theme-option {
    color: #ffffff !important; /* Bright White Text */
}

[data-theme="ios"] .theme-option:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

/* =========================================
   FIX: CHAT ISLAND MOBILE VISIBILITY
   ========================================= */

#chat-input-area {
    /* 1. Force it to stick to the bottom */
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    
    /* 2. FORCE IT TO BE ON TOP OF CONTENT */
    /* The content usually has z-0 or z-10. We give this z-50 to stay above it. */
    /* Note: Settings Widget is z-60, so it will float nicely above this bar. */
    z-index: 50 !important;
    
    /* 3. Mobile Safe Area Fix (iPhone Home Bar) */
    padding-bottom: env(safe-area-inset-bottom) !important;
}

/* Ensure the background of the input area is solid, not transparent */
#chat-input-area > div {
    background-color: var(--bg-card) !important;
    border-top: 1px solid var(--border-color) !important;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* Add padding to the chat view so the last message isn't hidden behind the bar */
#view-chat {
    padding-bottom: 120px !important; /* Give plenty of space at the bottom */
}