/* --- CSS VARIABLES & THEMES --- */
:root {
    --primary: #0056b3;
    --secondary: #6c757d;
    --success: #28a745;
    --danger: #dc3545;
    --background: #f4f7f6;
    --card-bg: #ffffff;
    --text-main: #333333;
    --text-muted: #6c757d;
    --border-color: #e0e0e0;
    --input-bg: #f8f9fa;
    --overlay-bg: rgba(0, 0, 0, 0.4);
    --primary-rgb: 0, 86, 179; 
}

[data-theme="dark"] {
    --primary: #66b0ff;
    --secondary: #aab2bd;
    --success: #4cd964;
    --danger: #ff6b6b;
    --background: #121212;
    --card-bg: #1e1e1e;
    --text-main: #e0e0e0;
    --text-muted: #88929e;
    --border-color: #333333;
    --input-bg: #2a2a2a;
    --overlay-bg: rgba(0, 0, 0, 0.7);
    --primary-rgb: 102, 176, 255;
}

/* --- BASE STYLES & SCROLLBAR ELIMINATION --- */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    -ms-overflow-style: none;
    scrollbar-width: none;
}
*::-webkit-scrollbar { display: none; }

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--background); 
    color: var(--text-main); 
    -webkit-font-smoothing: antialiased; 
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
    line-height: 1.5;
    overflow-x: hidden;
}

/* --- NAVIGATION & SHELL --- */
.top-bar { 
    position: sticky; 
    top: 0; 
    z-index: 500; 
    background: var(--card-bg); 
    border-bottom: 1px solid var(--border-color); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 0 12px; /* Tightened from 16px */
    height: 60px; /* Slightly shorter for proportion */
    box-shadow: 0 4px 20px rgba(0,0,0,0.03); 
    transition: background-color 0.3s, border-color 0.3s; 
}
.top-bar-left { display: flex; align-items: center; gap: 10px; } /* Tightened gap */
.top-bar-title { display: none; font-size: 1.2rem; font-weight: 700; color: var(--primary); letter-spacing: -0.3px; }
.nav-actions { display: flex; gap: 8px; align-items: center; } /* Tightened gap */
.nav-icon { 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    width: 36px; /* Scaled down slightly */
    height: 36px; 
    border-radius: 50%; 
    background: var(--input-bg); 
    transition: background 0.2s, transform 0.1s; 
}
.nav-icon:active { transform: scale(0.92); }
.nav-icon svg { width: 20px; height: 20px; stroke: var(--primary); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* SIDEBAR */
.sidebar { 
    position: fixed; top: 0; left: -280px; width: 280px; height: 100%; 
    background: var(--card-bg); z-index: 1100; 
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s; 
    border-right: 1px solid var(--border-color); 
    display: flex; flex-direction: column; padding-top: 24px; 
}
.sidebar.active { left: 0; }
.sidebar-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: var(--overlay-bg); z-index: 1050; display: none; 
    opacity: 0; transition: opacity 0.3s ease; 
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; opacity: 1; }
.sidebar-header { 
    font-size: 1.25rem; font-weight: 700; color: var(--primary); 
    padding: 0 24px 24px; border-bottom: 1px solid var(--border-color); 
    margin-bottom: 12px; letter-spacing: -0.3px;
}
.sidebar-link { 
    padding: 16px 24px; text-decoration: none; color: var(--text-main); 
    font-weight: 600; display: flex; align-items: center; gap: 16px; 
    transition: background 0.2s, color 0.2s; 
}
.sidebar-link:active { background: var(--input-bg); }
.sidebar-link svg { width: 22px; height: 22px; stroke: var(--secondary); stroke-width: 2; fill: none; transition: stroke 0.2s; }

/* --- CORE CONTAINERS & FORMS --- */
.container { padding: 24px 16px; max-width: 800px; margin: 0 auto; padding-bottom: 100px; }
.card { 
    background: var(--card-bg); 
    border-radius: 16px; 
    padding: 24px; 
    box-shadow: 0 8px 24px rgba(0,0,0,0.04); 
    margin-bottom: 24px; 
    border: 1px solid var(--border-color); 
    transition: background-color 0.3s, border-color 0.3s; 
}
label { 
    display: block; font-size: 0.8rem; font-weight: 700; 
    color: var(--text-muted); margin-bottom: 8px; margin-top: 16px; 
    text-transform: uppercase; letter-spacing: 0.8px; 
}
.card h3 + label, .card > label:first-child { margin-top: 0; }

input, select, textarea { 
    width: 100%; 
    padding: 14px 16px; 
    border: 1.5px solid var(--border-color); 
    border-radius: 12px; 
    background-color: var(--input-bg); 
    color: var(--text-main); 
    font-size: 1rem; 
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.3s, color 0.3s; 
    appearance: none;
}
select {
    background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%236c757d" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 16px;
    padding-right: 40px;
}
input:focus, select:focus, textarea:focus { 
    outline: none; 
    border-color: var(--primary); 
    box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.15); 
    background-color: var(--card-bg);
}

/* --- BUTTONS & ANIMATIONS --- */
button { 
    width: 100%; padding: 16px; border: none; border-radius: 12px; 
    font-size: 1.05rem; font-weight: 700; cursor: pointer; 
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s;
    letter-spacing: -0.2px;
}
button:active { transform: scale(0.96); }
.btn-submit { background-color: var(--primary); color: white; box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.2); }
.btn-add { background-color: var(--success); color: white; box-shadow: 0 4px 12px rgba(40, 167, 69, 0.2); }

.fade-in { animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }

/* --- GLASS MODAL --- */
.glass-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: var(--overlay-bg); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); 
    z-index: 2000; display: flex; justify-content: center; align-items: center; 
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease; 
}
.glass-overlay.active { opacity: 1; pointer-events: auto; }
.glass-modal { 
    background: var(--card-bg); border: 1px solid var(--border-color); 
    border-radius: 20px; padding: 30px 24px; width: 85%; max-width: 420px; 
    box-shadow: 0 20px 40px rgba(0,0,0,0.2); transform: scale(0.95); 
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); 
    text-align: center; color: var(--text-main); 
}
.glass-overlay.active .glass-modal { transform: scale(1); }
.glass-modal h3 { margin-bottom: 12px; color: var(--text-main); font-size: 1.3rem; font-weight: 800; letter-spacing: -0.5px; }
.glass-modal p { color: var(--text-muted); margin-bottom: 24px; font-size: 1rem; line-height: 1.5; }
.glass-modal .modal-buttons { display: flex; gap: 12px; margin-top: 24px; }
.glass-modal .btn-cancel { background: var(--input-bg); color: var(--text-main); margin-top: 0; border: 1px solid var(--border-color); }
.glass-modal .btn-confirm { margin-top: 0; }


/* ==========================================
   PHASE 5: TO-DO TRACKER SPECIFIC STYLES
   ========================================== */

/* Updated: Uses dynamic viewport height and extra padding for the FAB */
.todo-container { 
    padding-bottom: 120px !important; 
    min-height: 100vh;
    min-height: 100dvh; /* Adapts to mobile browser address bars */
    position: relative;
}

/* Forces horizontal scrolling for stats on mobile */
.horizontal-scroll {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 12px;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
}
.horizontal-scroll .stat-card {
    flex: 0 0 auto;
}
.todo-tab { display: none; animation: fadeIn 0.3s ease; }
.todo-tab.active { display: block; }

/* Stats Grid & Global Stats */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-card { 
    background: var(--card-bg); 
    border-radius: 12px; 
    padding: 16px; 
    border: 1px solid var(--border-color); 
    box-shadow: 0 4px 12px rgba(0,0,0,0.02); 
    display: flex; flex-direction: column; gap: 8px; 
}
.stat-card.primary { background: var(--primary); color: white; border: none; }
.stat-card.primary .stat-title, .stat-card.primary .stat-num { color: white; }
.stat-title { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.stat-num { font-size: 1.8rem; font-weight: 800; color: var(--text-main); }

/* Task List Elements */
.task-filters { 
    display: flex; gap: 16px; margin-bottom: 16px; 
    border-bottom: 1px solid var(--border-color); 
    padding-bottom: 8px; overflow-x: auto; 
}
.task-filter { 
    font-size: 0.95rem; font-weight: 600; color: var(--text-muted); 
    cursor: pointer; padding-bottom: 8px; position: relative; white-space: nowrap; 
}
.task-filter.active { color: var(--primary); }
.task-filter.active::after { 
    content: ''; position: absolute; bottom: -9px; left: 0; 
    width: 100%; height: 2px; background: var(--primary); border-radius: 2px; 
}

.task-card { 
    background: var(--card-bg); border-radius: 12px; padding: 16px; 
    margin-bottom: 12px; border: 1px solid var(--border-color); 
    display: flex; gap: 12px; align-items: flex-start; 
}
.task-checkbox { 
    width: 22px; height: 22px; border-radius: 50%; 
    border: 2px solid var(--text-muted); cursor: pointer; 
    flex-shrink: 0; margin-top: 2px; display: flex; 
    align-items: center; justify-content: center; 
}
.task-checkbox.done { background: var(--success); border-color: var(--success); }
.task-checkbox.done::after { content: '✓'; color: white; font-size: 14px; font-weight: bold; }
.task-content { flex: 1; }
.task-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; color: var(--text-main); }
.task-meta { font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }

/* Priority Badges */
.priority-badge { font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 12px; background: var(--input-bg); }
.priority-high { color: var(--danger); background: rgba(220,53,69,0.1); }
.priority-medium { color: #d39e00; background: rgba(255,193,7,0.1); }
.priority-low { color: var(--success); background: rgba(40,167,69,0.1); }

/* Bottom Navigation Bar */
.todo-bottom-nav { 
    position: fixed; bottom: 0; left: 0; width: 100%; height: 70px; 
    background: var(--card-bg); border-top: 1px solid var(--border-color); 
    display: flex; justify-content: space-around; align-items: center; 
    z-index: 1000; padding-bottom: env(safe-area-inset-bottom); 
}
.nav-item { 
    display: flex; flex-direction: column; align-items: center; gap: 4px; 
    color: var(--text-muted); cursor: pointer; font-size: 0.75rem; 
    font-weight: 600; transition: color 0.2s; width: 60px; 
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 2; fill: none; }

/* Central Floating Action Button (FAB) */
.fab-container { position: relative; top: -20px; }
.fab-btn { 
    width: 56px; height: 56px; border-radius: 50%; 
    background: var(--primary); color: white; display: flex; 
    align-items: center; justify-content: center; 
    box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.4); 
    border: none; cursor: pointer; transition: transform 0.2s; 
}
.fab-btn:active { transform: scale(0.92); }
.fab-btn svg { width: 28px; height: 28px; stroke: white; stroke-width: 2; }

/* Fix the Bottom Bar so it never floats up */
.todo-bottom-nav { 
    position: fixed !important; 
    bottom: 0 !important; 
    left: 0; 
    width: 100%; 
    z-index: 9999 !important; 
}
.todo-container { 
    padding-bottom: 100px !important; /* Forces scroll space so footer doesn't hide content */
    min-height: 100vh;
}

/* Fix the Dashboard Scroll (Wraps neatly into rows) */
.stats-wrap-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}
.stats-wrap-grid .stat-card {
    flex: 1 1 calc(33.333% - 12px); /* Attempts to put 3 cards on top, wraps the rest */
    min-width: 100px;
}