/* ==========================================================================
   1. GLOBAL VARIABLES & RESET
   ========================================================================== */
:root {
    /* "Zinc" Dark Theme Palette */
    --bg-main: #0a0a0a;       /* Near-black background */
    --text-primary: #f5f5f5;  /* High readability white */
    --text-muted: #737373;    /* Neutral gray */
    --border: #262626;        /* Subtle dividers */
    
    /* Brand Accent */
    --accent: #ef4444;        /* Academic Red */
    
    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-sans);
    margin: 0;
    padding: 0;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   2. HOMEPAGE LAYOUT
   ========================================================================== */
.layout-wrapper {
    max-width: 720px; /* Optimal reading width */
    margin: 0 auto;
    width: 100%;
    padding: 80px 20px 40px;
    box-sizing: border-box;
    flex-grow: 1; /* Pushes footer down */
}

/* Header Section */
.header-section {
    text-align: center;
    margin-bottom: 60px;
}

.site-title {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    margin: 0 0 10px 0;
    color: var(--text-primary);
}

.site-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 400;
    margin: 0;
}


/* Search Input */
.search-section {
    margin-bottom: 30px;
}

input#searchBar {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 1.25rem;
    padding: 15px 0;
    border-radius: 0;
    outline: none;
    font-family: var(--font-sans);
    transition: border-color 0.2s ease;
}

input#searchBar:focus {
    border-bottom-color: var(--accent);
}

input#searchBar::placeholder { color: #404040; font-weight: 300; }

.helper-text {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ==========================================================================
   3. FILTERS & CONTROLS
   ========================================================================== */
.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.filter-group {
    position: relative;
    display: block;
}

select#deptFilter {
    /* Reset default browser styles */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;

    /* Dark Theme Styling */
    background-color: #171717; 
    color: var(--text-primary);
    border: 1px solid var(--border);
    
    font-family: inherit;
    font-size: 0.9rem;
    padding: 10px 40px 10px 15px; /* Right padding for arrow */
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    min-width: 160px;
    transition: all 0.2s ease;

    /* Custom SVG Arrow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

select#deptFilter:hover {
    border-color: var(--text-muted);
    background-color: #262626;
}

select#deptFilter:focus { border-color: var(--accent); }

/* Ensure dropdown options are dark */
select#deptFilter option {
    background-color: #171717;
    color: #f5f5f5;
    padding: 10px;
}

/* ==========================================================================
   4. SEARCH RESULTS LIST
   ========================================================================== */
.results-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    transition: background-color 0.1s;
}

.result-row:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.row-left {
    display: flex;
    align-items: baseline;
    gap: 20px;
    overflow: hidden;
}

.c-code {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--text-primary);
    min-width: 90px;
}

.c-name {
    color: var(--text-muted);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s;
}

.result-row:hover .c-name { color: var(--text-primary); }

.row-link {
    font-size: 0.85rem;
    color: var(--accent);
    margin-left: 20px;
    white-space: nowrap;
    font-weight: 500;
}

/* Footer */
.footer-section {
    text-align: center;
    padding: 60px 0 40px;
    margin-top: auto;
}

.submit-btn {
    display: inline-block;
    text-decoration: none;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 10px 20px;
    font-size: 0.85rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.submit-btn:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

/* ==========================================================================
   5. COURSE VIEWER PAGE
   ========================================================================== */
body.viewer-mode {
    height: 100vh;
    overflow: hidden; /* Hide main scrollbar */
}

.viewer-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.viewer-header {
    padding: 15px 25px;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 50;
}

/* Header Left */
.header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.breadcrumb {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    transition: color 0.2s;
}
.breadcrumb:hover { color: var(--accent); }

.course-title-group {
    display: flex;
    align-items: baseline;
    gap: 15px;
}

.v-id {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--text-primary);
}

.v-name { color: var(--text-muted); font-size: 0.95rem; }

/* Header Right (Action Button) */
.header-right {
    display: flex;
    align-items: center;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 8px 16px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.3);
}

/* ==========================================================================
   6. ANALYSIS TABS & UI
   ========================================================================== */
.tabs-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-main);
    padding: 0 25px;
    gap: 25px;
    flex-shrink: 0;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 15px 0;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

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

.tab-btn.active {
    color: var(--text-primary);
    font-weight: 600;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent);
}

.tab-content {
    display: none;
    flex-grow: 1;
    overflow-y: auto; /* Enable scrolling for tab content */
    position: relative;
}

.tab-content.active { display: block; }

/* Analysis Container */
.analysis-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 20px;
    box-sizing: border-box;
}

.section-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 30px 0 10px 0;
    font-weight: 600;
}
.section-label:first-child { margin-top: 0; }

/* Attendance Box */
.attendance-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-left: 3px solid #10b981; /* Default Green (Relaxed) */
    padding: 20px;
    border-radius: 6px;
}

.attendance-box.strict {
    border-left-color: var(--accent); /* Red (Strict) */
    background: rgba(239, 68, 68, 0.05);
}

.att-title {
    display: block;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.att-reason {
    font-size: 0.9rem;
    color: #a3a3a3;
    line-height: 1.5;
}

/* Evaluation Table */
.eval-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.eval-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    padding: 10px 5px;
    font-size: 0.8rem;
}

.eval-table td {
    padding: 15px 5px;
    border-bottom: 1px solid #1a1a1a;
    color: var(--text-primary);
    vertical-align: top;
}

.eval-table tr:last-child td { border-bottom: none; }

.comp-name { font-weight: 500; display: block; margin-bottom: 4px; }
.comp-meta { font-size: 0.8rem; color: var(--text-muted); display: block; }

.nature-tag {
    display: inline-block;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    background: #262626;
    color: #a3a3a3;
    margin-left: 8px;
    vertical-align: middle;
}

/* PDF Viewer Specifics */
#pdf-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #050505;
    padding: 40px 0;
    min-height: 100%;
}

#pdf-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

canvas {
    box-shadow: 0 0 0 1px #1f1f1f;
    margin-bottom: 20px;
    max-width: 90%;
}

/* ==========================================================================
   7. MOBILE OPTIMIZATION (≤768px)
   ========================================================================== */
@media (max-width: 768px) {
    
    /* HOMEPAGE MOBILE */
    .layout-wrapper {
        padding: 50px 20px 40px;
    }

    .site-title { font-size: 2rem; }
    
    /* Stack Filters */
    .controls-row {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .filter-group, select#deptFilter {
        width: 100%;
    }
    
    select#deptFilter {
        font-size: 1rem; /* Prevent zoom */
        padding-top: 12px;
        padding-bottom: 12px;
    }

    /* Stack Results */
    .result-row {
        flex-direction: column;
        align-items: flex-start;
        padding: 20px 0;
        gap: 8px;
    }

    .row-left {
        flex-direction: column;
        gap: 4px;
        width: 100%;
    }

    .c-code { font-size: 1.1rem; }
    .c-name { white-space: normal; line-height: 1.3; }
    
    .row-link {
        margin-left: 0;
        margin-top: 5px;
        padding: 5px 0;
    }

    /* VIEWER MOBILE */
    .viewer-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        padding: 20px;
    }

    .header-right { width: 100%; }
    .action-btn { width: 100%; }

    .course-title-group {
        flex-direction: column;
        gap: 2px;
    }
    .v-id { font-size: 1.5rem; line-height: 1.2; }

    /* Tabs on Mobile */
    .tabs-nav {
        padding: 0 15px;
        justify-content: space-between;
    }
    .tab-btn { flex-grow: 1; text-align: center; }

    /* Analysis View Mobile */
    .analysis-container { padding: 30px 15px; }
    
    /* Convert Table to Stacked Cards */
    .eval-table thead { display: none; }
    
    .eval-table tr {
        display: flex;
        flex-direction: column;
        padding: 15px 0;
        border-bottom: 1px solid var(--border);
    }
    
    .eval-table td {
        padding: 2px 0;
        border: none;
    }
    
    .comp-weight {
        font-family: var(--font-mono);
        color: var(--accent);
        margin-top: 5px;
        font-weight: 600;
    }
    
    .nature-tag { float: right; }

    /* Maximize PDF Width */
    canvas { max-width: 95%; }
}

/* ==========================================================================
   7. SEMESTER SELECTOR STYLES
   ========================================================================== */
.sem-picker-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.sem-segmented-control {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border, #262626);
    border-radius: 20px;
    padding: 3px;
    gap: 2px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.sem-pill {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted, #737373);
    padding: 5px 14px;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    outline: none;
    user-select: none;
}

.sem-pill:hover {
    color: var(--text-primary, #f5f5f5);
    background: rgba(255, 255, 255, 0.08);
}

.sem-pill.active {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.25) 0%, rgba(185, 28, 28, 0.15) 100%);
    color: #ffffff;
    border: 1px solid rgba(239, 68, 68, 0.45);
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.25);
    font-weight: 600;
}

.sem-badge-single {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border, #262626);
    color: var(--text-muted, #a3a3a3);
    padding: 5px 14px;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 16px;
}