/* Custom Color Variables - Sleek Dark/Glassmorphic Theme */
:root {
    --bg-primary: #0b0f19;
    --bg-secondary: #131a26;
    --bg-glass: rgba(20, 30, 48, 0.6);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glass-focus: rgba(255, 255, 255, 0.2);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --accent: #6366f1; /* Indigo */
    --accent-glow: rgba(99, 102, 241, 0.4);
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    
    --gradient-header: linear-gradient(135deg, #1e1b4b 0%, #0f172a 100%);
    --gradient-card: linear-gradient(145deg, rgba(26, 36, 54, 0.7) 0%, rgba(15, 23, 42, 0.8) 100%);
    --gradient-button: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
    
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-circle: 50%;
}

/* Reset and Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

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

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

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
}

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

/* App Layout */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 24px;
    max-width: 1600px;
    margin: 0 auto;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    padding: 20px 32px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    box-shadow: var(--shadow-md);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-icon {
    font-size: 2.5rem;
    background: var(--gradient-button);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text h1 {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.logo-text h1 span {
    color: var(--accent);
}

.logo-text p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 2px;
}

/* Search Wrapper */
.search-wrapper {
    position: relative;
    width: 45%;
    max-width: 600px;
}

.search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.search-wrapper input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    padding: 14px 100px 14px 50px;
    border-radius: 30px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.search-wrapper input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
}

.search-count {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Main Layout */
.main-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
}

/* Sidebar Filters */
.sidebar-filters {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    padding: 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    height: fit-content;
}

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

.filter-header h2 {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
}

.btn-clear-filters {
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s ease;
}

.btn-clear-filters:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

.filter-group {
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    padding-bottom: 16px;
}

.filter-group:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.filter-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    margin-bottom: 12px;
}

.filter-group-header h3 {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}

.toggle-icon {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}

.filter-group.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.filter-group.collapsed .filter-options {
    display: none;
}

.filter-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.3s ease;
}

.scrollable-options {
    max-height: 220px;
    overflow-y: auto;
    padding-right: 5px;
}

/* Custom Checkbox styles */
.filter-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    padding: 4px 0;
}

.filter-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-item input {
    display: none;
}

.custom-checkbox {
    width: 18px;
    height: 18px;
    border: 1px solid var(--border-glass);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.02);
}

.filter-item:hover .custom-checkbox {
    border-color: var(--accent);
}

.filter-item input:checked + .custom-checkbox {
    background: var(--gradient-button);
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}

.custom-checkbox i {
    color: #fff;
    font-size: 0.7rem;
    display: none;
}

.filter-item input:checked + .custom-checkbox i {
    display: block;
}

.filter-item-count {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 10px;
    color: var(--text-muted);
}

.filter-item input:checked ~ .filter-item-left span {
    color: var(--text-primary);
    font-weight: 500;
}

/* Content Area */
.content-area {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Controls */
.content-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.btn-mobile-filters {
    display: none;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
}

.sort-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.sort-wrapper label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.sort-select {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.85rem;
    cursor: pointer;
}

.sort-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 24px;
    min-height: 400px;
}

/* Book Card */
.book-card {
    background: var(--gradient-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.book-card:hover {
    transform: translateY(-8px);
    border-color: rgba(99, 102, 241, 0.3);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(99, 102, 241, 0.15);
}

.card-cover-wrapper {
    width: 100%;
    aspect-ratio: 2/3;
    overflow: hidden;
    position: relative;
    background: #0d121c;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-cover-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.book-card:hover .card-cover-wrapper img {
    transform: scale(1.05);
}

.card-cover-fallback {
    font-size: 3rem;
    color: var(--text-muted);
}

/* Card badges */
.card-badge {
    display: inline-block;
    width: max-content;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: var(--text-normal);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 8px;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Color coding for certain badges */
.card-badge.badge-surgery { 
    background: rgba(239, 68, 68, 0.12); 
    border-color: rgba(239, 68, 68, 0.35); 
    color: #f87171; 
}
.card-badge.badge-cardiology { 
    background: rgba(59, 130, 246, 0.12); 
    border-color: rgba(59, 130, 246, 0.35); 
    color: #60a5fa; 
}
.card-badge.badge-imaging { 
    background: rgba(139, 92, 246, 0.12); 
    border-color: rgba(139, 92, 246, 0.35); 
    color: #a78bfa; 
}
.card-badge.badge-exotics { 
    background: rgba(245, 158, 11, 0.12); 
    border-color: rgba(245, 158, 11, 0.35); 
    color: #fbbf24; 
}

.card-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.card-title {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 2.7rem;
}

.card-authors {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 12px;
    margin-top: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.card-footer span i {
    margin-right: 4px;
}

/* Button Detail */
.btn-detail {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    width: 100%;
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.book-card:hover .btn-detail {
    background: var(--gradient-button);
    border-color: var(--accent);
}

/* States */
.loading-state, .error-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 0;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s infinite linear;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.empty-icon {
    font-size: 4rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.btn-primary {
    background: var(--gradient-button);
    border: none;
    color: #fff;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--accent-glow);
    transition: all 0.2s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

/* Modal Styles */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-backdrop.active {
    opacity: 1;
    pointer-events: all;
}

.modal-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 960px;
    max-height: 90vh;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow-y: auto;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-backdrop.active .modal-card {
    transform: scale(1) translateY(0);
}

.modal-close {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    z-index: 10;
}

.modal-close:hover {
    background: var(--accent);
    border-color: var(--accent);
    transform: rotate(90deg);
}

.modal-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 32px;
    padding: 32px;
}

/* Modal Left */
.modal-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-cover-wrapper {
    width: 100%;
    aspect-ratio: 2/3;
    background: #0d121c;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    position: relative;
    border: 1px solid var(--border-glass);
}

.modal-cover-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-cover-fallback {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    color: var(--text-muted);
}

.book-metrics {
    display: flex;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 12px;
    justify-content: space-around;
}

.metric-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.metric-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.metric-value {
    font-size: 1rem;
    font-weight: 700;
}

.btn-download {
    background: var(--gradient-button);
    color: #fff;
    text-decoration: none;
    padding: 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 1rem;
    text-align: center;
    box-shadow: 0 4px 15px var(--accent-glow);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-download:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-share {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-normal);
    padding: 12px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.btn-share:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(16, 185, 129, 0.9);
    backdrop-filter: blur(10px);
    color: #fff;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    z-index: 200;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.download-notice {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px;
    background: rgba(16, 185, 129, 0.05);
    border: 1px dashed rgba(16, 185, 129, 0.2);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--accent-success);
}

.download-notice i {
    font-size: 1.1rem;
    margin-top: 2px;
}

/* Modal Right */
.modal-right {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-spec-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.spec-badge {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.modal-right h2 {
    font-family: var(--font-heading);
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.3;
}

.modal-authors {
    font-size: 0.95rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-authors i {
    color: var(--accent);
}

.metadata-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    padding: 16px;
    border-radius: var(--radius-sm);
}

.meta-row {
    display: flex;
    font-size: 0.85rem;
}

.meta-label {
    width: 140px;
    color: var(--text-secondary);
    font-weight: 500;
}

.meta-label i {
    margin-right: 6px;
    color: var(--text-muted);
}

.meta-val {
    color: var(--text-primary);
}

/* Tabs */
.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-glass);
    gap: 20px;
    margin-top: 12px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 4px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
    padding-top: 12px;
}

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

.book-description {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.scrollable-toc {
    max-height: 300px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-glass);
    padding: 16px;
    border-radius: var(--radius-sm);
}

.toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toc-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 4px 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.03);
}

.toc-item:last-child {
    border-bottom: none;
}

.toc-title {
    padding-right: 20px;
    display: flex;
    gap: 8px;
}

.toc-page {
    color: var(--accent);
    font-weight: 600;
    white-space: nowrap;
}

/* Indentations for TOC levels */
.toc-item.level-1 { padding-left: 0; font-weight: 500; color: var(--text-primary); }
.toc-item.level-2 { padding-left: 16px; }
.toc-item.level-3 { padding-left: 32px; font-size: 0.8rem; }

/* Responsive styles */
@media (max-width: 992px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
    
    .sidebar-filters {
        display: none; /* Collapsed by default on mobile */
        position: fixed;
        top: 0;
        left: 0;
        width: 300px;
        height: 100vh;
        z-index: 50;
        border-radius: 0;
        overflow-y: auto;
    }
    
    .sidebar-filters.active {
        display: block;
    }
    
    .btn-mobile-filters {
        display: block;
    }
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
        padding: 16px;
    }
    
    .search-wrapper {
        width: 100%;
    }
    
    .modal-grid {
        grid-template-columns: 1fr;
        padding: 20px;
    }
    
    .modal-left {
        align-items: center;
    }
    
    .modal-cover-wrapper {
        width: 200px;
    }
    
    .btn-download {
        width: 100%;
    }
}
