/* --- Root & Layout --- */
:root {
    --primary-blue: #2196f3;
    --student-bg: #e3f2fd;
    --teacher-bg: #fff3e0;
    --border-color: #ddd;
}

body { 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    margin: 0; 
    background: #f4f7f6; 
}

.container { 
    width: 100%; 
    max-width: 1600px; 
    margin: 0 auto; 
    padding: 20px; 
    box-sizing: border-box; 
}

.app-layout { 
    display: flex; 
    gap: 25px; 
    align-items: flex-start; 
}

/* --- Sidebar Toolbox --- */
.sidebar { 
    width: 180px; 
    flex-shrink: 0; 
    position: sticky; 
    top: 20px; 
}

.toolbox { 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
}

.draggable-subject {
    padding: 12px; 
    background: white; 
    border: 1px solid var(--border-color);
    border-radius: 6px; 
    cursor: grab; 
    text-align: center; 
    font-weight: bold;
    transition: transform 0.2s, box-shadow 0.2s;
}

.draggable-subject:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 4px 8px rgba(0,0,0,0.1); 
}

/* --- Main Content Area & Scroll Fixes --- */
.main-content {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 100px);
    min-width: 0;
}

.scrollable-grid-area {
    flex: 1;
    overflow: auto; 
    background: white;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

/* FIX: This prevents the horizontal scrollbar during accordion toggle */
.table-container { 
    width: 100%; 
    max-width: 100%;
    overflow-x: hidden; 
    background: white; 
    border-radius: 8px; 
    padding-right: 2px;
}

details {
    width: 100%;
    overflow: hidden;
    margin-bottom: 15px;
}

/* --- Calendar Grid --- */
.calendar-grid {
    display: inline-grid;
    background: #fff;
    border: 1px solid var(--border-color);
}

.grid-header-row, .grid-time-row {
    display: grid;
}

.grid-cell {
    border-bottom: 1px solid #eee;
    border-right: 1px solid #eee;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 0.85em;
    padding: 4px;
    text-align: center;
    box-sizing: border-box;
    /* ENSURE THIS IS VISIBLE */
    overflow: visible !important; 
    /* Base z-index */
    z-index: 1; 
}

.grid-header-row {
    position: sticky;
    top: 0;
    z-index: 150; /* Above everything */
    background: white;
    border-bottom: 2px solid var(--border-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.grid-cell.popup-active {
    z-index: 200 !important; 
}

.grid-cell.student-header, 
.grid-cell.teacher-header {
white-space: normal !important; /* Overrides the default no-wrap */
    line-height: 1.2;              /* Tighter line height for stacked names */
    display: flex;
    align-items: center;           /* Vertically center */
    justify-content: center;       /* Horizontally center */
    text-align: center;
    padding: 5px;
    height: auto;                  /* Allow cell to grow */
    min-height: 40px;              /* Minimum height for single-line names */
}

.student-header, .teacher-header {
    white-space: nowrap;      /* Prevents name from dropping to 2nd line */
    overflow: hidden;         /* Hide spillover */
    text-overflow: ellipsis;  /* Adds ... if name is extremely long */
    padding: 12px 10px;
    font-weight: bold;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    cursor: pointer;
    transition: background 0.2;
    position: relative; /* Essential for popup positioning */
}

.student-header { background-color: var(--student-bg); }
.teacher-header { background-color: var(--teacher-bg); }

.student-header:hover {
    background-color: #bbdefb !important; /* Slightly darker blue on hover */
}

/* Copy Popup Container */
.copy-popup {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 200px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 5000; /* High enough to clear headers and time column */
    padding: 15px;
    text-align: left;
    color: #333;
    font-weight: normal;
}

.copy-popup h4 { margin: 0 0 10px 0; font-size: 0.9em; color: var(--primary-blue); }
.copy-popup p { font-size: 0.75em; margin-bottom: 10px; color: #666; }

.target-days-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin-bottom: 12px;
}
.target-days-grid label { font-size: 0.75em; display: flex; align-items: center; gap: 4px; cursor: pointer; }

.copy-popup .support-toggle {
    display: block;
    font-size: 0.75em;
    font-weight: bold;
    border-top: 1px solid #eee;
    padding-top: 8px;
    margin-bottom: 10px;
}

.btn-confirm-copy {
    width: 100%;
    background: #673ab7;
    color: white;
    border: none;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
    font-weight: bold;
}
.btn-confirm-copy:hover { background: #5e35b1; }

.time-col {
    position: sticky;
    left: 0;
    z-index: 100; /* Higher than header to stay in the corner */
    background: #fafafa !important;
    font-weight: bold;
    border-right: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Cell Content & Popups --- */
.cell-content { 
    width: 100%; 
    height: 100%; 
    display: flex; 
    align-items: center; /* Centers items vertically */
    justify-content: center; /* Centers items horizontally */
    position: relative; 
    padding-left: 20px; /* Make room for the indicator on the left */
}

.delete-btn {
    position: absolute; 
    top: -2px; 
    right: 2px; 
    color: red; 
    cursor: pointer;
    font-size: 14px; 
    font-weight: bold; 
    opacity: 0; 
    transition: opacity 0.2s;
    z-index: 101; /* Above hitboxes */
}

.grid-cell:hover .delete-btn { opacity: 1; }

/* The scrollable area for teacher names */
.support-list {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.support-option:hover {
    background-color: #e3f2fd !important;
    color: var(--primary-blue);
}

.grid-cell:hover,
.selected-cell { 
    outline: 1px solid var(--primary-blue); 
    z-index: 9999 !important; 
}

.teacher-assign-popup {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-75%);
    width: 220px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2); /* Increased shadow for depth */
    
    /* THE FIX: Set this higher than the time-col (160) and selected-cell (50) */
    z-index: 9999 !important; 
    
    padding: 0;
    overflow: hidden;
    text-align: left;
}

/* SMART ALIGNMENT: Right-hand side fix */
.teacher-assign-popup.align-right {
    left: auto;
    right: 0;
    transform: none; /* Removes the -50% shift */
}

/* SMART ALIGNMENT: Left-hand side fix (optional) */
.teacher-assign-popup.align-left {
    left: 0;
    transform: none;
}

.teacher-assign-popup .header {
    background: #f8f9fa;
    padding: 10px 15px;
    font-size: 0.85em;
    font-weight: bold;
    color: #666;
    border-bottom: 1px solid #eee;
}

.support-option {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid #f9f9f9;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    font-size: 0.9em;
    color: #333;
}

/* --- Interaction States & Stretching --- */
.drag-over { background: #e8f5e9 !important; outline: 2px dashed #4caf50; }
.stretching { background: #fff59d !important; opacity: 0.7; }

.selected-cell { 
    outline: 3px solid var(--primary-blue); 
    z-index: 40 !important;
}

/* Create physical hitboxes for stretching on top and bottom of selected cell */
.grid-cell.selected-cell:not(:empty)::before,
.grid-cell.selected-cell:not(:empty)::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 15px; 
    z-index: 90; /* Lower than delete-btn (101) and support-indicator (10) */
    cursor: ns-resize;
}

.grid-cell.selected-cell::before { top: 0; }
.grid-cell.selected-cell::after { bottom: 0; }

.resizing-active {
    cursor: ns-resize;
    user-select: none;
}

/* --- Support Circle Icon --- */
.support-indicator {
    position: absolute;
    left: 5px; /* Move to the left side */
    top: 50%; /* Start at 50% from top */
    transform: translateY(-50%); /* Offset by half its height to perfectly center */    
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--primary-blue);
    background: transparent;
    cursor: pointer;
    z-index: 11;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
}

/* Show on hover, or keep visible if assigned */
.grid-cell:hover .support-indicator,
.support-assigned .support-indicator {
    opacity: 1;
}

.support-assigned .support-indicator {
    background-color: var(--primary-blue) !important;
    opacity: 1 !important;
}
/* Tooltip for the icon */
.support-indicator:hover::after {
    content: "Assign Support";
    position: absolute;
    
    /* POSITIONING: Move it slightly to the right of the circle */
    top: 50%;
    left: 20px; 
    transform: translateY(-50%);
    
    background: #333;
    color: #fff;
    padding: 4px 8px;
    font-size: 10px;
    border-radius: 4px;
    white-space: nowrap;
    
    /* THE FIX: Higher z-index to clear the sticky time column (160) */
    z-index: 3000; 
    
    /* Ensure it doesn't capture mouse events */
    pointer-events: none; 
}

/* --- The Checkbox Circles --- */
.support-circle {
    width: 14px;
    height: 14px;
    border: 2px solid var(--primary-blue);
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
    transition: all 0.2s ease;
    position: relative;
}

.support-circle.filled {
    background-color: var(--primary-blue);
    box-shadow: inset 0 0 0 2px white; /* Creates a clean donut look */
}

/* --- Activity Colors --- */
.Math { background-color: #ffcdd2; }
.Reading { background-color: #e1bee7; }
.Class { background-color: #c8e6c9; }
.Lunch { background-color: #fff9c4; }
.PE { background-color: #b3e5fc; }
.Art { background-color: #ffe0b2; }
.Music { background-color: #d1c4e9; }
.Library { background-color: #cfd8dc; }
.Guidance { background-color: #dcedc8; }

/* --- Weekly Summary Cards --- */
.stats-grid {
    display: flex;      /* Switching to flex is often more reliable for 'bouncing' */
    flex-wrap: wrap;    /* This makes cards drop to the next line */
    gap: 15px;
    padding: 10px 0;
    align-items: center;
    justify-content: center;
}

.summary-card { 
    flex: 0 1 auto;      /* Card only takes up as much space as it needs */
    min-width: 320px;    /* Prevents the card from becoming too skinny */
    background: white; 
    border: 1px solid var(--border-color); 
    border-radius: 8px; 
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

.summary-row { 
    display: grid; 
    /* 1fr for Subject allows it to be flexible, 
       then 45px for data columns ensures they are perfectly aligned. */
    grid-template-columns: 1fr 45px 45px 45px 75px; 
    gap: 10px; 
    padding: 8px 0; 
    border-bottom: 1px solid #f0f0f0; 
    align-items: center;
}

/* Ensure numbers and headers are perfectly aligned */
.summary-row > div:not(.c-subject) {
    text-align: center; /* Center values under their headers */
    font-variant-numeric: tabular-nums; /* Makes numbers take up equal width */
}

.summary-header { 
    font-weight: bold; 
    border-bottom: 2px solid #eee; 
    color: #666; 
    font-size: 0.75rem; /* Slightly smaller headers to save space */
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-header .c-subject {
    font-weight: 800;
}

.card-header {
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 2px solid #eee;
    font-size: 1.15rem;   /* Increased size */
    text-align: center;
}

.c-subject {
    text-align: left; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: bold;
}

.goal-met { color: #28a745; font-weight: bold; }
.goal-missing { color: #dc3545; font-weight: bold; font-size: 0.85em; }
/* --- Custom Input Row (Bottom of Popup) --- */
.custom-input-row {
    display: flex;
    padding: 10px;
    gap: 5px;
    background: #fff;
    border-top: 1px solid #eee;
}

.custom-input-row input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.85em;
    outline: none;
}

.custom-input-row input:focus {
    border-color: var(--primary-blue);
}

.custom-input-row button {
    background: var(--primary-blue);
    color: white;
    border: none;
    padding: 0 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.custom-input-row button:hover {
    background: #1976d2;
}

/* --- Accessibility/UX --- */
.support-list::-webkit-scrollbar {
    width: 6px;
}

.support-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
}

            /* Sticky Carousel Strip */
            .day-carousel {
                position: sticky;
                top: 0;
                z-index: 1000;
                background: #f4f7f6;
                padding: 10px;
                display: flex;
                gap: 8px;
                border-bottom: 2px solid #ddd;
                margin-bottom: 10px;
                flex-shrink: 0;
                /* ADD THIS: ensures the bar stays the full width of the scrollable area */
                width: 100%;
                min-width: max-content; 
            }

            .day-tab {
                flex: 1;
                padding: 12px;
                border: 1px solid #ccc;
                border-radius: 6px;
                background: white;
                cursor: pointer;
                font-weight: bold;
                font-size: 0.9rem;
                transition: all 0.2s ease;
                text-transform: uppercase;
                color: #555;
            }

            .day-tab:hover { background: #eef; }

            .day-tab.active {
                background: #2196f3;
                color: white;
                border-color: #1976d2;
                box-shadow: 0 2px 8px rgba(33, 150, 243, 0.4);
            }



            .day-pane {
                display: none; /* Hide all days initially */
            }

            .day-pane.active {
                display: block; /* Only show active day */
            }

            #summary-accordion {
                margin-top: 20px;
                flex-shrink: 0;
            }

            .summary-pane {
                display: none; /* Hidden by default like the day panes */
                padding: 0px 10px 10px 10px;
                background: #f9f9f9;
            }
            
            .summary-pane.active {
                display: block; /* Shown when the 'Weekly Summary' tab is clicked */
            }

            .day-pane.summary-pane {
                display: none; 
                width: 100%;       /* Match the container width */
                min-width: 100%;   /* Don't shrink */
                box-sizing: border-box;
                background: #fafafa;
            }

            .summary-pane-content {
                width: 100%;
                max-width: 100%;   /* Prevents it from following the grid's massive width */
                padding: 0px 10px 10px 10px;
                box-sizing: border-box;
            }

            .day-pane.summary-pane.active {
                display: block !important;
            }

            .clickable-req {
                cursor: pointer;
                background: #f0f7ff; /* Light blue tint to imply interactivity */
                border-radius: 4px;
                transition: background 0.2s;
                font-weight: bold;
                text-decoration: underline dotted #ccc;
            }
            
            .clickable-req:hover {
                background: #e3f2fd;
                color: var(--primary-blue);
                text-decoration: underline solid var(--primary-blue);
            }
            
            /* Ensure inputs inside the row don't break the layout */
            .summary-row input {
                font-family: inherit;
                font-size: inherit;
                outline: none;
            }

            /* Enhanced Toast Notification */
#toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #333; /* Default */
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    font-weight: bold;
    display: none;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
    z-index: 10001; /* Above popups */
    transition: all 0.3s ease;
    min-width: 250px;
}

#toast.success { background-color: #4caf50; border-left: 6px solid #2e7d32; }
#toast.error { background-color: #f44336; border-left: 6px solid #c62828; }

@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
    100% { transform: translateX(0); }
  }
  
  #toast.error {
      animation: shake 0.4s ease-in-out;
  }