@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
    /* Color Palette - Default Dark (Premium) */
    --brand-primary: #3b82f6;
    --brand-primary-rgb: 59, 130, 246;
    --brand-secondary: #0f172a;
    --brand-accent: #6366f1;

    /* Semantic Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0ea5e9;

    /* Dark Theme (Default) */
    --bg-main: #020617;
    --bg-surface: #0f172a;
    --bg-elevated: #1e293b;
    --border-subtle: rgba(255, 255, 255, 0.05);
    --border-bright: rgba(255, 255, 255, 0.1);

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --grad-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0) 100%);
    --header-bg: rgba(2, 6, 23, 0.7);
    --card-shadow: 0 20px 48px -12px rgba(0, 0, 0, 0.5);
}

/* Light Theme Overrides */
[data-theme="light"] {
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-elevated: #f1f5f9;
    --border-subtle: rgba(15, 23, 42, 0.06);
    --border-bright: rgba(15, 23, 42, 0.1);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --grad-surface: linear-gradient(180deg, rgba(15, 23, 42, 0.02) 0%, rgba(15, 23, 42, 0) 100%);
    --header-bg: rgba(255, 255, 255, 0.7);
    --card-shadow: 0 10px 30px -5px rgba(15, 23, 42, 0.1);
}

:root {
    /* Shared Constants */
    --grad-primary: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    --grad-dark: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
    --grad-glass: linear-gradient(120deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0) 100%);

    --sidebar-width: 280px;
    --header-height: 72px;
    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 12px 24px -6px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 20px 48px -12px rgba(0, 0, 0, 0.5);
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass {
    background: var(--grad-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-bright);
}

.glass-dark {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

h1,
h2,
h3,
h4,
.font-heading {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    letter-spacing: -0.02em;
}

a {
    text-decoration: none;
    color: inherit;
    transition: var(--transition);
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--bg-elevated);
    border-radius: 10px;
    border: 2px solid var(--bg-main);
}

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

/* --- Layout Blocks --- */

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: 2.5rem 1.5rem;
    position: fixed;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 1001;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.1);
    transition: background 0.3s ease;
    margin: 0 !important;
}

[data-theme="dark"] .sidebar {
    background: linear-gradient(180deg, #0f172a 0%, #020617 100%);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.4);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 2.5rem;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--brand-primary);
}

.nav-section {
    margin-bottom: 2rem;
}

.nav-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
    padding-left: 0.75rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0;
    background: var(--brand-primary);
    transition: var(--transition);
    opacity: 0;
}

.nav-item.active::before {
    width: 4px;
    opacity: 1;
}

.nav-item i {
    width: 20px;
    font-size: 1.1rem;
    text-align: center;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(var(--brand-primary-rgb), 0.1);
    color: var(--brand-primary);
}

.nav-item.active {
    box-shadow: inset 0 0 0 1px rgba(var(--brand-primary-rgb), 0.2);
}

/* Main Content Area */
.main-area {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-bar {
    height: var(--header-height);
    background: rgba(var(--brand-secondary-rgb), 0.8);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border-bright);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4rem;
    position: fixed;
    top: 0;
    left: 0 !important;
    right: 0;
    z-index: 1000;
}

/* Admin / Librarian panel: header starts after sidebar */
.app-wrapper .main-area .top-bar {
    left: var(--sidebar-width) !important;
}

/* Base Top Bar for Mobile Overlay Override */
.top-bar {
    left: 0 !important;
}

[data-theme="light"] .top-bar {
    background: rgba(255, 255, 255, 0.8) !important;
}

[data-theme="light"] .top-bar {
    background: rgba(255, 255, 255, 0.8) !important;
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--border-bright);
    background: var(--bg-surface);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
}

.theme-toggle:hover {
    background: var(--bg-elevated);
    border-color: var(--brand-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.nav-links {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.nav-link {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-secondary);
    position: relative;
    padding: 0.5rem 0;
    transition: var(--transition);
}

.nav-link:hover {
    color: var(--text-primary);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--brand-primary);
    transition: var(--transition);
    border-radius: 2px;
}

.nav-link:hover::after {
    width: 100%;
}

.nav-link.active {
    color: var(--brand-primary);
}

.nav-link.active::after {
    width: 100%;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.user-quick-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 99px;
    transition: var(--transition);
}

.user-quick-profile:hover {
    background: rgba(255, 255, 255, 0.08);
}

.user-avatar-small {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--grad-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
}

.content-body {
    padding: 2.5rem;
    width: 100%;
}

/* --- Components --- */

/* Premium Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-4px);
    border-color: var(--border-bright);
    box-shadow: var(--shadow-lg);
}

.card-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
}

.card-body {
    padding: 1.5rem;
}

/* Dashboard Stats */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--bg-surface);
    padding: 2rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-info .stat-value {
    font-size: 2rem;
    font-weight: 800;
    font-family: 'Outfit';
    line-height: 1;
}

.stat-info .stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 4px;
}

/* Stat colors */
.bg-blue {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.bg-green {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.bg-orange {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.bg-purple {
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
}

/* Table Styling */
.table-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    background: rgba(255, 255, 255, 0.02);
    padding: 1rem 1.5rem;
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.9375rem;
    color: var(--text-primary);
}

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

.data-table tr:hover {
    background: rgba(255, 255, 255, 0.01);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    gap: 8px;
}

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

.btn-primary:hover {
    opacity: 0.9;
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-bright);
}

.btn-secondary:hover {
    background: var(--text-muted);
}

.btn-pill {
    border-radius: 999px;
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.badge-info {
    background: rgba(14, 165, 233, 0.1);
    color: #0ea5e9;
}

/* Form Controls */
.form-group {
    margin-bottom: 1.5rem;
}

.label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.input {
    width: 100%;
    background: var(--bg-main);
    border: 1px solid var(--border-subtle);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: var(--transition);
    outline: none;
}

.input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Book Grid (Public) */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 1.5rem;
}


.book-card {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: var(--transition);
}

.book-cover {
    height: 320px;
    background: var(--bg-elevated);
    position: relative;
    overflow: hidden;
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--transition);
}

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

.book-content {
    padding: 1.25rem;
}

.book-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-author {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

/* Hero Section */
.hero-section {
    background: var(--grad-primary);
    padding: 5rem 2.5rem;
    border-radius: var(--radius-lg);
    margin-bottom: 3rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero-content {
    position: relative;
    z-index: 1;
}

.hero-title {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    line-height: 1.1;
}

.hero-dots {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(rgba(255, 255, 255, 0.15) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.animate-fade {
    animation: fadeIn 0.4s ease forwards;
}

.animate-slide-up {
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hover-lift {
    transition: var(--transition);
}

.hover-lift:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.text-gradient {
    background: var(--grad-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Responsive */
@media (max-width: 1200px) {
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    }
}

@media (max-width: 1024px) {
    /* The sidebar rules here are removed as they are replaced by the 991px media query for a mobile sidebar */
    /* The main-area margin-left is also removed as it's handled by the 991px media query */
}

@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-area {
        margin-left: 0 !important;
    }

    .app-wrapper .main-area .top-bar {
        left: 0 !important;
    }

    .top-bar {
        padding: 0 1.5rem;
    }

    .hero-title {
        font-size: 2.5rem;
    }
}

@media (max-width: 768px) {
    .content-body {
        padding: 1rem;
    }

    .hero-section {
        padding: 3rem 1.5rem;
    }

    .hero-title {
        font-size: 1.8rem;
    }

    .stat-grid {
        grid-template-columns: 1fr;
    }

    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 1rem;
    }

    .book-cover {
        height: 200px;
    }

    .data-table thead {
        display: none;
        /* Consider responsive card view for tables */
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table tr {
        margin-bottom: 1rem;
        background: var(--bg-elevated);
        border-radius: var(--radius-sm);
    }

    .data-table td {
        text-align: right;
        padding-left: 50%;
        position: relative;
        border-bottom: 1px solid var(--border-subtle);
    }

    .data-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 1.5rem;
        width: 45%;
        text-align: left;
        font-weight: 700;
        color: var(--text-muted);
        font-size: 0.75rem;
        text-transform: uppercase;
    }
}

@media (max-width: 480px) {
    .book-grid {
        grid-template-columns: 1fr 1fr;
    }

    .hero-title {
        font-size: 1.5rem;
    }
}