/* ------------------------------------------------------------
   style.css — Thème inspiré de ReadEra : fond gris clair,
   cartes arrondies, boutons gris. Mobile d'abord.
   ------------------------------------------------------------ */

:root {
  --bg: #eef0f2;
  --card: #ffffff;
  --paper: #fbfaf7;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #dde1e6;
  --btn: #e3e6ea;
  --btn-hover: #d6dade;
  --primary: #4a5563;
  --primary-text: #ffffff;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --fs: 100%;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #16181b;
  --card: #23262a;
  --paper: #1b1d20;
  --text: #e4e6e8;
  --muted: #9aa0a6;
  --line: #34383d;
  --btn: #32363b;
  --btn-hover: #3d4248;
  --primary: #c9ced4;
  --primary-text: #16181b;
  --danger: #f97066;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3em;
  min-height: 40px; padding: .45em 1em;
  border: 0; border-radius: 999px;
  background: var(--btn); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; white-space: nowrap;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}
.btn:hover { background: var(--btn-hover); }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.icon { min-width: 40px; padding: .45em .6em; }
.btn.small { min-height: 32px; padding: .25em .8em; font-size: .85rem; }
form.inline { display: inline; margin: 0; }

/* ---------- Connexion ---------- */
.auth { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 16px; }
.auth-box {
  width: 100%; max-width: 400px; padding: 28px 24px;
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow); text-align: center;
}
.auth-box h1 { margin: .2em 0 0; }
.logo { font-size: 2.6rem; }
.tabs { display: flex; gap: 4px; margin: 20px 0 14px; padding: 4px; background: var(--bg); border-radius: 999px; }
.tabs a { flex: 1; padding: .5em; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 500; }
.tabs a.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.form { display: grid; gap: 12px; text-align: left; }
.form label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.form input {
  width: 100%; padding: .7em .9em; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px; /* 16px : pas de zoom sur iOS */
}
.form input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form .btn { margin-top: 6px; min-height: 46px; }
.alert { padding: .7em 1em; border-radius: 10px; background: rgba(180,35,24,.1); color: var(--danger); text-align: left; }

/* ---------- Bibliothèque ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.brand { margin: 0; font-size: 1.25rem; white-space: nowrap; }
.topbar .actions { display: flex; gap: 6px; align-items: center; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 8px 16px 40px; }
.status { padding: .6em 1em; background: var(--card); border-radius: 10px; box-shadow: var(--shadow); }
.empty { text-align: center; padding: 60px 10px; }

/* Barre de recherche (dans le header, entre le titre et les boutons) */
.search { position: relative; flex: 1 1 auto; min-width: 0; max-width: 520px; }
.search input {
  width: 100%; min-height: 40px; padding: .45em 4.2em .45em 2.5em;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card) no-repeat 1em center / 1.1em
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  color: var(--text); font: inherit; font-size: 16px; /* 16px : pas de zoom sur iOS */
  box-shadow: var(--shadow); -webkit-appearance: none; appearance: none;
}
.search input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.search #searchCount { position: absolute; right: 2.8em; /* à gauche du bouton ✕ natif */ top: 50%; transform: translateY(-50%); pointer-events: none; }
.empty .big { font-size: 1.2rem; font-weight: 600; }

/* Colonnes de taille fixe : une image trop large ne peut jamais les élargir.
   Grand écran (iPad, PC) : cartes de 150 à 170 px ; téléphone : 3 colonnes. */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 170px)); gap: 14px; } }

.card {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.cover {
  position: relative; display: flex; align-items: flex-end;
  aspect-ratio: 2 / 3; padding: 12px; text-decoration: none; color: #fff;
  overflow: hidden; min-width: 0;
  background: linear-gradient(160deg, hsl(var(--hue) 45% 58%), hsl(var(--hue) 50% 36%));
}
.cover-title {
  font-weight: 600; font-size: .95rem; line-height: 1.25; text-shadow: 0 1px 3px rgba(0,0,0,.35);
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word;
}
/* Couverture réelle du livre (miniature stockée sur l'appareil) */
.cover-pic { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.has-pic { background: var(--btn); }
.cover.has-pic .cover-title { display: none; }
.badge {
  z-index: 1;
  position: absolute; top: 8px; left: 8px;
  padding: 2px 8px; border-radius: 6px;
  background: rgba(0,0,0,.45); color: #fff; font-size: .7rem; font-weight: 700; letter-spacing: .05em;
}
.meta { display: flex; align-items: flex-start; gap: 2px; padding: 8px 4px 0 10px; min-width: 0; }
.meta-text { flex: 1; min-width: 0; }
.meta .more { min-width: 32px; min-height: 32px; padding: 0; background: transparent; font-size: 1.2rem; line-height: 1; color: var(--muted); }
.meta .more:hover { background: var(--btn); }
.state.is-done { color: #2e9e5b; font-weight: 600; }

/* Barre de progression en bas de la couverture */
.bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; height: 5px; background: rgba(0,0,0,.35); }
.bar i { display: block; height: 100%; width: 0; background: #4cc38a; }
.meta .title {
  margin: 0; font-size: .9rem; font-weight: 600; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 10px 10px; }
.card-actions:not(:has(:not([hidden]))) { padding: 0 0 6px; }
.card-actions .attach { flex: 1 1 100%; white-space: normal; text-align: center; line-height: 1.2; }

/* ---------- Filtres, étagère, tri ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin: 2px 0 14px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; max-width: 100%; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 34px; padding: .3em .9em; border: 0; border-radius: 999px;
  background: var(--btn); color: var(--text); font: inherit; font-size: .88rem; cursor: pointer; white-space: nowrap;
}
.chip .n { color: var(--muted); font-size: .8em; margin-left: .2em; }
.chip.on { background: var(--primary); color: var(--primary-text); }
.chip.on .n { color: inherit; opacity: .75; }
.selects { display: flex; gap: 6px; min-width: 0; }
.selects select {
  min-height: 34px; max-width: 200px; padding: 0 2em 0 .9em; border: 0; border-radius: 999px;
  background: var(--btn) no-repeat right .7em center / .7em
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.6'/%3E%3C/svg%3E");
  color: var(--text); font: inherit; font-size: .88rem; -webkit-appearance: none; appearance: none; cursor: pointer;
  text-overflow: ellipsis;
}

/* ---------- Bannière d'installation ---------- */
.install {
  display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 10px 10px 10px 14px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); font-size: .9rem;
}
.install #installText { flex: 1; }

/* ---------- Fenêtres (dialog) ---------- */
.dlg {
  width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); padding: 0;
  border: 0; border-radius: 18px; background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 6px 18px; }
.dlg-head h2 { flex: 1; margin: 0; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg section { padding: 10px 18px; border-top: 1px solid var(--line); }
.dlg section:last-child { padding-bottom: 18px; }
.dlg-head + section { border-top: 0; }
.lbl { display: block; margin-bottom: 6px; font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.row { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.row.wrap { flex-wrap: wrap; }
.row input {
  flex: 1; min-width: 0; min-height: 40px; padding: .4em .8em; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px;
}
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.check {
  display: inline-flex; align-items: center; gap: .3em; padding: .35em .8em; border-radius: 999px;
  background: var(--btn); cursor: pointer; font-size: .9rem;
}
.check input { accent-color: var(--primary); margin: 0; }
.shelf-list .row:first-child { margin-top: 0; }
.btn.danger { width: 100%; background: rgba(180,35,24,.1); color: var(--danger); }
.btn.danger:hover { background: rgba(180,35,24,.18); }
.danger-text { color: var(--danger); }
.absent { display: none; margin: 4px 10px 0; font-size: .75rem; color: var(--muted); }

/* Livre dont le fichier n'est pas sur cet appareil : carte grisée */
.card.missing .cover { filter: grayscale(1); opacity: .45; cursor: not-allowed; }
.card.missing .meta { opacity: .6; }
.card.missing .absent { display: block; }

.foot { margin-top: 30px; text-align: center; }

.drop {
  position: fixed; inset: 12px; z-index: 50;
  display: grid; place-items: center;
  border: 3px dashed var(--primary); border-radius: 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  font-size: 1.4rem; font-weight: 600; pointer-events: none;
}

.show-sm { display: none; }
@media (max-width: 520px) {
  .hide-sm { display: none; }
  .show-sm { display: inline; }
  .topbar { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .topbar .actions { gap: 4px; }
  .topbar .actions .btn { min-width: 40px; padding: .45em .7em; }
  .search input { padding-right: 3.2em; }
  .search #searchCount { right: 2.2em; font-size: .7rem; }
}

/* Téléphone : cartes plus compactes */
@media (max-width: 699px) {
  .cover { padding: 8px; }
  .cover-title { font-size: .8rem; }
  .badge { top: 5px; left: 5px; padding: 1px 6px; font-size: .62rem; }
  .meta { padding: 6px 8px 0; }
  .meta .title { font-size: .8rem; }
  .meta small { font-size: .72rem; }
  .card-actions { padding: 4px 8px 8px; gap: 4px; }
  .meta { padding: 6px 2px 0 8px; }
  .meta .more { min-width: 26px; min-height: 26px; font-size: 1rem; }
  .toolbar { gap: 8px; }
  .selects { width: 100%; }
  .selects select { flex: 1; max-width: none; }
  .card-actions .btn.small { min-height: 28px; padding: .2em .6em; font-size: .75rem; }
}

/* ---------- Lecteur ---------- */
.reader {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; overflow: hidden;
  background: var(--paper);
}
.rbar, .rfoot {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--bg); flex: none;
}
.rbar { padding-top: max(6px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.rfoot { justify-content: space-between; padding-bottom: max(6px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); min-height: 44px; }
.rfoot #pos { flex: 1; text-align: center; }
.rtitle { flex: 1; min-width: 0; margin: 0 4px; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toc {
  max-width: 34vw; min-height: 40px; padding: 0 .6em;
  border: 0; border-radius: 999px; background: var(--btn); color: var(--text); font: inherit; font-size: .9rem;
}

.view { flex: 1; min-height: 0; position: relative; overflow: auto; -webkit-overflow-scrolling: touch; overflow-anchor: auto; }
.view.paged { overflow: hidden; padding: 0 6px; }
.view.full { overflow: hidden; }
.loading { text-align: center; padding: 40px; color: var(--muted); }

iframe.pdf { width: 100%; height: 100%; border: 0; display: block; background: #525659; }

/* Texte continu : TXT, FB2, DOCX */
.doc {
  max-width: 44em; margin: 0 auto; padding: 24px 18px 60px;
  font-family: Georgia, "Times New Roman", serif; font-size: var(--fs); line-height: 1.65;
  word-wrap: break-word; overflow-wrap: break-word;
}
.doc.txt { white-space: pre-wrap; font-family: Georgia, serif; }
.doc img { max-width: 100%; height: auto; display: block; margin: 1em auto; }
.doc h1, .doc h2, .doc h3 { line-height: 1.3; text-align: center; }
.doc table { border-collapse: collapse; max-width: 100%; }
.doc td, .doc th { border: 1px solid var(--line); padding: 4px 8px; }
.doc a { color: inherit; }
.fb2 section > p { text-indent: 1.5em; margin: 0 0 .4em; }
.fb2 blockquote { margin: 1em 2em; font-style: italic; }
.fb2 .verse { margin: 0 0 0 2em; text-indent: 0; }
.fb2 .author { text-align: right; font-style: italic; }
.fb2 .cover-img { max-height: 70vh; }

/* Pages d'images : BD (CBZ) et PDF via pdf.js */
.pages { background: #3a3d41; padding: 8px 0; }
.page { max-width: 1000px; margin: 0 auto 8px; min-height: 60vh; background: rgba(255,255,255,.04); }
.page.ok, .pdfpage { min-height: 0; }
.page img, .page canvas { display: block; width: 100%; height: auto; }
.pdfpage { background: #fff; }

.notice {
  max-width: 520px; margin: 40px auto; padding: 24px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); text-align: center;
}
.notice h2 { margin-top: 0; font-size: 1.2rem; }

@media (max-width: 520px) {
  .toc { max-width: 28vw; }
  .rfoot .btn { padding: .45em .8em; }
}
