/* ============================================================ Police Ubuntu (auto-hébergée) */
@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ubuntu-400-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ubuntu-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/ubuntu-500-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/ubuntu-500.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/ubuntu-700-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/ubuntu-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Ubuntu';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ubuntu-400-italic-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Ubuntu';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ubuntu-400-italic.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ============================================================ Base */
:root {
  --sidebar-w: 280px;
  --bg: #f6f4ee;
  --paper: #fffdf8;
  --side-bg: #1c2431;
  --side-bg-2: #263143;
  --side-fg: #cbd3e1;
  --side-dim: #8792a6;
  --ink: #232a35;
  --ink-dim: #6b7482;
  --line: #e4e0d5;
  --accent: #4f46e5;
  --accent-soft: #e0e7ff;
  --danger: #b23b3b;
  --ok: #3d7a4f;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(20, 26, 36, .18);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Ubuntu", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

.hidden { display: none !important; }

/* ============================================================ Layout */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

/* ============================================================ Sidebar */
.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  background: var(--side-bg);
  color: var(--side-fg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 12px;
  font-weight: 700;
  letter-spacing: .02em;
  color: #fff;
}
.brand-name { flex: 1; font-size: 15px; }
.icon-btn.brand-close { display: none; color: var(--side-fg); }

.novel-box { padding: 0 12px 12px; }

.novel-select {
  width: 100%;
  background: var(--side-bg-2);
  border: 1px solid #35415a;
  color: #fff;
  border-radius: var(--radius);
  padding: 9px 10px;
  outline: none;
}
.novel-select:focus { border-color: var(--accent); }

.novel-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.novel-actions .icon-btn { flex: 1; }

.icon-btn {
  background: var(--side-bg-2);
  border: 1px solid #35415a;
  color: var(--side-fg);
  border-radius: 8px;
  min-width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: #31405c; border-color: #465a77; }
.icon-btn.danger:hover { background: #5b2626; border-color: #7d3030; }
.icon-btn.small { height: 26px; min-width: 26px; font-size: 13px; }

.side-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid #2b3648;
}

.side-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--side-dim);
}

.chapter-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--side-fg);
  transition: background .12s;
}
.chapter-item:hover { background: var(--side-bg-2); }
.chapter-item.active { background: var(--accent); color: #fff; }
.chapter-item.active .chap-no { color: #e0e7ff; }

.chap-no {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--side-dim);
  background: rgba(255, 255, 255, .07);
  border-radius: 6px;
  min-width: 24px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.chap-name {
  flex: 1;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chap-del {
  display: none;
  background: transparent;
  border: 0;
  color: inherit;
  opacity: .7;
  font-size: 15px;
  padding: 0 2px;
  line-height: 1;
}
.chapter-item:hover .chap-del { display: inline-block; }
.chap-del:hover { opacity: 1; }

.side-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-top: 1px solid #2b3648;
}

.side-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: 0;
  color: var(--side-fg);
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13.5px;
}
.side-link:hover { background: var(--side-bg-2); }
.side-link.active { background: var(--accent); color: #fff; }

.badge {
  background: rgba(255, 255, 255, .12);
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 8px;
  min-width: 22px;
  text-align: center;
}

.side-footer {
  padding: 10px 16px 14px;
  font-size: 11.5px;
  color: var(--side-dim);
  border-top: 1px solid #2b3648;
}

/* ============================================================ Main */
.main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.menu-btn {
  display: none;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
  height: 36px;
  min-width: 36px;
  border-radius: 8px;
  font-size: 16px;
}

.crumb {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crumb strong { color: var(--ink); font-weight: 600; }

.save-state {
  font-size: 12px;
  color: var(--ink-dim);
  white-space: nowrap;
}
.save-state.ok { color: var(--ok); }
.save-state.busy { color: var(--accent); }
.save-state.err { color: var(--danger); }

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============================================================ Éditeur */
.editor-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px 0;
  background: var(--paper);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.chap-num {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-dim);
  white-space: nowrap;
}
.chap-num input {
  width: 58px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 6px 6px;
  text-align: center;
}

.chap-title {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-family: "Ubuntu", sans-serif;
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
  padding: 6px 0;
  outline: none;
}
.chap-title::placeholder { color: #b9b3a4; }

.editor-body {
  flex: 1;
  min-height: 0;
  display: flex;
  background: var(--paper);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.chap-content {
  flex: 1;
  min-height: 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-family: "Ubuntu", sans-serif;
  font-size: 17.5px;
  line-height: 1.5;
  color: var(--ink);
  padding: 18px 24px 40px;
  overflow-y: auto;
  text-align: justify;
  text-justify: inter-word;
  text-align-last: left;
}
.chap-content::placeholder { color: #b9b3a4; }

.editor-foot {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 24px;
  background: var(--paper);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-dim);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

/* ============================================================ Vues secondaires */
#viewFiches, #viewNotes {
  overflow-y: auto;
  padding: 22px 24px 60px;
}

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 900px;
  margin: 0 auto 18px;
}
.view-head h1 {
  font-family: "Ubuntu", sans-serif;
  font-size: 22px;
  margin: 0;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: var(--radius);
  padding: 9px 15px;
  font-size: 14px;
  transition: filter .15s, background .15s;
}
.btn:hover { background: var(--bg); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #e3c4c4; }
.btn.danger:hover { background: #fbeeee; }

/* Fiches */
.fiches-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  max-width: 900px;
  margin: 0 auto;
}

.fiche {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fiche-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fiche-name {
  flex: 1;
  min-width: 0;
  border: 0;
  border-bottom: 2px solid var(--accent-soft);
  background: transparent;
  font-family: "Ubuntu", sans-serif;
  font-size: 17px;
  font-weight: 600;
  padding: 4px 0;
  outline: none;
}
.fiche-name:focus { border-bottom-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 3px; }
.field span {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-dim);
}
.field input, .field textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  padding: 7px 9px;
  font-size: 13.5px;
  outline: none;
  resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); background: #fff; }
.field textarea { min-height: 64px; font-family: inherit; line-height: 1.5; }

.fiche-row { display: flex; gap: 8px; }
.fiche-row .field { flex: 1; }


/* Notes */
.notes-list {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.note input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}
.note-text {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-size: 14.5px;
  padding: 4px 0;
  outline: none;
}
.note.done .note-text { text-decoration: line-through; color: var(--ink-dim); }
.note-del {
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font-size: 17px;
  line-height: 1;
  padding: 2px 4px;
}
.note-del:hover { color: var(--danger); }

/* ============================================================ État vide */
.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 6;
  padding: 24px;
}
.empty-card {
  text-align: center;
  max-width: 380px;
  color: var(--ink-dim);
}
.empty-icon { font-size: 46px; margin-bottom: 10px; }
.empty-card p { font-size: 15px; line-height: 1.6; margin: 0 0 18px; }

/* ============================================================ Modale */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 28, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--paper);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal-label {
  display: block;
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 5px;
}
.modal input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  outline: none;
  background: #fff;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ============================================================ Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #2b2f38;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  z-index: 200;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 40px);
}

.scrim { display: none; }

/* ============================================================ Smartphone */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow);
    width: min(84vw, 300px);
    flex-basis: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }

  .icon-btn.brand-close { display: inline-flex; }
  .menu-btn { display: inline-flex; }

  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 20, 28, .5);
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s;
  }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }

  .editor-head { padding: 12px 14px 0; flex-wrap: wrap; gap: 8px; }
  .chap-title { font-size: 20px; flex-basis: 100%; order: 2; }
  .chap-content { padding: 14px 16px 40px; font-size: 16.5px; }
  .editor-foot { padding: 8px 14px; }
  .hint { display: none; }

  #viewFiches, #viewNotes { padding: 16px 14px 60px; }
  .view-head { flex-direction: column; align-items: stretch; }
  .view-head .btn { width: 100%; }

  .chap-del { display: inline-block; }
}

@media (max-width: 400px) {
  .editor-head { padding: 10px 10px 0; }
}


/* ============================================================ Barre utilisateur (sidebar) */
.side-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-name {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--side-fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-link {
  font-size: 11.5px;
  color: var(--side-dim);
  text-decoration: none;
  border: 1px solid #35415a;
  border-radius: 7px;
  padding: 4px 9px;
  transition: background .15s, color .15s;
}
.logout-link:hover { background: #31405c; color: #fff; }

/* ============================================================ Page de connexion */
body.auth-page {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px;
  background:
    radial-gradient(1000px 500px at 20% -10%, rgba(138, 90, 43, .18), transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(20, 26, 36, .14);
  padding: 32px 28px 26px;
}

.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-mark { font-size: 40px; display: block; margin-bottom: 6px; }
.auth-brand h1 {
  font-family: "Ubuntu", sans-serif;
  font-size: 23px;
  margin: 0 0 4px;
}
.auth-tagline { margin: 0; font-size: 13.5px; color: var(--ink-dim); }

.auth-errors {
  background: #fbeeee;
  border: 1px solid #eccfcf;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.5;
}

.auth-form { display: flex; flex-direction: column; gap: 13px; }
.auth-form .field span { color: var(--ink-dim); }
.auth-form .field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  padding: 11px 12px;
  font-size: 15px;
  outline: none;
}
.auth-form .field input:focus { border-color: var(--accent); background: #fff; }

.auth-submit { width: 100%; padding: 12px; font-size: 15px; margin-top: 4px; }

.auth-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 13.5px;
  color: var(--ink-dim);
}
.auth-switch a { color: var(--accent); font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

