/* =====================================================================
   Aide à l'écriture — feuille de style
   Sobre, dense, pensée pour un grand écran. Rien qui clignote.
   ===================================================================== */

:root {
  --paper:      #faf8f5;
  --surface:    #ffffff;
  --surface-2:  #f3efe9;
  --ink:        #1f1c19;
  --ink-soft:   #5c554d;
  --ink-faint:  #8d857b;
  --line:       #e2dbd1;
  --accent:     #7a5c3e;
  --accent-ink: #ffffff;
  --accent-soft:#f0e7dc;
  --ok:         #2f6b44;
  --warn:       #9a6b1f;
  --error:      #a33a2c;

  --st-idee:      #b9b2a8;
  --st-plan:      #8aa1b8;
  --st-brouillon: #c9a227;
  --st-revise:    #7a9a5e;
  --st-valide:    #4a7c59;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(31,28,25,.05), 0 6px 20px rgba(31,28,25,.05);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono:  ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #171614;
    --surface:    #1f1e1b;
    --surface-2:  #26241f;
    --ink:        #ece7df;
    --ink-soft:   #b3aaa0;
    --ink-faint:  #837c73;
    --line:       #35322c;
    --accent:     #c49a6c;
    --accent-ink: #1a1815;
    --accent-soft:#2c2721;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.serif { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.big   { font-size: 22px; }

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; }
h1 { font-size: 28px; }
h2 { font-size: 17px; }

a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }

kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 3px;
}

/* --- Boutons et champs ----------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }

label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

input[type=text], input[type=email], input[type=password],
input[type=number], select, textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.row { display: flex; gap: 14px; align-items: flex-end; }
.row.end { justify-content: flex-end; align-items: center; }
.grow { flex: 1; }

/* --- Messages ---------------------------------------------------------- */

.flash, .error, .ok, .warn {
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  margin: 0 0 16px;
}
.flash { background: var(--accent-soft); }
.error { background: rgba(163,58,44,.1); color: var(--error); }
.ok    { background: rgba(47,107,68,.1);  color: var(--ok); }
.warn  { background: rgba(154,107,31,.12); color: var(--warn); }

.hint { font-size: 13px; color: var(--ink-faint); margin: 4px 0 14px; }

/* --- Pages hors projet -------------------------------------------------- */

.plain { max-width: 1100px; margin: 0 auto; padding: 48px 32px; }

.login-wrap { display: flex; justify-content: center; padding-top: 6vh; }
.login-card {
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.login-card.wide { width: 520px; }
.login-card h1 { font-size: 24px; }
.login-card h2 { margin-top: 26px; font-size: 15px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }

/* --- Accueil ------------------------------------------------------------ */

.home { max-width: 1100px; margin: 0 auto; padding: 48px 32px; }
.home-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 32px; }
.home-actions { display: flex; gap: 10px; }

.new-book {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 32px;
  box-shadow: var(--shadow);
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); color: inherit; }
.card h2 { font-size: 20px; margin: 8px 0 16px; }

.tag {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-soft);
}

.card-stats { display: flex; gap: 24px; margin-bottom: 14px; }
.card-stats strong { display: block; font-family: var(--serif); font-size: 20px; }
.card-stats span { font-size: 12px; color: var(--ink-faint); }

.bar { height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 12px; }
.bar span { display: block; height: 100%; background: var(--accent); }
.bar.big { height: 8px; max-width: 420px; }

.empty { text-align: center; padding: 72px 20px; color: var(--ink-faint); }
.empty .big { color: var(--ink-soft); margin-bottom: 6px; }

/* --- Coquille d'un projet ----------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.book { display: block; padding: 0 10px 20px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.book-title { display: block; font-family: var(--serif); font-size: 18px; line-height: 1.3; }
.book-genre { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); margin-top: 4px; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink-soft);
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--ink); }
.sidebar nav a.active { background: var(--accent-soft); color: var(--ink); font-weight: 500; }
.sidebar .ico { width: 18px; text-align: center; opacity: .65; }

.cmdk-hint {
  margin-top: auto;
  font: inherit;
  font-size: 12px;
  color: var(--ink-faint);
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  text-align: center;
}
.cmdk-hint:hover { border-color: var(--accent); color: var(--ink-soft); }

.content { flex: 1; padding: 40px 44px; max-width: 1400px; }
.screen-head { margin-bottom: 28px; }

/* --- Tableau de bord ---------------------------------------------------- */

.counter { margin-bottom: 36px; }
.counter-main strong { font-family: var(--serif); font-size: 56px; line-height: 1; }
.counter-main span { font-size: 15px; color: var(--ink-soft); margin-left: 10px; }
.counter-side { font-size: 13px; color: var(--ink-faint); margin: 6px 0 0; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}
.panel.accent { border-color: var(--accent); background: var(--accent-soft); }
.panel h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }

/* --- Pastilles de statut ------------------------------------------------- */

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-idee      { background: var(--st-idee); }
.dot-plan      { background: var(--st-plan); }
.dot-brouillon { background: var(--st-brouillon); }
.dot-revise    { background: var(--st-revise); }
.dot-valide    { background: var(--st-valide); }

/* --- Palette de commandes (Ctrl+K) --------------------------------------- */

#cmdk { position: fixed; inset: 0; z-index: 100; }
.cmdk-backdrop { position: absolute; inset: 0; background: rgba(31,28,25,.35); }
.cmdk-panel {
  position: relative;
  width: min(620px, 90vw);
  margin: 12vh auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  padding: 14px;
}
.cmdk-panel input {
  margin: 0;
  border: none;
  font-size: 17px;
  padding: 8px 6px;
  background: transparent;
}
.cmdk-panel input:focus { box-shadow: none; }
.cmdk-note {
  margin: 10px 0 2px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-faint);
}

/* --- Écran Plan ---------------------------------------------------------- */

.plan-head { display: flex; justify-content: space-between; align-items: flex-start; }
.plan-actions { display: flex; align-items: center; gap: 14px; }

.save-state { font-size: 12px; color: var(--ink-faint); min-width: 110px; text-align: right; }
.save-state.error-text { color: var(--error); }

.plan-layout { display: flex; gap: 24px; align-items: flex-start; }
.plan-table-wrap { flex: 1; min-width: 0; overflow-x: auto; }

.plan-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  font-size: 14px;
}

.plan-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-faint);
  font-weight: 500;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.plan-table td { padding: 2px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.plan-table tr:last-child td { border-bottom: none; }
.plan-table tbody tr:hover { background: var(--surface-2); }
.plan-table tbody tr.selected { background: var(--accent-soft); }
.plan-table tbody tr.dragging { opacity: .4; }

.col-drag   { width: 22px; color: var(--ink-faint); cursor: grab; text-align: center; user-select: none; }
.col-num    { width: 38px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.col-title  { width: 20%; }
.col-pov    { width: 130px; }
.col-status { width: 120px; }
.col-words  { width: 70px; text-align: right; color: var(--ink-faint);
              font-variant-numeric: tabular-nums; }

/* Champs fondus dans le tableau : on tape directement dedans */
.plan-table input[type=text],
.plan-table select {
  margin: 0;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 6px 7px;
  font-size: 14px;
  width: 100%;
}
.plan-table input[type=text]:hover,
.plan-table select:hover { border-color: var(--line); }
.plan-table input[type=text]:focus,
.plan-table select:focus { border-color: var(--accent); background: var(--surface); box-shadow: none; }
.plan-table input::placeholder { color: var(--ink-faint); opacity: .6; }

/* Pastille de couleur devant le statut */
.status-select { padding-left: 20px !important; background-repeat: no-repeat;
                 background-position: 6px center; background-size: 8px 8px; }
.st-idee      { background-image: radial-gradient(circle at center, #b9b2a8 58%, transparent 60%); }
.st-plan      { background-image: radial-gradient(circle at center, #8aa1b8 58%, transparent 60%); }
.st-brouillon { background-image: radial-gradient(circle at center, #c9a227 58%, transparent 60%); }
.st-revise    { background-image: radial-gradient(circle at center, #7a9a5e 58%, transparent 60%); }
.st-valide    { background-image: radial-gradient(circle at center, #4a7c59 58%, transparent 60%); }

.plan-foot { margin-top: 12px; }

/* --- Panneau de détail ---------------------------------------------------- */

.detail {
  width: 380px;
  flex: none;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: 14px 14px 0 0;
}
.detail-num { font-family: var(--serif); font-size: 16px; }
.detail-close {
  border: none; background: transparent; cursor: pointer;
  color: var(--ink-faint); font-size: 15px; padding: 4px 6px; border-radius: 6px;
}
.detail-close:hover { background: var(--surface-2); color: var(--ink); }

.detail-body { padding: 18px; }
.detail-body hr { border: none; border-top: 1px solid var(--line); margin: 20px 0; }
.detail-two   { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-three { display: grid; grid-template-columns: 1fr 90px 1fr; gap: 8px; }

.detail-body textarea { resize: vertical; line-height: 1.5; }

.change { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0 0 14px; }
.change legend { font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
                 color: var(--ink-soft); padding: 0 6px; }
.change .hint { margin-top: 0; }

.quick-create { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: -6px 0 14px; }
.link-btn {
  border: none; background: transparent; padding: 0; cursor: pointer;
  font: inherit; font-size: 12px; color: var(--accent); text-decoration: underline;
}
.link-btn.danger { color: var(--error); }
.quick-input { width: 160px !important; margin: 0 !important; font-size: 13px !important; }

.detail-danger { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }

/* --- Écran des fiches ----------------------------------------------------- */

.sheet-list-wrap { flex: 1; min-width: 0; }

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.sheet-card {
  display: block;
  text-align: left;
  font: inherit;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.sheet-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.sheet-card.selected { border-color: var(--accent); background: var(--accent-soft); }

.sheet-name { display: block; font-size: 17px; margin-bottom: 2px; }
.sheet-role { display: block; font-size: 13px; color: var(--ink-soft); }
.sheet-role .ph, .ph { color: var(--ink-faint); font-style: italic; }
.sheet-arc {
  display: block;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-faint);
  line-height: 1.45;
}

/* La fiche elle-même */
.sheet-detail { width: 420px; }

/* La question sous l'étiquette : c'est elle qui accompagne */
.q-hint {
  display: block;
  font-size: 12px;
  color: var(--ink-faint);
  font-weight: normal;
  margin-top: 2px;
  line-height: 1.4;
}
.sheet-detail label > input,
.sheet-detail label > textarea { margin-top: 7px; }

/* Bloc « approfondir » */
.deepen { margin: 6px 0 4px; border-top: 1px solid var(--line); padding-top: 14px; }
.deepen > summary {
  cursor: pointer;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  list-style: none;
  padding: 4px 0;
  user-select: none;
}
.deepen > summary::-webkit-details-marker { display: none; }
.deepen > summary::before { content: '▸ '; color: var(--ink-faint); }
.deepen[open] > summary::before { content: '▾ '; }
.deepen > *:not(summary) { margin-top: 12px; }

/* Relations et apparitions */
.relations h3, .appearances h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.relation-list, .appearance-list { list-style: none; margin: 0 0 12px; padding: 0; font-size: 13px; }
.relation-list li, .appearance-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.relation-list li:last-child, .appearance-list li:last-child { border-bottom: none; }

.relation-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.relation-add select, .relation-add input { margin: 0; font-size: 13px; padding: 7px 9px; }
.relation-add .btn { padding: 7px 12px; font-size: 13px; }

.ap-num { color: var(--ink-faint); font-variant-numeric: tabular-nums; margin-right: 4px; }
.ap-role { color: var(--ink-faint); font-size: 12px; white-space: nowrap; }
