/* =================================================================================
   Strashun Library - Academic Modern Theme
   Enhanced v2.0 - Fixed scrolling and improved layouts
   ================================================================================= */

/* --- Fonts --- */
/* Lora for headings (scholarly feel) and Inter for UI/body text (clarity) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Lora:wght@400;500;600;700&display=swap');

/* --- Root Variables for Colors --- */
:root {
    --bg-color: #F7FAFC; /* Light, warm gray */
    --card-bg-color: #FFFFFF;
    --text-primary: #2D3748; /* Dark gray for primary text */
    --text-secondary: #718096; /* Lighter gray for secondary text */
    --accent-primary: #4A5568; /* Slate Blue for primary actions/borders */
    --accent-secondary: #718096; /* Slate gray for secondary accents */
    --accent-green: #38A169;
    --accent-blue: #3182CE;
    --accent-purple: #805AD5;
    --accent-pink: #D53F8C;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --header-height: 64px;
}

/* --- Reset and Base Styles --- */
* {
    box-sizing: border-box;
}

html {
    height: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    line-height: 1.6;
    /* Allow normal scrolling */
    overflow-x: hidden;
    overflow-y: auto;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Lora', serif;
    font-weight: 600;
    margin-top: 0;
    line-height: 1.3;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }

p {
    margin-top: 0;
    margin-bottom: 1rem;
}

/* --- Main Layout Structure --- */
#main-content {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Remove fixed height to allow natural scrolling */
}

/* --- Header --- */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--card-bg-color);
    box-shadow: var(--card-shadow);
    border-bottom: 1px solid #E2E8F0;
    flex-shrink: 0;
}

/* --- Main Content Area --- */
main {
    flex: 1 0 auto;
    padding-bottom: 2rem;
    /* Remove overflow settings to allow natural flow */
}

/* --- Footer --- */
footer {
    flex-shrink: 0;
    background-color: var(--card-bg-color);
    border-top: 1px solid #E2E8F0;
    margin-top: auto;
}

/* --- Navigation --- */
.nav-link {
    display: inline-block;
    padding: 0.5rem 1rem;
    transition: all 0.2s ease-in-out;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
}

.nav-link.active {
    color: var(--accent-primary) !important;
    border-bottom-color: var(--accent-primary);
    font-weight: 600;
}

.nav-link:hover:not(.active) {
    color: var(--accent-primary);
    background-color: rgba(74, 85, 104, 0.05);
}

/* Mobile Navigation */
#mobile-menu {
    background-color: var(--card-bg-color);
}

#mobile-menu .nav-link {
    display: block;
    border-bottom: none;
    border-left: 3px solid transparent;
}

#mobile-menu .nav-link.active {
    border-left-color: var(--accent-primary);
    background-color: rgba(74, 85, 104, 0.05);
}

/* --- Card and Container Styling --- */
.card {
    background-color: var(--card-bg-color);
    border-radius: 0.75rem;
    box-shadow: var(--card-shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: box-shadow 0.2s ease-in-out;
}

.card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Quick stat cards */
.quick-stat-card {
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.quick-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* --- Chart Container --- */
.chart-container {
    position: relative;
    width: 100%;
    min-height: 200px;
}

/* Specific height constraints for different chart types */
.chart-container.dashboard-main {
    height: 400px;
}

.chart-container.dashboard-small {
    height: 200px;
}

/* --- View Management --- */
.view {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: translateY(10px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

/* --- Form Elements & Buttons --- */
.form-input, 
.form-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #CBD5E0;
    border-radius: 0.5rem;
    background-color: white;
    font-size: 0.875rem;
    transition: all 0.2s ease-in-out;
}

.form-input:focus, 
.form-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.1);
}

.form-input:disabled,
.form-select:disabled {
    background-color: #F7FAFC;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #2D3748;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.btn-secondary {
    background-color: var(--accent-green);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #2F855A;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* --- List Views --- */
.list-container {
    max-height: 600px;
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: 0.5rem;
}

.list-item {
    padding: 1rem;
    border-bottom: 1px solid #EDF2F7;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
}

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

.list-item:hover {
    background-color: #F7FAFC;
}

.list-item.book-item:hover,
.list-item.borrower-item:hover {
    background-color: #EDF2F7;
}

.list-item-title {
    font-family: 'Lora', serif;
    font-weight: 500;
    color: var(--accent-primary);
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.list-item-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* --- Pagination --- */
.pagination-btn {
    padding: 0.5rem 0.75rem;
    min-width: 2.5rem;
    border: 1px solid #E2E8F0;
    background-color: white;
    color: var(--text-primary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    border-radius: 0.375rem;
}

.pagination-btn:hover:not(:disabled) {
    background-color: #F7FAFC;
    border-color: #CBD5E0;
}

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

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

/* --- Network Visualization --- */
#network-graph,
#ego-network-graph-ego-network-container,
#ego-network-graph-ego-modal-content {
    width: 100%;
    height: 600px;
    border: 1px solid #E2E8F0;
    border-radius: 0.5rem;
    background: linear-gradient(to bottom right, #F7FAFC, #FFFFFF);
}

/* --- Ego Network Modal --- */
#ego-network-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

#ego-network-modal .modal-content {
    background: white;
    border-radius: 0.75rem;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* --- Detail View --- */
#detail-view .card {
    margin-bottom: 1.5rem;
}

#detail-content {
    max-width: 1024px;
    margin: 0 auto;
}

/* --- Statistics View --- */
#statistics-content .card {
    height: auto;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent-primary);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Loading States --- */
.spinner {
    border: 3px solid #E2E8F0;
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    animation: spin 0.8s linear infinite;
}

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

/* --- Badges and Tags --- */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.badge-blue {
    background-color: rgba(59, 130, 246, 0.1);
    color: #2563EB;
}

.badge-green {
    background-color: rgba(16, 185, 129, 0.1);
    color: #059669;
}

.badge-pink {
    background-color: rgba(236, 72, 153, 0.1);
    color: #DB2777;
}

.badge-gray {
    background-color: rgba(107, 114, 128, 0.1);
    color: #4B5563;
}

/* --- RTL Support --- */
.rtl {
    direction: rtl;
    text-align: right;
}

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

::-webkit-scrollbar-track {
    background: #F7FAFC;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb {
    background: #CBD5E0;
    border-radius: 5px;
    border: 2px solid #F7FAFC;
}

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

::-webkit-scrollbar-corner {
    background: #F7FAFC;
}

/* --- Utility Classes --- */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.font-normal { font-weight: 400; }

.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.text-3xl { font-size: 1.875rem; }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }

.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }

.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }

.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }

.rounded { border-radius: 0.25rem; }
.rounded-md { border-radius: 0.375rem; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-xl { border-radius: 0.75rem; }
.rounded-full { border-radius: 9999px; }

.shadow-sm { box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); }
.shadow { box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); }
.shadow-md { box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); }
.shadow-lg { box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); }
.shadow-xl { box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); }

.opacity-0 { opacity: 0; }
.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }
.opacity-100 { opacity: 1; }

.transition-all { transition-property: all; }
.transition-opacity { transition-property: opacity; }
.transition-shadow { transition-property: box-shadow; }
.transition-colors { transition-property: background-color, border-color, color; }

.duration-200 { transition-duration: 200ms; }
.duration-300 { transition-duration: 300ms; }
.duration-500 { transition-duration: 500ms; }

.ease-in-out { transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); }

/* --- Responsive Design --- */
@media (max-width: 768px) {
    .card {
        padding: 1rem;
        border-radius: 0.5rem;
    }
    
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.125rem; }
    
    .list-container {
        max-height: 400px;
    }
    
    #network-graph {
        height: 400px;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 13px;
    }
    
    .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.8125rem;
    }
    
    .form-input,
    .form-select {
        padding: 0.375rem 0.625rem;
        font-size: 0.8125rem;
    }
    
    .card {
        margin-bottom: 1rem;
    }
}

/* --- Print Styles --- */
@media print {
    body {
        background: white;
        color: black;
    }
    
    header,
    footer,
    .btn,
    .pagination-btn,
    #mobile-menu-button {
        display: none !important;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ccc;
        page-break-inside: avoid;
    }
    
    main {
        overflow: visible !important;
    }
}

/* --- Accessibility --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* --- Animations --- */
@keyframes slideIn {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.animate-slide-in {
    animation: slideIn 0.3s ease-out;
}

.animate-slide-up {
    animation: slideUp 0.3s ease-out;
}

.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}