:root {
    /* Modern Slate Dark Theme */
    --bg-main: #0f172a;         
    --bg-panel: #1e293b;         
    --bg-surface: #334155;
    --border-color: #475569;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --accent-primary: #10b981; /* Emerald */
    --accent-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    
    /* Thematic Area Base Colors */
    --theme-1: #10b981; /* Prevention */
    --theme-2: #3b82f6; /* Preparedness */
    --theme-3: #f59e0b; /* Response */
    --theme-4: #8b5cf6; /* Rehab */
    
    /* Dimensions */
    --left-panel-width: 420px;
    --timeline-spacer-width: 80px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
}

/* Base & Scrollbar */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: system-ui, -apple-system, sans-serif; }
body { background-color: var(--bg-main); color: var(--text-primary); height: 100vh; display: flex; flex-direction: column; overflow: hidden; padding: 24px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: var(--bg-surface); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-color); }

/* --- Header & Toolbar --- */
header { position: relative; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: flex-start;}
.header-titles h1 { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.5px;}
.header-titles h2 { font-size: 1rem; color: var(--text-secondary); font-weight: 500; margin-top: 4px; }

/* Functional Year Selector */
.year-selector { 
    background: var(--bg-surface); 
    color: var(--text-primary); 
    padding: 8px 36px 8px 16px;
    border-radius: var(--radius-full); 
    font-weight: 600; 
    font-size: 0.95rem; 
    border: 1px solid var(--border-color);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    transition: all 0.2s ease;
    outline: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.year-selector:focus, .year-selector:hover { 
    border-color: var(--accent-primary); 
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15); 
}
.year-selector option { 
    background: var(--bg-panel); 
    color: var(--text-primary); 
    font-weight: 500;
}

.toolbar { display: flex; align-items: center; gap: 16px; padding-bottom: 24px; }

.search-container { display: flex; align-items: center; background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: var(--radius-full); padding: 8px 16px; width: 450px; transition: border-color 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.1);}
.search-container:focus-within { border-color: var(--accent-primary); }
.search-icon { color: var(--text-muted); font-size: 1.1rem; margin-right: 12px; }
.search-input { background: transparent; border: none; color: var(--text-primary); outline: none; flex: 1; font-size: 0.95rem;}
.search-input::placeholder { color: var(--text-muted); }

.filter-dropdown { background: transparent; border: none; border-left: 1px solid var(--border-color); padding-left: 12px; color: var(--text-primary); outline: none; font-size: 0.9rem; cursor: pointer; margin-left: 12px;}
.filter-dropdown option { background: var(--bg-panel); color: var(--text-primary); }

.add-btn { background: var(--accent-primary); border: none; color: white; padding: 10px 20px; border-radius: var(--radius-full); font-weight: 600; cursor: pointer; font-size: 0.95rem; display: flex; align-items: center; gap: 8px; transition: all 0.2s; box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);}
.add-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.time-display { color: var(--text-secondary); font-size: 0.95rem; font-weight: 500; margin-left: auto; background: var(--bg-panel); padding: 8px 16px; border-radius: var(--radius-full); border: 1px solid var(--border-color);}

/* --- Workspace Layout --- */
.workspace-container { display: flex; flex-direction: column; flex: 1; overflow: hidden; background: var(--bg-panel); border-radius: var(--radius-lg); border: 1px solid var(--border-color); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);}

/* Headers */
.workspace-headers { display: flex; height: 48px; flex-shrink: 0; border-bottom: 1px solid var(--border-color); background: rgba(30, 41, 59, 0.95); backdrop-filter: blur(4px); z-index: 10;}
.header-left { width: var(--left-panel-width); color: var(--text-secondary); font-weight: 600; font-size: 0.8rem; padding: 0 20px; text-transform: uppercase; border-right: 1px solid var(--border-color); flex-shrink: 0; display: flex; align-items: center; letter-spacing: 0.5px;}
.header-right { flex: 1; display: flex; color: var(--text-secondary); font-weight: 600; font-size: 0.8rem;}
.timeline-label { width: var(--timeline-spacer-width); display: flex; align-items: center; justify-content: center; flex-shrink: 0; border-right: 1px solid var(--border-color);}
.months-row { flex: 1; display: grid; grid-template-columns: repeat(12, 1fr); text-align: center; }
.month-name { display: flex; align-items: center; justify-content: center; position: relative; z-index: 2; border-right: 1px solid transparent;}
.month-name.active { color: var(--accent-primary); font-weight: 700; background: rgba(16, 185, 129, 0.1); border-bottom: 2px solid var(--accent-primary);}

/* Scrollable Body */
.workspace-body { display: flex; flex: 1; overflow-y: auto; overflow-x: hidden; position: relative;}

/* Left Panel */
.left-panel { width: var(--left-panel-width); background-color: var(--bg-panel); flex-shrink: 0; border-right: 1px solid var(--border-color); padding-bottom: 50px;}

.thematic-header { padding: 12px 20px; color: white; font-weight: 600; display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; letter-spacing: 0.5px; text-transform: uppercase; position: sticky; top: 0; z-index: 5;}
.thematic-header span:last-child { cursor: pointer; font-size: 1.1rem; opacity: 0.8; transition: opacity 0.2s;} 
.thematic-header span:last-child:hover { opacity: 1; }

.theme-1 { background-color: var(--theme-1); }
.theme-2 { background-color: var(--theme-2); }
.theme-3 { background-color: var(--theme-3); }
.theme-4 { background-color: var(--theme-4); }

/* Project Display Styling */
.project-item { padding: 16px 20px; border-bottom: 1px solid var(--border-color); transition: background 0.2s;}
.project-item:hover { background: rgba(255,255,255,0.02); }
.project-title-row { display: flex; gap: 12px; font-weight: 600; font-size: 0.95rem; cursor: pointer; line-height: 1.4; color: var(--text-primary); align-items: flex-start;}
.add-icon { font-size: 1.2rem; color: var(--text-muted); cursor: pointer; transition: color 0.2s; margin-top: -2px;}
.add-icon:hover { color: var(--accent-primary); }

.proj-title-text { flex: 1; display: flex; justify-content: space-between; align-items: center; }
.proj-arrow { font-size: 0.8rem; color: var(--text-muted); transition: transform 0.3s ease; }
.expanded .proj-arrow { transform: rotate(180deg); }

/* Project Extra Details Box */
.project-extra-details { display: none; background: var(--bg-surface); padding: 12px 16px; border-radius: var(--radius-md); margin: 12px 0 12px 24px; font-size: 0.85rem; color: var(--text-secondary); position: relative; border: 1px solid var(--border-color);}
.expanded .project-extra-details { display: block; }
.project-extra-details strong { color: var(--text-primary); font-weight: 600;}
.minimize-details-btn { position: absolute; top: 8px; right: 8px; cursor: pointer; color: var(--text-muted); font-size: 0.8rem; padding: 4px; border-radius: 4px; transition: all 0.2s ease;}
.minimize-details-btn:hover { background: var(--border-color); color: var(--text-primary); }

/* Specific Item Display Styling */
.specific-item { margin-left: 24px; font-size: 0.9rem; margin-top: 12px; display: flex; gap: 8px; align-items: flex-start; }
.toggle-icon { font-size: 0.7rem; margin-top: 5px; cursor: pointer; color: var(--text-muted); transition: transform 0.3s ease; user-select: none; }
.item-expanded .toggle-icon { transform: rotate(180deg); }

.item-details { flex: 1; line-height: 1.5; color: var(--text-secondary);}
.lbl-spec { color: var(--theme-2); font-weight: 600; }
.lbl-qty { color: var(--theme-1); font-weight: 600; }

/* Hidden Item Extra Details */
.item-extra-details { display: none; background: rgba(15, 23, 42, 0.5); border: 1px solid var(--border-color); padding: 12px; border-radius: var(--radius-md); margin-top: 8px; font-size: 0.8rem; color: var(--text-secondary); border-left: 3px solid var(--theme-2); position: relative;}
.item-expanded .item-extra-details { display: block; }
.item-extra-details strong { color: var(--text-primary); }
.minimize-item-btn { position: absolute; top: 8px; right: 8px; cursor: pointer; color: var(--text-muted); font-size: 0.8rem; padding: 4px; border-radius: 4px; transition: all 0.2s ease;}
.minimize-item-btn:hover { background: var(--border-color); color: var(--text-primary); }

/* Right Panel */
.right-panel { flex: 1; display: flex; position: relative; min-height: 100%;}
.timeline-spacer { width: var(--timeline-spacer-width); flex-shrink: 0; border-right: 1px solid var(--border-color); }

.grid-columns { flex: 1; display: grid; grid-template-columns: repeat(12, 1fr); position: relative;}
.grid-col { border-right: 1px dashed rgba(255,255,255,0.05); height: 100%; box-sizing: border-box;}
.grid-col.active-bg { background-color: rgba(16, 185, 129, 0.03); border-left: 1px solid rgba(16, 185, 129, 0.2); border-right: 1px solid rgba(16, 185, 129, 0.2);}

.timeline-content { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none;}

/* Thematic Status Colors for Gantt Bars and Badges */
.gantt-bar { position: absolute; height: 28px; border-radius: 6px; color: white; font-size: 0.75rem; font-weight: 600; display: flex; justify-content: center; align-items: center; pointer-events: auto; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.2); transform: translateY(-50%); letter-spacing: 0.5px; transition: filter 0.2s;}
.gantt-bar:hover { filter: brightness(1.1); }

/* Theme 1: Prevention (Emerald) */
.bg-theme-1-ongoing { background: linear-gradient(90deg, #059669, #10b981); border: 1px solid #047857;}
.bg-theme-1-upcoming { background: linear-gradient(90deg, rgba(16,185,129,0.1), rgba(16,185,129,0.25)); border: 1px dashed #10b981; color: #34d399; }
.bg-theme-1-done { background: linear-gradient(90deg, #022c22, #064e3b); color: #6ee7b7; text-decoration: line-through; opacity: 0.8; border: 1px solid #064e3b;}

/* Theme 2: Preparedness (Blue) */
.bg-theme-2-ongoing { background: linear-gradient(90deg, #2563eb, #3b82f6); border: 1px solid #1d4ed8;}
.bg-theme-2-upcoming { background: linear-gradient(90deg, rgba(59,130,246,0.1), rgba(59,130,246,0.25)); border: 1px dashed #3b82f6; color: #60a5fa; }
.bg-theme-2-done { background: linear-gradient(90deg, #172554, #1e3a8a); color: #93c5fd; text-decoration: line-through; opacity: 0.8; border: 1px solid #1e3a8a;}

/* Theme 3: Response (Amber) */
.bg-theme-3-ongoing { background: linear-gradient(90deg, #d97706, #f59e0b); border: 1px solid #b45309;}
.bg-theme-3-upcoming { background: linear-gradient(90deg, rgba(245,158,11,0.1), rgba(245,158,11,0.25)); border: 1px dashed #f59e0b; color: #fbbf24; }
.bg-theme-3-done { background: linear-gradient(90deg, #451a03, #78350f); color: #fcd34d; text-decoration: line-through; opacity: 0.8; border: 1px solid #78350f;}

/* Theme 4: Rehab (Purple) */
.bg-theme-4-ongoing { background: linear-gradient(90deg, #7c3aed, #8b5cf6); border: 1px solid #6d28d9;}
.bg-theme-4-upcoming { background: linear-gradient(90deg, rgba(139,92,246,0.1), rgba(139,92,246,0.25)); border: 1px dashed #8b5cf6; color: #a78bfa; }
.bg-theme-4-done { background: linear-gradient(90deg, #2e1065, #4c1d95); color: #c4b5fd; text-decoration: line-through; opacity: 0.8; border: 1px solid #4c1d95;}

/* --- MODERN MODALS --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.7); backdrop-filter: blur(8px); display: none; justify-content: center; align-items: center; transition: all 0.3s ease;}

#crudModal { z-index: 1000; }
#formA { z-index: 1050; }
#formB { z-index: 1050; }
#linkModal { z-index: 1060; } 

.cal-modal { 
    background: var(--bg-panel); 
    width: 500px; 
    border-radius: var(--radius-lg); 
    padding: 32px; 
    position: relative; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); 
    border: 1px solid var(--border-color);
}

.close-modal { 
    position: absolute; top: 20px; right: 20px; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; background: transparent; border: none; transition: all 0.2s ease; width: 32px; height: 32px; border-radius: var(--radius-full); display: flex; align-items: center; justify-content: center;
}
.close-modal:hover { background: var(--bg-surface); color: var(--text-primary); }

.cal-modal h3 { font-size: 1.4rem; margin-bottom: 24px; font-weight: 600; color: var(--text-primary); border-bottom: 1px solid var(--border-color); padding-bottom: 16px;}

.cal-pill { display: none; margin: 0 auto 24px; text-align: center; padding: 6px 20px; border-radius: var(--radius-full); font-size: 0.8rem; font-weight: 600; color: white; width: fit-content; text-transform: uppercase; letter-spacing: 0.5px;}

.cal-form-group { margin-bottom: 20px; border-radius: var(--radius-md); transition: all 0.3s ease;}
.cal-label { display: block; font-size: 0.8rem; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 8px; font-weight: 600;}

.cal-input { width: 100%; background: var(--bg-main); border: 1px solid var(--border-color); color: var(--text-primary); font-size: 0.95rem; outline: none; padding: 12px 16px; border-radius: var(--radius-md); transition: all 0.2s ease;}
.cal-input::placeholder { color: var(--text-muted); }
.cal-input:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15); }

textarea.cal-input { resize: vertical; min-height: 80px;}

.cal-btn { width: 100%; padding: 14px; border-radius: var(--radius-md); border: none; background-color: var(--bg-surface); color: white; font-weight: 600; font-size: 1rem; cursor: pointer; margin-top: 10px; transition: all 0.2s ease; text-transform: uppercase; letter-spacing: 1px;}
.cal-btn:hover { filter: brightness(1.1); }

div:has(> select.cal-input), div:has(> input[type="month"].cal-input) { display: flex; flex-direction: column;}

/* --- MODERN CRUD LARGE TABLE MODAL --- */
.modal.large { width: 95%; max-width: 1400px; height: 90vh; display: flex; flex-direction: column; background: var(--bg-panel); border-radius: var(--radius-lg); padding: 0; overflow: hidden; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); border: 1px solid var(--border-color);}

.modal-header-dynamic { padding: 20px 32px; color: white; display: flex; justify-content: space-between; align-items: center; transition: background-color 0.3s ease;}
.modal-header-dynamic h2 { margin: 0; font-size: 1.25rem; font-weight: 600; letter-spacing: 0.5px;}

.close-modal-large { background: rgba(0,0,0,0.2); border: none; color: white; width: 36px; height: 36px; border-radius: var(--radius-full); display: flex; justify-content: center; align-items: center; cursor: pointer; font-size: 1.2rem; transition: background 0.2s;}
.close-modal-large:hover { background: rgba(0,0,0,0.4); }

.modal-body-large { padding: 24px 32px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; background: var(--bg-main); }

.crud-table-container { background: var(--bg-panel); border-radius: var(--radius-lg); border: 1px solid var(--border-color); overflow: hidden; flex: 1; display: flex; flex-direction: column;}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 16px 24px; text-align: left; border-bottom: 1px solid var(--border-color);}
th { background: var(--bg-surface); font-weight: 600; color: var(--text-secondary); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.5px; position: sticky; top: 0; z-index: 5;}

.project-row { background-color: rgba(51, 65, 85, 0.4); border-top: 2px solid var(--border-color); }

tbody tr { transition: background-color 0.2s ease;}
tbody tr:hover { background-color: rgba(255,255,255,0.02); }

.action-btn { border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; margin-right: 6px; font-weight: 500; transition: all 0.2s; display: inline-flex; align-items: center; gap: 6px; color: white; background: var(--bg-surface);}
.action-btn:hover { filter: brightness(1.2); }

.action-btn.delete { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2);}
.action-btn.delete:hover { background: var(--danger); color: white;}

.file-link { color: var(--theme-2); text-decoration: none; font-size: 0.85rem; margin-right: 12px; display: inline-flex; align-items: center; gap: 4px; font-weight: 500; padding: 4px 8px; background: rgba(59, 130, 246, 0.1); border-radius: 4px;}
.file-link:hover { background: rgba(59, 130, 246, 0.2); }

.status-badge { display: inline-block; padding: 4px 10px; border-radius: var(--radius-full); font-size: 0.7rem; font-weight: 700; color: white; letter-spacing: 0.5px; margin-bottom: 6px;}