/* =========================================
   1. VARIABLES & THEME ENGINE
   ========================================= */
:root {
    /* DEFAULT (LIGHT) THEME */
    --primary: #2563eb;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --card-hover: #eff6ff;
    --modal-overlay: rgba(0, 0, 0, 0.5);
    --focus-ring: rgba(37, 99, 235, 0.5);
}

/* DARK MODE OVERRIDES */
body.dark-mode {
    --primary: #3b82f6;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-light: #94a3b8;
    --border: #334155;
    --card-hover: #1e293b; 
    --modal-overlay: rgba(0, 0, 0, 0.8);
    --focus-ring: rgba(59, 130, 246, 0.6);
}

/* =========================================
   2. GLOBAL RESET & BASE STYLES
   ========================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; 
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* =========================================
   3. APP HEADER (Navigation)
   ========================================= */
.app-bar {
    background: var(--primary);
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
}

.logo {
    font-weight: bold;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* =========================================
   4. VIEW TRANSITIONS (Router)
   ========================================= */
#app {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    overflow-y: auto;
    background: var(--bg);
    transition: transform 0.3s ease-in-out;
}

.view.hidden { transform: translateX(100%); pointer-events: none; }
.view.active { transform: translateX(0); }

/* =========================================
   5. SEARCH & FILTERS
   ========================================= */
.search-container {
    padding: 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0; 
    z-index: 5;
    transition: background-color 0.3s;
}

/* Wrapper to put icon inside input */
.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    font-size: 1.2rem;
    color: var(--text-light);
    pointer-events: none;
}

#search-input {
    width: 100%;
    padding: 0.8rem;
    padding-left: 40px; /* Space for icon */
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}

/* Horizontal Scroll for Chips */
.filter-scroll {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.8rem;
    overflow-x: auto;
    padding-bottom: 0.2rem;
    scrollbar-width: none;
}
.filter-scroll::-webkit-scrollbar { display: none; }

.filter-chip {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* =========================================
   6. RESOURCE GRID & LAYOUTS
   ========================================= */
.resource-grid {
    padding: 1rem;
    display: grid;
    gap: 1rem;
    padding-bottom: 100px; /* Space for bottom content */
}

/* LAYOUT 1: LIST VIEW (Compact) */
.resource-grid.view-list { grid-template-columns: 1fr; }
.resource-grid.view-list .card { flex-direction: row; padding: 0.8rem; }
.resource-grid.view-list .card-icon { width: 40px; height: 40px; font-size: 1.5rem; }
.resource-grid.view-list .card-info { text-align: left; }
.resource-grid.view-list .action-btn { margin-left: auto; }

/* LAYOUT 2: GRID VIEW (Big Covers) */
.resource-grid.view-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.resource-grid.view-grid .card { flex-direction: column; text-align: center; padding: 1.5rem 1rem; }
.resource-grid.view-grid .card-icon { width: 80px; height: 80px; font-size: 3rem; margin-bottom: 0.5rem; }
.resource-grid.view-grid .action-btn { position: absolute; top: 8px; right: 8px; }

/* LAYOUT 3: HYBRID VIEW (Default) */
.resource-grid.view-hybrid { grid-template-columns: 1fr; }
.resource-grid.view-hybrid .card { flex-direction: row; align-items: flex-start; }
.resource-grid.view-hybrid .card-icon { width: 70px; height: 90px; font-size: 2.5rem; flex-shrink: 0; }
.resource-grid.view-hybrid .action-btn { margin-left: auto; align-self: center; }

/* =========================================
   7. CARD COMPONENT
   ========================================= */
.card {
    background: var(--surface);
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: transform 0.1s, background-color 0.3s, border-color 0.3s;
    position: relative; /* For absolute positioning inside */
}

.card:active { transform: scale(0.98); }

/* Hover Effect: "Pop" the icon */
.card:hover .card-icon {
    border-color: var(--primary);
    background-color: var(--bg);
}
.card:hover .card-icon i {
    transform: scale(1.15);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* FOCUS RINGS (Accessibility / TV Remote) */
.card:focus, 
.filter-chip:focus, 
#search-input:focus, 
.icon-btn:focus,
.primary-btn:focus,
.pin-input:focus {
    outline: 4px solid var(--primary);
    outline-offset: 2px;
    z-index: 2;
}

.card-icon {
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.card-info h3 { font-size: 1rem; margin-bottom: 0.2rem; line-height: 1.4; color: var(--text); }
.card-info p { font-size: 0.85rem; color: var(--text-light); }

/* Share Button on Card */
.action-btn {
    background: transparent;
    border: none;
    color: var(--text-light);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.action-btn:hover {
    color: var(--primary);
    background: var(--card-hover);
}

/* =========================================
   8. ICONS & ANIMATIONS
   ========================================= */
/* Icon Colors */
.icon-red { color: #ef4444; }
.icon-blue { color: #3b82f6; }
.icon-purple { color: #a855f7; }
.icon-green { color: #22c55e; }
.icon-default { color: var(--text-light); }

/* Animation: Spin (Settings Gear) */
#settings-btn:hover i { animation: spin 2s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Animation: Bob (Download Arrow) */
#download-btn:hover i { animation: bob 1s ease-in-out infinite; }
@keyframes bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(3px); }
}

/* Animation: Pulse (Audio Player) */
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; filter: drop-shadow(0 0 0 rgba(168, 85, 247, 0)); }
    50% { transform: scale(1.05); opacity: 0.8; filter: drop-shadow(0 0 10px rgba(168, 85, 247, 0.5)); }
    100% { transform: scale(1); opacity: 1; filter: drop-shadow(0 0 0 rgba(168, 85, 247, 0)); }
}

/* =========================================
   9. MODALS (Settings & Share)
   ========================================= */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--modal-overlay);
    display: flex;
    align-items: flex-end; /* Mobile: Bottom Sheet */
    z-index: 100;
    transition: opacity 0.2s, visibility 0.2s;
    backdrop-filter: blur(2px);
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-content {
    background: var(--surface);
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 1.5rem;
    animation: slideUp 0.3s ease-out;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}

/* Desktop Modal */
@media (min-width: 600px) {
    .modal { align-items: center; justify-content: center; }
    .modal-content { 
        width: 400px; 
        border-radius: 12px; 
        animation: popIn 0.2s ease-out; 
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.modal-header h3 { font-size: 1.2rem; }

.setting-group { margin-bottom: 1.5rem; }
.setting-group label { display: block; margin-bottom: 0.5rem; font-weight: 500; font-size: 0.9rem; color: var(--text-light); }

.modal-footer {
    text-align: center;
    color: var(--text-light);
    font-size: 0.8rem;
    margin-top: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

/* Segment Control (Toggle Switch) */
.segment-control {
    display: flex;
    background: var(--bg);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.segment-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 8px;
    color: var(--text-light);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.segment-btn.active {
    background: var(--surface);
    color: var(--primary);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* =========================================
   10. P2P SHARING STYLES
   ========================================= */
.pin-display {
    font-size: 3rem;
    font-weight: bold;
    letter-spacing: 5px;
    margin: 1rem 0;
    color: var(--primary);
    background: var(--bg);
    padding: 1rem;
    border-radius: 12px;
    border: 2px dashed var(--border);
}

.pin-input {
    font-size: 2rem;
    letter-spacing: 5px;
    text-align: center;
    width: 100%;
    padding: 10px;
    border: 2px solid var(--primary);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s, box-shadow 0.2s;
}
.primary-btn:active { transform: scale(0.98); }

/* =========================================
   11. VIEWER & MEDIA
   ========================================= */
.viewer-toolbar {
    background: #1e1e1e;
    color: white;
    padding: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.icon-btn {
    background: none;
    border: none;
    color: inherit; /* Inherit from parent (white in viewer, variable elsewhere) */
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#pdf-container {
    height: calc(100% - 60px);
    overflow-y: auto;
    background: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0;
}

canvas, video, img {
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    margin-bottom: 1rem;
    max-width: 100%;
}
audio, video { border-radius: 8px; }

/* =========================================
   12. SPLASH SCREEN
   ========================================= */
#splash-screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: var(--primary);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    transition: opacity 0.5s ease-out, visibility 0.5s;
}

#splash-screen.fade-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash-content { text-align: center; animation: float 2s ease-in-out infinite; }
.splash-logo { width: 80px; height: 80px; margin-bottom: 1rem; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.2)); }
.splash-content h2 { font-size: 1.5rem; margin-bottom: 1.5rem; font-weight: 600; }

.loading-bar {
    width: 150px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 auto;
}
.bar-fill {
    height: 100%;
    background: white;
    width: 50%;
    animation: loading 1.5s infinite linear;
}

/* =========================================
   13. KEYFRAME ANIMATIONS
   ========================================= */
@keyframes loading { 0% { transform: translateX(-100%); } 100% { transform: translateX(200%); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }