/*
 * base.css — V8.0
 * Variables CSS, reset, éléments de base, topbar, forms, statusbar,
 * layout grid, cover screen, reading mode, responsive global.
 * Chargé en premier — ne dépend d'aucun autre fichier CSS.
 */

/* ── Variables & Reset ────────────────────────────────────────────────────── */
:root {
  --bg:         #0e0f11;
  --surface:    #17191d;
  --surface2:   #1f2228;
  --border:     #2a2d35;
  --text:       #e8e9ec;
  --muted:      #7a7f8e;
  --accent:     #5b8ef0;
  --accent2:    #3d6ad4;
  --ok:         #3ecf8e;
  --err:        #f06060;
  --warn:       #f0a840;
  --reader-bg:  #f5f0e8;
  --font-ui:    'DM Sans', sans-serif;
  --font-serif: 'Lora', Georgia, serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', monospace;
  --r:          10px;
  --r-sm:       6px;
}

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

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.topbar-brand {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 18px;
  color: var(--accent);
  letter-spacing: -.3px;
  margin-right: 6px;
  white-space: nowrap;
  user-select: none;
}
.tb-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tb-sep   { width: 1px; height: 22px; background: var(--border); flex-shrink: 0; }

/* ── Boutons & formulaires ───────────────────────────────────────────────── */
input[type="text"],
input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  transition: border-color .15s;
}
input[type="text"]:focus,
input[type="password"]:focus { border-color: var(--accent); }

#apiBaseUrl    { width: 200px; }
#emailInput    { width: 155px; }
#passwordInput { width: 130px; }
#urlInput      { width: 210px; }

.btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 400;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover    { background: var(--border); }
.btn:active   { transform: scale(.98); }
.btn.primary  { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn.danger   { border-color: var(--err); color: var(--err); }
.btn.danger:hover { background: rgba(240,96,96,.12); }

select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 7px 10px;
  cursor: pointer;
  max-width: 220px;
}
input[type="file"] {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 5px 10px;
  cursor: pointer;
  margin-right: 8px;
}

/* ── Statusbar ───────────────────────────────────────────────────────────── */
.statusbar {
  display: flex;
  flex-wrap: wrap;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  flex-shrink: 0;
}
.status-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  border-right: 1px solid var(--border);
  white-space: nowrap;
}
.status-item .lbl { color: var(--muted); }
.status-item .val {
  color: var(--text);
  font-weight: 500;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge-ok   { color: var(--ok)  !important; }
.badge-err  { color: var(--err) !important; }
.badge-warn { color: var(--warn)!important; }

/* ── Layout principal ────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
body.reading-mode .layout {
  grid-template-columns: 1fr 300px;
}
.content-pane {
  position: relative;
  min-height: 0;
  background: var(--reader-bg);
  overflow: hidden;
}
.hidden { display: none !important; }

/* ── Cover screen ────────────────────────────────────────────────────────── */
#coverScreen {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
#coverBackBar {
  display: none;
  width: 100%;
  height: 44px;
  flex-shrink: 0;
  align-items: center;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
body.cover-mode #coverBackBar { display: flex; justify-content: space-between; align-items: center; }

#coverBackLibBtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  transition: color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#coverBackLibBtn:hover { color: var(--text); background: var(--surface2); }

#coverCloseBtn {
  display: none;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  width: 34px;
  height: 34px;
  color: #6b7280;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  box-shadow: none;
  outline: none;
}
#coverCloseBtn:hover { background: rgba(255,255,255,.08); color: #d1d5db; }
body.cover-mode #coverCloseBtn { display: flex; align-items: center; justify-content: center; }

#coverCardWrap {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Carte cover — grid 2 colonnes sur desktop */
.cover-card {
  width: min(900px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.4);
  overflow: hidden;
  display: grid;
  grid-template-columns: 300px 1fr;
  flex-shrink: 0;
}
.cover-visual {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 24px;
  min-height: 260px;
}
.cover-visual img {
  max-width: 100%;
  max-height: 42vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.cover-fallback {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  line-height: 1.6;
}
.cover-meta {
  padding: 32px 28px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-left: 1px solid var(--border);
}
.cover-meta h1 { font-family: var(--font-serif); font-size: 26px; line-height: 1.2; color: var(--text); font-weight: 600; }
.cover-meta .author { color: var(--muted); font-size: 16px; }
.cover-meta .muted  { color: var(--muted); font-size: 13px; line-height: 1.6; }
.cover-meta .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.cover-btn {
  padding: 11px 18px;
  border-radius: var(--r-sm);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}
.cover-btn:hover  { background: var(--border); }
.cover-btn:active { transform: scale(.98); }
.cover-btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.cover-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.cover-btn.primary:hover { background: var(--accent2); border-color: var(--accent2); }

.cover-series {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  margin-bottom: -4px;
}
.cover-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}
.cover-tag {
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  padding: 2px 8px;
  font-family: var(--font-ui);
}
.cover-description {
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
  max-height: 120px;
  overflow-y: auto;
  padding-right: 4px;
  border-left: 2px solid var(--border);
  padding-left: 10px;
}

/* Barre de progression cover screen */
.progress-bar-wrap {
  background: var(--surface2);
  border-radius: 99px;
  height: 5px;
  overflow: hidden;
  margin-top: 4px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .4s ease;
}

/* ── Sidebar (log + TOC desktop) ─────────────────────────────────────────── */
.side {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
body.reading-mode .side {
  display: flex;
}
.side-section-title {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* TOC desktop (dans la sidebar) */
#toc {
  padding: 10px 12px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  max-height: 42%;
  flex-shrink: 0;
}
#toc a,
#toc button.toc-cover-btn {
  display: block;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 5px;
  font-size: 12px;
  line-height: 1.5;
  background: none;
  border: none;
  padding: 3px 4px;
  text-align: left;
  font-family: var(--font-ui);
  cursor: pointer;
  border-radius: 4px;
  width: 100%;
  transition: background .12s;
}
#toc a:hover,
#toc button.toc-cover-btn:hover { background: var(--surface2); }

/* Log */
#log {
  padding: 10px 12px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.55;
  color: var(--muted);
  flex: 1;
  min-height: 0;
}
.log-line { margin-bottom: 1px; }
.log-ok   { color: var(--ok); }
.log-err  { color: var(--err); }
.log-warn { color: var(--warn); }
.log-info { color: var(--accent); }

/* ── Reading mode ────────────────────────────────────────────────────────── */
body.reading-mode .topbar,
body.reading-mode .statusbar,
body.reading-mode #coverScreen { display: none !important; }
body.reading-mode .layout      { display: block; flex: 1; }
body.reading-mode .content-pane { height: 100%; }
body.reading-mode #readerScreen {
  display: block !important;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 9999;
}

/* ── Statusbar et TOC : visibles uniquement en lecture ──────────────────── */
#mainStatusbar { display: none; }
body.reading-mode #mainStatusbar { display: flex; }

.toc-title { display: none; }
body.reading-mode .toc-title { display: block; }

#toc { display: none; }
body.reading-mode #toc { display: block; }

#showCoverBtn { display: none !important; }
body.reading-mode #showCoverBtn { display: inline-flex !important; }

.side-section-title.log-title { display: none; }
#log { display: none; }
body.log-enabled .side-section-title.log-title { display: block; }
body.log-enabled #log { display: block; }

/* ── Responsive global ───────────────────────────────────────────────────── */
@media (max-width: 960px) {
  body.cover-mode .topbar { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .content-pane { height: 100%; }
  .cover-card {
    grid-template-columns: 1fr;
    margin-bottom: 24px;
  }
  .cover-visual { min-height: 160px; }
  .nav-btn {
    width: 38px; height: 38px; font-size: 14px;
    background: rgba(14,15,17,.18);
    color: rgba(255,255,255,.6);
  }
  body.reading-mode .nav-btn {
    top: 50%;
    transform: translateY(-50%);
    bottom: auto;
  }
  #apiBaseUrl { width: 140px; }
}
@media (max-width: 600px) {
  .topbar { padding: 8px 10px; }
  #apiBaseUrl, #emailInput, #passwordInput { width: 110px; }
  #coverCardWrap { padding: 12px; }
  .cover-meta { padding: 20px 16px; }
  .cover-meta h1 { font-size: 20px; }
  .cover-meta .actions { flex-direction: column; }
  .cover-btn { text-align: center; }
}
