:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --surface: #ffffff;
  --fg: #1f2023;
  --muted: #62666d;
  --border: #dcdde1;
  --hover: rgba(0, 0, 0, .06);
  --active: #fbe7a6;
  --accent: #e6a800;
  --danger: #c0352b;
  --shadow: 0 1px 3px rgba(0, 0, 0, .14), 0 4px 12px rgba(0, 0, 0, .08);

  --c-red: #f7c6c0; --c-orange: #f8d1b0; --c-yellow: #fbefa8; --c-green: #d8efc8;
  --c-teal: #bfe3dc; --c-blue: #cfe1ef; --c-purple: #dccbe6; --c-pink: #f6d6e0;
  --c-brown: #e6dccb; --c-gray: #e7e8ea;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1d20;
    --surface: #26272b;
    --fg: #e9eaed;
    --muted: #a0a4ab;
    --border: #3b3d42;
    --hover: rgba(255, 255, 255, .08);
    --active: #4a3f17;
    --accent: #f5c518;
    --danger: #f08a80;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 12px rgba(0, 0, 0, .35);

    --c-red: #6b2a2a; --c-orange: #6b3c1d; --c-yellow: #645314; --c-green: #2f4a2c;
    --c-teal: #1f4a45; --c-blue: #234257; --c-purple: #43345a; --c-pink: #5e2f45;
    --c-brown: #4a3f31; --c-gray: #3a3c41;
  }
}

[data-color="red"] { --note: var(--c-red); }
[data-color="orange"] { --note: var(--c-orange); }
[data-color="yellow"] { --note: var(--c-yellow); }
[data-color="green"] { --note: var(--c-green); }
[data-color="teal"] { --note: var(--c-teal); }
[data-color="blue"] { --note: var(--c-blue); }
[data-color="purple"] { --note: var(--c-purple); }
[data-color="pink"] { --note: var(--c-pink); }
[data-color="brown"] { --note: var(--c-brown); }
[data-color="gray"] { --note: var(--c-gray); }

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.icon {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn.active { color: var(--fg); background: var(--hover); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 6px 16px;
  border: 1px solid var(--border); border-radius: 8px; background: transparent; font-weight: 500;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b1b1b; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn .icon { width: 18px; height: 18px; }

.link { border: 0; background: none; padding: 4px; color: var(--accent); font-weight: 600; }

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

/* Connexion */

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(400px, 100%); padding: 32px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; }
.login-card p { margin: 0; }
.login-logo { width: 64px; height: 64px; }
.login-card > .btn { width: 100%; }
.login-register { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.login-register label { display: flex; flex-direction: column; gap: 6px; text-align: left; font-weight: 500; }
.login-register input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  font-size: 17px; letter-spacing: .08em; text-transform: uppercase;
}
.login-error { color: var(--danger); min-height: 1em; }

/* Structure */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: 64px; padding: 0 12px; padding-top: env(safe-area-inset-top);
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 600; margin-right: 24px; }
.brand img { width: 32px; height: 32px; }
.search {
  flex: 1; max-width: 720px;
  display: flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 14px; border-radius: 10px; background: var(--hover); color: var(--muted);
}
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fg); font-size: 16px; }
.topbar > .icon-btn:last-child { margin-left: auto; }

.layout { display: flex; min-height: calc(100dvh - 64px); }

.sidebar {
  position: sticky; top: 64px; align-self: flex-start;
  width: 260px; flex: none; max-height: calc(100dvh - 64px); overflow-y: auto;
  padding: 8px 0;
}
.nav-item {
  display: flex; align-items: center; gap: 20px; width: calc(100% - 8px);
  height: 48px; padding: 0 24px; border: 0; border-radius: 0 24px 24px 0;
  background: transparent; text-align: left; font-weight: 500;
}
.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--active); }
.nav-title { padding: 16px 24px 4px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.nav-sep { margin: 8px 0; border-top: 1px solid var(--border); }
.scrim { display: none; }

.content { flex: 1; min-width: 0; padding: 24px 16px 96px; }

.banner {
  display: flex; align-items: center; gap: 10px;
  max-width: 600px; margin: 0 auto 20px; padding: 10px 14px;
  border-radius: 10px; background: var(--c-yellow); color: var(--fg);
}

.composer {
  display: flex; align-items: center; gap: 4px;
  max-width: 600px; margin: 0 auto 32px; padding: 4px 8px 4px 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.composer-main {
  flex: 1; height: 44px; padding: 0 12px; border: 0; background: transparent;
  text-align: left; color: var(--muted); font-size: 16px; font-weight: 500;
}

.section-title {
  max-width: 1300px; margin: 8px auto 8px; padding: 0 4px;
  font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.section-title + .masonry { margin-bottom: 28px; }

.masonry { display: flex; gap: 16px; max-width: 1300px; margin: 0 auto; align-items: flex-start; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

.card {
  position: relative; overflow: hidden;
  background: var(--note, var(--surface)); border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; transition: box-shadow .15s;
  overflow-wrap: anywhere;
}
.card[data-color]:not([data-color="default"]) { border-color: transparent; }
.card:hover { box-shadow: var(--shadow); }
.card h3 { margin: 12px 16px 4px; font-size: 16px; font-weight: 600; padding-right: 20px; }
.card-text {
  margin: 8px 16px 12px; white-space: pre-wrap;
  display: -webkit-box; -webkit-line-clamp: 12; -webkit-box-orient: vertical; overflow: hidden;
}
.card h3 + .card-text { margin-top: 4px; }
.card-img { position: relative; }
.card-img img { display: block; width: 100%; max-height: 280px; object-fit: cover; }
.img-count {
  position: absolute; right: 8px; bottom: 8px; padding: 2px 8px; border-radius: 10px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px;
}
.card-pin { position: absolute; top: 10px; right: 10px; color: var(--muted); }
.card-pin .icon { width: 18px; height: 18px; }
.card > .muted { margin: 12px 16px; }
.card-list { list-style: none; margin: 8px 16px 12px; padding: 0; }
.card-list li { display: flex; align-items: flex-start; gap: 8px; padding: 2px 0; }
.card-list input { margin: 3px 0 0; width: 16px; height: 16px; flex: none; accent-color: var(--muted); }
.card-actions { display: flex; justify-content: flex-end; padding: 0 4px 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 12px 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px 10px; border-radius: 12px; background: var(--hover); font-size: 12px; font-weight: 500;
}
.chip-x { border: 0; background: none; padding: 0 0 0 4px; font-size: 15px; line-height: 1; color: var(--muted); }

.trash-bar {
  display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap;
  margin: 0 auto 24px; font-style: italic; color: var(--muted);
}
.empty { display: flex; flex-direction: column; align-items: center; margin-top: 80px; color: var(--muted); }
.empty .icon { width: 96px; height: 96px; stroke-width: 1; opacity: .4; }
.empty p { font-size: 20px; }

/* Éditeur */

dialog {
  padding: 0; border: 0; color: var(--fg);
  background: var(--note, var(--surface));
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(20, 20, 20, .55); }

.editor[open] {
  display: flex; flex-direction: column;
  width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 64px);
  border-radius: 12px; overflow: hidden;
}
.ed-scroll { flex: 1; overflow-y: auto; padding: 8px 0 4px; }
.ed-title, .ed-text, .tag-input, .item-text {
  width: 100%; border: 0; outline: 0; background: transparent;
}
.ed-title { padding: 10px 16px; font-size: 20px; font-weight: 600; }
.ed-text { display: block; padding: 4px 16px 12px; resize: none; min-height: 80px; font-size: 16px; overflow: hidden; }
.ed-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px; margin: -8px 0 4px; }
.ed-img { position: relative; }
.ed-img img { display: block; width: 100%; height: 180px; object-fit: cover; }
.ed-img .icon-btn { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; background: rgba(0, 0, 0, .55); color: #fff; }
.ed-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 4px 16px; }
.tag-input { width: 140px; padding: 4px 2px; font-size: 14px; }
.ed-meta { padding: 8px 16px 4px; font-size: 12px; color: var(--muted); text-align: right; }

.items { padding: 0 8px 8px; }
.item { display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 0 0 8px; border-radius: 6px; }
.item:focus-within { background: var(--hover); }
.item input[type="checkbox"] { width: 18px; height: 18px; flex: none; margin: 0; accent-color: var(--muted); }
.item-text { flex: 1; min-width: 0; padding: 8px 4px; font-size: 16px; }
.item .icon-btn { width: 34px; height: 34px; opacity: 0; }
.item:hover .icon-btn, .item:focus-within .icon-btn { opacity: 1; }
.item.done .item-text { text-decoration: line-through; color: var(--muted); }
.item.add { color: var(--muted); padding-left: 6px; }
.item.add .icon { width: 20px; height: 20px; }
.done-items { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.done-items summary { padding: 6px 8px; color: var(--muted); cursor: pointer; font-size: 14px; }
.done-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; }

.palette { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border); }
.swatch {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--note, var(--surface));
}
.swatch.selected { border-color: var(--accent); }

.ed-tools { display: flex; align-items: center; gap: 2px; padding: 6px 8px; border-top: 1px solid var(--border); }
.ed-tools .spacer { flex: 1; }

/* Réglages */

.settings[open] { width: min(520px, calc(100vw - 32px)); border-radius: 12px; background: var(--surface); }
.settings-body { padding: 20px 24px; }
.settings-body h2 { margin: 0 0 8px; }
.settings-body h3 { margin: 20px 0 4px; font-size: 15px; }
.settings-body p { margin: 0 0 8px; font-size: 14px; }
.passkeys { list-style: none; margin: 8px 0 12px; padding: 0; }
.passkeys li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.passkeys li > div { display: flex; flex-direction: column; min-width: 0; }
.passkeys .muted { font-size: 12px; }
.settings-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 24px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 100; transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px;
  max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 8px;
  background: #2d2e31; color: #f1f1f1; box-shadow: var(--shadow);
}
.toast .link { color: #f5c518; }

/* Téléphone */

@media (max-width: 760px) {
  .brand span { display: none; }
  .brand { margin-right: 4px; }
  .sidebar {
    position: fixed; top: 64px; left: 0; bottom: 0; z-index: 15; max-height: none;
    background: var(--bg); transform: translateX(-100%); transition: transform .2s;
  }
  .drawer-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .drawer-open .scrim { display: block; position: fixed; inset: 64px 0 0; z-index: 14; background: rgba(0, 0, 0, .35); }
  .content { padding: 16px 8px 96px; }
  .masonry, .col { gap: 8px; }
  .card h3 { margin: 10px 12px 2px; font-size: 15px; }
  .card-text { margin: 6px 12px 10px; -webkit-line-clamp: 10; }
  .card-list { margin: 6px 12px 10px; }
  .composer { margin-bottom: 20px; }
}

@media (max-width: 600px) {
  .editor[open], .settings[open] {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0;
  }
  .ed-scroll { padding-top: env(safe-area-inset-top); }
  .ed-tools { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .item .icon-btn { opacity: 1; }
}

/* Coffre-fort */

.vault-locked {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  max-width: 420px; margin: 64px auto; padding: 32px 24px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}
.vault-locked .icon { width: 48px; height: 48px; color: var(--accent); }
.vault-locked h2, .vault-locked p { margin: 0; }
.vault { max-width: 1300px; margin: 0 auto; }
.vault-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.vault-count { flex: 1; font-size: 14px; }
.vault-progress { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-size: 14px; }
.vault-progress span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vault-progress progress { width: 100%; accent-color: var(--accent); }
.vault .section-title { margin: 20px 0 8px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 4px; }
.tile {
  position: relative; aspect-ratio: 1; padding: 0; border: 0; overflow: hidden;
  background: var(--hover); border-radius: 4px;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-placeholder { display: grid; place-items: center; width: 100%; height: 100%; color: var(--muted); }
.tile-badge {
  position: absolute; right: 6px; bottom: 6px; display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff;
}
.tile-badge .icon { width: 14px; height: 14px; fill: currentColor; }

.viewer[open] {
  display: flex; flex-direction: column;
  width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0;
  background: #000; color: #f1f1f1; box-shadow: none;
}
.viewer::backdrop { background: #000; }
.viewer-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px; padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(0, 0, 0, .6);
}
.viewer-bar .icon-btn { color: #f1f1f1; }
.viewer-bar .icon-btn:hover { background: rgba(255, 255, 255, .12); }
.viewer-info { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; }
.viewer-info span { color: #b5b5b5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-stage { flex: 1; min-height: 0; display: grid; place-items: center; touch-action: pan-y; }
.viewer-media { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .5); color: #fff;
}
.viewer-nav.prev { left: 12px; }
.viewer-nav.next { right: 12px; }
@media (max-width: 600px) { .viewer-nav { display: none; } }
