/* --- Global Variables & Base --- */
:root {
    --bg-main: #0a0a0a;
    --text-primary: #f5f5f5;
    --text-muted: #737373;
    --border: #262626;
    --accent: #ef4444; /* Academic Red */
    
    --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Courier New', Courier, monospace;
}

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

/* --- Layout Container --- */
.layout-wrapper {
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
    padding: 80px 20px 40px;
    box-sizing: border-box;
    flex-grow: 1;
}

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

.site-title {
    font-size: 2.9rem;
    font-weight: 800;
    letter-spacing: -0.05em;
    margin: 0 0 10px 0;
}

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

/* --- 2. Search Section --- */
.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;
}

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

input#searchBar::placeholder { color: #404040; }

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

/* --- 3. Filters & Metadata (Mobile Fix) --- */
.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    font-size: 0.85rem;
    color: var(--text-muted);
    width: 100%; /* Ensure container fills space */
}

/* Wrapper ensures the custom arrow stays positioned correctly */
.filter-group {
    position: relative;
    display: block;
}

select#deptFilter {
    /* RESET: Remove default browser glossy styles */
    appearance: none;
    -webkit-appearance: none; /* Safari/iOS */
    -moz-appearance: none;    /* Firefox */
    
    /* THEME: Dark mode styling */
    background-color: #171717; 
    color: var(--text-primary);
    border: 1px solid var(--border);
    
    font-family: inherit;
    font-size: 0.9rem;
    padding: 12px 40px 12px 16px; /* Right padding makes room for arrow */
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    
    /* ICON: 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;
    
    /* FIX: Ensure it has a width */
    min-width: 180px;
}

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

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

/* DARK MODE MENU ITEMS */
select#deptFilter option {
    background-color: #171717;
    color: #f5f5f5;
}

/* --- MOBILE SPECIFIC FIXES --- */
@media (max-width: 768px) {
    .controls-row {
        flex-direction: column;
        align-items: stretch; /* Forces children to take full width */
        gap: 15px;
    }

    .filter-group {
        width: 100%; /* Force wrapper to full width */
    }

    select#deptFilter {
        width: 100%;       /* Force dropdown to full width */
        font-size: 1rem;   /* Prevents iOS zoom on tap */
        padding-top: 14px; /* Taller tap target */
        padding-bottom: 14px;
        background-position: right 20px center; /* Move arrow slightly inward */
    }
    
    /* Ensure the stats text aligns left on mobile */
    #indexStats {
        padding-left: 2px;
    }
}

/* --- 4. 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;
}

/* --- 5. 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);
}

/* --- VIEWER STYLES --- */
body.viewer-mode {
    height: 100vh;
    overflow: hidden;
}

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

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

.header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.breadcrumb {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 5px;
}

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

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

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

.header-right {
    text-align: right;
    display: flex;
    align-items: center;
}

.meta-block {
    display: inline-block;
    margin-left: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.meta-label { display: block; font-size: 0.7rem; text-transform: uppercase; margin-bottom: 2px; }
.meta-value { color: var(--text-primary); }

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    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;
    margin-right: 20px;
    transition: all 0.2s ease;
}

/* --- PDF Area --- */
#pdf-container {
    flex-grow: 1;
    background-color: #050505;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 40px 0;
}

#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%;
}


/* ==========================================================================
   📱 MOBILE OPTIMIZATION (≤768px)
   Strictly enforces vertical hierarchy and thumb-friendly sizing.
   ========================================================================== */
@media (max-width: 768px) {

    /* --- Typography & Spacing --- */
    .layout-wrapper {
        padding: 60px 20px 40px; /* Reduced side padding */
    }

    .site-title {
        font-size: 3rem; /* Scaled down */
        margin-bottom: 8px;
    }

    .site-desc {
        font-size: 0.85rem;
        line-height: 1.4;
        max-width: 280px; /* Force readable wrapping */
        margin: 0 auto;
    }

    /* --- Search & Inputs --- */
    .search-section {
        margin-top: 40px; /* Separate from header */
        margin-bottom: 20px;
    }

    input#searchBar {
        font-size: 1.1rem; /* Readable, no zoom */
        padding: 12px 0;   /* Taller target */
    }

    .helper-text {
        font-size: 0.8rem;
        opacity: 0.9; /* Higher contrast */
    }

    /* --- Stacked Controls --- */
    .controls-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 30px;
        padding-top: 10px;
    }
    
    select#deptFilter {
        font-size: 0.9rem;
        padding: 8px 0;
    }

    /* --- Thumb-Friendly 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; } /* Larger hit target */
    .c-name { 
        font-size: 0.95rem; 
        white-space: normal; /* Allow wrap */
        line-height: 1.3;
    }

    .row-link {
        margin-left: 0;
        margin-top: 8px;
        font-size: 0.85rem;
        opacity: 0.9;
        padding: 4px 0; /* Easier to tap */
    }

    /* --- Footer Action --- */
    .footer-section {
        padding: 40px 0;
    }
    .submit-btn {
        width: 100%;       /* Full width tap area */
        box-sizing: border-box;
        text-align: center;
        padding: 15px;     /* Comfortable height */
    }

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

    .header-left { width: 100%; }

    .course-title-group {
        flex-direction: column;
        gap: 2px;
        margin-top: 5px;
    }

    .v-id { font-size: 1.75rem; line-height: 1.1; }
    .v-name { font-size: 1rem; line-height: 1.3; }

    /* Stacked Metadata */
    .header-right {
        width: 100%;
        text-align: left;
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        border-top: 1px solid var(--border);
        padding-top: 15px;
    }

    /* Secondary Action Button */
    .action-btn {
        width: 100%;
        margin-right: 0;
        justify-content: center;
        padding: 10px;
        /* Less aggressive style on mobile */
        background: transparent;
        border: 1px solid var(--border);
        color: var(--text-muted);
    }
    .action-btn:hover {
        border-color: var(--accent);
        color: var(--accent);
    }

    .meta-block {
        margin-left: 0;
        margin-right: 20px;
        margin-bottom: 5px;
    }

    /* PDF Display */
    #pdf-container {
        padding: 20px 0; /* Less vertical padding */
    }

    canvas {
        max-width: 92%; /* Margins, not edge-to-edge */
        box-shadow: none; /* Flatter look */
        border: 1px solid var(--border);
    }
}