:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --ink: #2e2620;
  --ink-soft: #6b5f52;
  --border: #e7ddd0;
  --accent: #a8562f;
  --accent-soft: #f1e2d5;
  --to-read: #8a7a68;
  --reading: #c8862f;
  --read: #4c7a52;
  --error: #b3261e;
  --fr-en-cours: #3a6ea5;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.hidden { display: none !important; }

h1 { font-size: 1.4rem; margin: 0; }

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  background: var(--accent);
  color: white;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: default; }

.btn-link {
  background: none;
  color: var(--ink-soft);
  padding: 0.3rem 0.5rem;
  text-decoration: underline;
  font-size: 0.85rem;
}

input, textarea, select {
  font-size: 1rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
}

/* ---------- Login ---------- */

#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
}

.subtitle { color: var(--ink-soft); margin: 0.5rem 0 1.5rem; }

#login-form { display: flex; flex-direction: column; gap: 0.8rem; }

.error { color: var(--error); font-size: 0.9rem; margin-top: 1rem; }

/* ---------- App layout ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-right { display: flex; align-items: center; gap: 0.8rem; font-size: 0.9rem; }
#current-user-name { color: var(--ink-soft); }

.tabs {
  display: flex;
  gap: 0.3rem;
  padding: 0.6rem 1.2rem 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab-btn {
  background: none;
  color: var(--ink-soft);
  border-radius: 8px 8px 0 0;
  padding: 0.5rem 0.9rem;
  font-size: 1.3rem;
  line-height: 1;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

main { max-width: 720px; margin: 0 auto; padding: 1rem; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Search ---------- */

#search-form { display: flex; gap: 0.6rem; margin-bottom: 1rem; }
#search-input { flex: 1; }

.empty-state { color: var(--ink-soft); text-align: center; padding: 2rem 1rem; }

#manual-add-toggle { text-align: center; margin: 0.5rem 0 1rem; }

#manual-add-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

/* ---------- Vue liste / grille ---------- */

.view-toggle { display: flex; gap: 0.5rem; margin-bottom: 1rem; }

.view-btn {
  background: none;
  color: var(--ink-soft);
  border: 1px solid var(--border);
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}
.view-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-soft);
  font-weight: 600;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 1rem;
}

.grid-tile {
  cursor: pointer;
  text-align: center;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
}

.grid-tile .book-cover {
  width: 100%;
  height: 150px;
  margin: 0;
}

.grid-tile .grid-title {
  font-size: 0.78rem;
  font-weight: 600;
  margin: 0.4rem 0 0.2rem;
  line-height: 1.25;
  max-height: 2.5em;
  overflow: hidden;
  text-align: left;
}

.grid-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.3rem;
}
.grid-dot.to_read { background: var(--to-read); }
.grid-dot.reading { background: var(--reading); }
.grid-dot.read { background: var(--read); }
.grid-dot.unset { background: var(--border); }

/* ---------- Modale (fiche livre depuis la grille) ---------- */

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

.modal-box {
  background: var(--bg);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  padding: 1rem;
}

.modal-box .book-card {
  border: none;
  padding: 0;
}

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  padding: 0;
  line-height: 1;
  z-index: 1;
}

/* ---------- Book list ---------- */

.book-list { display: flex; flex-direction: column; gap: 0.9rem; }

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  gap: 1rem;
}

.book-cover {
  width: 60px;
  height: 90px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--accent-soft);
  flex-shrink: 0;
}
.book-cover.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.book-info { flex: 1; min-width: 0; }
.book-title { font-weight: 600; margin: 0 0 0.2rem; }
.book-author { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 0.6rem; }

.book-card .add-btn { font-size: 0.85rem; padding: 0.5rem 0.9rem; }

/* Statuses of the 4 family members on a shared book */
.status-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  flex-wrap: wrap;
}
.status-row:first-of-type { border-top: none; margin-top: 0.4rem; }

.status-name { font-weight: 600; width: 70px; flex-shrink: 0; }

.status-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  color: white;
  white-space: nowrap;
}
.status-badge.to_read { background: var(--to-read); }
.status-badge.reading { background: var(--reading); }
.status-badge.read { background: var(--read); }
.status-badge.unset { background: var(--border); color: var(--ink-soft); }

.stars { color: var(--reading); font-size: 0.85rem; letter-spacing: 1px; }

.status-comment {
  color: var(--ink-soft);
  font-style: italic;
  width: 100%;
  margin-top: 0.1rem;
}

/* Editable panel for the logged-in user's own status */
.my-status-panel {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.my-status-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.star-picker { display: flex; gap: 0.15rem; font-size: 1.2rem; cursor: pointer; }
.star-picker .star { color: var(--border); }
.star-picker .star.filled { color: var(--reading); }

.my-status-panel textarea {
  width: 100%;
  resize: vertical;
  min-height: 2.4rem;
}

.save-hint { font-size: 0.75rem; color: var(--ink-soft); }

.delete-book-btn {
  background: none;
  color: var(--error);
  padding: 0.3rem 0;
  font-size: 0.8rem;
  text-decoration: underline;
  align-self: flex-start;
}

/* ---------- Chat ---------- */

#chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.chat-msg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.8rem;
  max-width: 85%;
}
.chat-msg.mine { align-self: flex-end; background: var(--accent-soft); }

.chat-meta { font-size: 0.75rem; color: var(--ink-soft); margin-bottom: 0.15rem; }
.chat-body { white-space: pre-wrap; word-break: break-word; }

#chat-form { display: flex; gap: 0.6rem; }
#chat-input { flex: 1; }

/* ---------- Demandes d'amélioration ---------- */

#feature-request-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
}
#feature-request-input { min-height: 4.5rem; resize: vertical; }

#feature-request-list { display: flex; flex-direction: column; gap: 0.8rem; }

.feature-request-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
}

.feature-request-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

.feature-request-body { margin: 0; white-space: pre-wrap; word-break: break-word; }

.status-badge.fr-demande { background: var(--to-read); }
.status-badge.fr-a_faire { background: var(--reading); }
.status-badge.fr-en_cours { background: var(--fr-en-cours); }
.status-badge.fr-fait { background: var(--read); }
.status-badge.fr-pas_possible { background: var(--error); }

/* ---------- Livre du mois ---------- */

.progress-pill {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}

.progress-label { font-size: 0.85rem; color: var(--ink-soft); }
.my-progress-range { width: 100%; accent-color: var(--accent); }

#month-vote-section { margin-top: 1.5rem; text-align: center; }

#month-vote-panel {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
}

.vote-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
}
.vote-row.voted { border-color: var(--accent); background: var(--accent-soft); }

.vote-title { flex: 1; font-weight: 600; }
.vote-count { font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; }
.vote-btn { font-size: 0.85rem; padding: 0.4rem 0.8rem; }

@media (max-width: 480px) {
  .app-header { padding: 0.8rem; }
  main { padding: 0.7rem; }
  .book-cover { width: 50px; height: 75px; }
}
