:root {
    /* Light Theme Variables */
    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --edit-mode-color: #ef4444;
    --slot-bg: #f1f5f9;
    --slot-hover-border: #cbd5e1;
    --header-bg: #f8fafc;
    --font-family: 'Inter', sans-serif;

    /* Grid Configuration */
    /* 8:00 to 17:00 = 9 hours. 4 quarters per hour = 36 rows */
    --grid-rows: 36;
    --row-height: 20px;
    /* 15 mins = 20px height */
    --hour-height: calc(var(--row-height) * 4);
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 2rem;
    padding-bottom: 2rem;
}

.app-container {
    width: 95%;
    max-width: 1200px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

/* Buttons */
.btn {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.btn:hover {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
}

.btn.edit-active {
    background-color: #fef2f2;
    border-color: #fca5a5;
    color: var(--edit-mode-color);
    animation: pulse-light 2s infinite;
}

@keyframes pulse-light {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.2);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.btn-primary {
    background-color: var(--accent-color);
    border: none;
    color: white;
}

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

.btn-danger {
    background-color: #fff;
    border: 1px solid #fca5a5;
    color: #ef4444;
}

.btn-danger:hover {
    background-color: #fef2f2;
}

/* Timetable Layout Wrapper */
.timetable-wrapper {
    display: flex;
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background-color: var(--surface-color);
    overflow-x: auto;
}

/* Y-Axis (Time) */
.time-axis {
    width: 60px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background-color: var(--header-bg);
    margin-top: 50px;
    /* Offset for headers */
}

.time-label {
    height: var(--hour-height);
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding-right: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    transform: translateY(-8px);
    /* center text on the line */
}

/* Main Grid */
.timetable {
    display: flex;
    flex-grow: 1;
    min-width: 600px;
}

.day-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    position: relative;
}

.day-column:last-child {
    border-right: none;
}

.day-header {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    z-index: 10;
}

.day-grid {
    position: relative;
    height: calc(var(--grid-rows) * var(--row-height));
    background-size: 100% calc(var(--hour-height) / 4);
    /* Quarter hour lines */
    background-image: linear-gradient(to bottom, transparent 19px, var(--border-color) 20px);
}

.day-grid::before {
    /* Full hour stronger lines overlay */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background-size: 100% var(--hour-height);
    background-image: linear-gradient(to bottom, transparent calc(var(--hour-height) - 1px), #cbd5e1 var(--hour-height));
}

/* Event Slots in Grid */
.slot {
    position: absolute;
    left: 4px;
    right: 4px;
    border-radius: 6px;
    padding: 0.5rem;
    overflow: hidden;
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    border-left: 4px solid var(--text-primary);
    /* overriden by JS inline style */
    z-index: 5;
    background-color: white;
    /* Base bg, color applied via JS as tint */
    box-sizing: border-box;
}

.slot:hover {
    z-index: 6;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.slot-inner {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.time-range {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 2px;
}

.subject {
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.details {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Edit Mode Interactive Grid Elements */
.grid-cell-interactive {
    position: absolute;
    left: 0;
    right: 0;
    height: var(--row-height);
    z-index: 2;
    cursor: pointer;
    opacity: 0;
    background-color: rgba(59, 130, 246, 0.1);
}

body.edit-mode .grid-cell-interactive:hover {
    opacity: 1;
}

body.edit-mode .slot {
    cursor: pointer;
    outline: 2px dashed transparent;
}

body.edit-mode .slot:hover {
    outline-color: var(--accent-color);
    transform: scale(0.98);
}


/* Modal Tooltip */
.tooltip {
    position: fixed;
    background: #1e293b;
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    transform: translate(-50%, -100%);
    margin-top: -10px;
}

.tooltip.show {
    opacity: 1;
    visibility: visible;
}

.tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    margin-left: -6px;
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: #1e293b transparent transparent transparent;
}

/* Modal Form styling */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    width: 90%;
    max-width: 450px;
    position: relative;
    transform: translateY(-20px);
    transition: transform 0.3s ease;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal.show .modal-content {
    transform: translateY(0);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    color: var(--text-secondary);
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 1.25rem;
}

.row {
    display: flex;
    gap: 1rem;
}

.col {
    flex: 1;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    background-color: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.modal-actions .btn {
    flex: 1;
    padding: 0.75rem;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .app-container {
        width: 100%;
        border-radius: 0;
        border-left: none;
        border-right: none;
        padding: 1rem;
    }

    .modal-content {
        width: 95%;
        padding: 1.5rem;
    }

    .row {
        flex-direction: column;
        gap: 0;
    }

    .timetable-wrapper {
        border: none;
        background: transparent;
        display: block;
        border-radius: 0;
    }

    .timetable {
        display: flex;
        flex-direction: column;
        min-width: 100%;
        gap: 1.5rem;
    }

    .mobile-day-container {
        background-color: var(--surface-color);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    }

    .mobile-day-header {
        background-color: var(--header-bg);
        padding: 1rem;
        font-weight: 700;
        font-size: 1.1rem;
        border-bottom: 1px solid var(--border-color);
        color: var(--text-primary);
    }

    .mobile-events {
        display: flex;
        flex-direction: column;
        padding: 1rem;
        gap: 0.75rem;
    }

    .mobile-slot {
        background-color: white;
        border-left: 4px solid var(--accent-color);
        border-radius: 8px;
        padding: 1rem;
        display: grid;
        grid-template-columns: 80px 1fr;
        align-items: center;
        gap: 1rem;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }

    .mobile-slot-edit {
        cursor: pointer;
        border: 2px dashed transparent;
        transition: border-color 0.2s, background-color 0.2s;
    }

    .mobile-slot-edit:hover {
        border-color: var(--accent-color);
        background-color: rgba(59, 130, 246, 0.05) !important;
    }

    .mobile-time {
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--text-secondary);
        white-space: pre-wrap;
    }

    .mobile-subject-info {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

    .mobile-add-btn {
        padding: 1rem;
        border: 2px dashed #94a3b8;
        border-radius: 8px;
        text-align: center;
        color: #64748b;
        font-weight: 600;
        cursor: pointer;
        background-color: #f8fafc;
        transition: all 0.2s;
    }

    .mobile-add-btn:hover {
        border-color: var(--accent-color);
        color: var(--accent-color);
        background-color: #eff6ff;
    }

    .mobile-empty {
        padding: 1rem;
        text-align: center;
        color: #94a3b8;
        font-size: 0.9rem;
        font-style: italic;
    }
}