/* Librarzen - Main Styles */

:root {
    /* Light Theme (Default) */
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8ecf1;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --border-color: #e2e8f0;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --premium-gold: #fbbf24;
    
    /* Gaming/Tech aesthetic */
    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent-primary: #818cf8;
    --accent-secondary: #a5b4fc;
    --accent-glow: rgba(129, 140, 248, 0.3);
    --border-color: #334155;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    background: rgba(var(--bg-secondary), 0.9);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
}

.user-points {
    background: var(--accent-glow);
    color: var(--accent-primary);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    box-shadow: 0 2px 4px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px var(--accent-glow);
}

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

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-link {
    background: none;
    border: none;
    color: var(--accent-primary);
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}

.btn-danger {
    background: var(--bg-tertiary);
    color: var(--error, #e5484d);
    border: 1px solid var(--border-color);
}

.btn-danger:hover {
    background: var(--error, #e5484d);
    color: white;
    border-color: var(--error, #e5484d);
}

/* Hero Section */
.hero {
    text-align: center;
    padding: 4rem 0;
}

.hero h2 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.hero-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin: 2rem 0;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.premium-card {
    border: 2px solid var(--premium-gold);
    background: linear-gradient(135deg, var(--bg-secondary), rgba(251, 191, 36, 0.1));
    position: relative;
}

.premium-badge {
    position: absolute;
    top: -12px;
    right: 20px;
    background: var(--premium-gold);
    color: #000;
    padding: 0.25rem 1rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.75rem;
}

.premium-features {
    list-style: none;
    margin: 1.5rem 0;
}

.premium-features li {
    padding: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
}

.premium-features li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--success);
    font-weight: 700;
}

.premium-price {
    text-align: center;
    margin: 1.5rem 0;
}

.price-amount {
    font-size: 2rem;
    font-weight: 700;
    color: var(--premium-gold);
    font-family: var(--font-mono);
}

.premium-note {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

/* Ads Section */
.ads-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin: 2rem 0;
}

.ad-card {
    background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    text-align: center;
}

.ad-card h4 {
    margin-bottom: 0.5rem;
    color: var(--accent-primary);
}

/* Sections */
.section {
    padding: 2rem 0;
}

/* Novels Grid */
.novels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.novel-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    border: 1px solid var(--border-color);
}

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

.novel-cover {
    height: 200px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
}

.novel-info-card {
    padding: 1rem;
}

.novel-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.novel-meta {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Chapters List */
.chapters-list {
    margin-top: 1.5rem;
}

.chapter-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border: 1px solid var(--border-color);
}

.chapter-item:hover {
    background: var(--bg-tertiary);
}

.chapter-item.locked {
    opacity: 0.7;
}

.chapter-item.locked::after {
    content: "🔒";
    margin-left: 0.5rem;
}

/* Reader View */
.reader-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.font-controls {
    display: flex;
    gap: 0.5rem;
}

.chapter-content {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: var(--radius-lg);
    font-size: 1.125rem;
    line-height: 1.8;
    max-width: 800px;
    margin: 0 auto;
    white-space: pre-wrap;
}

.reader-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Forms */
.form {
    max-width: 600px;
    margin: 0 auto;
}

.form-group {
    margin-bottom: 1.5rem;
}

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

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea.form-control {
    resize: vertical;
    font-family: inherit;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.form-note {
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
}

/* ============================================
   COMMENTS
   ============================================ */

.comments {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.comments-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.comments-title {
    font-size: 1.25rem;
}

.comments-count {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.comments-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.comments-empty {
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.comment {
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}

.comment-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.comment-author {
    font-weight: 600;
    font-size: 0.9375rem;
}

.comment-date {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

/* Pushed to the end of the row, so the head stays author · date · control. */
.comment-delete {
    margin-left: auto;
}

.comment-body {
    margin: 0;
    line-height: 1.7;
    /* A comment is a stranger's words, and it is never markup. */
    white-space: pre-wrap;
    word-break: break-word;
}

.comment-form {
    margin-top: 1.5rem;
}

.comment-form textarea {
    resize: vertical;
}

.comments-notice {
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ============================================
   ENTERPRISE
   ============================================ */

/* The badge in the header, saying the reader's organisation has the tier. */
.enterprise-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: rgba(245, 158, 11, 0.2);
    color: #d97706;
    border: 1px solid rgba(245, 158, 11, 0.4);
    white-space: nowrap;
}

/* On a dark background the amber needs lifting, or it disappears. */
[data-theme="dark"] .enterprise-badge {
    background: rgba(245, 158, 11, 0.18);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.35);
}

/* Modal */
.modal {
    border: none;
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 500px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.modal-content h3 {
    margin-bottom: 1.5rem;
    color: var(--accent-primary);
}

.legal-text {
    margin-bottom: 1.5rem;
    max-height: 400px;
    overflow-y: auto;
}

.legal-text h4 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.legal-text p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Footer */
.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    margin-top: 4rem;
    text-align: center;
}

.footer p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.legal-links {
    margin-top: 0.5rem;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Writer Dashboard */
.writer-actions {
    margin-bottom: 2rem;
}

.my-novels {
    display: grid;
    gap: 1rem;
}

.novel-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.novel-row-actions {
    display: flex;
    gap: 0.5rem;
}

.my-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.item-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .header-content {
        flex-wrap: wrap;
    }
    
    .nav {
        width: 100%;
        justify-content: space-between;
        margin-top: 1rem;
    }
    
    .hero h2 {
        font-size: 1.75rem;
    }
    
    .hero-actions {
        flex-direction: column;
    }
    
    .novels-grid {
        grid-template-columns: 1fr;
    }
    
    .chapter-content {
        padding: 1rem;
        font-size: 1rem;
    }
}

/* RTL Support for Arabic */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .premium-features li {
    padding-right: 1.5rem;
    padding-left: 0;
}

[dir="rtl"] .premium-features li::before {
    right: 0;
    left: auto;
}

/* Search results metadata and the scope note below it. */
.search-stats {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.search-scope-note {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.35rem;
    line-height: 1.4;
}

/* Category picker on the create-novel form. */
.tag-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag-option {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem;
}

.tag-option:has(input:checked) {
    border-color: var(--primary-color);
    background: rgba(47, 98, 235, 0.08);
}

.novel-tags {
    margin-top: 0.35rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.novel-tags .tag {
    font-size: 0.7rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}
