:root {
  --bg: #ffffff;
  --fg: #202124;
  --muted: #5f6368;
  --border: #e0e0e0;
  --hover: rgba(95, 99, 104, .12);
  --active: #feefc3;
  --primary: #1a73e8;
  --danger: #c5221f;
  --card-shadow: 0 1px 2px rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15);
  --radius: 8px;
  --sidebar-w: 280px;

  --c-default: transparent;
  --c-red: #faafa8; --c-orange: #f39f76; --c-yellow: #fff8b8; --c-green: #e2f6d3;
  --c-teal: #b4ddd3; --c-blue: #d4e4ed; --c-cerulean: #aeccdc; --c-purple: #d3bfdb;
  --c-pink: #f6e2dd; --c-brown: #e9e3d4; --c-gray: #efeff1;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202124; --fg: #e8eaed; --muted: #9aa0a6; --border: #5f6368;
    --hover: rgba(232, 234, 237, .08); --active: #41331c; --primary: #8ab4f8; --danger: #f28b82;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, .6), 0 1px 3px 1px rgba(0, 0, 0, .3);
    --c-red: #77172e; --c-orange: #692b17; --c-yellow: #7c4a03; --c-green: #264d3b;
    --c-teal: #0c625d; --c-blue: #256377; --c-cerulean: #284255; --c-purple: #472e5b;
    --c-pink: #6c394f; --c-brown: #4b443a; --c-gray: #232427;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--fg);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--primary); }
code { font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }
.warning { background: var(--active); padding: 10px 12px; border-radius: var(--radius); font-size: 13px; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 8px; max-width: 360px; }

/* Icônes (SVG injecté) */
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent;
  color: var(--muted); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn.on { color: var(--fg); }
.icon-btn.on svg.i { fill: currentColor; }
.btn {
  border: 1px solid var(--border); background: transparent; border-radius: 6px;
  padding: 8px 16px; cursor: pointer; font-weight: 500;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #202124; } }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; cursor: progress; }

input[type=text], input[type=password], input[type=search], input[type=datetime-local], select, .auth input {
  border: 1px solid var(--border); border-radius: 6px; padding: 9px 11px; background: transparent; width: 100%;
}
select { width: auto; background: var(--bg); }

/* Connexion */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; text-align: left; font-weight: 500; }
.auth-card h1 { margin: 0; font-weight: 500; }
.auth-logo { margin: 0 auto; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 4px;
  height: 64px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  height: calc(64px + env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 22px; color: var(--muted); padding: 0 16px 0 4px; }
.search {
  flex: 1; max-width: 720px; display: flex; align-items: center; gap: 8px; margin: 0 auto;
  background: var(--hover); border-radius: 8px; padding: 0 14px; height: 46px; color: var(--muted);
}
.search input { border: 0; background: transparent; padding: 0; height: 100%; outline: none; color: var(--fg); }
@media (max-width: 640px) { .brand span { display: none; } .brand { padding: 0 4px; } }

/* Barre latérale */
.sidebar {
  position: fixed; top: calc(64px + env(safe-area-inset-top)); bottom: 0; left: 0; width: var(--sidebar-w);
  overflow-y: auto; padding: 8px 0; background: var(--bg); z-index: 15;
}
.nav-item {
  display: flex; align-items: center; gap: 28px; width: calc(100% - 8px); height: 48px; padding: 0 12px 0 24px;
  border: 0; border-radius: 0 25px 25px 0; background: transparent; cursor: pointer; text-align: left; font-weight: 500;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--active); }
.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { margin-left: var(--sidebar-w); padding: 24px 16px 80px; }
body.collapsed .sidebar { width: 80px; }
body.collapsed .nav-item span { display: none; }
body.collapsed .main { margin-left: 80px; }
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; visibility: hidden; }
  body.nav-open .sidebar { transform: none; visibility: visible; box-shadow: var(--card-shadow); }
  .main, body.collapsed .main { margin-left: 0; }
  body.collapsed .sidebar { width: var(--sidebar-w); }
  body.collapsed .nav-item span { display: inline; }
}

/* Saisie rapide */
.composer {
  display: flex; align-items: center; max-width: 600px; margin: 0 auto 32px; padding: 2px 8px 2px 4px;
  border-radius: var(--radius); box-shadow: var(--card-shadow);
}
.composer-input {
  flex: 1; text-align: left; border: 0; background: transparent; padding: 12px; color: var(--muted);
  font-size: 15px; font-weight: 500; cursor: text;
}
.section-info { text-align: center; color: var(--muted); font-style: italic; }
.section-title { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 8px 0 8px 8px; }
.more-sentinel { height: 1px; }
.empty { text-align: center; color: var(--muted); font-size: 18px; margin-top: 15vh; }

/* Grille façon Keep (masonry) */
.grid {
  display: grid; column-gap: 16px; row-gap: 0; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  grid-auto-rows: 1px; align-items: start; margin-bottom: 32px;
}
@media (max-width: 560px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 10px; } }
.card {
  position: relative; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--note-bg, var(--bg)); cursor: default; transition: box-shadow .15s; word-wrap: break-word;
}
.card:hover { box-shadow: var(--card-shadow); }
.card:focus-visible { outline: 2px solid var(--primary); }
.card-body { padding: 12px 16px 8px; }
.card-title { font-weight: 500; font-size: 16px; margin: 0 0 6px; }
.card-text { white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 18; -webkit-box-orient: vertical; overflow: hidden; }
.card-text.big { font-size: 22px; line-height: 1.3; }
.card ul { list-style: none; margin: 0; padding: 0; }
.card li { display: flex; gap: 8px; align-items: flex-start; padding: 2px 0; }
.card li .box { width: 14px; height: 14px; border: 1.5px solid var(--muted); border-radius: 2px; flex: none; margin-top: 3px; }
.card li.checked { text-decoration: line-through; color: var(--muted); }
.card li.checked .box { background: var(--muted); }
.card .more { color: var(--muted); font-size: 13px; margin-top: 4px; }
.card-pin { position: absolute; top: 4px; right: 4px; opacity: 0; }
.card:hover .card-pin, .card-pin.on { opacity: 1; }
.card-imgs { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); }
.card-imgs img { width: 100%; display: block; max-height: 260px; object-fit: cover; background: var(--hover); min-height: 60px; }
.card-actions { display: flex; padding: 0 4px 4px; opacity: 0; transition: opacity .15s; }
.card:hover .card-actions, .card:focus-within .card-actions { opacity: 1; }
@media (hover: none) { .card-actions, .card-pin { display: none; } }
.card-actions .icon-btn { width: 34px; height: 34px; }
.card-actions svg.i { width: 18px; height: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 10px; border-radius: 12px;
  background: rgba(0, 0, 0, .08); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .chip { background: rgba(255, 255, 255, .12); } }
.chip svg.i { width: 14px; height: 14px; }
.chip.past { text-decoration: line-through; opacity: .7; }
.chip button { border: 0; background: transparent; padding: 0; margin-left: 2px; cursor: pointer; display: inline-flex; }

/* Couleurs des notes */
.c-default { --note-bg: var(--bg); }
.c-red { --note-bg: var(--c-red); } .c-orange { --note-bg: var(--c-orange); } .c-yellow { --note-bg: var(--c-yellow); }
.c-green { --note-bg: var(--c-green); } .c-teal { --note-bg: var(--c-teal); } .c-blue { --note-bg: var(--c-blue); }
.c-cerulean { --note-bg: var(--c-cerulean); } .c-purple { --note-bg: var(--c-purple); } .c-pink { --note-bg: var(--c-pink); }
.c-brown { --note-bg: var(--c-brown); } .c-gray { --note-bg: var(--c-gray); }
.card:not(.c-default), .editor:not(.c-default) { border-color: transparent; }

/* Fenêtres */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(32, 33, 36, .6);
  display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; overflow-y: auto;
}
.editor, .dialog {
  position: relative; width: 100%; max-width: 600px; background: var(--note-bg, var(--bg));
  border-radius: var(--radius); box-shadow: 0 4px 24px rgba(0, 0, 0, .3);
}
.editor { display: flex; flex-direction: column; max-height: 84vh; }
.editor-scroll { overflow-y: auto; padding: 0 16px 8px; }
.ed-head { display: flex; align-items: flex-start; gap: 4px; padding-top: 12px; }
.ed-title, .ed-text, .ed-item input[type=text] { border: 0 !important; background: transparent !important; outline: none; padding: 4px 0 !important; }
.ed-title { flex: 1; font-size: 20px; font-weight: 500; }
.ed-text { width: 100%; resize: none; min-height: 80px; font-size: 15px; line-height: 1.5; overflow: hidden; }
.ed-meta { text-align: right; color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.ed-toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 8px 8px; flex-wrap: wrap; position: relative; }
.ed-toolbar .icon-btn { width: 36px; height: 36px; }
.ed-list { display: flex; flex-direction: column; }
.ed-item { display: flex; align-items: center; gap: 6px; border-top: 1px solid transparent; border-bottom: 1px solid transparent; }
.ed-item:focus-within { border-color: var(--border); }
.ed-item input[type=checkbox] { width: 18px; height: 18px; margin: 0 4px; flex: none; accent-color: var(--muted); }
.ed-item input[type=text] { flex: 1; width: auto; font-size: 15px; }
.ed-item.checked input[type=text] { text-decoration: line-through; color: var(--muted); }
.ed-item .icon-btn { width: 30px; height: 30px; opacity: .6; }
.ed-add { display: flex; align-items: center; gap: 10px; padding: 6px 4px; color: var(--muted); border: 0; background: transparent; cursor: text; text-align: left; }
.ed-sep { border-top: 1px solid var(--border); margin: 8px 0; padding-top: 6px; font-size: 13px; color: var(--muted); }
.ed-attachments { margin: 0 -16px; }
.ed-attachments img { width: 100%; display: block; max-height: 60vh; object-fit: contain; background: var(--hover); }
.att { position: relative; }
.att-del { position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, .55) !important; color: #fff !important; }
.att-file { display: flex; align-items: center; gap: 8px; padding: 8px 16px; }
.att-file audio { flex: 1; min-width: 0; }
.att-file .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.popover {
  position: absolute; bottom: 52px; left: 8px; z-index: 5; background: var(--bg); color: var(--fg);
  border-radius: var(--radius); box-shadow: 0 2px 12px rgba(0, 0, 0, .35); padding: 12px; min-width: 240px; max-width: calc(100% - 16px);
}
.palette { display: grid; grid-template-columns: repeat(6, 32px); gap: 6px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; background: var(--note-bg); }
.swatch.c-default { border-color: var(--border); }
.swatch.sel { border-color: var(--primary); }
.pop-list { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; margin-top: 8px; }
.pop-list label { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 0; }

.dialog { padding: 8px 24px 24px; max-width: 640px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog h2 { font-weight: 500; }
.dialog h3 { font-size: 15px; margin: 24px 0 6px; }

.toast {
  position: fixed; left: 24px; bottom: 24px; z-index: 100; background: #323232; color: #fff;
  padding: 12px 20px; border-radius: 4px; box-shadow: var(--card-shadow); max-width: calc(100% - 48px);
}
.toast button { background: none; border: 0; color: #8ab4f8; font-weight: 600; margin-left: 16px; cursor: pointer; }

/* Affichage en liste : une seule colonne centrée, comme Keep */
body.list-view .grid { grid-template-columns: minmax(0, 1fr); max-width: 600px; margin-left: auto; margin-right: auto; }
body.list-view .section-title { max-width: 600px; margin-left: auto; margin-right: auto; padding-left: 8px; }
body.list-view .card-imgs img { max-height: 240px; }

/* --- Sélection et glisser-déposer (comme Keep) */
.card { overflow: visible; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.card-imgs { overflow: hidden; border-radius: var(--radius) var(--radius) 0 0; }
.card:hover { border-color: var(--muted); }
.card:not(.c-default):hover { border-color: rgba(0, 0, 0, .35); }
.card-check {
  position: absolute; top: -11px; left: -11px; z-index: 3; width: 24px; height: 24px; padding: 0;
  border: 0; border-radius: 50%; background: var(--fg); color: var(--bg); cursor: pointer;
  display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .15s;
}
.card-check svg.i { width: 16px; height: 16px; stroke-width: 3; }
.card:hover .card-check, .card:focus-within .card-check, body.selecting .card-check { opacity: 1; }
body.selecting .card:not(.selected) .card-check { background: var(--bg); color: transparent; box-shadow: 0 0 0 2px var(--muted) inset; }
.card.selected { border-color: var(--fg) !important; box-shadow: 0 0 0 1px var(--fg); }
@media (hover: none) {
  .card-check { display: none; }
  body.selecting .card-check { display: flex; }
}
.card.press { transform: scale(.97); transition: transform .35s; }
.card.drag-src { opacity: 0; }
.drag-ghost {
  position: fixed; z-index: 70; margin: 0; pointer-events: none; opacity: .97;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .35); grid-row-end: auto !important;
}
.drag-ghost .card-check, .drag-ghost .card-actions { display: none; }
body.dragging, body.dragging * { cursor: grabbing !important; }

.selbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30; display: flex; align-items: center; gap: 2px;
  height: calc(64px + env(safe-area-inset-top)); padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: var(--bg); box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
.sel-count { font-size: 18px; font-weight: 500; margin-left: 8px; white-space: nowrap; }
.selbar .popover { top: 60px; bottom: auto; left: auto; right: 8px; }
@media (max-width: 560px) { .sel-count { font-size: 15px; } .selbar .icon-btn { width: 36px; } }
.editor .popover.below { bottom: auto; top: calc(100% - 6px); }
