:root {
    --primary-color: #4361ee;
    --secondary-color: #3a0ca3;
    --accent-color: #4cc9f0;
    --text-color: #333;
    --text-light: #666;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --header-bg: linear-gradient(135deg, #4361ee, #3a0ca3);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --hover-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
    --temporary-bg: #fff8e1;
    --saved-bg: #e8f5e9;
    --conflict-bg: #ffebee;
    --notification-success: #4caf50;
    --notification-error: #f44336;
    --notification-info: #2196f3;
    --button-hover: #3a0ca3;
    --table-header-bg: #f1f3f9;
    --table-border: #e0e0e0;
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --primary-color: #4cc9f0;
    --secondary-color: #4361ee;
    --accent-color: #7209b7;
    --text-color: #e0e0e0;
    --text-light: #b0b0b0;
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --border-color: #333;
    --header-bg: linear-gradient(135deg, #3a0ca3, #7209b7);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --hover-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    --temporary-bg: #332d00;
    --saved-bg: #1b3a1e;
    --conflict-bg: #3e1a1a;
    --table-header-bg: #252836;
    --table-border: #333;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: var(--transition);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    margin-bottom: 15px;
    padding: 15px;
    background: var(--header-bg);
    color: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

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

.title-section h1 {
    font-size: 1.8rem;
    margin-bottom: 5px;
    font-weight: 700;
}

.title-section p {
    font-size: 0.9rem;
    opacity: 0.9;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.author-credit {
    font-size: 0.8rem;
    opacity: 0.9;
    font-weight: 500;
}

.theme-toggle {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.search-section {
    margin-bottom: 15px;
}

.search-wrapper {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

#search-input {
    flex: 1;
    padding: 10px 15px;
    border: none;
    font-size: 0.9rem;
    background-color: var(--card-bg);
    color: var(--text-color);
}

#search-button {
    padding: 10px 15px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition);
}

#search-button:hover {
    background-color: var(--button-hover);
}

.main-content {
    display: flex;
    gap: 15px;
    flex: 1;
    height: calc(100vh - 150px);
}

.course-list-container {
    flex: 1;
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 15px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    max-height: 100%;
}

.course-list-container h2 {
    margin-bottom: 10px;
    color: var(--primary-color);
    font-size: 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#course-count {
    font-size: 0.8rem;
    background-color: var(--primary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
}

.course-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    overflow-y: auto;
    padding-right: 5px;
    flex: 1;
}

.course-item {
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.course-item h3 {
    margin-bottom: 0;
    color: var(--primary-color);
    font-size: 0.95rem;
}

.course-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--hover-shadow);
    border-color: var(--primary-color);
}

.course-item h3 {
    margin-bottom: 3px;
    color: var(--primary-color);
    font-size: 0.95rem;
}

.course-item p {
    color: var(--text-light);
    font-size: 0.8rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.course-schedule {
    background-color: var(--accent-color);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 3px;
    font-size: 0.75rem;
}

.routine-container {
    flex: 2;
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 15px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    max-height: 100%;
}

.routine-container h2 {
    margin-bottom: 10px;
    color: var(--primary-color);
    font-size: 1.2rem;
}

.routine-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.routine-actions button {
    padding: 6px 12px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 5px;
}

.routine-actions button:hover {
    background-color: var(--button-hover);
}

#clear-routine {
    background-color: var(--notification-error);
}

#clear-routine:hover {
    background-color: #d32f2f;
}

#export-routine {
    background-color: var(--accent-color);
}

#export-routine:hover {
    background-color: #3d99c2;
}

.routine-table-container {
    overflow: auto;
    flex: 1;
}

.routine-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.routine-table th, .routine-table td {
    border: 1px solid var(--table-border);
    padding: 6px;
    text-align: center;
}

.routine-table th {
    background-color: var(--table-header-bg);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

.routine-table th:first-child, .routine-table td:first-child {
    font-weight: 600;
    background-color: var(--table-header-bg);
    position: sticky;
    left: 0;
    z-index: 5;
}

.routine-table th:first-child {
    z-index: 15;
}

.course-cell {
    position: relative;
    padding: 4px 2px;
    border-radius: 3px;
    background-color: #1e40af;
    color: white;
    font-size: 0.75rem;
    text-align: center;
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.course-cell.saved {
    background-color: #1e40af;
    color: white;
    font-weight: 500;
}

.course-cell.saved strong {
    font-size: 0.8rem;
    margin-bottom: 1px;
    display: block;
}

.course-cell.temporary {
    background-color: var(--temporary-bg);
}

.course-cell.conflict {
    background-color: var(--conflict-bg);
    color: white;
}

.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 10px 15px;
    background-color: var(--notification-error);
    color: white;
    border-radius: 4px;
    box-shadow: var(--shadow);
    display: none;
    z-index: 1000;
    font-size: 0.9rem;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
        height: auto;
    }
    
    .course-list-container, .routine-container {
        max-height: 400px;
    }
    
    .course-list {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}

/* Styling for multi-slot courses */
.multi-slot {
    position: relative;
}

.multi-slot .course-cell {
    height: 100%;
}

/* Optimize CSS variables for faster theme switching */
:root, [data-theme="light"] {
    --primary-color: #4361ee;
    --secondary-color: #3a0ca3;
    --accent-color: #4cc9f0;
    --text-color: #333;
    --text-light: #666;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --header-bg: linear-gradient(135deg, #4361ee, #3a0ca3);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --hover-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
    --temporary-bg: #fff8e1;
    --saved-bg: #e8f5e9;
    --conflict-bg: #ffebee;
    --notification-success: #4caf50;
    --notification-error: #f44336;
    --notification-info: #2196f3;
    --button-hover: #3a0ca3;
    --table-header-bg: #f1f3f9;
    --table-border: #e0e0e0;
    --transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

[data-theme="dark"] {
    --primary-color: #4cc9f0;
    --secondary-color: #4361ee;
    --accent-color: #7209b7;
    --text-color: #e0e0e0;
    --text-light: #b0b0b0;
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --border-color: #333;
    --header-bg: linear-gradient(135deg, #3a0ca3, #7209b7);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --hover-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    --temporary-bg: #332d00;
    --saved-bg: #1b3a1e;
    --conflict-bg: #3e1a1a;
    --table-header-bg: #252836;
    --table-border: #333;
}

/* Optimize transitions for better performance */
body {
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: var(--transition);
    will-change: background-color, color;
}

.course-item, .theme-toggle, .search-button, .routine-actions button {
    transition: var(--transition);
    will-change: transform, background-color;
}

/* Add styles for the remove course button */
.remove-course {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 9px;
    color: #f44336;
    opacity: 0.7;
    transition: all 0.2s ease;
}

.remove-course:hover {
    opacity: 1;
    transform: scale(1.1);
    background-color: rgba(255, 255, 255, 1);
}

[data-theme="dark"] .course-cell,
[data-theme="dark"] .course-cell.saved {
    background-color: #4cc9f0;
}