/* =========================================
   1. THEME VARIABLES
   ========================================= */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f4f4f4; /* App Background */
    --bg-tertiary: #e9e9e9;  /* Item Backgrounds */
    --bg-modal: #fefefe;
    
    --text-primary: #333333;
    --text-secondary: #555555;
    --text-muted: #aaaaaa;
    
    --border-primary: #e2e8f0;
    --border-secondary: #dddddd;
    --border-hour-slot: #cccccc;
    
    --accent-primary: #4f46e5; /* Modern Indigo */
    --accent-primary-hover: #4338ca;
    --accent-delete: #ef4444;
    --accent-delete-hover: #dc2626;
    --accent-recover: #22c55e;
    --accent-recover-hover: #16a34a;
    --accent-warning: #f59e0b;
    --accent-warning-hover: #d97706;
    
    --shadow-primary: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    
    /* Timeline Specifics */
    --scheduled-task-bg: rgba(79, 70, 229, 0.9);
    --scheduled-task-border: #4338ca;
    --scheduled-task-text: #ffffff;
    --overlapping-task-bg: rgba(239, 68, 68, 0.85);
    --overlapping-task-border: #b91c1c;
    --drop-target-bg: #e0e7ff;
    --timeline-bg: #ffffff;
    
    --button-secondary-bg: #64748b;
    --button-secondary-hover-bg: #475569;
    
    --list-item-bg: #f8fafc;
    --list-item-hover-bg: #f1f5f9;
    --list-item-border: #e2e8f0;
    
    --message-success-bg: #dcfce7;
    --message-success-text: #166534;
    --message-success-border: #bbf7d0;
    --message-error-bg: #fee2e2;
    --message-error-text: #991b1b;
    --message-error-border: #fecaca;

    /* Priority Colors */
    --priority-critical-bg: #fee2e2;
    --priority-critical-text: #991b1b;
    --priority-critical-border: #fecaca;
    --priority-high-bg: #ffedd5;
    --priority-high-text: #9a3412;
    --priority-high-border: #fed7aa;
    --priority-medium-bg: #dbeafe;
    --priority-medium-text: #1e40af;
    --priority-medium-border: #bfdbfe;
    --priority-low-bg: #dcfce7;
    --priority-low-text: #166534;
    --priority-low-border: #bbf7d0;
    --priority-optional-bg: #f1f5f9;
    --priority-optional-text: #475569;
    --priority-optional-border: #e2e8f0;
    --due-date-overdue-text: #dc2626;
}

/* DARK THEME */
body[data-theme="dark"] {
    --bg-primary: #1e293b; /* Panel BG */
    --bg-secondary: #0f172a; /* Body BG */
    --bg-tertiary: #334155;
    --bg-modal: #1e293b;
    
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --border-primary: #334155;
    --border-secondary: #475569;
    --border-hour-slot: #334155;
    
    --accent-primary: #6366f1;
    --accent-primary-hover: #818cf8;
    --accent-delete: #ef4444;
    --accent-delete-hover: #f87171;
    --accent-recover: #22c55e;
    --accent-recover-hover: #4ade80;
    --accent-warning: #fbbf24;
    
    --shadow-primary: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    
    --scheduled-task-bg: rgba(99, 102, 241, 0.8);
    --scheduled-task-border: #4f46e5;
    --overlapping-task-bg: rgba(220, 38, 38, 0.7);
    --drop-target-bg: #312e81;
    --timeline-bg: #1e293b;
    
    --button-secondary-bg: #475569;
    --button-secondary-hover-bg: #64748b;
    --list-item-bg: #1e293b;
    --list-item-hover-bg: #334155;
    --list-item-border: #334155;
    
    --message-success-bg: #064e3b;
    --message-success-text: #a7f3d0;
    --message-success-border: #065f46;
    --message-error-bg: #7f1d1d;
    --message-error-text: #fecaca;
    --message-error-border: #991b1b;

    /* Priority Dark */
    --priority-critical-bg: #450a0a;
    --priority-critical-text: #fecaca;
    --priority-critical-border: #7f1d1d;
    --priority-high-bg: #431407;
    --priority-high-text: #fed7aa;
    --priority-high-border: #7c2d12;
    --priority-medium-bg: #172554;
    --priority-medium-text: #bfdbfe;
    --priority-medium-border: #1e3a8a;
    --priority-low-bg: #052e16;
    --priority-low-text: #bbf7d0;
    --priority-low-border: #14532d;
    --priority-optional-bg: #1e293b;
    --priority-optional-text: #cbd5e1;
    --priority-optional-border: #334155;
    --due-date-overdue-text: #ef4444;
}

/* SEPIA THEME */
body[data-theme="sepia"] {
    --bg-primary: #fdf6e3;
    --bg-secondary: #eee8d5;
    --bg-tertiary: #e0d6be;
    --bg-modal: #fdf6e3;
    --text-primary: #5f4b32;
    --text-secondary: #8c7356;
    --text-muted: #a69279;
    --border-primary: #d3c6a6;
    --border-secondary: #d3c6a6;
    --border-hour-slot: #d3c6a6;
    --accent-primary: #b58900;
    --accent-primary-hover: #987300;
    --accent-delete: #cb4b16;
    --accent-delete-hover: #a63b0f;
    --accent-recover: #859900;
    --accent-recover-hover: #6c7c00;
    --accent-warning: #d33682;
    
    --shadow-primary: 0 4px 6px -1px rgba(95, 75, 50, 0.15);
    
    --scheduled-task-bg: rgba(181, 137, 0, 0.85);
    --scheduled-task-border: #987300;
    --scheduled-task-text: #fff;
    --overlapping-task-bg: rgba(203, 75, 22, 0.8);
    --drop-target-bg: #fdf6e3;
    --timeline-bg: #fdf6e3;
    
    --button-secondary-bg: #93a1a1;
    --button-secondary-hover-bg: #839496;
    --list-item-bg: #eee8d5;
    --list-item-hover-bg: #e0d6be;
    --list-item-border: #d3c6a6;

    /* Sepia Priorities */
    --priority-critical-bg: #eecbc3;
    --priority-critical-text: #782618;
    --priority-critical-border: #d8a89d;
    --priority-high-bg: #faeac1;
    --priority-high-text: #966b03;
    --priority-high-border: #e9d598;
    --priority-medium-bg: #d2e4e6;
    --priority-medium-text: #215d63;
    --priority-medium-border: #add3d6;
    --priority-low-bg: #d8e6d0;
    --priority-low-text: #3c612f;
    --priority-low-border: #b9d6ab;
    --priority-optional-bg: #eee8d5;
    --priority-optional-text: #657b83;
    --priority-optional-border: #d3c6a6;
}

/* =========================================
   2. GLOBAL RESET & BASE STYLES
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; 
    transition: background-color 0.3s ease, color 0.3s ease;
}

button { cursor: pointer; font-family: inherit; }

/* =========================================
   3. HEADER & CONTROLS
   ========================================= */
.app-header {
    background-color: var(--bg-primary);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-primary);
    box-shadow: var(--shadow-primary);
    z-index: 1000;
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.25rem;
    color: var(--accent-primary);
    font-weight: 700;
}

.controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-options-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Header Inputs */
.controls select, .controls button {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-secondary);
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.controls button:hover, .controls select:hover {
    border-color: var(--accent-primary);
}

.controls button svg { fill: currentColor; height: 1em; vertical-align: -0.125em;}

/* Mobile Toggle (Hidden by default) */
.mobile-controls-toggle {
    display: none;
    background: transparent;
    border: 1px solid transparent;
}

/* =========================================
   4. MAIN DASHBOARD LAYOUT (CSS GRID)
   ========================================= */
#app-content-wrapper {
    flex: 1;
    overflow: hidden;
    padding: 1rem;
    width: 100%;
}

.app-container {
    display: grid;
    /* 3 Columns: 30% Tasks, Flexible Schedule, 280px History */
    grid-template-columns: 1fr 1.5fr 300px;
    gap: 1.25rem;
    height: 100%;
    max-width: 1800px;
    margin: 0 auto;
}

/* Card Containers */
.task-project-container, 
.schedule-container, 
.history-container {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-primary);
    overflow: hidden;
    height: 100%;
    transition: all 0.3s ease;
}

h2 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* =========================================
   5. COLUMN 1: TASKS & PROJECTS
   ========================================= */
.project-selector-area {
    background-color: var(--bg-secondary);
    padding: 0.75rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.project-controls-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.project-controls-row:last-child { margin-bottom: 0; }

.project-filter-wrapper { flex: 1; }
.project-filter-wrapper label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
}
.project-filter-wrapper select {
    width: 100%;
    padding: 6px;
    border-radius: 4px;
    border: 1px solid var(--border-secondary);
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.button-small {
    padding: 4px 8px;
    font-size: 0.75rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-secondary);
    border-radius: 4px;
}

/* Add Task Input */
.add-task { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
#new-task-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}
#add-task-button {
    background-color: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0 1.25rem;
    font-weight: 600;
}
#add-task-button:hover { background-color: var(--accent-primary-hover); }

/* Task List */
#task-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding-right: 4px;
}

#task-list li {
    background-color: var(--list-item-bg);
    border: 1px solid var(--list-item-border);
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    cursor: grab;
    transition: transform 0.1s;
}

#task-list li:hover {
    border-color: var(--accent-primary);
    background-color: var(--list-item-hover-bg);
}

#task-list li input[type="checkbox"] {
    margin-top: 4px;
    cursor: pointer;
    width: 16px; height: 16px;
}

.task-text-content { flex: 1; word-break: break-word; }
.task-actions { display: flex; gap: 4px; }
.task-actions button {
    padding: 2px 6px;
    font-size: 0.7rem;
    border-radius: 4px;
    background: transparent;
    border: 1px solid var(--border-secondary);
}

/* Priority Badges */
.task-priority-badge {
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    margin-right: 5px;
    border-width: 1px;
    border-style: solid;
}
.task-priority-badge.priority-1 { background: var(--priority-critical-bg); color: var(--priority-critical-text); border-color: var(--priority-critical-border); }
.task-priority-badge.priority-2 { background: var(--priority-high-bg); color: var(--priority-high-text); border-color: var(--priority-high-border); }
.task-priority-badge.priority-3 { background: var(--priority-medium-bg); color: var(--priority-medium-text); border-color: var(--priority-medium-border); }
.task-priority-badge.priority-4 { background: var(--priority-low-bg); color: var(--priority-low-text); border-color: var(--priority-low-border); }
.task-priority-badge.priority-5 { background: var(--priority-optional-bg); color: var(--priority-optional-text); border-color: var(--priority-optional-border); }

/* Due Date Badge */
.task-due-date-badge {
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-secondary);
    margin-right: 5px;
}
.task-due-date-badge.overdue {
    color: var(--due-date-overdue-text);
    border-color: var(--due-date-overdue-text);
    font-weight: bold;
}

/* =========================================
   6. COLUMN 2: SCHEDULE
   ========================================= */
#schedule-timeline {
    flex: 1;
    overflow-y: auto;
    position: relative;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    background-color: var(--timeline-bg);
    margin-top: 0.5rem;
    padding-left: 60px; /* Space for time labels */
}

.hour-slot {
    height: 60px;
    border-bottom: 1px dotted var(--border-hour-slot);
    position: relative;
    box-sizing: border-box;
}

.hour-label {
    position: absolute;
    left: -55px;
    top: -8px;
    width: 50px;
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.hour-slot.drop-target { background-color: var(--drop-target-bg); }

.scheduled-task {
    position: absolute;
    left: 4px; right: 4px;
    background-color: var(--scheduled-task-bg);
    border: 1px solid var(--scheduled-task-border);
    color: var(--scheduled-task-text);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8rem;
    overflow: hidden;
    cursor: grab;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

.scheduled-task.overlapping {
    background-color: var(--overlapping-task-bg);
    border-color: var(--overlapping-task-border);
    z-index: 20;
    width: 80%;
}

/* =========================================
   7. COLUMN 3: HISTORY
   ========================================= */
.mobile-history-toggle { display: none; } 

#history-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.history-item {
    background-color: var(--list-item-bg);
    border: 1px solid var(--list-item-border);
    padding: 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}
.history-item.pinned { border-left: 3px solid var(--accent-warning); background-color: var(--bg-primary); }

.history-item-header { display: flex; justify-content: space-between; gap: 8px; }
.history-description { color: var(--text-primary); }
.history-timestamp { display: block; font-size: 0.75em; color: var(--text-muted); margin-top: 4px;}

.history-actions button {
    background: none; border: none; padding: 2px;
    color: var(--text-secondary);
}
.history-actions button:hover { color: var(--text-primary); }

.history-notes-area { display: none; margin-top: 8px; }
.history-notes-area.visible { display: block; }
.history-notes-area textarea {
    width: 100%;
    border: 1px solid var(--border-secondary);
    border-radius: 4px;
    padding: 4px;
    font-size: 0.8em;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* =========================================
   8. MODALS & AUTH
   ========================================= */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.6);
    backdrop-filter: blur(2px);
    overflow-y: auto;
}

.modal-content {
    background-color: var(--bg-modal);
    margin: 5% auto;
    padding: 1.5rem;
    border: 1px solid var(--border-secondary);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: var(--shadow-primary);
    color: var(--text-primary);
}

.close-button {
    position: absolute;
    right: 1.5rem; top: 1rem;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.modal input, .modal select, .modal textarea {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid var(--border-secondary);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 15px; }
.modal-actions button { padding: 8px 16px; border-radius: 4px; border: none; color: white; }
#modal-save-task-button { background-color: var(--accent-primary); }
#modal-delete-task-button { background-color: var(--accent-delete); }
#modal-complete-task-button { background-color: var(--accent-recover); }
.button-secondary { background-color: var(--button-secondary-bg) !important; }

/* Auth Pages */
body.auth-page {
    justify-content: center;
    align-items: center;
    background-color: var(--bg-secondary);
}
.auth-container {
    background-color: var(--bg-primary);
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-primary);
    width: 100%;
    max-width: 400px;
    text-align: center;
}
.auth-container h1 { color: var(--accent-primary); margin-bottom: 1.5rem; }
.auth-form input {
    width: 100%; padding: 12px; margin-bottom: 1rem;
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}
.auth-form button {
    width: 100%; padding: 12px;
    background-color: var(--accent-primary);
    color: white; border: none; border-radius: 6px;
    font-weight: 600; font-size: 1rem;
}
.auth-message { margin-top: 1rem; padding: 0.75rem; border-radius: 6px; font-size: 0.9rem; }
.auth-message.error { background-color: var(--message-error-bg); color: var(--message-error-text); }
.auth-message.success { background-color: var(--message-success-bg); color: var(--message-success-text); }


/* =========================================
   9. MOBILE BOTTOM NAVIGATION & TABS
   ========================================= */

/* Default: Hide bottom nav on desktop */
.mobile-bottom-nav { display: none; }

/* Desktop/Tablet Rules */
@media (min-width: 769px) {
    .mobile-visible { display: flex !important; } /* Ensure everything shows on desktop */
}

/* Tablet Adjustment (Hide History Panel Sidebar) */
@media (max-width: 1024px) {
    .app-container { grid-template-columns: 1fr 1fr; }
    .history-container { display: none; } /* Use toggle button logic for tablet sidebar */
}

/* MOBILE RULES (The Tab System) */
@media (max-width: 768px) {
    
    /* 1. Header Cleanup */
    .app-header { padding: 10px; flex-wrap: wrap; }
    .mobile-controls-toggle { display: inline-flex; }
    #collapsible-header-options { 
        display: none; width: 100%; flex-direction: column; margin-top: 10px; 
    }
    #collapsible-header-options.show { display: flex; }

    /* 2. Reset the Main Grid to a Block */
    .app-container {
        display: block;
        height: auto;
        border: none;
        box-shadow: none;
        background: transparent;
        margin-bottom: 70px; /* Space for bottom nav */
    }

    /* 3. Panel Logic: Hide all by default, Show only active */
    .task-project-container,
    .schedule-container,
    .history-container {
        display: none;
        height: calc(100vh - 140px); /* Fill screen minus header/nav */
        margin-bottom: 0;
    }

    /* This class is added by JS to the active tab */
    .mobile-visible {
        display: flex !important;
        animation: fadeIn 0.2s ease-in-out;
        width: 380px;
    }

    /* 4. Bottom Navigation Styling */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 60px;
        background-color: var(--bg-primary);
        border-top: 1px solid var(--border-primary);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
        z-index: 2000;
        justify-content: space-around;
        align-items: center;
    }

    .nav-item {
        background: none;
        border: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        font-size: 0.75rem;
        padding: 5px;
        flex: 1;
        height: 100%;
    }

    .nav-item svg {
        margin-bottom: 4px;
        fill: var(--text-secondary);
        transition: fill 0.2s;
    }

    .nav-item.active {
        color: var(--accent-primary);
        background-color: var(--bg-tertiary);
    }

    .nav-item.active svg {
        fill: var(--accent-primary);
    }
    
    @keyframes fadeIn {
        from { opacity: 0.9; transform: translateY(5px); }
        to { opacity: 1; transform: translateY(0); }
    }
}

/* SNOOZE MODAL STYLES */
.snooze-options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 15px;
}

.snooze-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-secondary);
    border-radius: 8px;
    color: var(--text-primary);
    transition: all 0.2s;
}

.snooze-btn:hover {
    background-color: var(--bg-secondary);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.snooze-btn .icon { font-size: 1.5rem; margin-bottom: 5px; }
.snooze-btn .label { font-weight: 600; font-size: 0.9rem; }
.snooze-btn .detail { font-size: 0.75rem; color: var(--text-muted); }