/* ========================================== */
/* 1. MASTER DESIGN TOKENS                    */
/* ========================================== */
:root {
    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --success: #10b981;
    --border-color: #e5e7eb;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    
    --high-priority: #f59e0b;
    --critical-priority: #dc2626;
}

/* Dark Mode Tokens (Swaps everything instantly!) */
html.dark {
    --bg-body: #111827;
    --bg-card: #1f2937;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --border-color: #374151;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

/* ========================================== */
/* 2. BASE STYLES & UTILITIES                 */
/* ========================================== */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', sans-serif; }

html { transition: background-color 0.3s ease, color 0.3s ease; }
body { background-color: var(--bg-body); color: var(--text-main); display: flex; justify-content: center; -webkit-font-smoothing: antialiased; }

/* Critical view toggles */
.hidden { display: none !important; }
.active { display: block; }

/* Custom Scrollbars (The Secret Polish) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ========================================== */
/* 3. PREMIUM UI ELEMENTS                     */
/* ========================================== */
/* Auth & Modals */
#auth-view { 
    height: 100vh; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    width: 100%; 
    background-color: #f8fafc;
    position: relative;
    overflow: hidden;
}

/* Generates the geometric line background from the image */
#auth-view::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: 
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25'%3E%3Cg stroke='%23cbd5e1' stroke-width='1.5' fill='none' opacity='0.4'%3E%3Cpath d='M-100,-100 L300,400 M-50,200 L400,0 M150,-100 L500,500 M100%25,0 Lcalc(100%25 - 400px),400 M100%25,200 Lcalc(100%25 - 500px),-100 Mcalc(100%25 - 150px),-100 Lcalc(100%25 - 600px),600'/%3E%3C/g%3E%3C/svg%3E");
    background-size: cover;
    z-index: 0;
    pointer-events: none;
}

/* Dark Mode Fallback */
html.dark #auth-view { background-color: var(--bg-body); }
html.dark #auth-view::before { opacity: 0.1; stroke: #4b5563; }

/* The Exact Frosted Glass Card */
.auth-card { 
    padding: 3rem 2.5rem; 
    width: 90%; 
    max-width: 440px; 
    
    /* Glassmorphism settings */
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    
    /* Subtle white glowing border */
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 16px;
    
    /* Soft diffuse shadow */
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.04), inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

html.dark .auth-card {
    background: rgba(31, 41, 55, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

/* ========================================== */
/* OVERLAY MODALS (Restored)                  */
/* ========================================== */
.modal { 
    position: fixed; 
    z-index: 1000; 
    left: 0; 
    top: 0; 
    width: 100vw; 
    height: 100vh; 
    background-color: rgba(0,0,0,0.5); /* The dark overlay */
    display: flex; 
    align-items: center; 
    justify-content: center; 
}

.modal-content, #profile-dropdown {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.modal-content { 
    padding: 2rem; 
    width: 90%; 
    max-width: 500px; 
    position: relative; 
}

.close-btn { 
    position: absolute; 
    top: 1rem; 
    right: 1.5rem; 
    font-size: 1.5rem; 
    cursor: pointer; 
    color: var(--text-muted); 
}

.modal-content h2 { margin-bottom: 1.5rem; }

/* ========================================== */
/* 4. DASHBOARD & TASKS                       */
/* ========================================== */
#dashboard-view { width: 100%; max-width: 700px; padding: 1rem; }
#admin-view { width: 100%; }

header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; margin-top: 1rem; border-bottom: 1px solid var(--border-color); padding-bottom: 1rem; }

/* Categories */
.horizontal-scroll { display: flex; overflow-x: auto; gap: 0.5rem; padding-bottom: 1rem; }
.horizontal-scroll::-webkit-scrollbar { display: none; }
.category-pill { 
    background-color: var(--bg-card); 
    color: var(--text-muted); 
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap; 
    transition: all 0.2s ease; 
}
.category-pill:hover { background-color: var(--border-color); color: var(--text-main); }
.category-pill.active-cat { background-color: var(--primary); color: white; border-color: var(--primary); }

/* Tasks */
#task-list { list-style: none; }
.task-item { 
    background-color: var(--bg-card); 
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 1rem; 
    border-radius: var(--radius); 
    margin-bottom: 0.75rem; 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-start; 
    box-shadow: var(--shadow-sm); 
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: grab;
}
.task-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.task-item[data-priority="3"] { border-left: 4px solid var(--high-priority); }
.task-item[data-priority="4"] { border-left: 4px solid var(--critical-priority); }

/* Subtasks & Markdown */
.subtasks-container { margin-top: 12px; margin-left: 28px; border-left: 2px solid var(--border-color); padding-left: 12px; }
.subtask-text { color: var(--text-muted); font-size: 0.85rem; }
.new-subtask-input { background: transparent; color: var(--text-muted); border: none; box-shadow: none; padding: 0; margin-top: 5px; margin-bottom: 0; width: 100%; outline: none; font-size: 0.85rem; }
.new-subtask-input:focus { box-shadow: none; color: var(--text-main); border: none; }

.task-desc { background: rgba(0,0,0,0.03); color: var(--text-muted); padding: 10px; border-radius: 6px; margin-top: 8px; font-size: 0.85rem; }
.task-desc a { color: var(--primary); text-decoration: underline; }
.task-desc p { margin: 0 0 5px 0; }
html.dark .task-desc { background: rgba(255,255,255,0.05); }

/* Drag & Drop */
.sortable-ghost { opacity: 0.4; background-color: var(--bg-body); border: 2px dashed var(--text-muted); }
.sortable-drag { cursor: grabbing !important; box-shadow: var(--shadow-lg); }

/* ========================================== */
/* 5. ANIMATIONS & SKELETONS                  */
/* ========================================== */
@keyframes shimmer {
    0% { background-position: -1000px 0; }
    100% { background-position: 1000px 0; }
}
.skeleton {
    background: #f6f7f8;
    background: linear-gradient(to right, #eeeeee 8%, #dddddd 18%, #eeeeee 33%);
    background-size: 1000px 100%;
    animation: shimmer 2s infinite linear;
    border-radius: var(--radius);
}
html.dark .skeleton {
    background: #374151;
    background: linear-gradient(to right, #374151 8%, #4b5563 18%, #374151 33%);
    background-size: 1000px 100%;
}
.skeleton-task { height: 70px; margin-bottom: 12px; width: 100%; border: 1px solid var(--border-color); }

.fade-out-right { opacity: 0; transform: translateX(30px); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
hr { border: 0; border-top: 1px solid var(--border-color); margin: 1rem 0; }

/* ========================================== */
/* MOBILE-FIRST RESPONSIVE LAYER           */
/* ========================================== */

/* Base Mobile Optimization */
body {
    max-width: 100vw;
    overflow-x: hidden;
}

#dashboard-view {
    width: 100%;
    max-width: 100%;
    padding: 0.75rem;
}

/* Header Fix */
header {
    flex-direction: row;
    gap: 10px;
}

header h2 {
    font-size: 1.2rem;
}

/* Category Scroll (Better UX) */
.horizontal-scroll {
    gap: 8px;
    padding-bottom: 10px;
    scroll-snap-type: x mandatory;
}

.category-pill {
    scroll-snap-align: start;
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
}

/* Tasks Mobile Optimization */
.task-item {
    flex-direction: column;
    gap: 8px;
    padding: 0.85rem;
}


/* Buttons Full Width Mobile */
#add-task-btn {
    width: 100%;
    margin: 10px 0;
}

/* Inputs Mobile Friendly */
input, textarea {
    font-size: 16px; /* Prevent zoom on iOS */
}

/* Auth Card Mobile */
.auth-card {
    padding: 1.5rem;
}

/* ========================================== */
/* SMALL PHONES (≤ 480px)                  */
/* ========================================== */
@media (max-width: 480px) {

    body {
        font-size: 14px;
    }

    header h2 {
        font-size: 1rem;
    }

    .task-item {
        padding: 0.7rem;
    }

    .category-pill {
        font-size: 0.75rem;
    }

    button {
        padding: 0.6rem;
    }
}

/* ========================================== */
/* TABLETS (481px - 768px)                 */
/* ========================================== */
@media (min-width: 481px) and (max-width: 768px) {

    #dashboard-view {
        max-width: 600px;
        margin: auto;
    }

    .task-item {
        flex-direction: row;
        align-items: center;
    }
}

/* ========================================== */
/* 💻 DESKTOP (≥ 769px)                      */
/* ========================================== */
@media (min-width: 769px) {

    #dashboard-view {
        max-width: 700px;
        margin: auto;
    }

    .task-item {
        flex-direction: row;
        align-items: center;
    }

    .auth-card {
        max-width: 400px;
    }
}

/* ========================================== */
/* ✨ TOUCH IMPROVEMENTS (VERY IMPORTANT)     */
/* ========================================== */

/* Bigger tap targets */
button, .category-pill {
    min-height: 40px;
}

/* Smooth touch scrolling */
.horizontal-scroll {
    -webkit-overflow-scrolling: touch;
}

/* Remove tap highlight */
* {
    -webkit-tap-highlight-color: transparent;
}

/* ========================================== */
/* 🚀 APP-LIKE EXPERIENCE                    */
/* ========================================== */

/* Safe area for mobile notch */
body {
    padding-bottom: env(safe-area-inset-bottom);
}

/* Prevent bounce scroll */
html, body {
    overscroll-behavior: none;
}

/* Smooth transitions */
.task-item {
    transition: all 0.2s ease;
}

/* ========================================== */
/* MODAL FORM LAYOUTS (Restored)              */
/* ========================================== */

.modal-content label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 12px;
    margin-bottom: 4px;
    display: block; /* Forces label to sit above the input */
    font-weight: 500;
}

.modal-content input, 
.modal-content select, 
.modal-content textarea {
    background-color: var(--bg-body);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    width: 100%; /* Forces inputs to take full width */
    box-sizing: border-box;
    font-size: 0.95rem;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.modal-content input:focus, 
.modal-content select:focus, 
.modal-content textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Fix the Save/Submit Buttons */
.modal-content button[type="submit"] {
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.85rem 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%; /* Forces button to stretch across the bottom */
    margin-top: 1.5rem;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.modal-content button[type="submit"]:hover {
    background-color: var(--primary-hover);
}

/* Specific fix for file inputs to look clean */
.modal-content input[type="file"] {
    padding: 0.5rem;
    background: transparent;
    border: 1px dashed var(--border-color);
}

/* ========================================== */
/* FOLDABLES & EXTREME NARROW SCREENS (< 360px) */
/* Addresses Galaxy Z Fold cover screens & Flip phones */
/* ========================================== */

/* 1. Global Safety Net: Never allow elements to stretch the screen horizontally */
* {
    overflow-wrap: break-word;
    word-wrap: break-word;
}

@media (max-width: 360px) {
    /* 2. Reclaim precious screen space by reducing outer margins */
    #dashboard-view { 
        padding: 0.5rem !important; 
    }

    /* 3. Compress the Login Card so it doesn't hit the edges */
    .auth-card {
        padding: 1.5rem 1rem !important;
        width: 96% !important;
    }

    /* 4. Compress Modals (keeps the X button safe) */
    .modal-content {
        padding: 2.5rem 1rem 1rem 1rem !important;
        width: 96% !important;
    }

    /* 5. Shrink large text to fit narrow widths */
    header h1 { 
        font-size: 1.4rem !important; 
    }
    
    #header-username {
        max-width: 120px !important; /* Slightly smaller for tiny screens */
    }

    /* 6. Tasks: Reduce padding and allow action buttons to wrap */
    .task-item {
        padding: 0.75rem 0.5rem !important;
    }
    
    .task-item strong { 
        font-size: 0.95rem !important; 
    }

    /* 7. Allow the Edit/Delete buttons to wrap to a new line if they run out of space */
    .task-item > div:last-child {
        flex-wrap: wrap !important;
        justify-content: flex-end;
        gap: 8px !important;
    }

    /* 8. Make the Dashboard Top Navigation scrollable if it gets too tight */
    .flex.gap-4.mb-6 {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 5px;
    }
}

/* ========================================== */
/* FOLDABLE INNER SCREENS (Square Tablets) */
/* ========================================== */
@media (min-width: 600px) and (max-width: 850px) {
    /* Ensures the app uses the full width of the square inner display */
    #dashboard-view {
        max-width: 95% !important;
    }
}


/* Floating Voice Assistant Button */
#voice-assistant-btn {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.4);
    z-index: 2000;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#voice-assistant-btn:active {
    transform: scale(0.9);
}

/* Pulsing effect when listening */
.listening-pulse {
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); background: #ef4444; }
    70% { box-shadow: 0 0 0 15px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); background: #ef4444; }
}

/* Microphone Styling */
.input-wrapper {
    position: relative;
    width: 100%;
    margin-bottom: 1rem;
}

#dictate-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 5;
    padding: 5px;
}

/* Fix for the task cards in your first image */
.task-item {
    display: flex;
    flex-direction: column !important;
    align-items: stretch !important;
}