/* Book Maniac - Main Styles */
:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-secondary: #64748b;
    --color-bg: #f8fafc;
    --color-bg-card: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-error: #dc2626;
    --color-success: #16a34a;
    --color-badge: #ef4444;
    --color-star: #f59e0b;
    --color-star-inactive: #d1d5db;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-lg: 12px;
    --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* Dark mode */
body.dark-mode {
    --color-primary: #3b82f6;
    --color-primary-hover: #2563eb;
    --color-bg: #0f172a;
    --color-bg-card: #1e293b;
    --color-text: #e2e8f0;
    --color-text-muted: #94a3b8;
    --color-border: #334155;
    --color-star-inactive: #475569;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-container {
    background: var(--color-bg-card);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.login-title {
    margin: 0 0 0.25rem;
    font-size: 1.75rem;
    font-weight: 700;
}

.login-subtitle {
    margin: 0 0 1.5rem;
    color: var(--color-text-muted);
}

.login-form .form-group {
    margin-bottom: 1rem;
}

.login-form .btn {
    width: 100%;
    margin-top: 0.5rem;
}

/* Header */
.header {
    background: var(--color-bg-card);
    padding: 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    box-shadow: var(--shadow);
    transition: background 0.3s;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    text-decoration: none;
}

.logo:hover {
    text-decoration: underline;
}

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

.nav-link {
    color: var(--color-text);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
}

.nav-link:hover {
    background: var(--color-bg);
}

.nav-link.active {
    background: var(--color-primary);
    color: white;
}

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

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--color-text);
    position: relative;
}

.btn-icon:hover {
    color: var(--color-primary);
}

.notifications-wrap {
    position: relative;
}

.badge-count {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--color-badge);
    color: white;
    font-size: 0.75rem;
    min-width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notifications-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--color-bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 320px;
    max-width: 400px;
    max-height: 400px;
    overflow: hidden;
    z-index: 100;
}

.notifications-dropdown.open {
    display: block;
}

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

.notifications-list {
    max-height: 300px;
    overflow-y: auto;
}

.notification-item {
    padding: 1rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}

.notification-item:last-child {
    border-bottom: none;
}

.btn-mark-read {
    background: none;
    border: none;
    color: var(--color-primary);
    cursor: pointer;
    font-size: 0.875rem;
}

.locale-switcher select {
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-card);
    color: var(--color-text);
}

/* Main */
.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Sections */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.filters-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filters-bar select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-card);
    color: var(--color-text);
}

/* Search input */
.search-input {
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-card);
    color: var(--color-text);
    font-size: 0.95rem;
    min-width: 220px;
}

.search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Table */
.table-wrap {
    overflow-x: auto;
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.books-table {
    width: 100%;
    border-collapse: collapse;
}

.books-table th,
.books-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.books-table th {
    background: var(--color-bg);
    font-weight: 600;
    white-space: nowrap;
    user-select: none;
}

.books-table th[data-sort] {
    cursor: pointer;
}

.books-table th[data-sort]:hover {
    background: var(--color-border);
}

.sort-arrow {
    font-size: 0.75em;
    color: var(--color-primary);
    margin-left: 2px;
}

.books-table tbody tr:hover {
    background: var(--color-bg);
}

.books-table .loading {
    text-align: center;
    color: var(--color-text-muted);
    padding: 2rem;
}

.book-link {
    color: var(--color-primary);
    text-decoration: none;
}

.book-link:hover {
    text-decoration: underline;
}

.review-cell {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.review-cell:hover {
    white-space: normal;
    overflow: visible;
}

.score-cell {
    white-space: nowrap;
}

.actions-cell {
    white-space: nowrap;
}

/* Pagination */
.pagination {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
}

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

.pagination-info {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

/* Profile */
.profile-section h2 {
    margin: 0 0 1.5rem;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.profile-card {
    background: var(--color-bg-card);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.profile-card-full {
    grid-column: 1 / -1;
}

.profile-card h3 {
    margin: 0 0 1rem;
    font-size: 1.25rem;
}

.profile-form .form-group {
    margin-bottom: 1rem;
}

.achievements-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--color-bg);
    border-radius: var(--radius);
}

.achievement-item img {
    width: 40px;
    height: 40px;
}

.recent-achievements {
    margin-top: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.profile-books-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.profile-book-item {
    padding: 0.75rem;
    background: var(--color-bg);
    border-radius: var(--radius);
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--color-bg-card);
    color: var(--color-text);
}

.form-group textarea {
    resize: vertical;
}

.form-hint {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--color-primary);
    color: white;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}

.btn-danger {
    background: var(--color-error);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #b91c1c;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    margin: 0;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-muted);
}

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

.modal-form {
    padding: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Alert */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.alert-error {
    background: #fef2f2;
    color: var(--color-error);
}

body.dark-mode .alert-error {
    background: #451a1a;
}

.alert-success {
    background: #f0fdf4;
    color: var(--color-success);
}

body.dark-mode .alert-success {
    background: #14291a;
}

/* Star Rating */
.star-rating {
    display: flex;
    gap: 2px;
    align-items: center;
}

.star {
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--color-star-inactive);
    transition: color 0.1s, transform 0.1s;
    user-select: none;
    line-height: 1;
}

.star.star-active {
    color: var(--color-star);
}

.star.star-hover {
    color: var(--color-star);
    transform: scale(1.15);
}

/* Mini stars in table */
.score-stars {
    display: inline-flex;
    gap: 0;
}

.mini-star {
    font-size: 0.85rem;
    color: var(--color-star-inactive);
    line-height: 1;
}

.mini-star.mini-star-active {
    color: var(--color-star);
}

/* Statistics */
.stats-section h2 {
    margin: 0 0 1.5rem;
}

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.stats-overview-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.stats-overview-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    text-align: center;
}

.stats-card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
}

.stats-card-label {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.stats-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.stats-card-full {
    width: 100%;
}

.stats-card h3 {
    margin: 0 0 1rem;
    font-size: 1.15rem;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table th,
.stats-table td {
    padding: 0.5rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.stats-table th {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

/* Bar chart */
.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.bar-label {
    min-width: 80px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    text-align: right;
}

.bar-track {
    flex: 1;
    height: 22px;
    background: var(--color-bg);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 4px;
    min-width: 4px;
    transition: width 0.5s ease-out;
}

.bar-fill-score {
    background: var(--color-star);
}

.bar-fill-lang {
    background: var(--color-success);
}

.bar-value {
    min-width: 30px;
    font-size: 0.85rem;
    font-weight: 600;
}

/* Mobile */
@media (max-width: 768px) {
    .header {
        padding: 1rem;
        gap: 0.75rem;
    }

    .nav {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }

    .nav-link {
        padding: 0.4rem 0.75rem;
        font-size: 0.9rem;
    }

    .nav-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Notifications dropdown — fixed position on mobile for reliability */
    .notifications-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        margin-top: 0;
        min-width: 0;
        max-width: 100%;
        width: 100%;
        max-height: 70vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
    }

    .table-wrap {
        overflow-x: scroll;
    }

    .books-table {
        min-width: 800px;
    }

    .filters-bar {
        flex-direction: column;
    }

    .search-input {
        min-width: auto;
        width: 100%;
    }

    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .modal {
        max-height: 95vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .stats-overview-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .main {
        padding: 1rem;
    }
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 1rem 2rem;
    border-radius: var(--radius);
    color: white;
    font-weight: 500;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}

.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-success {
    background: var(--color-success);
}

.toast-error {
    background: var(--color-error);
}

.toast-info {
    background: var(--color-primary);
}

/* Achievement Celebration Overlay */
.celebration-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    animation: fadeIn 0.3s ease-out;
}

.celebration-content {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.4s ease-out;
}

.celebration-icon {
    font-size: 4rem;
    margin-bottom: 0.5rem;
}

.celebration-content h2 {
    margin: 0 0 1rem;
    font-size: 1.25rem;
}

.celebration-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.celebration-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.celebration-badge img {
    width: 64px;
    height: 64px;
}

/* Notification unread */
.notification-unread {
    background: #eff6ff;
    font-weight: 500;
}

body.dark-mode .notification-unread {
    background: #1e3a5f;
}

/* Achievement item layout tweak */
.achievement-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--color-bg);
    border-radius: var(--radius);
}

.achievement-item div {
    text-align: left;
}

.achievement-item small {
    color: var(--color-text-muted);
}

/* Custom tooltip for achievements */
.achievement-item[title] {
    position: relative;
    cursor: help;
}

.achievement-item[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-text);
    color: var(--color-bg);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    white-space: nowrap;
    z-index: 50;
    pointer-events: none;
    animation: fadeIn 0.15s ease-out;
}

.achievement-item[title]:hover::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--color-text);
    z-index: 50;
    pointer-events: none;
}

