/* CSS Variables */
:root {
    --bg-primary: #0f0f13;
    --bg-secondary: #16161d;
    --bg-card: #1c1c26;
    --bg-hover: #252532;
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;
    --accent: #6366f1;
    --accent-dark: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --border: #2a2a3a;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Typography */
h1,
h2,
h3 {
    font-weight: 600;
    line-height: 1.3;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--text-primary);
}

/* Header */
.header {
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border);
    padding: 2rem 1.5rem;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
}

.header h1 {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.back-link {
    display: inline-block;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.back-link:hover {
    color: var(--accent);
}

/* Course Meta Badges */
.course-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-type {
    background: var(--accent);
    color: white;
}

.badge-code {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.badge-ects {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.badge-lang {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

/* Container Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.5rem;
}

/* Filters Sidebar */
.filters {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    height: fit-content;
    position: sticky;
    top: 1.5rem;
    border: 1px solid var(--border);
}

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

.filter-header h2 {
    font-size: 1.1rem;
}

.btn-reset {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-reset:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}

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

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

.filter-group input,
.filter-group select {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: all var(--transition);
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-group input::placeholder {
    color: var(--text-muted);
}

.filter-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23a0a0b0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

.ects-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ects-inputs input {
    flex: 1;
    text-align: center;
}

.ects-inputs span {
    color: var(--text-muted);
}

/* Results Section */
.results {
    min-width: 0;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 1rem 1.25rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.results-count {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.results-count span {
    font-weight: 600;
    color: var(--accent);
}

.results-per-page {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.results-per-page label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.results-per-page select {
    padding: 0.4rem 2rem 0.4rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23a0a0b0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

/* Table */
.table-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    min-height: 400px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

tbody {
    transition: opacity 0.15s ease;
}

tbody.loading {
    opacity: 0.5;
}

thead {
    background: var(--bg-secondary);
}

th {
    padding: 1rem 1.25rem;
    text-align: left;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color var(--transition);
}

th.sortable:hover {
    color: var(--accent);
}

th.sortable::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 0.5rem;
    vertical-align: middle;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid transparent;
    opacity: 0.3;
}

th.sortable.asc::after {
    border-top: 4px solid var(--accent);
    opacity: 1;
}

th.sortable.desc::after {
    border-top: none;
    border-bottom: 4px solid var(--accent);
    opacity: 1;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
    cursor: pointer;
}

tbody tr:last-child {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--bg-hover);
}

td {
    padding: 1rem 1.25rem;
    font-size: 0.9rem;
    vertical-align: top;
}

td:first-child {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 0.85rem;
    color: var(--accent);
}

.course-name {
    font-weight: 500;
    max-width: 350px;
}

.course-type-cell {
    color: var(--text-secondary);
}

.instructor-cell {
    color: var(--text-secondary);
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.schedule-cell {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.ects-cell {
    font-weight: 600;
    color: var(--success);
}

/* Loading */
.loading-row td {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 0.75rem;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Empty State */
.empty-row td {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.pagination button {
    padding: 0.6rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
    min-width: 40px;
}

.pagination button:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}

.pagination button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-ellipsis {
    color: var(--text-muted);
    padding: 0 0.5rem;
}

/* Detail Page */
.detail-container {
    display: block;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.detail-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--border);
}

.detail-card.full-width {
    grid-column: 1 / -1;
}

.detail-card h2 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.detail-list {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 0.75rem;
}

.detail-list dt {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.detail-list dd {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.description-text {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

.btn-primary {
    display: inline-block;
    margin-top: 1.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all var(--transition);
}

.btn-primary:hover {
    background: var(--accent-dark);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

/* Footer */
.footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

/* Mobile Responsive */
@media (max-width: 900px) {
    .container {
        grid-template-columns: 1fr;
    }

    .filters {
        position: static;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 1rem;
    }

    .filter-header {
        grid-column: 1 / -1;
    }

    .filter-group {
        margin-bottom: 0;
    }

    th,
    td {
        padding: 0.75rem;
    }

    .course-name {
        max-width: 200px;
    }
}

@media (max-width: 600px) {
    .header {
        padding: 1.5rem 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .container {
        padding: 1rem;
    }

    .filters {
        grid-template-columns: 1fr;
    }

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

    table {
        min-width: 700px;
    }

    .detail-list {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .detail-list dt {
        margin-top: 0.5rem;
    }
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}