/* Scellé — style inspiré d'Apple Notes. Clair ou sombre selon le système. */
:root {
  --bg: #ffffff;
  --side: rgba(246, 246, 248, 0.86);
  --side-solid: #f6f6f8;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.2);
  --sep: rgba(60, 60, 67, 0.14);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #8e8e93;
  --accent: #8e44ec; /* violet système, un peu plus sombre pour le contraste sur blanc */
  --accent-soft: rgba(142, 68, 236, 0.12);
  --select: #8e44ec; /* fond de la note sélectionnée : texte blanc lisible (≥ 4,5:1) */
  --on-accent: #ffffff;
  --danger: #ff3b30;
  --code-bg: #f5f5f7;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 28px rgba(0, 0, 0, 0.08);
  --sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI Variable Text', 'Segoe UI', system-ui, 'Helvetica Neue', sans-serif;
  --display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI Variable Display', 'Segoe UI', system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --side: rgba(36, 36, 38, 0.82);
    --side-solid: #242426;
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(118, 118, 128, 0.36);
    --sep: rgba(84, 84, 88, 0.6);
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #8e8e93;
    --accent: #bf5af2;
    --accent-soft: rgba(191, 90, 242, 0.2);
    --select: #8a3ad0;
    --on-accent: #ffffff;
    --danger: #ff453a;
    --code-bg: #2c2c2e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.47 var(--sans);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}
button,
input,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}
button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}
:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 1px;
  border-radius: 8px;
}
svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.muted {
  color: var(--text-3);
}
.danger {
  color: var(--danger);
}
kbd {
  font: 500 12px var(--sans);
  background: var(--fill);
  border-radius: 5px;
  padding: 1px 6px;
}

.btn-primary {
  background: var(--select);
  color: var(--on-accent);
  font-weight: 600;
  border-radius: 12px;
  padding: 12px 20px;
  width: 100%;
}
.btn-primary:hover {
  filter: brightness(1.06);
}
.btn-primary:active {
  filter: brightness(0.94);
}
.btn-primary:disabled {
  opacity: 0.55;
  cursor: progress;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: var(--text-2);
}
.icon-btn:hover {
  background: var(--fill);
  color: var(--text);
}
.icon-btn.accent {
  color: var(--accent);
}
.icon-btn svg {
  width: 21px;
  height: 21px;
}

/* ---------- Écran d'ouverture ---------- */
.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: var(--side-solid);
}
.gate-box {
  width: min(360px, 100%);
  text-align: center;
}
.gate-icon {
  display: block;
  margin: 0 auto 18px;
  filter: drop-shadow(0 6px 16px rgba(110, 40, 200, 0.28));
}
.gate h1 {
  font: 700 30px/1.15 var(--display);
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.gate-lead {
  color: var(--text-2);
  margin: 0 0 26px;
  font-size: 15px;
}
.gate form {
  display: grid;
  gap: 14px;
}
.field-group {
  background: var(--bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: left;
}
.field-group input {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 14px 16px;
  font-size: 16px;
  outline: none;
}
.field-group > div input,
.field-group > div:not([hidden]) {
  border-top: 1px solid var(--sep);
}
.field-group > div:not([hidden]) input {
  border-top: 0;
}
.field-group input:focus {
  background: var(--accent-soft);
}
.gate-warn {
  font-size: 13px;
  color: var(--text-2);
  margin: 0;
  text-align: left;
}
.gate-error {
  color: var(--danger);
  min-height: 1.4em;
  margin: 0;
  font-size: 14px;
}

.fatal {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.fatal p {
  max-width: 480px;
  background: var(--side-solid);
  border-radius: 14px;
  padding: 18px 20px;
}

/* ---------- Application ---------- */
.app {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--side);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-right: 1px solid var(--sep);
}
.side-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 22px 14px 10px 20px;
}
.side-title h1 {
  font: 700 28px/1.1 var(--display);
  letter-spacing: -0.025em;
  margin: 0;
}
.count {
  display: block;
  font-size: 13px;
  color: var(--text-3);
  margin-top: 2px;
  min-height: 1.2em;
}

.search-wrap {
  position: relative;
  margin: 0 14px 10px;
}
.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  background: var(--fill);
  border: 0;
  border-radius: 10px;
  padding: 8px 10px 8px 32px;
  font-size: 15px;
  outline: none;
}
.search-wrap input::placeholder {
  color: var(--text-3);
}
.search-wrap input:focus {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 16px;
}
.group + .group {
  margin-top: 6px;
}
.list-head {
  margin: 0;
  padding: 14px 10px 6px;
  font: 700 13px var(--display);
  color: var(--text);
  letter-spacing: -0.01em;
}
.list-empty {
  padding: 18px 10px;
  margin: 0;
  font-size: 14px;
  text-align: center;
}
.item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  position: relative;
}
.item + .item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 12px;
  right: 12px;
  border-top: 1px solid var(--sep);
}
.item:hover {
  background: var(--fill);
}
.item:hover::before,
.item:hover + .item::before,
.item.active::before,
.item.active + .item::before {
  border-color: transparent;
}
.item.active {
  background: var(--select);
  color: var(--on-accent);
}
.item-title {
  display: block;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-meta {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.item-meta time {
  color: var(--text);
  margin-right: 6px;
  font-variant-numeric: tabular-nums;
}
.item.active .item-meta,
.item.active .item-meta time {
  color: rgba(255, 255, 255, 0.85);
}

.side-foot {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-top: 1px solid var(--sep);
}
.foot-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 13px;
  text-decoration: none;
}
.foot-btn svg {
  width: 16px;
  height: 16px;
}
.foot-btn:hover {
  background: var(--fill);
  color: var(--text);
}
.version {
  margin-left: auto;
  padding-right: 8px;
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.empty {
  margin: auto;
  text-align: center;
  color: var(--text-2);
}
.empty img {
  opacity: 0.35;
  filter: grayscale(1);
  margin-bottom: 10px;
}
.empty p {
  margin: 4px 0;
  font-size: 17px;
}
.empty .muted {
  font-size: 14px;
}

.editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 56px;
}
.back {
  display: none;
  align-items: center;
  gap: 2px;
  color: var(--accent);
  font-size: 17px;
  margin-left: -8px;
}
.back svg {
  width: 26px;
  height: 26px;
  stroke-width: 2.2;
}
.segmented {
  display: inline-flex;
  background: var(--fill);
  border-radius: 9px;
  padding: 2px;
}
.segmented button {
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 7px;
  color: var(--text);
}
.segmented button[aria-pressed='true'] {
  background: var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  .segmented button[aria-pressed='true'] {
    background: #636366;
  }
}
.status {
  flex: 1;
  text-align: right;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 6px;
}
#pin[aria-pressed='true'] {
  color: var(--accent);
}
#pin[aria-pressed='true'] svg {
  fill: currentColor;
}
#delete:hover {
  color: var(--danger);
}

.note-date {
  margin: 0 0 4px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.panes {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.panes[data-mode='write'],
.panes[data-mode='read'] {
  grid-template-columns: minmax(0, 1fr);
}
.panes[data-mode='write'] .preview,
.panes[data-mode='read'] textarea {
  display: none;
}
.panes textarea {
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  padding: 12px 36px 40vh;
  font: 16px/1.6 var(--sans);
  tab-size: 4;
  min-height: 0;
  overflow-y: auto;
  caret-color: var(--accent);
}
.panes textarea::placeholder {
  color: var(--text-3);
}
.panes[data-mode='split'] textarea {
  border-right: 1px solid var(--sep);
}
.panes[data-mode='write'] textarea,
.panes[data-mode='read'] .preview {
  max-width: 780px;
  width: 100%;
  justify-self: center;
}

/* ---------- Rendu Markdown ---------- */
.preview {
  overflow-y: auto;
  padding: 6px 40px 40vh;
  min-height: 0;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.6;
}
.md h1,
.md h2,
.md h3,
.md h4 {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 1.3em 0 0.45em;
}
.md h1 {
  font-size: 28px;
}
.md h2 {
  font-size: 21px;
}
.md h3 {
  font-size: 18px;
}
.md > :first-child {
  margin-top: 0.4em;
}
.md p,
.md ul,
.md ol,
.md blockquote,
.md pre,
.md table {
  margin: 0 0 0.85em;
}
.md a {
  color: var(--accent);
  text-decoration: none;
}
.md a:hover {
  text-decoration: underline;
}
.md ul,
.md ol {
  padding-left: 1.4em;
}
.md li + li {
  margin-top: 0.15em;
}
.md li:has(> input[type='checkbox']) {
  list-style: none;
  margin-left: -1.4em;
}
/* Cases rondes, comme les listes de contrôle d'Apple Notes */
.md input[type='checkbox'] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin: 0 10px 0 0;
  vertical-align: -4px;
  border: 1.5px solid var(--text-3);
  border-radius: 50%;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: background-color 0.15s, border-color 0.15s;
}
.md input[type='checkbox']:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.md input[type='checkbox']:checked::after {
  content: '';
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}
.md li:has(> input:checked) {
  color: var(--text-3);
}
.md blockquote {
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 14px;
  color: var(--text-2);
  margin-left: 0;
}
.md code {
  font: 0.86em var(--mono);
  background: var(--code-bg);
  border-radius: 5px;
  padding: 0.12em 0.4em;
}
.md pre {
  position: relative;
  background: var(--code-bg);
  border-radius: 12px;
  padding: 14px 16px;
  overflow-x: auto;
}
.md pre code {
  background: none;
  padding: 0;
  font-size: 13.5px;
  line-height: 1.6;
}
.md pre .copy {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--bg);
  border-radius: 7px;
  padding: 3px 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  opacity: 0;
  transition: opacity 0.15s;
}
.md pre:hover .copy,
.md pre .copy:focus-visible {
  opacity: 1;
}
.md hr {
  border: 0;
  border-top: 1px solid var(--sep);
  margin: 1.6em 0;
}
.md table {
  border-collapse: collapse;
  font-size: 15px;
}
.md th,
.md td {
  border-bottom: 1px solid var(--sep);
  padding: 6px 12px 6px 0;
  text-align: left;
}
.md img {
  max-width: 100%;
  border-radius: 10px;
}

/* ---------- iPhone / petit écran ---------- */
@media (max-width: 800px) {
  html,
  body {
    font-size: 16px;
  }
  .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .side {
    border-right: 0;
    background: var(--side-solid);
    padding-top: env(safe-area-inset-top);
  }
  .side-title h1 {
    font-size: 34px;
  }
  .main {
    display: none;
  }
  body.show-editor .side {
    display: none;
  }
  body.show-editor .main {
    display: flex;
  }
  .back {
    display: inline-flex;
  }
  .toolbar {
    padding: calc(8px + env(safe-area-inset-top)) 12px 6px;
  }
  .mode-split {
    display: none;
  }
  .panes[data-mode='split'] {
    grid-template-columns: minmax(0, 1fr);
  }
  .panes[data-mode='split'] .preview {
    display: none;
  }
  .panes[data-mode='split'] textarea {
    border-right: 0;
  }
  .panes textarea,
  .preview {
    padding: 8px 18px 40vh;
  }
  .item {
    padding: 12px;
  }
  .md pre .copy {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .item,
  .icon-btn,
  .foot-btn,
  .segmented button {
    transition: background-color 0.15s, color 0.15s;
  }
}
