/* ============================================
   Cali — Library Manager Styles
   ============================================ */

:root {
    --bg-body: #0f0f1a;
    --bg-sidebar: #12122a;
    --bg-surface: #1a1a2e;
    --bg-surface-2: #1e1e38;
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-active: rgba(59, 130, 246, 0.12);
    --accent: #3B82F6;
    --accent-hover: #2563EB;
    --accent-glow: rgba(59, 130, 246, 0.25);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --radius: 8px;
    --radius-sm: 5px;
    --radius-lg: 12px;
    --sidebar-w: 260px;
    --topbar-h: 56px;
    --inspector-w: 380px;
    --transition: 200ms ease;
    --transition-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

.hidden { display: none !important; }

/* ============ LAYOUT ============ */

#app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr 0px;
    height: 100vh;
    transition: grid-template-columns var(--transition-slow);
}
#app.sidebar-collapsed { grid-template-columns: 0px 1fr 0px; }
#app.inspector-open { grid-template-columns: var(--sidebar-w) 1fr var(--inspector-w); }
#app.sidebar-collapsed.inspector-open { grid-template-columns: 0px 1fr var(--inspector-w); }

#main-wrapper {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ============ SIDEBAR ============ */

#sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-slow);
}
#app.sidebar-collapsed #sidebar { transform: translateX(-100%); pointer-events: none; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    position: sticky;
    top: 0;
    background: var(--bg-sidebar);
    z-index: 2;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}
.logo .icon { color: var(--accent); }
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }

.sidebar-nav { padding: 4px 8px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    user-select: none;
    font-size: 13px;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-active); color: var(--accent); }
.nav-item .badge {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255,255,255,0.06);
    padding: 1px 7px;
    border-radius: 10px;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 16px;
}

.sidebar-bottom { margin-top: auto; padding-bottom: 12px; }

/* ---- Filters ---- */

.filters-section { padding: 0 8px; flex: 1; overflow-y: auto; }

.filters-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}
.filter-badge {
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    min-width: 18px;
    text-align: center;
}
.btn-text {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}
.btn-text:hover { background: var(--bg-hover); }

.filter-group { margin-bottom: 2px; }

.filter-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    text-align: left;
}
.filter-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

.filter-toggle .icon { width: 16px; flex-shrink: 0; }
.filter-toggle .filter-count {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
}
.chevron-icon {
    transition: transform var(--transition);
    flex-shrink: 0;
}
.filter-group.expanded .chevron-icon { transform: rotate(90deg); }

.filter-options {
    padding: 2px 0 4px 20px;
    max-height: 240px;
    overflow-y: auto;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all var(--transition);
}
.filter-option:hover { background: var(--bg-hover); color: var(--text-primary); }
.filter-option.active { color: var(--accent); }

.filter-option input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 14px; height: 14px;
    border: 1.5px solid var(--border-strong);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: all var(--transition);
}
.filter-option input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}
.filter-option input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 3.5px; top: 1px;
    width: 4px; height: 7px;
    border: solid #fff;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
}
.filter-option .filter-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-option .filter-count { font-size: 11px; color: var(--text-muted); }
.filter-more { font-size: 11px; color: var(--text-muted); padding: 4px 10px; }

/* ============ TOPBAR ============ */

#topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    height: var(--topbar-h);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 5;
}

.search-box {
    position: relative;
    flex: 1;
    max-width: 440px;
}
.search-box .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.search-box input {
    width: 100%;
    padding: 8px 12px 8px 38px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    transition: all var(--transition);
}
.search-box input::placeholder { color: var(--text-muted); }
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.kbd {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255,255,255,0.06);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
    font-family: var(--font);
    pointer-events: none;
}

.filter-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    max-width: 300px;
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px 3px 10px;
    background: var(--bg-active);
    color: var(--accent);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}
.chip-remove {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 0;
    display: flex;
    opacity: 0.7;
}
.chip-remove:hover { opacity: 1; }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.sort-select {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12px;
    font-family: var(--font);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
}
.sort-select:focus { border-color: var(--accent); }
.sort-select option { background: var(--bg-surface); }

.view-toggle {
    display: flex;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.view-toggle .btn-icon {
    border-radius: 0;
    border: none;
    border-right: 1px solid var(--border);
}
.view-toggle .btn-icon:last-child { border-right: none; }
.view-toggle .btn-icon.active { background: var(--bg-active); color: var(--accent); }

/* ============ BUTTONS ============ */

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: var(--font);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn:hover { background: var(--bg-surface-2); color: var(--text-primary); border-color: var(--border-strong); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: rgba(239,68,68,0.3); }
.btn-active { color: var(--accent); border-color: rgba(59,130,246,0.3); background: var(--bg-active); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ CONTENT ============ */

#content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-body);
}

/* ---- Grid ---- */

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 20px;
    padding: 24px;
}

.book-card {
    cursor: pointer;
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
    background: var(--bg-surface);
    border: 1px solid var(--border);
}
.book-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    border-color: var(--border-strong);
}

.card-cover {
    position: relative;
    aspect-ratio: 2 / 3;
    background: var(--bg-surface-2);
    overflow: hidden;
}
.card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}
.book-card:hover .card-cover img { transform: scale(1.04); }
.card-cover.no-cover {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.card-cover.no-cover::after {
    content: '📖';
    font-size: 40px;
    opacity: 0.4;
}

.card-overlay {
    position: absolute;
    top: 0; right: 0;
    padding: 8px;
    opacity: 0;
    transition: opacity var(--transition);
}
.book-card:hover .card-overlay { opacity: 1; }

.btn-fav {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: all var(--transition);
}
.btn-fav:hover { background: rgba(0, 0, 0, 0.8); color: #fff; }
.btn-fav.active { color: var(--danger); }

.card-info {
    padding: 10px 12px 12px;
}
.card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.card-author {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- List ---- */

.book-list { padding: 0 24px 24px; }

.list-header {
    display: grid;
    grid-template-columns: 48px 1fr 160px 140px 100px 40px;
    gap: 12px;
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-body);
    z-index: 2;
}

.list-row {
    display: grid;
    grid-template-columns: 48px 1fr 160px 140px 100px 40px;
    gap: 12px;
    padding: 8px 12px;
    align-items: center;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
    font-size: 13px;
}
.list-row:hover { background: var(--bg-hover); }

.list-row .list-col-cover img {
    width: 36px;
    height: 48px;
    object-fit: cover;
    border-radius: 3px;
}

.list-title {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}
.list-series {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-col-author {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.list-col-date {
    color: var(--text-muted);
    font-size: 12px;
}
.list-col-format { display: flex; gap: 4px; flex-wrap: wrap; }

.format-badge {
    display: inline-block;
    padding: 1px 6px;
    background: rgba(59, 130, 246, 0.12);
    color: var(--accent);
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.format-badge.large { padding: 3px 10px; font-size: 11px; }

/* ---- States ---- */

.loading-state, .empty-state, .error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted);
    gap: 12px;
    text-align: center;
}
.empty-state .icon { width: 48px; height: 48px; opacity: 0.4; }
.empty-state h3 { color: var(--text-secondary); font-size: 16px; }

.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }

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

/* ============ INSPECTOR ============ */

#inspector {
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    width: 0;
    transition: width var(--transition-slow);
}
#inspector.open { width: var(--inspector-w); }

.inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-sidebar);
    z-index: 2;
}
.inspector-header h3 { font-size: 14px; font-weight: 600; }

.inspector-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.inspector-cover {
    width: 100%;
    max-width: 200px;
    margin: 0 auto 20px;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.inspector-cover img { width: 100%; display: block; }
.inspector-cover.no-cover {
    aspect-ratio: 2/3;
    background: var(--bg-surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.inspector-meta { text-align: center; margin-bottom: 20px; }
.inspector-title { font-size: 18px; font-weight: 700; line-height: 1.3; margin-bottom: 4px; }
.inspector-author { color: var(--text-secondary); font-size: 14px; }

.meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 6px;
}
.meta-row .icon { width: 14px; color: var(--text-muted); }

.inspector-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.inspector-section h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.inspector-description {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}
.inspector-description p { margin-bottom: 8px; }

.tag-list, .format-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
    padding: 3px 10px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border-radius: 12px;
    font-size: 12px;
}

.inspector-actions {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: sticky;
    bottom: 0;
    background: var(--bg-sidebar);
}

/* ============ COMMAND PALETTE ============ */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 20vh;
}

.palette-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.palette-dialog {
    position: relative;
    width: 560px;
    max-width: 90vw;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    animation: palette-in 0.15s ease-out;
}

@keyframes palette-in {
    from { opacity: 0; transform: scale(0.96) translateY(-8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.palette-search {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.palette-search .icon { color: var(--text-muted); flex-shrink: 0; }
.palette-search input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font);
    outline: none;
}
.palette-search input::placeholder { color: var(--text-muted); }

.palette-results {
    max-height: 360px;
    overflow-y: auto;
    padding: 6px;
}

.palette-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 8px 12px 4px;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 80ms;
}
.palette-item:hover, .palette-item.selected { background: var(--bg-hover); color: var(--text-primary); }

.palette-item-info { flex: 1; min-width: 0; }
.palette-item-title { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item-sub { display: block; font-size: 11px; color: var(--text-muted); }

.palette-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ============ CONTEXT MENU ============ */

.context-menu {
    position: fixed;
    z-index: 200;
    min-width: 180px;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    padding: 4px;
    animation: ctx-in 0.1s ease-out;
}

@keyframes ctx-in {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 80ms;
}
.ctx-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.ctx-danger:hover { background: var(--danger-bg); color: var(--danger); }
.ctx-divider { height: 1px; background: var(--border); margin: 4px 8px; }

/* ============ READER ============ */

#reader {
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(10px);
    align-items: stretch;
    padding: 0;
}

.reader-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.reader-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: rgba(15, 15, 26, 0.9);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 2;
}
.reader-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reader-controls { display: flex; gap: 4px; }
.reader-controls .btn-icon { font-size: 14px; font-weight: 600; width: auto; padding: 0 8px; }

.reader-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    padding: 40px 20px;
}

.reader-text {
    max-width: 680px;
    width: 100%;
    color: var(--text-secondary);
    line-height: 1.8;
    font-size: 18px;
}
.reader-text p { margin-bottom: 1em; }

.reader-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    padding-top: 100px;
}

/* ============ STORE ============ */

.store-view { padding: 32px; max-width: 800px; margin: 0 auto; }
.store-header { margin-bottom: 24px; }
.store-header h2 { font-size: 22px; font-weight: 700; }
.store-header p { margin-top: 4px; }

.store-search {
    position: relative;
    margin-bottom: 24px;
}
.store-search .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.store-search input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    transition: all var(--transition);
}
.store-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.store-results { display: flex; flex-direction: column; gap: 2px; }

.store-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all var(--transition);
}
.store-item:hover { border-color: var(--border-strong); }
.store-item-info { flex: 1; min-width: 0; }
.store-item-title {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.store-item-author {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ============ TOASTS ============ */

#toasts {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 10px 18px;
    background: var(--bg-surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: auto;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--accent); }

/* ============ ICONS ============ */

.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    line-height: 1;
}
.icon svg { width: 100%; height: 100%; }

/* ============ MISC ============ */

.text-muted { color: var(--text-muted); }
.text-small { font-size: 12px; }

/* ============ MOBILE ELEMENTS ============ */

.hamburger-btn {
    display: none;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 49;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.sidebar-backdrop.visible {
    display: block;
}

/* ============ RESPONSIVE ============ */

@media (max-width: 1024px) {
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 16px;
        padding: 20px;
    }
    .search-box { max-width: 360px; }
}

@media (max-width: 768px) {
    /* Force single-column layout */
    #app,
    #app.sidebar-collapsed,
    #app.inspector-open,
    #app.sidebar-collapsed.inspector-open {
        grid-template-columns: 1fr !important;
    }

    /* Show hamburger menu button */
    .hamburger-btn { display: inline-flex; }

    /* Hide desktop sidebar expand button */
    #btn-expand { display: none !important; }

    /* Sidebar — fixed drawer, hidden by default */
    #sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        width: min(280px, 85vw);
        z-index: 50;
        transform: translateX(-100%);
        transition: transform var(--transition-slow);
        box-shadow: none;
    }
    /* Override ALL desktop sidebar states on mobile */
    #app.sidebar-collapsed #sidebar,
    #app:not(.sidebar-collapsed) #sidebar {
        transform: translateX(-100%);
    }
    /* Mobile open state takes priority */
    #sidebar.mobile-open {
        transform: translateX(0) !important;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    }

    /* Search bar — full width */
    .search-box { max-width: none; flex: 1; }

    /* Hide keyboard shortcut hints */
    .kbd { display: none; }

    /* Topbar */
    #topbar {
        padding: 8px 12px;
        gap: 8px;
        height: auto;
        min-height: var(--topbar-h);
        flex-wrap: wrap;
    }

    /* Filter chips horizontal scroll */
    .filter-chips {
        max-width: none;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .filter-chips::-webkit-scrollbar { display: none; }

    .topbar-right { gap: 6px; }
    .sort-select { max-width: 120px; }

    /* Book grid */
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
        padding: 12px;
    }

    /* List view — fewer columns */
    .list-header, .list-row {
        grid-template-columns: 40px 1fr 40px;
    }
    .list-col-author, .list-col-format, .list-col-date { display: none; }
    .book-list { padding: 0 12px 12px; }

    /* Inspector — full-screen overlay */
    #inspector {
        position: fixed;
        top: 0; right: 0; bottom: 0;
        z-index: 55;
        width: 0 !important;
        max-width: 100vw;
        transition: width var(--transition-slow);
    }
    #inspector.open { width: 100vw !important; }

    /* Command palette — full screen */
    .overlay { padding-top: 0; align-items: stretch; }
    .palette-dialog {
        width: 100%;
        max-width: 100vw;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        height: 100%;
    }
    .palette-results { flex: 1; max-height: none; }

    /* Reader */
    .reader-toolbar { padding: 8px 12px; }
    .reader-content { padding: 20px 16px; }
    .reader-text { font-size: 16px; }

    /* Store */
    .store-view { padding: 16px; }
    .store-header h2 { font-size: 18px; }
    .store-item { flex-wrap: wrap; gap: 10px; }

    /* Touch-friendly tap targets (44px minimum) */
    .btn-icon { min-width: 44px; min-height: 44px; }
    .nav-item { padding: 12px; min-height: 44px; }
    .filter-toggle { padding: 10px 12px; min-height: 44px; }
    .filter-option { padding: 8px 10px; min-height: 44px; }
    .ctx-item { padding: 12px; min-height: 44px; }
    .palette-item { padding: 12px; min-height: 44px; }
    .btn { padding: 10px 14px; min-height: 44px; }
    .store-item { padding: 12px; }

    /* Always show card overlay (no hover on touch devices) */
    .card-overlay { opacity: 1; }

    /* Toasts — full width at bottom */
    #toasts { left: 12px; right: 12px; bottom: 12px; }
    .toast { width: 100%; }

    /* Context menu — bottom sheet */
    .context-menu {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        min-width: 100% !important;
        max-height: 60vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        animation: ctx-slide-up 0.2s ease-out;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    @keyframes ctx-slide-up {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .view-toggle .btn-icon {
        min-width: 38px; min-height: 38px;
        width: 38px; height: 38px;
    }
}

@media (max-width: 480px) {
    .book-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 10px;
    }

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

    /* Stack search full-width below controls */
    #topbar { flex-wrap: wrap; }
    .search-box { order: 10; flex-basis: 100%; margin-top: 4px; }
    .hamburger-btn { order: 1; }
    #btn-expand { order: 1; }
    .topbar-right { order: 2; margin-left: auto; }
    .filter-chips { order: 9; flex-basis: 100%; margin-top: 4px; }

    .sort-select { max-width: 100px; font-size: 11px; }

    .inspector-body { padding: 16px; }
    .inspector-title { font-size: 16px; }
    .inspector-author { font-size: 13px; }

    .reader-text { font-size: 15px; line-height: 1.7; }
    .reader-content { padding: 16px 12px; }
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .inspector-actions { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
    #toasts { bottom: calc(12px + env(safe-area-inset-bottom)); }
    .reader-toolbar { padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
}
