/* ════════════════════════════════════════════════════════════════════════════
   iBédéthèque — main stylesheet
   Original styles preserved; new sections marked with ★
════════════════════════════════════════════════════════════════════════════ */

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    line-height: 1.1;
    background-color: #1a1a2e;
    color: #e0e0e0;
}

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

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar-container {
    width: 100%;
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background-color: #3F51B5;
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    z-index: 50;
    transition: opacity 0.3s ease-in-out;
    opacity: 1.0;
    flex-wrap: nowrap;
    min-height: 56px;
}

.topbar-container:hover {
    opacity: 1.0 !important;
}

.logo img {
    height: 40px;
    width: auto;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.book-count {
    font-size: 0.9rem;
    white-space: nowrap;
    flex-shrink: 0;
}
}

.search-group {
    display: flex;
    border-radius: 4px;
    overflow: hidden;
    flex: 1 1 160px;
    min-width: 0;
    max-width: 320px;
}

.search-input {
    padding: 7px 10px;
    border: none;
    font-size: 0.95rem;
    flex-grow: 1;
    min-width: 0;
    width: 100%;
}

.search-button {
    padding: 7px 12px;
    border: none;
    background-color: #ff9800;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: background-color 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.search-button:hover {
    background-color: #e65100;
    transform: translateY(-2px);
}

/* ★ User info (avatar + logout) ─────────────────────────────────────────── */

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
    object-fit: cover;
}

.user-initial {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9rem;
    border: 2px solid rgba(255, 255, 255, 0.6);
}

.logout-link {
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: bold;
    padding: 4px 6px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.logout-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.15);
}

/* ── Responsive (≤ 600 px) ───────────────────────────────────────────────── */

@media (max-width: 600px) {
    .topbar-container {
        padding: 6px 10px;
        gap: 6px;
        min-height: 48px;
    }

    .logo img { height: 30px; }

    .app-title {
        font-size: 1rem;
    }

    .book-count { display: none; }

    .search-group {
        flex: 1 1 80px;
        max-width: none;
    }

    .search-input {
        padding: 5px 7px;
        font-size: 0.85rem;
    }

    .search-button {
        padding: 5px 8px;
        font-size: 0.8rem;
    }

    .topbar-nav-link {
        padding: 4px 6px;
        font-size: 0.78rem;
    }

    .user-info { gap: 4px; }
    .user-avatar, .user-initial { width: 26px; height: 26px; }
}

/* ── Scanner reader ──────────────────────────────────────────────────────── */

#reader {
    width: 100%;
    max-width: 500px;
    margin: 16px auto 0;
}

/* ── Book grid ───────────────────────────────────────────────────────────── */

.view-controls {
  display: flex;
  justify-content: flex-end;
  padding: 0.5em 1.5em 0;
}

.btn-group-toggle {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  color: #ccc;
  padding: 0.3em 0.9em;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s, color 0.2s;
}
.btn-group-toggle:hover { background: rgba(255,255,255,0.1); color: #fff; }
.btn-group-toggle.active { background: #3F51B5; border-color: #3F51B5; color: #fff; }

.series-group {
  width: 100%;
  padding: 0 1em;
}

.series-header {
  font-size: 1rem;
  font-weight: 600;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 0.4em;
  margin: 1.2em 0 0.6em;
  display: flex;
  align-items: center;
  gap: 0.6em;
}

.series-count {
  font-size: 0.75rem;
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 0.1em 0.55em;
  font-weight: 400;
  letter-spacing: 0;
}

.series-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1em;
  justify-content: flex-start;
}

/* Missing / ghost book cards */
.bd-missing {
  opacity: 0.45;
  filter: grayscale(60%);
}
.bd-missing:hover {
  opacity: 0.75;
  filter: grayscale(30%);
}

.missing-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(180,0,0,0.85);
  color: #fff;
  font-size: 0.85rem;
  font-weight: bold;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.missing-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 0.65rem;
  padding: 2px 4px;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.missing-notice {
  color: #FF9800;
  font-size: 0.9rem;
  margin: 0.5em 0 1em;
}

#content {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 1em;
    padding: 1em;
    gap: 1em;
}

.bd-collection {
    flex: 0 0 auto;
    position: relative;
}

/* ★ Cover wrapper (holds badge) ─────────────────────────────────────────── */

.cover-wrapper {
    position: relative;
    display: inline-block;
}

/* ★ Favorite badge on grid card ─────────────────────────────────────────── */

.favorite-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(255, 152, 0, 0.9);
    color: #fff;
    font-size: 0.85rem;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* ── Book detail popup ───────────────────────────────────────────────────── */

.details {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 1.5em;
    text-align: left;
    color: #222;
}

.details .cover-col {
    flex: 0 0 auto;
}

.details .info-col {
    flex: 1 1 0;
    min-width: 0;
    text-align: left;
}

.details div p  { margin: 10px; }
.details div h2 { margin: 0; }

@media (max-width: 500px) {
    .details {
        flex-direction: column;
        align-items: center;
    }
}

/* ★ Action row in detail popup ──────────────────────────────────────────── */

.detail-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 10px;
}

/* ★ Favorite button ─────────────────────────────────────────────────────── */

.favorite-btn {
    background: none;
    border: 2px solid #ccc;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    font-size: 1.3rem;
    cursor: pointer;
    color: #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, border-color 0.2s, transform 0.1s;
    line-height: 1;
    padding: 0;
}

.favorite-btn:hover {
    color: #ff9800;
    border-color: #ff9800;
    transform: scale(1.1);
}

.favorite-btn.active {
    color: #ff9800;
    border-color: #ff9800;
}

/* ── Cover image ─────────────────────────────────────────────────────────── */

.cover-image {
    height: auto;
    border-radius: 4px;
    box-shadow: 5px 5px 15px #aaaaaa;
}

.align-center { display: block; margin: 0 auto; }

/* ── Subject tags ────────────────────────────────────────────────────────── */

.subject {
    display: inline-block;
    background-color: #e0e0e0;
    color: #333;
    padding: 5px 10px;
    margin: 2px;
    border-radius: 15px;
    font-size: 0.9em;
}

/* ── Popup (shared: book detail & scanner) ───────────────────────────────── */

.popup-container {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    overflow-y: auto;
    padding: 20px;
}

.popup-content {
    background-color: #ffffff;
    color: #222;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    width: 94%;
    position: relative;
    text-align: center;
}

@media (max-width: 600px) {
    .popup-content {
        padding: 16px 12px;
        width: 100%;
        border-radius: 6px;
    }
    .close-button { top: 6px; right: 8px; font-size: 24px; }
}

/* ★ Scanner popup additions ─────────────────────────────────────────────── */

.scanner-popup {
    max-width: 600px;
}

.scanner-popup h2 {
    margin: 0 0 16px;
    color: #3F51B5;
}

.isbn-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.isbn-manual-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

.btn-add {
    padding: 8px 16px;
    background-color: #3F51B5;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.btn-add:hover {
    background-color: #303f9f;
}

/* ★ Status messages ─────────────────────────────────────────────────────── */

.status-msg {
    margin-top: 10px;
    padding: 8px 14px;
    border-radius: 4px;
    font-size: 0.95rem;
    text-align: center;
    min-height: 36px;
}

.status-info    { background: #e3f2fd; color: #1565c0; }
.status-success { background: #e8f5e9; color: #2e7d32; }
.status-warning { background: #fff3e0; color: #e65100; }
.status-error   { background: #ffebee; color: #c62828; }

/* ── Close button ────────────────────────────────────────────────────────── */

.close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 30px;
    font-weight: bold;
    color: #333;
    cursor: pointer;
    line-height: 1;
    padding: 5px 10px;
    transition: color 0.2s;
}

.close-button:hover {
    color: #ff0000;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

footer {
    text-align: center;
    margin-top: auto;
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,0.1);
    color: #888;
    font-size: 0.9em;
    display: flex;
    justify-content: center;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

footer a, footer label {
    color: #3F51B5;
    text-decoration: none;
    font-weight: 500;
}

footer a:hover, footer label:hover {
    text-decoration: underline;
}

/* ★ Login page ───────────────────────────────────────────────────────────── */

.login-page {
    background: linear-gradient(135deg, #3F51B5 0%, #303f9f 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-container {
    background: #fff;
    border-radius: 12px;
    padding: 40px 24px;
    text-align: center;
    width: 100%;
    max-width: 380px;
    margin: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.login-logo {
    height: 72px;
    width: auto;
    margin-bottom: 12px;
}

.login-container h1 {
    color: #3F51B5;
    margin: 0 0 6px;
    font-size: 1.8rem;
}

.login-subtitle {
    color: #666;
    font-size: 0.95rem;
    margin: 0 0 28px;
}

.login-error {
    background: #ffebee;
    color: #c62828;
    border-radius: 6px;
    padding: 10px 16px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px 24px;
    font-size: 1rem;
    color: #333;
    text-decoration: none;
    cursor: pointer;
    transition: box-shadow 0.2s, background 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.btn-google:hover {
    background: #f8f8f8;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

/* ★ Error page ───────────────────────────────────────────────────────────── */

.error-container {
    max-width: 500px;
    margin: 80px auto;
    text-align: center;
    padding: 20px;
}

.error-container h2 {
    font-size: 2rem;
    color: #3F51B5;
}

.btn-back {
    display: inline-block;
    margin-top: 16px;
    padding: 10px 24px;
    background-color: #3F51B5;
    color: #fff;
    border-radius: 4px;
    text-decoration: none;
    transition: background-color 0.2s;
}

.btn-back:hover {
    background-color: #303f9f;
}

/* ★ Topbar nav links ─────────────────────────────────────────────────────── */

.topbar-nav {
    display: flex;
    gap: 4px;
}

.topbar-nav-link {
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 5px 12px;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.topbar-nav-link:hover,
.topbar-nav-link.active {
    background: rgba(255,255,255,0.18);
    color: #fff;
}

@media (max-width: 600px) {
    .topbar-nav-link { padding: 4px 8px; font-size: 0.8rem; }
}

/* ★ Book detail — definition list ──────────────────────────────────────── */

.detail-cover {
    width: 180px;
    max-width: 100%;
}

.detail-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    margin: 10px 0;
    font-size: 0.95rem;
}

.detail-list dt {
    font-weight: 600;
    color: #444;
    white-space: nowrap;
}

.detail-list dd {
    margin: 0;
    color: #333;
    word-break: break-word;
}

.detail-notes {
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
    margin: 8px 10px;
    border-left: 3px solid #ddd;
    padding-left: 8px;
}

.detail-subjects {
    margin: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.subject--people { background-color: #e8f5e9; color: #2e7d32; }
.subject--place  { background-color: #e3f2fd; color: #1565c0; }

.ol-link {
    display: block;
    margin-top: 10px;
    font-size: 0.8rem;
    color: #3F51B5;
    text-decoration: none;
    text-align: center;
}

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

/* ★ Book detail page ────────────────────────────────────────────────────── */

.book-detail-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px 60px;
    color: #e0e0e0;
}

.back-link {
    display: inline-block;
    color: #9e9e9e;
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 1.5em;
    padding: 6px 0;
}
.back-link:hover { color: #fff; }

.book-detail {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 2em;
}

.book-cover-col {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1em;
}

.book-cover-img {
    width: min(180px, 40vw);
    height: auto;
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.book-info-col {
    flex: 1 1 0;
    min-width: 0;
}

.book-info-col h1 {
    margin: 0 0 0.2em;
    font-size: clamp(1.1rem, 4vw, 1.6rem);
    line-height: 1.2;
    color: #f0f0f0;
}

.book-subtitle {
    color: #aaa;
    font-style: italic;
    margin: 0 0 1em;
}

.book-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 1em 0;
}

.btn-delete {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    opacity: 0.6;
    padding: 0;
}
.btn-delete:hover { opacity: 1; }

@media (max-width: 600px) {
    .book-detail {
        flex-direction: column;
        align-items: center;
    }
    .book-info-col { text-align: center; width: 100%; }
    .book-actions { justify-content: center; }
    .detail-list { text-align: left; font-size: 0.88rem; }
    .book-detail-page { padding: 16px 12px 40px; }
}

/* ★ Statistics page ─────────────────────────────────────────────────────── */

.stats-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px 40px;
    color: #e0e0e0;
}

.stats-loading {
    text-align: center;
    padding: 60px;
    color: #888;
    font-size: 1.1rem;
}

/* Summary cards */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: #2a2a45;
    border-radius: 12px;
    padding: 20px 16px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-card--gold { border-top: 4px solid #FF9800; }

.stat-card-value {
    font-size: 2rem;
    font-weight: 700;
    color: #7986CB;
    line-height: 1;
}

.stat-card--gold .stat-card-value { color: #FF9800; }

.stat-card-label {
    font-size: 0.8rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Charts grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.chart-card {
    background: #2a2a45;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.chart-card--wide {
    grid-column: 1 / -1;
}

.chart-card h3 {
    margin: 0 0 16px;
    font-size: 1rem;
    color: #ccc;
    font-weight: 600;
}

@media (max-width: 700px) {
    .stats-grid { grid-template-columns: 1fr; }
    .chart-card--wide { grid-column: 1; }
    .stats-cards { grid-template-columns: repeat(2, 1fr); }
    .stats-page { padding: 16px 10px 40px; }
}
