/* Carnet : feuille de style.
   Deux surfaces : l'index (outils, sans-serif) et la page (écriture, Newsreader).
   Signature visuelle : le trait de surligneur jaune (wordmark, résultats de recherche,
   notes épinglées, action du toast). Tout le reste reste discret. */

@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("fonts/newsreader-normal-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Newsreader";
  font-style: italic;
  font-weight: 200 800;
  font-display: swap;
  src: url("fonts/newsreader-italic-latin.woff2") format("woff2");
}

:root {
  --paper: #f4f4ef;
  --paper-2: #ebebe5;
  --paper-3: #e2e2db;
  --ink: #1b2430;
  --ink-2: #566270;
  --ink-3: #8b95a1;
  --line: #d8d9d1;
  --accent: #2b5c8a;
  --marker: #f7df6b;
  --marker-ink: #1b2430;
  --danger: #a33a2e;
  --btn: #1b2430;
  --btn-ink: #f4f4ef;
  --hover: rgba(27, 36, 48, 0.05);
  --shadow: 0 10px 30px rgba(27, 36, 48, 0.14);
  --shadow-soft: 0 1px 2px rgba(27, 36, 48, 0.06), 0 6px 18px rgba(27, 36, 48, 0.05);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Newsreader", Charter, "Iowan Old Style", Georgia, serif;

  --index-w: 320px;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14181f;
    --paper-2: #1a1f27;
    --paper-3: #232a34;
    --ink: #e8eaee;
    --ink-2: #a4adb9;
    --ink-3: #6c7583;
    --line: #2a313c;
    --accent: #8fb3e0;
    --marker: #d9b93f;
    --marker-ink: #14181f;
    --danger: #e08a7e;
    --btn: #e8eaee;
    --btn-ink: #14181f;
    --hover: rgba(232, 234, 238, 0.06);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- Disposition ---- */

.app {
  display: grid;
  grid-template-columns: var(--index-w) 1fr;
  height: 100vh;
}
@supports (height: 100dvh) { .app { height: 100dvh; } }

/* ---- Index ---- */

.index {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--paper-2);
}

.index-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 18px 12px;
}
.index-head h1 {
  position: relative;
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.01em;
}
/* Le trait de surligneur derrière le mot, légèrement de biais, comme un vrai coup de feutre. */
.index-head h1::before {
  content: "";
  position: absolute;
  left: -4px; right: -6px; bottom: -1px;
  height: 11px;
  background: var(--marker);
  transform: skewX(-8deg) rotate(-1deg);
  border-radius: 2px;
  z-index: -1;
  opacity: 0.9;
}
.index-head h1 { z-index: 0; }

.search {
  position: relative;
  margin: 0 18px 8px;
}
.search input {
  width: 100%;
  padding: 9px 56px 9px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: box-shadow 120ms ease;
}
.search input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search kbd {
  position: absolute;
  right: 9px; top: 50%;
  transform: translateY(-50%);
  font-family: var(--sans);
  font-size: 11px;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  pointer-events: none;
}
.search:has(input:focus) kbd,
.search:has(input:not(:placeholder-shown)) kbd { display: none; }

/* Tags (#mot-clé) : une rangée de filtres sous la recherche */
.tags {
  display: flex;
  gap: 6px;
  margin: 2px 18px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tags::-webkit-scrollbar { display: none; }
.tags[hidden] { display: none; }
.tag {
  flex: none;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12.5px;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.tag:hover { border-color: var(--ink-3); color: var(--ink); }
.tag[aria-pressed="true"] { background: var(--marker); border-color: var(--marker); color: var(--marker-ink); }

.list {
  list-style: none;
  margin: 0;
  padding: 2px 10px 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.row { position: relative; }
.item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 36px 11px 12px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  line-height: 1.35;
  transition: background-color 120ms ease, box-shadow 120ms ease;
}
.item:hover { background: var(--hover); }
.item[aria-selected="true"] {
  background: var(--paper);
  box-shadow: var(--shadow-soft);
}
.item-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.item-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.005em;
}
.item-title span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.25;
}
.item-title.untitled { color: var(--ink-3); font-style: italic; font-weight: 400; }
.item-pin {
  flex: none;
  width: 10px; height: 5px;
  border-radius: 1px;
  background: var(--marker);
  transform: translateY(-4px) skewX(-8deg);
}
.item-date {
  flex: none;
  color: var(--ink-3);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.item-excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.4;
  margin-top: 3px;
}
.item-excerpt:empty { display: none; }
.row.trashed .item-date { display: block; margin-top: 4px; color: var(--danger); font-size: 12px; }
mark {
  background: var(--marker);
  color: var(--marker-ink);
  border-radius: 2px;
  padding: 0 1px;
  box-decoration-break: clone;
}

/* Croix de suppression : visible au survol ou au clavier à la souris, toujours au doigt. */
.item-delete {
  position: absolute;
  top: 7px; right: 7px;
  width: 26px; height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-3);
  font-size: 20px;
  line-height: 1;
  opacity: 0;
  transition: opacity 120ms ease, color 120ms ease, background-color 120ms ease;
}
.row:hover .item-delete,
.row:focus-within .item-delete,
.item-delete:focus-visible { opacity: 1; }
.item-delete:hover { color: var(--danger); background: var(--hover); }
@media (hover: none) { .item-delete { opacity: 1; } }

/* État vide : une page et un trait de surligneur */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 24px 20px 40px;
  color: var(--ink-2);
  text-align: center;
}
.empty[hidden] { display: none; }
.empty svg { width: 64px; height: 64px; margin-bottom: 10px; color: var(--ink-3); }
.empty svg .stroke { fill: var(--marker); }
.empty p { margin: 0 0 12px; font-family: var(--serif); font-size: 18px; color: var(--ink-2); }
.app.trash .empty button { display: none; }

/* Vue Corbeille */
.trash-bar {
  margin: 0 18px 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow-soft);
  font-size: 13px;
  color: var(--ink-2);
}
.trash-bar[hidden] { display: none; }
.trash-bar p { margin: 0 0 8px; }
.trash-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.trash-actions .btn { font-size: 13px; padding: 5px 10px; }
.app.trash .index-head h1::before { display: none; }
.app.trash .index-head h1::after { content: " · corbeille"; font-size: 15px; font-weight: 400; font-style: italic; color: var(--ink-3); }
.app.trash #new { display: none; }

.index-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 10px 18px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-2);
}
.net::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #3f9a5a;
  margin-right: 7px;
}
.net.offline::before { background: var(--ink-3); }

.more { position: relative; }
.more summary {
  list-style: none;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  transition: background-color 120ms ease;
}
.more summary::-webkit-details-marker { display: none; }
.more summary:hover { background: var(--hover); }
.more summary.attention::after {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--marker);
  vertical-align: 1px;
}
.more-menu {
  position: absolute;
  right: 0; bottom: calc(100% + 8px);
  min-width: 260px;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 5;
}
.more-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
}
.more-menu button:hover { background: var(--paper-2); }
.more-menu button[hidden] { display: none; }
.more-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  color: var(--ink);
}
.more-row select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  padding: 3px 6px;
  font-size: 13px;
}
.more-hint {
  margin: 6px 10px 4px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-3);
}
.more-hint.warn { color: var(--danger); }
.more-hint[hidden] { display: none; }

/* ---- Boutons ---- */

.btn {
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover { border-color: var(--ink-3); }
.btn-primary {
  background: var(--btn);
  border-color: var(--btn);
  color: var(--btn-ink);
  font-weight: 500;
}
.btn-primary:hover { border-color: var(--btn); opacity: 0.9; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-3); }
.btn-ghost:hover { color: var(--ink); background: var(--hover); border-color: transparent; }
.btn-ghost[aria-pressed="true"] { color: var(--marker-ink); background: var(--marker); border-color: var(--marker); }
.btn-ghost[aria-pressed="true"]#view { background: var(--paper-2); border-color: transparent; color: var(--ink); }
.btn-danger:hover { color: var(--danger); }

/* ---- Page d'écriture ---- */

.page {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.page-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 10px 14px 0;
  min-height: 48px;
}
.page-bar-spacer { flex: 1; }
.saved { font-size: 12.5px; color: var(--ink-3); padding-left: 8px; }

.editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: min(100%, 68ch);
  margin: 0 auto;
  padding: 32px 28px 0;
  font-family: var(--serif);
}
.editor[hidden] { display: none; }

.title {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  resize: none;
  overflow: hidden;
  field-sizing: content;              /* le titre s'étend sur plusieurs lignes ; JS en secours */
  font-family: var(--serif);
  font-size: 38px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.015em;
}
.title:focus { outline: none; }
.title::placeholder { color: var(--ink-3); font-weight: 400; }

.meta {
  margin: 10px 0 22px;
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--ink-3);
}

.body {
  flex: 1;
  min-height: 0;
  width: 100%;
  resize: none;
  border: 0;
  padding: 0 0 40vh;
  background: transparent;
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.65;
}
.body:focus { outline: none; }
.body::placeholder { color: var(--ink-3); }

/* Aperçu (Markdown léger) */
.preview {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 40vh;
  font-size: 19px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.preview[hidden] { display: none; }
.preview > :first-child { margin-top: 0; }
.preview h2, .preview h3, .preview h4 { font-weight: 500; line-height: 1.2; letter-spacing: -0.01em; margin: 1.3em 0 0.4em; }
.preview h2 { font-size: 28px; }
.preview h3 { font-size: 23px; }
.preview h4 { font-size: 20px; font-style: italic; font-weight: 400; }
.preview p { margin: 0 0 0.9em; }
.preview ul, .preview ol { margin: 0 0 0.9em; padding-left: 1.4em; }
.preview li { margin: 0.15em 0; }
.preview ul.tasks { list-style: none; padding-left: 0.1em; }
.preview ul.tasks li { display: flex; align-items: baseline; gap: 11px; }
.preview ul.tasks input { width: 18px; height: 18px; flex: none; transform: translateY(3px); accent-color: var(--accent); cursor: pointer; }
.preview ul.tasks li.done span { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--ink-3); }
.preview code { font-family: ui-monospace, Consolas, monospace; font-size: 0.82em; background: var(--paper-2); padding: 1px 6px; border-radius: 5px; }
.preview a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.preview a.tag-link { text-decoration: none; background: var(--paper-2); padding: 0 6px; border-radius: 5px; }
.preview .preview-empty { color: var(--ink-3); font-style: italic; }

.placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 22px;
  font-style: italic;
  line-height: 1.4;
}
.placeholder p { margin: 0 0 8px; max-width: 30ch; }
.placeholder-hint { font-family: var(--sans); font-style: normal; font-size: 13px; color: var(--ink-3); }
.placeholder[hidden] { display: none; }

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 50%; bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 10;
  width: max-content;                 /* sinon left: 50 % limite la largeur à la moitié de l'écran */
  max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
.toast button {
  flex: none;
  border: 0;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--marker);
  color: #1b2430;
  font-weight: 600;
}
.toast button[hidden] { display: none; }

/* ---- Mobile : un écran à la fois ---- */

.only-mobile { display: none; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .index { border-right: 0; }
  .page { display: none; }
  .app.show-page .index { display: none; }
  .app.show-page .page { display: flex; }
  .only-mobile { display: inline-block; }
  .page-bar { padding-left: 6px; padding-right: 8px; gap: 0; }
  .page-bar .btn { padding-left: 8px; padding-right: 8px; }
  .saved { display: none; }           /* l'enregistrement est automatique ; la place manque à côté des boutons */
  .editor { padding: 14px 18px 0; }
  .title { font-size: 30px; }
  .body, .preview { font-size: 18px; }
  .search kbd { display: none; }
  .index-head { padding-top: max(20px, env(safe-area-inset-top)); }
  .page-bar { padding-top: max(10px, env(safe-area-inset-top)); }
  .item[aria-selected="true"] { background: transparent; box-shadow: none; }
}

/* Un seul mouvement : la page glisse quand on ouvre une note sur mobile. */
@media (max-width: 720px) and (prefers-reduced-motion: no-preference) {
  .app.show-page .page { animation: page-in 200ms cubic-bezier(0.2, 0.7, 0.2, 1); }
  @keyframes page-in {
    from { opacity: 0; transform: translateX(24px); }
    to { opacity: 1; transform: none; }
  }
}
