/* MemoFlux — styles */

:root {
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --surface-2: #efe8de;
  --ink: #221d17;
  --ink-2: #6b6157;
  --line: #e2d8cb;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --ok: #29a36a;
  --info: #2e86de;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(34, 29, 23, .06), 0 6px 20px rgba(34, 29, 23, .06);
  --ig: linear-gradient(45deg, #f9a03f 0%, #e4572e 35%, #d6336c 65%, #8e44ad 100%);
  --fb: #1877f2;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --surface: #211d18;
    --surface-2: #2b261f;
    --ink: #f3ece2;
    --ink-2: #b0a597;
    --line: #3a332a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: inherit; }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }

/* ---------- Barre du haut ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: url("icon.svg") center / cover no-repeat;
}
.topnav { display: flex; gap: 4px; }
.topnav a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--ink-2); font-weight: 500;
}
.topnav a.is-active { background: var(--ink); color: var(--bg); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 16px; }

/* ---------- Boutons & champs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink-2); }
.btn-ghost.is-on { border-color: var(--accent); color: var(--accent); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: .9rem; }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font-size: 15px; cursor: pointer; text-decoration: none; padding: 0;
}
.icon-btn:hover { border-color: var(--ink-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-danger:hover { border-color: var(--danger); color: var(--danger); }

input[type=text], input[type=search], input[type=password], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; /* évite le zoom iOS */
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
input[type=color] { width: 42px; height: 42px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; flex: none; }

label { display: grid; gap: 6px; font-weight: 600; font-size: .92rem; }
.stack { display: grid; gap: 14px; }
.narrow { max-width: 420px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Messages ---------- */

.flash {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--ok);
}
.flash-error { border-left-color: var(--danger); }
.flash-info { border-left-color: var(--info); }
.flash a { font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-weight: 600; font-size: .92rem; transition: .25s ease; max-width: calc(100% - 32px);
}
.toast.is-on { transform: translate(-50%, 0); opacity: 1; }
.toast.is-error { background: var(--danger); color: #fff; }

/* ---------- Barre d'outils & catégories ---------- */

.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.search { display: flex; gap: 8px; flex: 1 1 360px; }
.search input { flex: 1; }
.search select { width: auto; flex: none; }
.toolbar-actions { display: flex; gap: 8px; }

.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; margin-bottom: 8px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  --c: var(--ink-2);
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  padding: 6px 12px 6px 10px; border-radius: 999px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: .92rem;
}
.chip::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.chip span { color: var(--ink-2); font-weight: 500; font-size: .85rem; }
.chip.is-active { background: var(--c); border-color: var(--c); color: #fff; }
.chip.is-active span { color: rgba(255, 255, 255, .85); }
.chip.is-active::before { background: #fff; }
.chip-none { --c: #9a8f83; }
.chip-manage { border-style: dashed; color: var(--ink-2); }
.chip-manage::before { display: none; }

/* ---------- Grille de publications ---------- */

.grid {
  display: grid; gap: 16px; align-items: start;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}

.card {
  --c: transparent;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; position: relative;
  border-top: 4px solid var(--c);
  transition: opacity .3s, transform .3s;
}
.card.is-leaving { opacity: 0; transform: scale(.97); }
.card:target { outline: 3px solid var(--accent); outline-offset: 2px; }

.card-embed { background: var(--surface-2); min-height: 120px; display: grid; position: relative; }
/* Tant qu'Instagram n'a pas remplacé la citation par son cadre, on la masque et on garde la vignette-lien */
.card-embed blockquote.instagram-media { position: absolute !important; inset: 0; opacity: 0; pointer-events: none; overflow: hidden; }
.card-embed .instagram-media { margin: 0 !important; min-width: 0 !important; width: 100% !important; max-width: 100% !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; }
.card-embed iframe { width: 100%; border: 0; display: block; background: #fff; }
.embed-fallback {
  display: grid; place-content: center; justify-items: center; gap: 8px;
  min-height: 160px; text-decoration: none; color: var(--ink-2);
}
.embed-host { font-size: .85rem; }
.card-embed.is-loaded .embed-fallback { display: none; }

.card-body { padding: 12px 14px 14px; display: grid; gap: 8px; }
.card-meta { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--ink-2); }
.card-meta time { flex: 1; }
.card-title { font-size: 1rem; margin: 0; }
.card-note { margin: 0; color: var(--ink-2); font-size: .92rem; white-space: normal; }
.card-actions { display: flex; gap: 6px; align-items: center; }
.card-actions select { flex: 1; min-height: 34px; padding: 4px 8px; font-size: 15px; }
.card-actions form { display: contents; }

.fav { background: none; border: 0; cursor: pointer; font-size: 20px; color: var(--ink-2); padding: 0 2px; line-height: 1; }
.fav.is-on { color: #f2a541; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: .75rem; font-weight: 700; color: #fff; background: #7a8b99;
}
.badge-instagram { background: var(--ig); }
.badge-facebook { background: var(--fb); }

.pill {
  --c: var(--ink-2);
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c);
}
.pill-none { --c: var(--ink-2); }

/* Mode compact : pas d'intégration, cartes resserrées */
body.is-compact .card-embed { display: none; }
body.is-compact .grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 24px 0; }

.empty, .panel, .auth-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
}
.empty { text-align: center; padding: 48px 24px; }
.empty-inline { color: var(--ink-2); }
.panel { margin-bottom: 16px; }
.panel h1, .panel h2 { margin-bottom: .4em; }

/* ---------- Connexion / installation ---------- */

.auth-card { max-width: 400px; margin: 10vh auto 0; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 18px; }

/* ---------- Catégories ---------- */

.cat-add { display: flex; gap: 8px; margin: 16px 0 20px; }
.cat-add input[type=text] { flex: 1; }
.cat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cat-item {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px; border: 1px solid var(--line); border-left: 5px solid var(--c); border-radius: 12px;
}
.cat-edit { display: flex; align-items: center; gap: 8px; flex: 1 1 360px; }
.cat-edit input[type=text] { flex: 1; }
.cat-count { font-size: .85rem; color: var(--ink-2); white-space: nowrap; text-decoration: none; }
.cat-count:hover { text-decoration: underline; }
.cat-tools { display: flex; gap: 6px; }

/* ---------- Réglages ---------- */

.kv { display: grid; gap: 8px; margin: 16px 0; }
.kv-row { display: grid; grid-template-columns: 130px 1fr auto; gap: 10px; align-items: center; }
.kv-label { font-weight: 600; font-size: .92rem; }
.kv-value { padding: 8px 10px; }
.howto { border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; }
.howto summary { font-weight: 700; cursor: pointer; }
.howto ol { padding-left: 20px; display: grid; gap: 10px; margin: 14px 0; }
.inline-form { display: inline; }
.devices { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.devices li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.bookmarklet { cursor: grab; }

/* ---------- Fenêtres ---------- */

.modal {
  width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 40px);
  border: 1px solid var(--line); border-radius: 18px; padding: 20px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.modal::backdrop { background: rgba(20, 16, 12, .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
  .wrap { padding: 12px; }
  .brand-name { display: none; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn-primary { margin-left: auto; }
  .grid { grid-template-columns: 1fr; }
  body.is-compact .grid { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .kv-row { grid-template-columns: 1fr auto; }
  .kv-label { grid-column: 1 / -1; }
  .cat-add { flex-wrap: wrap; }
  .cat-add input[type=text] { flex: 1 1 200px; }
  .modal { padding: 16px; }
}
