:root {
  --ink:    #141A2E;
  --paper:  #FFFFFF;
  --wash:   #EEF1F6;
  --line:   #D9DFEA;
  --muted:  #6B7690;
  --accent: #0F766E;
  --danger: #B4232A;
  --ui: "Inter", ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--ui);
  font-size: 15px;
  color: var(--ink);
  background: var(--wash);
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.spacer { flex: 1; }

button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- typographie de marque ---------- */
.wordmark {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .01em;
  margin: 0;
}

/* ---------- boutons ---------- */
.btn {
  border: 1px solid transparent;
  background: none;
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #0b5c56; }
.btn-ghost { border-color: var(--line); background: var(--paper); }
.btn-ghost:hover { background: var(--wash); }
.btn-link { color: var(--muted); text-decoration: underline; }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.danger { color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.field input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--paper);
}
.field input[type="color"] { padding: 4px; width: 58px; height: 42px; }
.error { color: var(--danger); font-size: 13px; margin: 4px 0 10px; }
.notice {
  color: var(--accent); font-size: 13px; margin: 4px 0 10px;
  background: var(--wash); border-radius: var(--radius); padding: 9px 11px;
}

/* ---------- connexion ---------- */
.auth { display: grid; place-items: center; min-height: 100%; padding: 24px; }
.auth-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  width: min(380px, 100%);
}
.auth-sub { color: var(--muted); margin: 4px 0 22px; font-size: 14px; }

/* ---------- structure ---------- */
.app {
  display: grid;
  grid-template-columns: 230px 380px 1fr;
  height: 100dvh;
}
.rail, .list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.rail { background: var(--paper); padding: 16px 12px; gap: 4px; }
.list { background: var(--paper); }
.editor { background: var(--paper); display: flex; flex-direction: column; min-height: 0; }

.rail-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 2px; }
.rail-user { color: var(--muted); font-size: 13px; margin: 0 4px 14px; }

.pane-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  min-height: 60px;
}
.pane-head h2 { font-size: 15px; margin: 0; flex: 1; font-weight: 600; }
.pane-head .count {
  font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  background: var(--wash);
  border-radius: 999px;
  padding: 3px 9px;
  flex: none;
}

/* ---------- tags ---------- */
.tag-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.tag-row {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left;
  padding: 8px 10px;
  border: 0; background: none; border-radius: var(--radius);
  cursor: pointer;
}
.tag-row:hover { background: var(--wash); }
.tag-row.is-active { background: var(--wash); font-weight: 600; }
.tag-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.tag-edit { opacity: 0; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; }
.tag-row:hover .tag-edit, .tag-row:focus-within .tag-edit { opacity: 1; }

/* ---------- liste des notes ---------- */
.notes { overflow-y: auto; flex: 1; }
.note-item {
  display: block; width: 100%; text-align: left;
  padding: 13px 16px;
  border: 0; border-bottom: 1px solid var(--line);
  background: none; cursor: pointer;
}
.note-item:hover { background: var(--wash); }
.note-item.is-active { background: var(--wash); box-shadow: inset 3px 0 0 var(--accent); }
.note-item h3 {
  font-family: var(--serif); font-size: 16px; font-weight: 600;
  margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.note-item time { font-size: 12px; color: var(--muted); }
.empty { padding: 40px 20px; color: var(--muted); text-align: center; }

/* ---------- chips de tags sur une note ---------- */
/* La couleur du tag est portée par la bordure : pas de pastille à caser. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 20px 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  border: 2px solid var(--line); border-radius: 999px;
  padding: 3px 11px; font-size: 13px;
  background: var(--paper); cursor: pointer;
}
.chip.on { color: #fff; font-weight: 500; }
.chip.read { cursor: default; }

/* ---------- éditeur ---------- */
.toolbar {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: 8px 16px; border-bottom: 1px solid var(--line);
}
.toolbar button {
  min-width: 34px; height: 32px; padding: 0 8px;
  border: 0; border-radius: 7px; background: none; cursor: pointer;
}
.toolbar button:hover { background: var(--wash); }
.toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }

.toolbar .toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted);
  cursor: pointer; user-select: none;
  padding: 4px 2px;
}
.toolbar .toggle input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.toolbar .toggle:hover { color: var(--ink); }

/* Icône d'attente pendant la recherche du titre de la page */
.link-loading {
  display: inline-block; vertical-align: -2px;
  width: 13px; height: 13px; margin: 0 5px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .link-loading { animation: none; border-top-color: var(--accent); opacity: .6; }
}

.content {
  flex: 1; overflow-y: auto;
  padding: 22px 20px 60vh;
  font-family: var(--serif);
  font-size: 17px; line-height: 1.65;
  max-width: 70ch;
  outline: none;
}
.content:empty::before { content: "Écris ici…"; color: var(--muted); }
.content h2 { font-size: 21px; margin: 1.4em 0 .4em; }
.content h3 { font-size: 18px; margin: 1.3em 0 .4em; }
.content blockquote {
  margin: 1em 0; padding-left: 14px;
  border-left: 3px solid var(--line); color: var(--muted);
}
.content a { color: var(--accent); }
.content ul, .content ol { padding-left: 1.4em; }
.saved { font-size: 13px; color: var(--muted); }

/* ---------- fenêtre tag ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: 16px;
  padding: 22px; width: min(380px, 92vw);
  background: var(--paper); color: var(--ink);
}
.dialog::backdrop { background: rgba(20,26,46,.45); }
.dialog h3 { margin: 0 0 16px; font-family: var(--serif); font-size: 19px; }
.tag-form-row { display: flex; gap: 12px; align-items: flex-end; }
.tag-form-row .grow { flex: 1; }
.emoji-picker { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.emoji-picker button {
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); width: 34px; height: 34px; cursor: pointer; font-size: 16px;
}
.dialog-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- fenêtre d'export ---------- */
.dialog-wide {
  width: min(860px, 94vw);
  height: 88vh;
  max-height: 88vh;
  display: flex; flex-direction: column;
  padding: 18px 20px;
}
.export-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.export-head h3 { margin: 0; font-family: var(--serif); font-size: 19px; }

.export-body {
  flex: 1; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--paper);
  margin-bottom: 14px;
}
.export-note {
  margin-bottom: 26px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  font-family: var(--serif); font-size: 16px; line-height: 1.6;
}
.export-note:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.export-date {
  display: block;
  font-family: var(--ui); font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.export-note h2 { font-size: 20px; margin: .6em 0 .3em; }
.export-note h3 { font-size: 17px; margin: .6em 0 .3em; }
.export-note a { color: var(--accent); }
.export-note blockquote {
  margin: .8em 0; padding-left: 12px;
  border-left: 3px solid var(--line); color: var(--muted);
}

/* ---------- mobile ---------- */
.only-mobile { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .rail, .list, .editor { border-right: 0; }
  .app > section, .app > aside { display: none; }
  .app[data-view="rail"]   #rail        { display: flex; }
  .app[data-view="list"]   #list-pane   { display: flex; }
  .app[data-view="editor"] #editor-pane { display: flex; }
  .only-mobile { display: inline-block; }
  .content { padding: 18px 16px 60vh; font-size: 18px; }
  .pane-head { padding: 10px 12px; }
}

@media (prefers-reduced-motion: no-preference) {
  .note-item, .tag-row, .btn { transition: background-color .12s ease; }
}
