/* ————————————————————————————————————————————————
   Carnet — thème « cahier d'écolier »
   Papier ligné bleu, marge rouge, encre bleu nuit.
   ———————————————————————————————————————————————— */
:root {
  --paper:      #FAF9F2;
  --paper-deep: #F1EFE4;
  --rule:       #D7E3F1;   /* lignes du cahier */
  --margin-red: #D8524A;   /* marge rouge */
  --ink:        #26357A;   /* encre bleue */
  --ink-soft:   #5A67A5;
  --text:       #2E2D36;
  --highlight:  #F6E27F;   /* surligneur */
  --line-h: 32px;
  --font-body: "Nunito Sans", system-ui, sans-serif;
  --font-hand: "Caveat", cursive;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--paper-deep);
}

/* ————— papier ligné (élément signature) ————— */
.ruled-paper {
  background-color: var(--paper);
  background-image:
    linear-gradient(to right, transparent 56px, var(--margin-red) 56px, var(--margin-red) 58px, transparent 58px),
    repeating-linear-gradient(to bottom, transparent, transparent calc(var(--line-h) - 1px), var(--rule) calc(var(--line-h) - 1px), var(--rule) var(--line-h));
}

/* ————— marque ————— */
.brand {
  font-family: var(--font-hand);
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
  letter-spacing: .5px;
}
.brand-pen { color: var(--margin-red); }

/* ————— boutons ————— */
button { font-family: inherit; font-size: .9rem; cursor: pointer; }
.btn-primary {
  background: var(--ink); color: #fff; border: none;
  padding: .55rem .9rem; border-radius: 8px; font-weight: 700;
}
.btn-primary:hover { background: #1C2A66; }
.btn-secondary {
  background: transparent; color: var(--ink);
  border: 1.5px solid var(--ink); padding: .5rem .8rem;
  border-radius: 8px; font-weight: 700;
}
.btn-secondary:hover { background: rgba(38,53,122,.08); }
.btn-danger {
  background: transparent; border: 1.5px solid var(--margin-red);
  color: var(--margin-red); border-radius: 8px; padding: .45rem .6rem;
}
.btn-danger:hover { background: rgba(216,82,74,.1); }
.btn-ghost {
  background: none; border: none; color: var(--ink-soft);
  text-decoration: underline; padding: 0;
}
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 2px;
}

/* ————— connexion ————— */
.login-body {
  display: grid; place-items: center; min-height: 100vh; padding: 1rem;
}
.login-card {
  width: min(420px, 100%);
  border: 1px solid #E3E0D2;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(38,53,122,.12);
  padding: 2rem 2rem 2rem 76px; /* le texte commence après la marge rouge */
}
.login-sub { color: var(--ink-soft); margin-top: .25rem; }
.login-error {
  color: var(--margin-red); font-weight: 700; margin: .5rem 0 0;
}
.login-form { display: flex; flex-direction: column; gap: .35rem; margin-top: 1rem; }
.login-form label { font-weight: 700; color: var(--ink); font-size: .85rem; }
.login-form input {
  font: inherit; padding: .55rem .7rem; margin-bottom: .6rem;
  border: 1.5px solid var(--rule); border-radius: 8px; background: #fff;
}
.login-form .btn-primary { margin-top: .4rem; }

/* ————— mise en page principale ————— */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
}

/* ————— colonne latérale ————— */
.sidebar {
  border-right: 1px solid #E3E0D2;
  background: var(--paper);
  display: flex; flex-direction: column;
  padding: 1rem; gap: .9rem; overflow-y: auto;
}
.whoami {
  display: flex; align-items: baseline; gap: .5rem;
  font-size: .85rem; color: var(--ink-soft); margin-top: .15rem;
}
.whoami > span:first-child { font-weight: 800; color: var(--text); }
.duo { font-style: italic; }
.whoami form { margin-left: auto; }

.new-buttons { display: flex; gap: .5rem; }
.new-buttons .btn-primary, .new-buttons .btn-secondary { flex: 1; }

.filters { display: flex; flex-wrap: wrap; gap: .3rem; }
.filter {
  border: none; background: transparent; color: var(--ink-soft);
  padding: .3rem .55rem; border-radius: 999px; font-weight: 700; font-size: .8rem;
}
.filter.active { background: var(--ink); color: #fff; }

.note-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.note-card {
  border: 1px solid #E3E0D2; border-radius: 10px; background: #fff;
  padding: .6rem .75rem; cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
}
.note-card:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(38,53,122,.1); }
.note-card.selected { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }
.note-card h3 {
  margin: 0; font-family: var(--font-hand); font-size: 1.3rem;
  color: var(--ink); font-weight: 600; line-height: 1.1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.note-card .card-meta {
  display: flex; gap: .4rem; align-items: center;
  font-size: .72rem; color: var(--ink-soft); margin-top: .2rem;
}
.tag {
  background: var(--paper-deep); border-radius: 999px; padding: .05rem .45rem;
  font-weight: 700;
}
.tag.shared { background: var(--highlight); color: #6B5A00; }
.tag.theirs { background: rgba(216,82,74,.12); color: var(--margin-red); }
.empty-msg { color: var(--ink-soft); text-align: center; margin-top: 2rem; }

/* ————— éditeur ————— */
.editor-pane {
  display: flex; flex-direction: column; min-width: 0;
}
.editor-pane.placeholder {
  display: grid; place-items: center; color: var(--ink-soft);
  font-family: var(--font-hand); font-size: 1.6rem; text-align: center;
}
.editor-toolbar {
  display: flex; gap: .75rem; align-items: center; flex-wrap: wrap;
  padding: .8rem 1rem; border-bottom: 1px solid #E3E0D2; background: var(--paper);
}
.note-title {
  flex: 1; min-width: 180px;
  font-family: var(--font-hand); font-size: 1.7rem; font-weight: 600;
  color: var(--ink); border: none; background: transparent;
  border-bottom: 2px dashed transparent; padding: .1rem .2rem;
}
.note-title:focus { border-bottom-color: var(--rule); outline: none; }
.toolbar-controls { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.toolbar-controls select {
  font: inherit; font-weight: 700; color: var(--ink);
  border: 1.5px solid var(--rule); border-radius: 8px;
  padding: .4rem .5rem; background: #fff;
}
.share-toggle {
  display: flex; align-items: center; gap: .35rem;
  font-weight: 700; font-size: .85rem; color: var(--ink); user-select: none;
}

.emoji-bar {
  display: flex; gap: .15rem; flex-wrap: wrap;
  padding: .35rem .8rem; background: var(--paper); border-bottom: 1px solid #E3E0D2;
}
.emoji-bar button {
  border: none; background: transparent; font-size: 1.15rem;
  border-radius: 6px; padding: .15rem .3rem;
}
.emoji-bar button:hover { background: var(--paper-deep); }

.toolbar-extra {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: center;
  padding: .35rem .8rem; background: var(--paper); border-bottom: 1px solid #E3E0D2;
}
.emoji-picker-wrap { position: relative; }
.popover {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 14px 34px rgba(38,53,122,.22);
}
emoji-picker {
  --num-columns: 8;
  --emoji-size: 1.3rem;
  --background: #fff;
  --border-color: #E3E0D2;
  --indicator-color: var(--ink);
  width: min(340px, 88vw);
  height: 360px;
}

/* images insérées dans les notes */
.note-image {
  display: block; max-width: 100%; height: auto;
  border-radius: 10px; margin: .5rem 0;
  border: 1px solid var(--rule);
}

.editor-body { flex: 1; display: flex; min-height: 0; }
#note-content, .preview {
  flex: 1; min-width: 0; overflow-y: auto;
  padding: calc(var(--line-h) * 0.55) 1.5rem calc(var(--line-h)) 76px;
  font-size: 1.02rem; line-height: var(--line-h);
}
#note-content {
  border: none; resize: none; font-family: var(--font-body); color: var(--text);
}
#note-content:focus { outline: none; }

/* ————— aperçu ————— */
.preview h1, .preview h2, .preview h3 { color: var(--ink); line-height: 1.25; }
.preview mark { background: var(--highlight); }
.preview code {
  background: var(--paper-deep); border-radius: 4px; padding: .05em .35em;
  font-size: .9em;
}
.preview pre {
  background: #fff; border: 1px solid var(--rule); border-radius: 8px;
  padding: .8rem; overflow-x: auto; line-height: 1.45;
}
.preview pre code { background: none; padding: 0; }
.preview blockquote {
  margin: 0; padding-left: .9rem;
  border-left: 3px solid var(--highlight); color: var(--ink-soft);
}
.preview a { color: var(--ink); }
.preview table { border-collapse: collapse; }
.preview th, .preview td { border: 1px solid var(--rule); padding: .3rem .6rem; }

/* liste de courses */
.check-item {
  display: flex; align-items: center; gap: .55rem;
  min-height: var(--line-h); cursor: pointer;
}
.check-item input { width: 1.05rem; height: 1.05rem; accent-color: var(--ink); }
.check-item.done span { text-decoration: line-through; color: var(--ink-soft); }

.editor-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: .45rem 1rem; font-size: .78rem; color: var(--ink-soft);
  border-top: 1px solid #E3E0D2; background: var(--paper);
}
.save-status.saved { color: #3E7C4B; font-weight: 700; }
.save-status.error { color: var(--margin-red); font-weight: 700; }

/* ————— mobile ————— */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .sidebar { border-right: none; border-bottom: 1px solid #E3E0D2; max-height: 45vh; }
  .editor-body { min-height: 55vh; }
  #note-content, .preview { padding-left: 64px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
