/* Notes — Apple Notes inspired, light + dark. */

:root {
  --bg: #ffffff;
  --sidebar-bg: #f7f7f7;
  --border: #dedede;
  --text: #1d1d1f;
  --text-dim: #86868b;
  --text-faint: #a1a1a6;
  --sel-bg: #fbe79a;
  --sel-text: #1d1d1f;
  --sel-dim: #7d6a25;
  --accent: #d69e00;
  --danger: #d9342b;
  --field-bg: #e8e8ea;
  --hover: rgba(0, 0, 0, .045);
  --shadow: 0 8px 28px rgba(0, 0, 0, .16);
  --sidebar-w: 300px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --sidebar-bg: #252528;
    --border: #3a3a3c;
    --text: #f2f2f7;
    --text-dim: #98989f;
    --text-faint: #7c7c82;
    --sel-bg: #3a3a3c;
    --sel-text: #ffffff;
    --sel-dim: #b0b0b6;
    --accent: #ffd60a;
    --danger: #ff6a5e;
    --field-bg: #34343a;
    --hover: rgba(255, 255, 255, .055);
    --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

/* L'attribut hidden doit gagner contre les display: flex ci-dessous. */
[hidden] { display: none !important; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
               "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100%;
}

/* ── Sidebar ─────────────────────────────────────────────────── */

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-top: env(safe-area-inset-top);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 6px 16px;
}

.sidebar-head h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  transition: background .12s ease;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 21px; height: 21px; fill: currentColor; }
.icon-btn.danger { color: var(--text-dim); }
.icon-btn.danger:hover { color: var(--danger); }

.search-wrap {
  position: relative;
  margin: 4px 12px 10px;
}

.search-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  fill: var(--text-faint);
  pointer-events: none;
}

#search {
  width: 100%;
  border: 0;
  border-radius: 9px;
  background: var(--field-bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 8px 28px 8px 29px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

#search::-webkit-search-cancel-button { display: none; }
#search::placeholder { color: var(--text-faint); }
#search:focus { box-shadow: 0 0 0 3px rgba(214, 158, 0, .22); }

.search-clear {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: var(--text-faint);
  color: var(--sidebar-bg);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.list-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 12px;
}

.note-row {
  border-radius: 9px;
  padding: 9px 11px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.note-row:hover { background: var(--hover); }

.note-row.active {
  background: var(--sel-bg);
  color: var(--sel-text);
}

.note-row .row-title {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-row .row-sub {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-row.active .row-sub { color: var(--sel-dim); }
.note-row .row-date { font-weight: 500; }
.note-row .row-snippet { }

.list-state {
  padding: 28px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13.5px;
}

.state-title { font-weight: 600; color: var(--text); margin: 0 0 4px; }
.state-sub { margin: 0; font-size: 13px; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 7px 16px calc(7px + env(safe-area-inset-bottom));
  font-size: 11.5px;
  color: var(--text-faint);
  text-align: center;
}

/* ── Éditeur ─────────────────────────────────────────────────── */

.editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.editor-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-faint);
}

.editor-placeholder svg { width: 52px; height: 52px; fill: currentColor; opacity: .5; }
.editor-placeholder p { margin: 0; font-size: 15px; }

.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 6px;
  padding-top: calc(10px + env(safe-area-inset-top));
}

.back-btn { display: none; }

.editor-meta {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.save-status {
  font-size: 11.5px;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity .2s ease;
  white-space: nowrap;
}

.save-status.show { opacity: 1; }
.save-status.error { color: var(--danger); }

.editor-scroll {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 8px calc(16px + env(safe-area-inset-bottom));
}

.note-title,
.note-body {
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 24px;
}

.note-title {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.25;
  padding-top: 6px;
  padding-bottom: 8px;
}

.note-body {
  flex: 1;
  min-height: 55vh;
  font-size: 16.5px;
  line-height: 1.58;
  resize: none;
  padding-bottom: 40vh;
}

.note-title::placeholder,
.note-body::placeholder { color: var(--text-faint); }

/* ── Toast ───────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: 88vw;
  text-align: center;
}

/* ── Mobile : une seule colonne ──────────────────────────────── */

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }

  .sidebar,
  .editor {
    grid-column: 1;
    grid-row: 1;
  }

  .editor {
    display: none;
    border-left: 0;
  }

  body.editing .sidebar { display: none; }
  body.editing .editor { display: flex; }

  .back-btn { display: inline-flex; }
  .editor-placeholder { display: none; }

  .note-title { font-size: 23px; padding: 6px 16px 8px; }
  .note-body { font-size: 16.5px; padding: 0 16px 45vh; }
  .sidebar-head { padding-top: 16px; }
  .note-row { padding: 11px 11px; }
  .sidebar-foot { display: none; }
}
