/* ── Reset & Base ──────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --success: #22c55e;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.12);
}

body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
}

/* ── Container ────────────────────────────────────── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ── Topbar ───────────────────────────────────────── */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    height: 60px;
    gap: 24px;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}
.logo:hover { text-decoration: none; }

.nav-links {
    display: flex;
    gap: 16px;
    flex: 1;
}

.nav-links a {
    color: var(--text-muted);
    font-weight: 500;
    padding: 4px 0;
}
.nav-links a:hover,
.nav-links a.active {
    color: var(--primary);
    text-decoration: none;
}

.auth-area {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

[dir="rtl"] .auth-area {
    margin-left: 0;
    margin-right: auto;
}

/* Language toggle button */
.btn-lang {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 4px 12px;
    cursor: pointer;
    border-radius: 16px;
}
.btn-lang:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.username-display {
    font-weight: 500;
    color: var(--text-muted);
}

/* ── Buttons ──────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 18px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all .15s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-dark);
    text-decoration: none;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}

.btn-full {
    width: 100%;
}

.btn-lg {
    padding: 12px 28px;
    font-size: 1rem;
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.8rem;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ── Page Title ───────────────────────────────────── */
.page-title {
    font-size: 1.5rem;
    margin: 28px 0 20px;
}

/* ── Product Grid ─────────────────────────────────── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    padding-bottom: 40px;
}

.product-card {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform .15s ease, box-shadow .15s ease;
    cursor: pointer;
}
.product-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.product-card-cover {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    background: var(--border);
}

.product-card-info {
    padding: 14px;
}

.product-card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-card-author {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.product-card-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
}

/* ── Category Tabs ────────────────────────────────── */
.category-filter {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
}

.category-tabs {
    display: flex;
    gap: 10px;
    overflow-x: auto;
}

.category-tab {
    padding: 6px 16px;
    border-radius: 20px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
}
.category-tab:hover,
.category-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ── Book Detail ──────────────────────────────────── */
.book-detail {
    display: flex;
    gap: 32px;
    margin: 30px 0;
    align-items: flex-start;
}

.book-detail-cover {
    flex-shrink: 0;
    width: 280px;
}
.book-detail-cover img {
    width: 100%;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.book-detail-info {
    flex: 1;
}
.book-detail-info h1 {
    font-size: 1.5rem;
    margin-bottom: 10px;
}

.book-author, .book-pages {
    color: var(--text-muted);
    margin-bottom: 8px;
}

.book-desc {
    margin-bottom: 16px;
    line-height: 1.8;
}

.book-price {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 20px;
}

.book-actions {
    margin-top: 10px;
}

/* ── Modal ───────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--text);
    opacity: 0.45;
    z-index: 200;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 201;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 18px 18px 16px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: var(--radius);
    cursor: pointer;
}

.modal-close:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 10px;
}

.modal-error {
    color: var(--danger);
    font-size: 0.85rem;
    min-height: 20px;
    margin-top: 6px;
}

/* ── Loading & Empty ──────────────────────────────── */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    grid-column: 1 / -1;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state .btn {
    margin-top: 16px;
}

.error {
    color: var(--danger);
    text-align: center;
    padding: 40px;
}

/* ── Footer ───────────────────────────────────────── */
.footer {
    margin-top: auto;
    text-align: center;
    padding: 20px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 768px) {
    .topbar-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 16px;
        gap: 10px;
    }
    .nav-links { order: 3; width: 100%; }
    .book-detail { flex-direction: column; }
    .book-detail-cover { width: 200px; margin: 0 auto; }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
}
