/* ========================================
   BookVault — Premium Sidebar Layout
   ======================================== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --gray-100: #fafafa;
    --gray-200: #f5f5f5;
    --gray-300: #e5e5e5;
    --gray-400: #d4d4d4;
    --gray-500: #a3a3a3;
    --gray-600: #737373;
    --gray-700: #525252;
    --gray-800: #404040;
    --gray-900: #262626;
    --gray-1000: #171717;

    --bg-1: #ffffff;
    --bg-2: #fcfcfc;

    --accent: #171717;
    --focus: rgba(0,0,0,0.12);
    --sidebar-w: 260px;
    --nav-h: 48px;

    --shadow-xs: 0 1px 2px rgba(0,0,0,0.03);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
    --shadow-md: 0 2px 6px -1px rgba(0,0,0,0.05), 0 4px 12px -2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px -2px rgba(0,0,0,0.06), 0 12px 24px -4px rgba(0,0,0,0.05);

    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 14px;

    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-2);
    color: var(--gray-1000);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

/* ========================================
   Navigation
   ======================================== */

.nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--nav-h);
    background: rgba(255,255,255,0.82);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

.nav-inner {
    height: 100%;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14px;
    color: var(--gray-1000);
    text-decoration: none;
    letter-spacing: -0.02em;
    white-space: nowrap;
    flex-shrink: 0;
    transition: opacity var(--transition);
}

.nav-brand:hover { opacity: 0.7; }

.nav-brand svg { color: var(--gray-800); }

/* Search */
.search-wrapper {
    position: relative;
    flex: 1;
    max-width: 440px;
    display: flex;
    align-items: center;
}

.search-wrapper .search-icon {
    position: absolute;
    left: 10px;
    color: var(--gray-500);
    pointer-events: none;
    transition: color var(--transition);
}

.search-wrapper input {
    width: 100%;
    height: 32px;
    padding: 0 36px 0 32px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: var(--bg-1);
    font-family: inherit;
    font-size: 13px;
    color: var(--gray-1000);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.search-wrapper input::placeholder { color: var(--gray-500); }

.search-wrapper input:hover {
    border-color: var(--gray-400);
    background: #fff;
}

.search-wrapper input:focus {
    border-color: var(--gray-1000);
    box-shadow: 0 0 0 3px var(--focus);
    background: #fff;
}

.search-wrapper input:focus + kbd { opacity: 0; }

.search-wrapper kbd {
    position: absolute;
    right: 8px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    color: var(--gray-500);
    background: var(--gray-200);
    border: 1px solid var(--gray-300);
    border-radius: 5px;
    padding: 0 5px;
    line-height: 1.6;
    pointer-events: none;
    transition: opacity var(--transition);
}

/* Nav Stats */
.nav-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-left: auto;
    flex-shrink: 0;
    padding-left: 16px;
    border-left: 1px solid var(--gray-300);
}

.nav-stat {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.nav-stat-num {
    font-size: 14px;
    font-weight: 700;
    color: var(--gray-1000);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

.nav-stat-label {
    font-size: 12px;
    color: var(--gray-500);
}

/* ========================================
   Layout
   ======================================== */

.layout {
    display: flex;
    height: calc(100vh - var(--nav-h));
    margin-top: var(--nav-h);
}

/* ========================================
   Sidebar
   ======================================== */

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-1);
    border-right: 1px solid rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--gray-200);
}

.sidebar-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.clear-btn {
    display: none;
    align-items: center;
    gap: 4px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    color: var(--gray-600);
    background: var(--gray-200);
    border: none;
    border-radius: 100px;
    padding: 3px 10px 3px 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.clear-btn:hover {
    background: var(--gray-300);
    color: var(--gray-800);
}

.clear-btn.visible { display: flex; }

.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) transparent;
}

.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }
.sidebar-list::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* Category Items */
.cat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
    position: relative;
}

.cat-item:hover {
    background: var(--gray-200);
}

.cat-item:active {
    transform: scale(0.985);
}

.cat-item.active {
    background: var(--gray-1000);
    border-color: var(--gray-1000);
    box-shadow: var(--shadow-sm);
}

.cat-item.active .cat-item-name,
.cat-item.active .cat-item-count,
.cat-item.active .cat-item-icon { color: white; }

.cat-item-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-200);
    border-radius: 6px;
    flex-shrink: 0;
    color: var(--gray-600);
    transition: all var(--transition);
}

.cat-item.active .cat-item-icon {
    background: rgba(255,255,255,0.15);
    color: white;
}

.cat-item-body { flex: 1; min-width: 0; }

.cat-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.cat-item-count {
    font-size: 11px;
    color: var(--gray-500);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

/* Category Tooltip — JS positioned, fixed */
.cat-tooltip {
    position: fixed;
    background: var(--gray-1000);
    color: white;
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 12px;
    line-height: 1.4;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 150ms ease, transform 150ms var(--ease-out);
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateX(-4px);
}

.cat-tooltip::before {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: var(--gray-1000);
}

.cat-tooltip strong {
    font-weight: 600;
}

/* ========================================
   Main Content
   ======================================== */

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-2);
}

.main-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    background: var(--bg-1);
    flex-shrink: 0;
    gap: 12px;
}

.main-head-left {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
}

.page-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-1000);
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.page-count {
    font-size: 13px;
    color: var(--gray-500);
    white-space: nowrap;
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.view-toggle {
    display: flex;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-1);
}

.view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--gray-500);
    cursor: pointer;
    transition: all var(--transition);
}

.view-btn:not(:last-child) { border-right: 1px solid var(--gray-300); }
.view-btn:hover { background: var(--gray-200); color: var(--gray-700); }
.view-btn.active { background: var(--gray-1000); color: white; }

.controls select {
    height: 28px;
    padding: 0 26px 0 10px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: var(--bg-1);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-700);
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23737373' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: all var(--transition);
}

.controls select:hover { border-color: var(--gray-400); }
.controls select:focus { border-color: var(--gray-1000); box-shadow: 0 0 0 3px var(--focus); }

/* ========================================
   Book Grid
   ======================================== */

.book-grid {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px 32px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
    align-content: start;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) transparent;
}

.book-grid::-webkit-scrollbar { width: 5px; }
.book-grid::-webkit-scrollbar-track { background: transparent; }
.book-grid::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
.book-grid::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

.book-grid.list-view {
    grid-template-columns: 1fr;
    gap: 4px;
}

.book-card {
    padding: 14px 16px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-lg);
    background: var(--bg-1);
    transition: all var(--transition);
    cursor: default;
    position: relative;
}

.book-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    opacity: 0;
    transition: opacity var(--transition);
    pointer-events: none;
}

.book-card:hover {
    border-color: var(--gray-400);
}

.book-card:hover::after {
    opacity: 1;
}

.book-card:active {
    transform: scale(0.99);
}

/* Book Tooltip — shared, fixed position */
.book-tooltip {
    position: fixed;
    background: var(--gray-1000);
    color: white;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 12px;
    line-height: 1.5;
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 150ms ease, transform 150ms var(--ease-out);
    z-index: 300;
    box-shadow: 0 4px 14px rgba(0,0,0,0.2);
    transform: translateY(4px);
}

.book-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--gray-1000);
}

.book-tooltip .tooltip-title {
    font-weight: 600;
    margin-bottom: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tooltip-author {
    color: rgba(255,255,255,0.6);
    font-size: 11px;
}

.book-num {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    color: var(--gray-500);
    background: var(--gray-200);
    padding: 2px 7px;
    border-radius: 5px;
    font-variant-numeric: tabular-nums;
    margin-bottom: 8px;
    letter-spacing: 0.01em;
}

.book-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-1000);
    line-height: 1.4;
    margin-bottom: 3px;
    letter-spacing: -0.01em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    font-size: 12px;
    color: var(--gray-600);
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 500;
    color: var(--gray-600);
    background: var(--gray-200);
    border-radius: 100px;
    padding: 2px 8px;
    max-width: 100%;
    transition: background var(--transition);
}

.book-tag svg {
    width: 11px;
    height: 11px;
    flex-shrink: 0;
}

.book-tag span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-card:hover .book-tag {
    background: var(--gray-300);
}

/* List View */
.book-grid.list-view .book-card {
    display: grid;
    grid-template-columns: 36px 1fr auto auto;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    border-radius: var(--radius);
}

.book-grid.list-view .book-card::after { border-radius: var(--radius); }

.book-grid.list-view .book-num {
    margin: 0;
    text-align: center;
    padding: 2px 0;
    min-width: 36px;
}

.book-grid.list-view .book-title {
    margin: 0;
    -webkit-line-clamp: 1;
    font-size: 13px;
}

.book-grid.list-view .book-author {
    margin: 0;
    font-size: 12px;
}

.book-grid.list-view .book-tag { flex-shrink: 0; }

/* No Results */
.no-results {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 24px;
    text-align: center;
}

.no-results-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-200);
    border-radius: 50%;
    color: var(--gray-500);
    margin-bottom: 14px;
}

.no-results h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 3px;
}

.no-results p {
    font-size: 13px;
    color: var(--gray-500);
}

/* ========================================
   Focus
   ======================================== */

:focus-visible {
    outline: 2px solid var(--gray-1000);
    outline-offset: 2px;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
    :root { --sidebar-w: 0px; }

    .nav-inner { padding: 0 12px; gap: 10px; }
    .nav-stats { display: none; }
    .search-wrapper { max-width: none; }
    .search-wrapper kbd { display: none; }

    .layout { flex-direction: column; }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid rgba(0,0,0,0.06);
    }

    .sidebar-head { padding: 10px 12px 8px; }

    .sidebar-list {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 4px 12px 8px;
        gap: 6px;
        scroll-snap-type: x mandatory;
    }

    .sidebar-list::-webkit-scrollbar { height: 0; }

    .cat-item {
        flex-shrink: 0;
        padding: 6px 12px;
        border-radius: 100px;
        border: 1px solid var(--gray-300);
        background: var(--bg-1);
        scroll-snap-align: start;
        gap: 6px;
    }

    .cat-item:hover { border-color: var(--gray-400); }
    .cat-item.active { background: var(--gray-1000); border-color: var(--gray-1000); }
    .cat-item-icon { display: none; }

    .cat-item-name { font-size: 12px; white-space: nowrap; }

    .cat-item-count {
        font-size: 10px;
        background: var(--gray-200);
        padding: 1px 5px;
        border-radius: 100px;
    }

    .cat-item.active .cat-item-count {
        background: rgba(255,255,255,0.15);
        color: white;
    }

    .cat-tooltip { display: none; }
    .book-tooltip { display: none; }

    .main-head { padding: 10px 12px; }

    .book-grid {
        padding: 10px 12px 24px;
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 8px;
    }

    .book-card { padding: 10px 12px; }
    .book-title { font-size: 12px; }
    .book-author { font-size: 11px; }
}

@media (max-width: 480px) {
    .page-title { font-size: 14px; }
    .book-grid { grid-template-columns: 1fr 1fr; }
    .book-grid.list-view { grid-template-columns: 1fr; }
}
