/* ==========================================
   VARIABLES & RESET
   ========================================== */
:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --primary-light: #eef2ff;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #9ca3af;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ==========================================
   VIEW MANAGEMENT
   ========================================== */
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

/* ==========================================
   LOGIN
   ========================================== */
#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #eef2ff 0%, #f0f9ff 100%);
}

#login-view.active { display: flex; }

.login-container {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.logo-area {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-area svg {
    color: var(--primary);
    margin-bottom: 0.75rem;
}

.logo-area h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.logo-area p {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.auth-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 0.25rem;
}

.auth-tabs .tab-btn {
    flex: 1;
    padding: 0.6rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-tabs .tab-btn.active {
    background: var(--bg-primary);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.auth-step { display: flex; flex-direction: column; gap: 0.75rem; }

.auth-step label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.auth-step input, .auth-step select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s;
    outline: none;
}

.auth-step input:focus, .auth-step select:focus {
    border-color: var(--primary);
}

.error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    min-height: 1.2em;
}

/* ==========================================
   BUTTONS
   ========================================== */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 0.7rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.18s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

.btn-danger {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #fca5a5;
}

.btn-danger:hover { background: #fecaca; }

.icon-btn {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    font-size: 1.1rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: background 0.15s;
}

.icon-btn:hover { background: var(--bg-tertiary); }

/* ==========================================
   APP HEADER
   ========================================== */
.app-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    padding: 0.875rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-left { display: flex; align-items: center; gap: 0.75rem; }
.header-right { display: flex; align-items: center; gap: 1rem; }

.app-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.header-right span {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ==========================================
   TEACHER DASHBOARD
   ========================================== */
.dashboard-content {
    padding: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 640px) {
    .cards-grid { grid-template-columns: 1fr; }
}

.card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.current-period-card { border-left: 4px solid var(--primary); }
.next-period-card { border-left: 4px solid var(--warning); }

.card-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
}

.card-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.period-details { display: flex; flex-direction: column; gap: 0.7rem; }

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--bg-tertiary);
}

.detail-row:last-child { border-bottom: none; padding-bottom: 0; }

.detail-row .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.detail-row .value {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    text-align: right;
}

.detail-row .value.highlight {
    color: var(--primary);
    font-size: 1.1rem;
}

.time-remaining {
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    margin-top: 0.25rem;
}

/* ==========================================
   BADGES
   ========================================== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.badge.live { background: #fee2e2; color: #dc2626; }
.badge.upcoming { background: var(--warning-light); color: var(--warning); }

/* ==========================================
   SECTION CARDS & TABLES
   ========================================== */
.section-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.section-card h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.table-responsive { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th {
    background: var(--bg-tertiary);
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--bg-tertiary);
    color: var(--text-secondary);
    vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--bg-secondary); }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table .highlight-row {
    background: var(--primary-light) !important;
}

.data-table .highlight-row td { color: var(--primary); font-weight: 500; }

/* Interval Row Styling */
.interval-row { background: var(--warning-light) !important; }
.interval-row td { color: var(--warning); font-weight: 600; }

/* ==========================================
   SIDEBAR
   ========================================== */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    max-width: 90vw;
    height: 100vh;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 300;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 299;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s;
}

.sidebar.open ~ .sidebar-backdrop,
.sidebar-backdrop.open {
    opacity: 1;
    pointer-events: all;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

#staff-search {
    width: 100%;
    padding: 0.65rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}

#staff-search:focus { border-color: var(--primary); }

.staff-list { display: flex; flex-direction: column; gap: 0.5rem; }

.staff-item {
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid var(--border);
    font-size: 0.875rem;
    transition: background 0.15s;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.staff-item:hover { background: var(--primary-light); }

.staff-item small { 
    color: var(--text-muted); 
    display: block; 
    font-size: 0.78rem; 
}

/* ==========================================
   ADMIN DASHBOARD
   ========================================== */
.admin-header { justify-content: space-between; }

.admin-tabs {
    display: flex;
    gap: 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    padding: 0 1rem;
}

.admin-tabs .tab-btn {
    padding: 1rem 1.25rem;
    border: none;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    white-space: nowrap;
    transition: all 0.18s;
}

.admin-tabs .tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.admin-tabs .tab-btn:hover:not(.active) {
    color: var(--text-secondary);
    background: var(--bg-secondary);
}

.admin-content { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }

.admin-tab { display: none; }
.admin-tab.active { display: block; }

.search-bar { margin-bottom: 1.25rem; }

.search-bar input {
    width: 100%;
    padding: 0.8rem 1.1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-family: var(--font);
    background: var(--bg-primary);
    outline: none;
    transition: border-color 0.2s;
}

.search-bar input:focus { border-color: var(--primary); }

.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.action-bar h3 { font-size: 1rem; font-weight: 700; }

/* Period Configuration Controls */
.period-config-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.period-config-controls select {
    padding: 0.65rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    min-width: 200px;
    font-family: var(--font);
    font-size: 0.9rem;
    outline: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.2s;
}

.period-config-controls select:focus {
    border-color: var(--primary);
}

/* ==========================================
   TIMETABLE BUILDER
   ========================================== */
.builder-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.builder-controls select {
    padding: 0.65rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font);
    background: var(--bg-primary);
    outline: none;
    cursor: pointer;
    min-width: 180px;
    transition: border-color 0.2s;
}

.builder-controls select:focus { border-color: var(--primary); }

.hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.assignable-cell {
    cursor: pointer;
    transition: background 0.15s;
    min-width: 110px;
}

.assignable-cell:hover {
    background: var(--primary-light) !important;
    color: var(--primary);
}

/* ==========================================
   MODAL
   ========================================== */
.modal {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0;
    max-width: 440px;
    width: 95vw;
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
}

.modal-content { padding: 2rem; }

.modal-content h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

#modal-context {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

#assign-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

#assign-form label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

#assign-form select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}

#assign-form select:focus { border-color: var(--primary); }

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
    .dashboard-content { padding: 1rem; }
    .admin-content { padding: 1rem; }
    .section-card { padding: 1rem; }
    .card { padding: 1rem; }
    .builder-controls { flex-direction: column; align-items: stretch; }
    .builder-controls select { min-width: unset; width: 100%; }
    .modal-actions { flex-wrap: wrap; }
    .admin-tabs { padding: 0; }
    .admin-tabs .tab-btn { padding: 0.75rem 0.875rem; font-size: 0.8rem; }
    .action-bar { flex-direction: column; align-items: flex-start; }
}

/* ==========================================
   ADMIN ACTION BUTTONS
   ========================================== */
.action-cell { white-space: nowrap; }

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.15s;
    margin-right: 4px;
}

.btn-edit {
    background: var(--primary-light);
    color: var(--primary);
}
.btn-edit:hover { background: #dde3fb; }

.btn-del {
    background: var(--danger-light);
    color: var(--danger);
}
.btn-del:hover { background: #fecaca; }

/* ==========================================
   GENERIC CRUD MODAL
   ========================================== */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.modal-header h3 { margin: 0; }

.modal-sub {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
}

.generic-modal-body {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
}

.generic-modal-body label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.generic-modal-body input,
.generic-modal-body select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
}

.generic-modal-body input:focus,
.generic-modal-body select:focus { border-color: var(--primary); }

/* ==========================================
   BUILDER CELL EMPTY STATE
   ========================================== */
.cell-empty {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ==========================================
   MULTI-SELECT CHECKBOXES (TEACHER SUBJECTS)
   ========================================== */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 150px;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    transition: all 0.15s;
}

.checkbox-label:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

/* ==========================================
   MULTI-CLASS UI POLISH (OPTIONAL)
   ========================================== */

/* 1. Prevents long lists of classes (e.g. "6A, 6B, 6C, 6D") from overflowing the dashboard cards */
.detail-row .value {
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 60%; /* Ensures it doesn't push the label off-screen */
}

/* 2. Makes the injected "Current Assignments" list in the Assign Modal look a bit more integrated */
#existing-assignments-container ul {
    padding-left: 0 !important;
}

#existing-assignments-container li {
    background: var(--bg-primary);
    padding: 6px 8px !important;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 6px !important;
}

/* 3. Ensures the builder grid cells don't get infinitely tall if a PE teacher has 5 classes in one slot */
.assignable-cell div {
    font-size: 0.8rem;
    line-height: 1.2;
}