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

:root {
    --primary-color: #FFD700;
    --primary-dark: #FFA500;
    --secondary-color: #8B00FF;
    --accent-electric: #00D9FF;
    --background: #0A0E27;
    --card-background: #1A1F3A;
    --text-primary: #FFFFFF;
    --text-secondary: #B8B8D1;
    --border-color: #2D3561;
    --shadow: 0 4px 20px rgba(255, 215, 0, 0.1);
    --shadow-hover: 0 8px 32px rgba(255, 215, 0, 0.3);
    --glow: 0 0 20px rgba(255, 215, 0, 0.5);
    --glow-electric: 0 0 30px rgba(0, 217, 255, 0.6);
}

html {
    overflow-x: hidden;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    background-image: 
        radial-gradient(ellipse at 20% 20%, rgba(139, 0, 255, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(255, 215, 0, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(0, 217, 255, 0.05) 0%, transparent 70%);
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* Index Page Styles */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px 0;
}

header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
}

header h1.logo {
    color: white;
    font-weight: 700;
    font-size: 1.75rem;
    letter-spacing: -0.5px;
    font-family: 'Space Grotesk', 'Poppins', 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    display: flex;
    align-items: center;
    gap: 10px;
    text-transform: none;
}

header h1.logo .spark-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}


/* Search and Actions Section */
.search-and-actions {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.search-bar {
    position: relative;
    flex: 0 0 50%;
    display: flex;
    align-items: center;
    background: var(--card-background);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 4px;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
    animation: search-pulse 3s ease-in-out infinite;
}

@keyframes search-pulse {
    0%, 100% {
        box-shadow: var(--shadow);
    }
    50% {
        box-shadow: 0 4px 20px rgba(255, 215, 0, 0.15), 0 0 15px rgba(255, 215, 0, 0.1);
    }
}

.search-bar:focus-within {
    border-color: var(--primary-color);
    box-shadow: var(--glow);
    transform: translateY(-2px);
    animation: none;
}

.search-icon {
    margin-left: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: color 0.3s ease;
}

.search-bar:focus-within .search-icon {
    color: var(--primary-color);
}

#book-search {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
}

#book-search::placeholder {
    color: var(--text-secondary);
}

.clear-search {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    padding: 8px 12px;
    margin-right: 4px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.clear-search:hover {
    background: var(--background);
    color: var(--text-primary);
}

.action-buttons {
    display: flex;
    gap: 12px;
    align-items: center;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card-background);
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
    padding: 12px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.action-btn svg {
    flex-shrink: 0;
}

.action-btn:hover {
    color: var(--text-primary);
    border-color: var(--primary-color);
    box-shadow: var(--glow);
    transform: translateY(-2px);
}

/* Grid Layout Dropdown */
.grid-layout-dropdown,
.category-dropdown {
    position: relative;
    display: inline-block;
}

.category-dropdown.has-filters #category-filter-btn {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.2);
}

.category-dropdown #category-filter-btn span {
    font-weight: 500;
    white-space: nowrap;
}

.grid-layout-menu,
.category-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--card-background);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    padding: 8px;
    min-width: 160px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 1000;
}

.category-menu {
    min-width: 200px;
    max-height: 400px;
    overflow-y: auto;
}

.grid-layout-dropdown:hover .grid-layout-menu,
.category-dropdown:hover .category-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.menu-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 12px 4px;
    margin-bottom: 4px;
}

.menu-option {
    width: 100%;
    background: transparent;
    color: var(--text-primary);
    border: 2px solid transparent;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    text-align: left;
    transition: all 0.2s ease;
    margin-bottom: 4px;
}

.menu-option:last-child {
    margin-bottom: 0;
}

.menu-option:hover {
    background: var(--background);
    border-color: var(--border-color);
}

.menu-option.active {
    background: var(--background);
    color: var(--text-primary);
    border-color: var(--primary-color);
    font-weight: 600;
}

/* Category Options with Checkboxes */
.category-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 4px;
    user-select: none;
}

.category-option:last-child {
    margin-bottom: 0;
}

.category-option:hover {
    background: var(--background);
}

.category-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
    flex-shrink: 0;
}

.category-option-label {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.category-option-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--background);
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
}

.category-option.checked {
    background: var(--background);
    border: 2px solid var(--primary-color);
    padding: 8px 10px; /* Adjust for border */
}

.category-option.checked .category-option-label {
    font-weight: 600;
}

/* Category Filter */
.category-filter {
    margin-bottom: 30px;
}

.category-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.category-btn {
    padding: 8px 18px;
    background: var(--card-background);
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.category-btn:hover {
    color: var(--text-primary);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.2);
}

.category-btn.active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--background);
    border-color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

.category-btn.active:hover {
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.category-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.category-btn.active .category-count {
    background: rgba(0, 0, 0, 0.2);
}

.upload-hint-section {
    margin-bottom: 30px;
}

.upload-hint-section .upload-hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.upload-section {
    text-align: center;
    margin-bottom: 40px;
    padding: 40px;
    background: var(--card-background);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.upload-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 215, 0, 0.1),
        transparent
    );
    animation: lightning-sweep 4s infinite;
}

@keyframes lightning-sweep {
    0% {
        left: -100%;
    }
    50%, 100% {
        left: 100%;
    }
}

.upload-btn {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--background);
    padding: 16px 32px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    font-weight: 700;
    border: 2px solid var(--primary-color);
    font-family: inherit;
    position: relative;
    overflow: hidden;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.upload-btn::after {
    content: '⚡';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.5rem;
    opacity: 0;
    transition: all 0.3s ease;
}

.upload-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: var(--glow);
    filter: brightness(1.2);
}

.upload-btn:hover::after {
    opacity: 1;
    right: 15px;
}

.upload-hint {
    margin-top: 15px;
    color: var(--text-secondary);
}

.books-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 30px;
    margin-top: 30px;
}

/* Books per row variants */
.books-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.books-grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.books-grid-5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.books-grid-6 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

@media (max-width: 1600px) {
    .books-grid-6 {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (max-width: 1400px) {
    .books-grid-5,
    .books-grid-6 {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1200px) {
    .books-grid,
    .books-grid-3,
    .books-grid-4,
    .books-grid-5,
    .books-grid-6 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .books-grid,
    .books-grid-3,
    .books-grid-4,
    .books-grid-5,
    .books-grid-6 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .books-grid,
    .books-grid-3,
    .books-grid-4,
    .books-grid-5,
    .books-grid-6 {
        /* Keep 2 columns even on small screens for better book browsing */
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

.book-card {
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    position: relative;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.book-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 8px;
    opacity: 0;
    background: radial-gradient(circle at center, rgba(255, 215, 0, 0.2), transparent);
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.book-card:hover {
    transform: translateY(-12px);
}

.book-card:hover::before {
    opacity: 1;
    animation: pulse-spark 1.5s ease-in-out infinite;
}

@keyframes pulse-spark {
    0%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

.book-cover {
    width: 100%;
    max-width: 100%;
    aspect-ratio: 2 / 3;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    overflow: hidden;
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    position: relative;
}

.book-cover::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(255, 215, 0, 0.1) 50%,
        transparent 70%
    );
    animation: rotate-glow 4s linear infinite;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

.book-card:hover .book-cover {
    box-shadow: var(--glow);
    border-color: var(--primary-color);
}

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

.book-card h3 {
    margin: 15px 0 8px;
    color: var(--text-primary);
    font-size: 1.2rem;
    display: none; /* Hide title below book card */
}

.book-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    display: none; /* Hide author below book card */
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: var(--card-background);
    margin: 5% auto;
    padding: 0;
    border-radius: 16px;
    border: 2px solid var(--border-color);
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow-hover), 0 0 50px rgba(255, 215, 0, 0.2);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 30px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    color: var(--text-primary);
}

.close {
    color: var(--text-secondary);
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s ease;
}

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

.modal-body {
    padding: 30px;
}

.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    background: var(--background);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
}

.form-group small {
    display: block;
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.save-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--background);
    border: 2px solid var(--primary-color);
    padding: 14px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.save-btn::before {
    content: '⚡';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 2rem;
    opacity: 0;
    transition: all 0.3s ease;
}

.save-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow);
}

.save-btn:hover::before {
    transform: translate(-50%, -50%) scale(3);
    opacity: 0.2;
}

/* Conversation Page Styles */
.conversation-container {
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height on supported browsers */
    display: flex;
    flex-direction: row;
    background: var(--background);
    overflow: hidden;
    position: relative;
}

/* Desktop Sidebar */
.desktop-sidebar {
    width: 16%;
    min-width: 220px;
    max-width: 280px;
    background: #060A1A;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    flex-shrink: 0;
}

.desktop-sidebar-content {
    padding: 10px 0;
}

.desktop-sidebar-section {
    padding: 0;
    border-bottom: none;
}

.desktop-sidebar-section:last-child {
    border-bottom: none;
}

.desktop-sidebar-section-title {
    padding: 12px 16px 8px;
    margin: 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.desktop-sidebar-auth,
.desktop-sidebar-item {
    width: 100%;
    background: transparent;
    border: none;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 400;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
    text-align: left;
}

.desktop-sidebar-auth:hover,
.desktop-sidebar-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.desktop-sidebar-conversations {
    max-height: 60vh;
    overflow-y: auto;
}

.desktop-sidebar-conversation {
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
    text-align: left;
    width: 100%;
    border-bottom: none;
}

.desktop-sidebar-conversation:hover {
    background: rgba(255, 255, 255, 0.05);
}

.desktop-sidebar-conversation.active {
    background: rgba(255, 215, 0, 0.1);
    border-left: 3px solid var(--primary-color);
}

.desktop-sidebar-conversation-icon {
    width: 28px;
    height: 28px;
    background: rgba(255, 215, 0, 0.1);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.desktop-sidebar-conversation-info {
    flex: 1;
    min-width: 0;
}

.desktop-sidebar-conversation-title {
    font-weight: 400;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.85rem;
}

.desktop-sidebar-conversation-author {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.desktop-sidebar-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Main conversation area */
.conversation-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* Mobile Menu Button - Hidden on desktop */
.mobile-menu-btn {
    display: none;
}

/* Mobile Side Menu */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
    display: block;
    opacity: 1;
}

.mobile-menu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80%;
    max-width: 320px;
    background: #060A1A;
    z-index: 10001;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.3);
}

.mobile-menu.active {
    transform: translateX(0);
}

.mobile-menu-content {
    padding: 10px 0;
}

.mobile-menu-section {
    padding: 0;
    border-bottom: none;
}

.mobile-menu-section:last-child {
    border-bottom: none;
}

.mobile-menu-section-title {
    padding: 12px 16px 8px;
    margin: 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.mobile-menu-auth {
    width: 100%;
    background: transparent;
    border: none;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 400;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
    text-align: left;
}

.mobile-menu-auth:hover {
    background: rgba(255, 255, 255, 0.05);
}

.mobile-menu-item {
    width: 100%;
    background: transparent;
    border: none;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 400;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
    text-align: left;
}

.mobile-menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.mobile-menu-conversations {
    max-height: 400px;
    overflow-y: auto;
}

.mobile-menu-conversation {
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
    text-align: left;
    width: 100%;
    border-bottom: none;
}

.mobile-menu-conversation:hover {
    background: rgba(255, 255, 255, 0.05);
}

.mobile-menu-conversation.active {
    background: rgba(255, 215, 0, 0.1);
    border-left: 3px solid var(--primary-color);
}

.mobile-menu-conversation-icon {
    width: 28px;
    height: 28px;
    background: rgba(255, 215, 0, 0.1);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.mobile-menu-conversation-info {
    flex: 1;
    min-width: 0;
}

.mobile-menu-conversation-title {
    font-weight: 400;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.85rem;
}

.mobile-menu-conversation-author {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-menu-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.chat-header {
    background: var(--card-background);
    padding: 20px 30px;
    box-shadow: var(--shadow);
    border-bottom: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    position: relative;
}

.chat-header::before {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 30%;
    height: 2px;
    background: linear-gradient(90deg, var(--primary-color), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Animate only when waiting for response */
.chat-header.loading::before {
    opacity: 1;
    animation: slide-glow 3s ease-in-out infinite;
}

@keyframes slide-glow {
    0%, 100% {
        left: 0;
        width: 30%;
    }
    50% {
        left: 70%;
        width: 30%;
    }
}

/* Hide auth container on desktop (it's in the sidebar) */
.chat-header .auth-container {
    display: none;
}

.book-info {
    flex: 1;
    min-width: 200px;
}

.book-info h2 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.book-info p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.book-stats {
    display: flex;
    gap: 20px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.book-stats .stat {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: var(--background);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.book-stats .stat strong {
    color: var(--primary-color);
    font-weight: 600;
}

.book-stats .stat span {
    font-family: 'Courier New', monospace;
    font-weight: 500;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.model-selector label {
    font-weight: 600;
}

.model-selector select {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    background: var(--background);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
}

.model-selector select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.2);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
    justify-content: center;
}

.welcome-message {
    text-align: center;
    width: 100%;
    max-width: 600px;
    padding: 0;
    background: transparent;
    margin: 0 auto;
}

.welcome-message p {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'SF Pro Display', 'Inter', 'Helvetica Neue', system-ui, sans-serif;
    letter-spacing: -0.01em;
    line-height: 1.4;
    margin: 0;
}

.message {
    display: flex;
    gap: 12px;
    animation: messageSlideIn 0.3s ease;
}

.message.assistant {
    max-width: 100%;
    width: 100%;
    position: relative;
}

.message.user {
    max-width: 80%;
}

/* Speech button for assistant messages */
.speech-btn {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
    color: var(--text-secondary);
}

.speech-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.speech-btn.loading {
    opacity: 0.6;
    cursor: wait;
}

.speech-btn.loading svg {
    animation: spin 1s linear infinite;
}

.speech-btn.playing {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

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

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

.message.user {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.15) 0%, rgba(218, 165, 32, 0.15) 100%);
    color: var(--text-primary);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.1);
    border: 1px solid rgba(255, 215, 0, 0.2);
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--accent-electric) 100%);
    color: white;
    box-shadow: 0 0 15px rgba(139, 0, 255, 0.5);
}

.message-content {
    width: 100%;
}

.message.user .message-content {
    background: rgba(255, 215, 0, 0.08);
    color: var(--text-primary);
    border: 1px solid rgba(255, 215, 0, 0.2);
    font-weight: 500;
    padding: 15px 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message.assistant .message-content {
    background: transparent;
    padding: 20px 0;
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text-primary);
}

.message-content p {
    margin: 0;
    white-space: pre-wrap;
}

.message.assistant .message-content p {
    line-height: 1.8;
    margin-bottom: 1em;
}

.message.user .message-content p {
    line-height: 1.6;
}

/* Markdown rendering styles for assistant messages */
.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3,
.message.assistant .message-content h4 {
    color: var(--primary-color);
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
}

.message.assistant .message-content h1 {
    font-size: 1.5em;
}

.message.assistant .message-content h2 {
    font-size: 1.3em;
}

.message.assistant .message-content h3 {
    font-size: 1.1em;
}

.message.assistant .message-content ul,
.message.assistant .message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message.assistant .message-content li {
    margin: 0.3em 0;
}

.message.assistant .message-content strong {
    font-weight: 700;
    color: var(--text-primary);
}

.message.assistant .message-content em {
    font-style: italic;
    color: var(--text-primary);
}

.message.assistant .message-content code {
    background: rgba(255, 215, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: var(--primary-color);
}

.message.assistant .message-content pre {
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.message.assistant .message-content pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
}

.message.assistant .message-content blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 1em;
    margin: 0.5em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.message.assistant .message-content a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s ease;
}

.message.assistant .message-content a:hover {
    border-bottom-color: var(--primary-color);
}

.message.assistant .message-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1em 0;
}

.message.assistant .message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5em 0;
}

.message.assistant .message-content th,
.message.assistant .message-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.message.assistant .message-content th {
    background: var(--background);
    font-weight: 600;
    color: var(--primary-color);
}

.message.assistant .message-content p:first-child {
    margin-top: 0;
}

.message.assistant .message-content p:last-child {
    margin-bottom: 0;
}

/* Streaming message animation - removed blinking cursor */

/* Suggestions */
.suggestions-wrapper {
    background: transparent;
    padding: 0 30px 15px 30px;
    flex-shrink: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.suggestions-toggle {
    width: 100%;
    background: var(--card-background);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.suggestions-toggle:hover {
    background: var(--background);
    border-color: var(--primary-color);
    color: var(--text-primary);
}

.suggestions-toggle .suggestions-icon {
    flex-shrink: 0;
}

.suggestions-toggle span {
    flex: 1;
    text-align: left;
    font-weight: 500;
}

.suggestions-toggle .chevron {
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.suggestions-toggle.expanded .chevron {
    transform: rotate(180deg);
}

.suggestions-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: 0;
}

.suggestions-content.expanded {
    max-height: 500px;
    opacity: 1;
    padding-top: 12px;
}

.suggestion-chip {
    background: var(--background);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    padding: 12px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: inherit;
    text-align: left;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.suggestion-chip:hover {
    background: var(--card-background);
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.chat-input-container {
    background: transparent;
    padding: 20px 30px;
    display: flex;
    gap: 15px;
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 24px;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    background: var(--background);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

#chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
}

#send-btn {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--background);
    border: 2px solid var(--primary-color);
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

#send-btn::before {
    content: '⚡';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0) rotate(0deg);
    font-size: 2rem;
    opacity: 0;
    transition: all 0.4s ease;
}

#send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--glow);
}

#send-btn:hover:not(:disabled)::before {
    transform: translate(-50%, -50%) scale(2) rotate(15deg);
    opacity: 0.3;
}

#send-btn:disabled {
    background: linear-gradient(135deg, var(--border-color) 0%, var(--text-secondary) 100%);
    cursor: not-allowed;
    opacity: 0.5;
    border-color: var(--border-color);
}

.loading-indicator {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-background);
    padding: 15px 30px;
    border-radius: 12px;
    box-shadow: var(--shadow-hover);
    display: flex;
    align-items: center;
    gap: 12px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid transparent;
    border-top-color: var(--primary-color);
    border-right-color: var(--accent-electric);
    border-radius: 50%;
    animation: spin 0.8s linear infinite, glow-pulse 2s ease-in-out infinite;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

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

@keyframes glow-pulse {
    0%, 100% {
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
    }
    50% {
        box-shadow: 0 0 25px rgba(255, 215, 0, 0.8), 0 0 35px rgba(0, 217, 255, 0.5);
    }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
}

/* Footer */
.footer {
    background: var(--card-background);
    border-top: 2px solid var(--border-color);
    margin-top: 60px;
    padding: 40px 20px 20px;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 40px;
    margin-bottom: 30px;
}

.footer-section h3,
.footer-section h4 {
    color: var(--text-primary);
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.footer-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Space Grotesk', 'Poppins', 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
}

.footer-logo .spark-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.footer-tagline {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 8px;
}

.footer-links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-links li {
    margin-bottom: 10px;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.3s ease;
    display: inline-block;
}

.footer-links a:hover {
    color: var(--primary-color);
    transform: translateX(5px);
}

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

.footer-bottom {
    max-width: 1400px;
    margin: 0 auto;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Modal for Terms and Privacy */
.legal-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

.legal-modal-content {
    background-color: var(--card-background);
    margin: 3% auto;
    padding: 0;
    border-radius: 16px;
    border: 2px solid var(--border-color);
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    box-shadow: var(--shadow-hover), 0 0 50px rgba(255, 215, 0, 0.2);
    animation: slideDown 0.3s ease;
    display: flex;
    flex-direction: column;
}

.legal-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 30px;
    border-bottom: 1px solid var(--border-color);
}

.legal-modal-header h2 {
    color: var(--text-primary);
    margin: 0;
}

.legal-modal-body {
    padding: 30px;
    overflow-y: auto;
    flex: 1;
}

.legal-modal-body h3 {
    color: var(--primary-color);
    margin-top: 25px;
    margin-bottom: 15px;
}

.legal-modal-body p,
.legal-modal-body ul {
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 15px;
}

.legal-modal-body ul {
    padding-left: 20px;
}

.legal-modal-body li {
    margin-bottom: 8px;
}

/* GDPR Cookie Consent Banner */
.cookie-consent {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-background);
    border-top: 2px solid var(--primary-color);
    box-shadow: 0 -4px 30px rgba(255, 215, 0, 0.2);
    z-index: 3000;
    animation: slideUp 0.5s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.cookie-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 25px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 30px;
    flex-wrap: wrap;
}

.cookie-text {
    flex: 1;
    min-width: 300px;
}

.cookie-text h3 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.cookie-text p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
    font-size: 0.95rem;
}

.cookie-buttons {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.cookie-btn {
    padding: 12px 30px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    font-family: inherit;
}

.cookie-btn-accept {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--background);
    border-color: var(--primary-color);
}

.cookie-btn-accept:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow);
}

.cookie-btn-decline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.cookie-btn-decline:hover {
    color: var(--text-primary);
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
}

@media (max-width: 768px) {
    .cookie-content {
        flex-direction: column;
        align-items: stretch;
    }
    
    .cookie-buttons {
        justify-content: stretch;
    }
    
    .cookie-btn {
        flex: 1;
    }
}

@keyframes slideDown {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(100%);
    }
}

/* ========================================
   MOBILE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
    /* Hide desktop sidebar on mobile */
    .desktop-sidebar {
        display: none;
    }
    
    /* Conversation container goes back to column layout on mobile */
    .conversation-container {
        flex-direction: column;
    }
    
    /* Prevent horizontal overflow and unwanted zooming */
    html, body {
        max-width: 100%;
        overflow-x: hidden;
        /* Prevent iOS text size adjustment on orientation change */
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
    
    /* Container and spacing */
    .container {
        padding: 15px;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Ensure all major containers don't overflow */
    .chat-container,
    .conversation-header,
    .chat-messages,
    .chat-input-container,
    .suggestions-wrapper,
    .footer,
    .cookie-consent {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Header */
    header {
        margin-bottom: 20px;
        padding: 15px 0;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .spark-icon {
        width: 24px;
        height: 24px;
    }
    
    /* Search and actions */
    .search-and-actions {
        flex-direction: column;
        gap: 12px;
        max-width: 100%;
    }
    
    .search-bar {
        width: 100%;
        max-width: 100%;
        flex: 1;
    }
    
    .search-bar input {
        width: 100%;
        max-width: 100%;
    }
    
    .category-dropdown {
        width: 100%;
    }
    
    .category-dropdown #category-filter-btn {
        width: 100%;
        justify-content: center;
    }
    
    .action-buttons {
        width: 100%;
        max-width: 100%;
        justify-content: space-between;
    }
    
    .action-btn {
        flex: 1;
        padding: 10px 12px;
        font-size: 0.85rem;
        min-width: 0;
        max-width: 100%;
    }
    
    /* Grid layout dropdown - hide on mobile, use default */
    .grid-layout-dropdown,
    .category-dropdown {
        display: none;
    }
    
    /* Categories */
    .category-buttons {
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .category-buttons::-webkit-scrollbar {
        display: none;
    }
    
    .category-btn {
        white-space: nowrap;
        padding: 8px 16px;
        font-size: 0.85rem;
    }
    
    /* Book cards - always 2 columns on mobile */
    .books-grid,
    .books-grid-3,
    .books-grid-4,
    .books-grid-5,
    .books-grid-6 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px;
        max-width: 100%;
    }
    
    .book-card {
        font-size: 0.85rem;
        max-width: 100%;
        overflow: hidden;
    }
    
    .book-cover {
        /* Keep proper book aspect ratio on mobile (2:3 like physical books) */
        aspect-ratio: 2 / 3;
        width: 100%;
        height: auto;
        max-width: 100%;
    }
    
    .book-cover img {
        max-width: 100%;
        height: 100%;
        object-fit: contain;
    }
    
    .book-title {
        font-size: 0.9rem;
        margin: 8px 0 4px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .book-author {
        font-size: 0.75rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* Footer */
    .footer {
        padding: 30px 15px;
    }
    
    .footer-content {
        gap: 25px;
    }
    
    .footer-section h3,
    .footer-section h4 {
        font-size: 1rem;
    }
    
    /* Modals */
    .modal-content,
    .legal-modal-content {
        width: 95%;
        max-width: none;
        margin: 10px;
    }
    
    .modal-header,
    .legal-modal-header {
        padding: 20px;
    }
    
    .modal-body,
    .legal-modal-body {
        padding: 20px;
    }
    
    /* Cookie consent */
    .cookie-consent {
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 0;
    }
    
    .cookie-text {
        min-width: auto;
    }
    
    .cookie-text h3 {
        font-size: 1rem;
    }
    
    .cookie-text p {
        font-size: 0.85rem;
    }
}

/* Header tap area for mobile */
.header-tap-area {
    display: none;
}

.tap-indicator {
    display: none;
}

/* Auth Container and Button Styles */
.auth-container {
    position: relative;
    display: inline-block;
}

#auth-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: var(--card-background);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
}

#auth-btn:hover {
    border-color: var(--primary-color);
    box-shadow: var(--glow);
}

#auth-btn svg {
    width: 20px;
    height: 20px;
}

/* User Menu Dropdown */
.user-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 150px;
    background: var(--card-background);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-hover);
    z-index: 1000;
}

.user-menu .menu-item {
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    transition: background 0.2s ease;
    font-size: 0.95rem;
}

.user-menu .menu-item:hover {
    background: rgba(255, 215, 0, 0.1);
}

/* Auth Modal Styles */
.auth-modal-content {
    max-width: 400px;
    padding: 40px;
}

.auth-modal-content h2 {
    margin-bottom: 30px;
    color: var(--text-primary);
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(26, 31, 58, 0.5);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.1);
}

.auth-error {
    margin: 15px 0;
    padding: 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    text-align: center;
    min-height: 20px;
}

.auth-submit-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    color: var(--background);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.auth-submit-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--glow);
}

.auth-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-toggle {
    margin-top: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-toggle a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.auth-toggle a:hover {
    text-decoration: underline;
}

/* Mobile back button - hidden on desktop */
.back-btn-mobile {
    display: none;
}

.back-btn-desktop {
    display: inline-block;
}

/* Conversation Page Mobile */
@media (max-width: 768px) {
    /* Ensure conversation container fits viewport exactly */
    .conversation-container {
        /* Use visual viewport height to account for keyboard */
        height: 100vh;
        height: 100svh; /* Small viewport height - excludes keyboard */
        max-height: 100vh;
        max-height: 100svh;
        overflow: hidden;
        position: relative;
    }
    
    /* Mobile menu button - show on mobile */
    .mobile-menu-btn {
        display: flex;
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 9999; /* High z-index to stay above keyboard and all overlays */
        background: transparent;
        color: var(--text-primary);
        border: none;
        width: 44px;
        height: 44px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        transition: all 0.3s ease;
        /* Ensure it stays fixed even with keyboard */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        will-change: transform;
    }
    
    .mobile-menu-btn:hover {
        color: var(--primary-color);
    }
    
    .back-btn-desktop {
        display: none;
    }
    
    /* Header tap area - hidden on mobile since header is always visible */
    .header-tap-area {
        display: none;
    }
    
    .tap-indicator {
        display: none;
    }
    
    /* Header - always visible on mobile, compact design */
    .chat-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 9997; /* Below back button, but above content */
        background: var(--card-background);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        padding: 8px 15px 8px 60px; /* Space for menu button on left */
        display: flex;
        align-items: center;
        justify-content: flex-start;
        border-bottom: 1px solid var(--border-color);
        min-height: 56px;
        /* Ensure it stays fixed even with keyboard */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        will-change: transform;
    }
    
    /* Conversation header */
    .conversation-header {
        padding: 15px;
    }
    
    .book-info {
        text-align: left;
        min-width: 0;
        flex: 1;
        position: relative;
        display: flex;
        align-items: center;
    }
    
    .book-info h2 {
        font-size: 1rem;
        font-weight: 600;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        position: relative;
        max-width: 100%;
        /* Fade out effect */
        mask-image: linear-gradient(to right, black 80%, transparent 100%);
        -webkit-mask-image: linear-gradient(to right, black 80%, transparent 100%);
    }
    
    /* Hide author on mobile */
    .book-info p {
        display: none;
    }
    
    /* Auth button - hide on mobile, shown in menu instead */
    .chat-header .auth-container {
        display: none;
    }
    
    /* Stats on same line with smaller font */
    .book-stats {
        display: flex;
        flex-wrap: nowrap;
        gap: 12px;
        align-items: center;
    }
    
    .stat {
        font-size: 0.7rem;
        white-space: nowrap;
    }
    
    .stat strong {
        font-weight: 500;
    }
    
    /* Chat messages - adjust for tap area */
    .chat-messages {
        padding: 15px;
        padding-top: 60px; /* Space for fixed header */
        max-width: 100%;
        overflow-x: hidden;
        overflow-y: auto;
        flex: 1;
        min-height: 0; /* Important for flex children to scroll properly */
    }
    
    .message.user {
        max-width: 90%;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .message.assistant {
        max-width: 100%;
        width: 100%;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 1rem;
        flex-shrink: 0;
    }
    
    .message.user .message-content {
        font-size: 0.9rem;
        padding: 12px 16px;
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 100%;
    }
    
    .message.assistant .message-content {
        font-size: 1rem;
        padding: 15px 0;
        line-height: 1.75;
    }
    
    .message-content * {
        max-width: 100%;
        overflow-wrap: break-word;
    }
    
    .message-content pre,
    .message-content code {
        white-space: pre-wrap;
        word-break: break-all;
    }
    
    /* Suggestions */
    .suggestions-wrapper {
        padding: 0 15px 12px 15px;
    }
    
    .suggestions-toggle {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
    
    .suggestion-chip {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
    
    /* Chat input */
    .chat-input-container {
        padding: 12px 15px;
        gap: 10px;
        flex-shrink: 0;
        min-height: 0;
    }
    
    #chat-input {
        /* IMPORTANT: font-size must be at least 16px (1rem) to prevent iOS auto-zoom */
        font-size: 16px;
        padding: 10px 14px;
        border-radius: 20px;
    }
    
    #send-btn {
        width: 44px;
        height: 44px;
    }
    
    /* Loading indicator */
    .loading-indicator {
        bottom: 80px;
        font-size: 0.85rem;
    }
}

/* Extra small phones */
@media (max-width: 400px) {
    header h1 {
        font-size: 1.5rem;
    }
    
    /* Keep 2 columns even on extra small screens with tighter spacing */
    .books-grid,
    .books-grid-3,
    .books-grid-4,
    .books-grid-5,
    .books-grid-6 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }
    
    /* Show "Sign In" text on mobile, hide other button text */
    .action-btn span {
        display: none;
    }
    
    /* Exception: Show sign in button text */
    #auth-btn span {
        display: inline;
    }
    
    .action-btn {
        padding: 12px;
    }
    
    .message.user {
        max-width: 95%;
    }
    
    .message.assistant {
        max-width: 100%;
        width: 100%;
    }
}

/* Landscape mobile optimization */
@media (max-height: 600px) and (orientation: landscape) {
    .chat-messages {
        padding: 10px;
    }
    
    .conversation-header {
        padding: 10px 15px;
    }
    
    .chat-header {
        min-height: 48px;
    }
    
    .book-info h2 {
        font-size: 0.95rem;
    }
    
    .book-stats {
        display: none;
    }
}

/* Touch improvements for all mobile devices */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    button,
    .action-btn,
    .category-btn,
    .book-card,
    .suggestions-toggle,
    .suggestion-chip {
        min-height: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .book-card:hover {
        transform: none;
    }
    
    /* Make dropdowns tap-friendly */
    .grid-layout-menu {
        display: none;
    }
}

