/* =================================================================== */
/* ==================== VARIABLES & GLOBAL RESET ===================== */
/* =================================================================== */
:root {
    --font-family: 'Poppins', sans-serif;
    --radius: 16px;

    /* Light Theme - Teal & Rose Palette (Refined for lighter feel) */
    --primary-color: #0d9488; /* Teal for primary actions */
    --primary-light: #f0fdfa; /* Very light teal for backgrounds */
    --primary-border: #ccfbf1;
    --danger-color: #f43f5e;   /* Rose for destructive actions */
    --bg-color: #f8fafc;       /* Lighter background */
    --surface-color: #ffffff;
    --text-color: #0f172a;     /* Deep slate for high contrast text */
    --text-muted: #64748b;
    --border-color: #e2e8f0;   /* Softer border color */
    --shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 8px 16px -4px rgba(15, 23, 42, 0.1);
    
    /* Accent Colors for semantic meaning */
    --subject-accent: #059669; /* Success/Go */
    --lab-accent: #0ea5e9;     /* Informational */
    --activity-accent: #f97316;/* Attention */
}

[data-theme="dark"] {
    /* Dark Theme - Teal & Rose Palette */
    --primary-color: #2dd4bf;
    --primary-light: rgba(15, 23, 42, 0.8);
    --primary-border: #1e293b;
    --danger-color: #fb7185;
    --bg-color: #020617; 
    --surface-color: #0f172a;
    --text-color: #e2e8f0;
    --text-muted: #94a3b8;
    --border-color: #1e293b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    height: 100vh;
    overflow: hidden;
}
.material-symbols-outlined { font-size: inherit; vertical-align: -0.15em; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* =================================================================== */
/* ============================= LAYOUT ============================== */
/* =================================================================== */
.app-container {
    display: grid;
    grid-template-columns: 500px minmax(0, 1fr);
    gap: 2.5rem;
    padding: 2.5rem;
    height: 100%;
}
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    overflow-y: auto; 
    padding: 0 1rem 1rem 0;
}
.control-panel::-webkit-scrollbar { width: 6px; }
.control-panel::-webkit-scrollbar-track { background: transparent; }
.control-panel::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* =================================================================== */
/* ====================== HEADER & THEME TOGGLE ====================== */
/* =================================================================== */
.app-header { display: flex; justify-content: space-between; align-items: flex-start; }
.app-title h1 { font-size: 2rem; font-weight: 700; color: var(--primary-color); letter-spacing: -1px; }
.app-title span { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.header-controls { display: flex; align-items: center; gap: 1rem; }

.icon-btn {
    padding: 0.6rem; line-height: 1; border-radius: var(--radius);
    background: var(--surface-color); border: 1px solid var(--border-color);
    color: var(--text-muted); box-shadow: var(--shadow);
    transition: all 0.2s ease-out;
    cursor: pointer;
}
.icon-btn:hover { background-color: var(--bg-color); color: var(--text-color); transform: translateY(-1px); }

.icon-btn.danger-btn { color: white; }
.icon-btn.danger-btn:hover { color: white; background-color: var(--danger-color); opacity: 0.85; }


[data-theme="dark"] .icon-btn { border: 1px solid var(--border-color); }
.moon-icon { display: none; }
[data-theme="dark"] .moon-icon { display: inline-block; }
[data-theme="dark"] .sun-icon { display: none; }

/* =================================================================== */
/* ======================= GENERAL COMPONENTS ======================== */
/* =================================================================== */
button {
    font-family: var(--font-family); padding: 0.75rem 1.25rem;
    border: none; border-radius: var(--radius); cursor: pointer;
    background-color: var(--primary-color); color: white;
    font-weight: 600; font-size: 0.95rem;
    transition: all 0.2s ease-out; box-shadow: var(--shadow);
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
}
button:hover { opacity: 0.9; transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.danger-btn { background-color: var(--danger-color); }
button.secondary-btn {
    background-color: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}
button.secondary-btn:hover { background-color: var(--bg-color); }


input, select {
    font-family: var(--font-family); width: 100%; padding: 0.75rem;
    border: 1px solid var(--border-color); border-radius: var(--radius);
    background: var(--surface-color); color: var(--text-color); font-size: 0.95rem;
    transition: all 0.2s ease-out;
}
input:focus, select:focus {
    outline: none; border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-border);
}

h2 {
    font-size: 1.2rem; font-weight: 600;
    padding-bottom: 0.75rem; border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem; display: flex; align-items: center; gap: 0.75rem;
}

.config-section {
    padding: 2rem; border-radius: var(--radius);
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}
.add-form { display: flex; gap: 1rem; }

hr.config-divider {
    border: none;
    height: 1px;
    background-color: var(--border-color);
    margin: 2rem 0 1rem 0;
}

/* =================================================================== */
/* ===================== FACULTY & SUBJECT MGMT ====================== */
/* =================================================================== */
#faculty-list-container { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1.5rem; }
.faculty-card {
    padding: 1.25rem; border-radius: var(--radius);
    background-color: var(--surface-color); border: 1px solid var(--border-color);
    position: relative; box-shadow: var(--shadow);
    display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center;
    transition: box-shadow 0.2s ease-out;
}
.faculty-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.07); }
.faculty-header h4 { 
    font-size: 1.1rem; font-weight: 600; color: var(--text-color); margin: 0;
}
.faculty-card .subjects-list { grid-column: 1 / -1; }
.subject-tag {
    display: inline-flex; align-items: center; gap: 0.5rem;
    background: var(--bg-color); border: 1px solid var(--border-color);
    border-radius: 999px; padding: 0.3rem 0.8rem;
    margin: 0.5rem 0.5rem 0 0; font-size: 0.85rem;
}
.subject-tag .remove-subject-btn { cursor: pointer; }
.add-subject-form { display: grid; grid-template-columns: 1fr auto auto; gap: 0.5rem; margin-top: 1rem; }

.availability-grid {
    display: grid;
    grid-template-columns: 35px repeat(8, 1fr); 
    gap: 0.5rem; margin-top: 1rem; text-align: center; align-items: center;
}
.availability-grid .header { font-weight: 600; font-size: 0.8rem; }
.availability-grid input[type="checkbox"] {
    width: 1.2rem; height: 1.2rem; margin: 0 auto;
    cursor: pointer; accent-color: var(--primary-color);
}

/* =================================================================== */
/* ===================== SECTION & COURSE ASSIGNMENT ================= */
/* =================================================================== */
#section-tags-container { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.5rem; }
.section-tag {
    background: var(--primary-color); color: white; padding: 0.4rem 1rem;
    border-radius: 999px; display: flex; align-items: center; gap: 0.5rem; font-weight: 500;
}
.remove-tag { cursor: pointer; font-weight: bold; font-size: 1.2rem; }

.in-charge-selector {
    margin-bottom: 1.5rem; display: flex; align-items: center; gap: 1rem;
    padding: 1rem; background-color: var(--primary-light);
    border: 1px solid var(--primary-border); border-radius: var(--radius);
}
[data-theme="dark"] .in-charge-selector { border-color: var(--border-color); }
.in-charge-selector label { font-weight: 600; color: var(--primary-color); flex-shrink: 0; }
.in-charge-selector select { flex-grow: 1; }

.course-assignment-card {
    padding: 1rem 1rem 1rem 1.25rem; margin-bottom: 1rem; border-left: 5px solid; position: relative;
    border-radius: var(--radius); border: 1px solid var(--border-color);
    display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 1rem;
    background-color: var(--surface-color);
}
.assignment-details strong { font-size: 1.05rem; font-weight: 600; display: block; }
.assignment-details span { font-size: 0.9rem; color: var(--text-muted); }

.assignment-fields-container { display: flex; gap: 1rem; }
.assignment-field { display: flex; flex-direction: column; }
.assignment-field label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.assignment-field input { max-width: 100px; padding: 0.5rem; }

.course-assignment-card.subject { border-left-color: var(--subject-accent); }
.course-assignment-card.lab { border-left-color: var(--lab-accent); }
.course-assignment-card.activity { border-left-color: var(--activity-accent); }

.card-delete-btn {
    position: absolute; top: -10px; right: -10px;
    width: 28px; height: 28px; padding: 0; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; z-index: 10;
    background-color: var(--danger-color);
    color: white;
    border: 2px solid var(--surface-color);
    box-shadow: var(--shadow);
    font-size: 1.2rem;
    transition: transform 0.2s ease;
}
.card-delete-btn:hover {
    transform: scale(1.1);
}

.preference-row {
    display: grid;
    grid-template-columns: 100px 1fr 1fr;
    gap: 1rem;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}
.preference-row:last-child { border-bottom: none; }
.preference-row span { font-weight: 500; font-size: 0.9rem; }


/* =================================================================== */
/* ======================= OUTPUT PANEL & TABS ======================= */
/* =================================================================== */
.output-panel {
    background-color: var(--surface-color); border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg); border-radius: var(--radius);
    display: flex; flex-direction: column; overflow: hidden;
}

#timetables-container { padding: 2rem; overflow: auto; flex-grow: 1; }

.placeholder-card { text-align: center; color: var(--text-muted); padding: 5rem 2rem; }
.placeholder-icon { font-size: 4rem; margin-bottom: 1rem; color: var(--primary-color); opacity: 0.5; }

.placeholder-card h2 {
    display: block;
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 1rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
}

.tab-buttons {
    display: flex; border-bottom: 1px solid var(--border-color);
    margin: -2rem -2rem 2rem -2rem; padding: 0 2rem; flex-shrink: 0;
}
.tab-button {
    background: none; border: none; padding: 1rem 1.25rem; font-weight: 600;
    font-size: 0.95rem; color: var(--text-muted); border-bottom: 3px solid transparent;
    transform: translateY(1px); box-shadow: none; position: relative;
}
.tab-button:hover { color: var(--text-color); }
.tab-button.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
.tab-button.incomplete::after {
    content: ''; position: absolute; top: 1rem; right: 0.5rem; width: 8px;
    height: 8px; background-color: var(--activity-accent); border-radius: 50%;
    border: 1px solid var(--surface-color);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.timetable-header {
    padding-bottom: 1rem; margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color); display: flex;
    justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 1rem;
}
.timetable-header h3 { font-size: 1.75rem; font-weight: 700; color: var(--primary-color); }
.timetable-header .actions { display: flex; gap: 0.5rem; flex-shrink: 0; align-self: flex-start; }
.timetable-header .actions button { box-shadow: none; border: 1px solid var(--border-color); }

.timetable-table-container { overflow-x: auto; border: 1px solid var(--border-color); border-radius: var(--radius); }
.timetable-table { border-collapse: collapse; }
.timetable-table th, .timetable-table td {
    padding: 0.75rem; min-width: 120px; text-align: center;
    border: 1px solid var(--border-color); white-space: normal; vertical-align: middle;
}
.timetable-table thead th { background-color: var(--bg-color); font-weight: 600; }
.timetable-table .time-slot { display: block; font-size: 0.8em; color: var(--text-muted); }
.timetable-table .day-header {
    text-align: left; font-weight: 600; background-color: var(--surface-color);
    position: sticky; left: 0; z-index: 1; width: 100px; min-width: 100px;
}
[data-theme="dark"] .timetable-table .day-header { background-color: var(--surface-color); }
.timetable-table .lunch-break { background-color: var(--bg-color); color: var(--text-muted); }

.split-lab-cell .course-item:not(:last-child) {
    border-bottom: 1px dashed var(--border-color); padding-bottom: 0.75rem; margin-bottom: 0.75rem;
}

.unassigned-list {
    background-color: rgba(244, 63, 94, 0.05); border: 1px solid rgba(244, 63, 94, 0.2);
    border-radius: var(--radius); padding: 1.5rem; margin-top: 2rem;
}
.unassigned-list h4 { color: var(--danger-color); margin-bottom: 1rem; font-size: 1.1rem; }
.unassigned-list ul { list-style-type: none; padding-left: 0; }
.unassigned-list li { padding: 0.75rem 0; border-bottom: 1px solid var(--border-color); }
.unassigned-list li:last-child { border-bottom: none; }
[data-theme="dark"] .unassigned-list { background-color: rgba(251, 113, 133, 0.05); border: 1px solid rgba(251, 113, 133, 0.2); }

.faculty-table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: 0.9rem; }
.faculty-table th, .faculty-table td { border: 1px solid var(--border-color); padding: 0.75rem; text-align: left; }
.faculty-table th { background-color: var(--bg-color); font-weight: 600; }

/* =================================================================== */
/* ============================== MODAL ============================== */
/* =================================================================== */
.modal {
    position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(15, 23, 42, 0.5);
    display: flex; justify-content: center; align-items: center;
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal.show { opacity: 1; visibility: visible; }
.modal-content {
    padding: 2rem; border-radius: var(--radius); width: 90%; max-width: 500px; position: relative;
    background-color: var(--surface-color); box-shadow: var(--shadow-lg); max-height: 90vh;
    overflow-y: auto; transform: scale(0.95); transition: transform 0.3s ease;
}
.modal.show .modal-content { transform: scale(1); }
.modal-content.large { max-width: 800px; }
.modal-close {
    position: absolute; top: 0.75rem; right: 0.75rem; cursor: pointer; color: var(--text-muted);
    background: none; border: none; padding: 0.5rem; line-height: 1;
}
.modal-close:hover { color: var(--text-color); }
.modal-content h2 { margin-top: 0; }

/* =================================================================== */
/* ========================== RESPONSIVENESS ========================= */
/* =================================================================== */
@media (max-width: 1200px) {
    body { height: auto; overflow-y: auto; }
    .app-container { grid-template-columns: 1fr; padding: 1.5rem; gap: 2rem; height: auto; }
    .control-panel { max-height: none; overflow-y: visible; }
    .output-panel { max-height: 80vh; }
    .add-form { flex-direction: column; }
    .add-subject-form { display: flex; gap: 0.75rem; flex-direction: column; }
    .course-assignment-card { grid-template-columns: 1fr; }
    .assignment-field input { max-width: none; }
    .assignment-fields-container { justify-content: space-around; }
}