:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e3e1da;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --tag-bg: #fbe9df;
  --tag-text: #9a3412;
  --code-bg: #f1efe9;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --surface: #212226;
    --text: #ececee;
    --muted: #9a9aa2;
    --border: #33343a;
    --accent: #f97316;
    --accent-text: #1a1a1a;
    --tag-bg: #3a2418;
    --tag-text: #fdba74;
    --code-bg: #2b2c31;
    --danger: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }

input, textarea, button { font: inherit; color: inherit; }
input, textarea {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 4.5em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }

button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); }
button.danger { color: var(--danger); }
button.icon { padding: 6px 10px; font-size: 18px; line-height: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Connexion */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 320px; padding: 28px 24px; display: grid; gap: 12px; text-align: center; justify-items: center; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card img { border-radius: 14px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { margin: 0; font-size: 18px; font-weight: 700; color: var(--accent); }
.topbar input { flex: 1; max-width: 420px; margin-left: auto; background: var(--surface); }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }

/* Saisie */
.composer { padding: 12px; display: grid; gap: 8px; }
.composer #new-title { border-color: transparent; font-weight: 600; padding-left: 4px; }
.composer #new-title:focus { border-color: var(--border); }
.composer-row { display: flex; gap: 8px; }
.composer-row input { flex: 1; font-size: 14px; }

/* Tags */
.tagbar { display: flex; gap: 6px; overflow-x: auto; padding: 14px 0 6px; scrollbar-width: none; }
.tagbar::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid transparent;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.chip.active { background: var(--accent); color: var(--accent-text); }
.chip small { opacity: .7; margin-left: 3px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); padding: 4px 0; }

/* Liste */
.list { display: grid; gap: 12px; margin-top: 10px; }
.note { padding: 14px 16px; overflow-wrap: anywhere; }
.note-head { display: flex; align-items: baseline; gap: 8px; }
.note-title { margin: 0; font-size: 17px; flex: 1; }
.note-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.note-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.note-actions { display: flex; gap: 4px; justify-content: flex-end; margin-top: 6px; opacity: .55; }
.note:hover .note-actions, .note:focus-within .note-actions { opacity: 1; }
.note-actions button { padding: 3px 10px; font-size: 13px; }
.note.editing { display: grid; gap: 8px; }
.note.editing textarea { min-height: 12em; }
.edit-row { display: flex; gap: 8px; justify-content: flex-end; }

.empty { text-align: center; color: var(--muted); padding: 32px 0; }
.more { display: block; margin: 16px auto 0; }

/* Markdown */
.md > :first-child { margin-top: 6px; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { line-height: 1.25; margin: 1em 0 .4em; }
.md h1 { font-size: 1.3em; } .md h2 { font-size: 1.15em; } .md h3 { font-size: 1.05em; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md table { margin: .5em 0; }
.md ul, .md ol { padding-left: 1.4em; }
.md a { color: var(--accent); }
.md a.chip { color: var(--tag-text); }
.md code { background: var(--code-bg); padding: .1em .35em; border-radius: 4px; font-size: .88em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.md pre { background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--border); margin-left: 0; padding-left: 12px; color: var(--muted); }
.md img { max-width: 100%; border-radius: 6px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; }
.md hr { border: 0; border-top: 1px solid var(--border); }
.md input[type=checkbox] { width: auto; margin-right: 6px; }

@media (max-width: 520px) {
  .brand { display: none; }
  .topbar input { margin-left: 0; }
}
