:root {
  color-scheme: light dark;
  --bg: #f7f5f0;
  --surface: #fffdf9;
  --ink: #23201b;
  --muted: #736d62;
  --border: #ddd7cb;
  --accent: #2f6f5e;
  --on-accent: #ffffff;
  --danger: #b3402e;
  --shadow: 0 6px 20px rgb(40 30 10 / 0.16);

  --n-default: var(--surface);
  --n-coral: #fbd9d0;
  --n-amber: #fbe7b2;
  --n-lime: #e3efb8;
  --n-mint: #c9eedd;
  --n-sky: #cfe6f8;
  --n-lilac: #e0d9f7;
  --n-rose: #f8d7e6;
  --n-sand: #ece3d3;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171613;
    --surface: #201f1b;
    --ink: #ece8df;
    --muted: #a39d91;
    --border: #3a3832;
    --accent: #7fc8ae;
    --on-accent: #10261f;
    --danger: #f08a78;
    --shadow: 0 6px 20px rgb(0 0 0 / 0.5);

    --n-coral: #5a2e26;
    --n-amber: #55431a;
    --n-lime: #3d4a1d;
    --n-mint: #1f4a3a;
    --n-sky: #1f3f57;
    --n-lilac: #3a3260;
    --n-rose: #55283e;
    --n-sand: #4a4234;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.4;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  flex: none;
}

.icon-btn:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.icon-btn.active {
  color: var(--accent);
}

.icon-btn.active svg {
  fill: color-mix(in srgb, var(--accent) 30%, transparent);
}

.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 22px;
  border: 1px solid var(--border);
  font-weight: 600;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn.danger {
  color: var(--danger);
}

/* --- Connexion ---------------------------------------------------------- */
.login {
  min-height: 100dvh;
  max-width: 340px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.login h1 {
  margin: 0 0 16px;
  font-size: 1.8rem;
}

.login label {
  font-size: 0.9rem;
  color: var(--muted);
}

.login input,
.field {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.error {
  min-height: 1.4em;
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

/* --- Barre du haut ------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: linear-gradient(var(--bg) 80%, transparent);
}

.searchbar {
  display: flex;
  align-items: center;
  max-width: 720px;
  margin: 0 auto;
  padding: 2px 4px;
  border-radius: 28px;
  background: color-mix(in srgb, var(--accent) 11%, var(--surface));
}

.searchbar input {
  flex: 1;
  min-width: 0;
  height: 44px;
  border: 0;
  background: none;
  outline: none;
}

.searchbar input::placeholder {
  color: var(--muted);
}

.offline {
  max-width: 720px;
  margin: 8px auto 0;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  color: var(--muted);
  border: 1px dashed var(--border);
}

/* --- Liste -------------------------------------------------------------- */
.list {
  padding: 4px 10px calc(var(--safe-bottom) + 96px);
  max-width: 1200px;
  margin: 0 auto;
}

.section-title {
  margin: 14px 8px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.grid {
  columns: 2;
  column-gap: 10px;
}

@media (min-width: 720px) {
  .grid {
    columns: 3;
  }
}

@media (min-width: 1040px) {
  .grid {
    columns: 4;
  }
}

.layout-list .grid {
  columns: 1;
  max-width: 640px;
  margin: 0 auto;
}

.card {
  display: block;
  width: 100%;
  margin: 0 0 10px;
  padding: 12px 14px;
  break-inside: avoid;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--n-default);
  overflow: hidden;
  cursor: pointer;
}

.card:hover {
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.12);
}

[data-color='coral'] { background: var(--n-coral); }
[data-color='amber'] { background: var(--n-amber); }
[data-color='lime'] { background: var(--n-lime); }
[data-color='mint'] { background: var(--n-mint); }
[data-color='sky'] { background: var(--n-sky); }
[data-color='lilac'] { background: var(--n-lilac); }
[data-color='rose'] { background: var(--n-rose); }
[data-color='sand'] { background: var(--n-sand); }

.card:not([data-color='default']) {
  border-color: transparent;
}

.card h2 {
  margin: 0 0 6px;
  font-size: 1.02rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.card-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 10;
  line-clamp: 10;
  overflow: hidden;
}

.card-text.big {
  font-size: 1.3rem;
}

.card-items {
  margin: 0;
  padding: 0;
  list-style: none;
}

.card-items li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 3px 0;
  overflow-wrap: anywhere;
}

.box {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1.8px solid var(--muted);
  border-radius: 4px;
}

.box svg {
  width: 14px;
  height: 14px;
  stroke-width: 3;
  visibility: hidden;
}

.box.checked {
  background: var(--muted);
  color: var(--bg);
}

.box.checked svg {
  visibility: visible;
}

.more-count {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  background: color-mix(in srgb, var(--ink) 9%, transparent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip svg {
  width: 13px;
  height: 13px;
}

.chip.overdue {
  color: var(--danger);
}

.empty {
  margin: 22vh auto 0;
  max-width: 300px;
  text-align: center;
  color: var(--muted);
}

.empty svg {
  width: 64px;
  height: 64px;
  stroke-width: 1.2;
  opacity: 0.6;
}

.trash-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- Barre de création -------------------------------------------------- */
.quickbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px calc(var(--safe-bottom) + 8px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.fab {
  width: 60px;
  height: 60px;
  margin-top: -34px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow);
}

.fab svg {
  width: 30px;
  height: 30px;
  stroke-width: 2.2;
}

/* --- Menu latéral ------------------------------------------------------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(0 0 0 / 0.4);
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 21;
  width: min(300px, 84vw);
  padding: calc(var(--safe-top) + 16px) 10px calc(var(--safe-bottom) + 16px);
  overflow-y: auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.drawer h1 {
  margin: 4px 14px 14px;
  font-size: 1.4rem;
}

.drawer hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 24px;
  text-align: left;
}

.menu-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-item:hover {
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}

.menu-item.current {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  font-weight: 600;
}

.menu-item.danger {
  color: var(--danger);
}

/* --- Éditeur ------------------------------------------------------------ */
.editor {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: var(--vvh, 100dvh);
  display: flex;
  flex-direction: column;
  background: var(--n-default);
}

.editor-top,
.editor-bottom {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  flex: none;
}

.editor-top {
  padding-top: calc(var(--safe-top) + 6px);
}

.editor-bottom {
  padding-bottom: calc(var(--safe-bottom) + 6px);
}

.spacer {
  flex: 1;
}

.edited {
  flex: 1;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 18px 24px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.editor textarea,
.editor input[type='text'] {
  display: block;
  width: 100%;
  border: 0;
  outline: none;
  background: none;
  resize: none;
  padding: 0;
  overflow: hidden;
}

.editor ::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.title-input {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.content-input {
  min-height: 40vh;
  font-size: 1.05rem;
}

.item-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 40px;
  padding: 4px 0;
}

.item-row .box {
  margin-top: 10px;
  cursor: pointer;
}

/* Agrandit la zone tactile de la case sans changer sa taille visible */
.item-row .box::after {
  content: '';
  position: absolute;
  inset: -12px;
}

.item-row .box {
  position: relative;
}

.item-row textarea {
  flex: 1;
  padding: 8px 0;
  font-size: 1.05rem;
}

.item-row.done textarea {
  text-decoration: line-through;
  color: var(--muted);
}

.item-row .icon-btn {
  width: 40px;
  height: 40px;
  color: var(--muted);
}

.add-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--muted);
  width: 100%;
  text-align: left;
}

.add-item svg {
  width: 20px;
  height: 20px;
}

.done-title {
  margin: 14px 0 4px;
  padding-top: 12px;
  border-top: 1px solid color-mix(in srgb, var(--ink) 15%, transparent);
  color: var(--muted);
  font-size: 0.9rem;
}

.readonly-banner {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

/* --- Feuille du bas ----------------------------------------------------- */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  max-width: 560px;
  max-height: 86dvh;
  margin: 0 auto;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  overflow-y: auto;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sheet h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.sheet p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.sheet .row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.sheet .row .field {
  flex: 1;
  min-width: 0;
}

.sheet .actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 12px;
}

.swatch {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  background: var(--n-default);
}

.swatch.selected {
  border-color: var(--accent);
  border-width: 3px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
}

.check-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

code.block {
  display: block;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  overflow-wrap: anywhere;
  user-select: all;
}

/* --- Toast -------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 90px);
  z-index: 40;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.92rem;
  box-shadow: var(--shadow);
}
