:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe8da;
  --ink: #26211b;
  --ink-2: #5f564a;
  --ink-3: #8a8070;
  --line: #ddd3c0;
  --accent: #8a4b2a;
  --accent-ink: #ffffff;
  --accent-soft: #f0dccd;
  --ok: #3f7d4e;
  --warn: #b7791f;
  --bad: #b3372b;
  --off: #a39a8a;
  --shadow: 0 6px 24px rgba(40, 28, 10, .16);
  --hh: 52px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1713;
    --surface: #24201a;
    --surface-2: #2e2922;
    --ink: #efe8da;
    --ink-2: #bdb3a2;
    --ink-3: #8c8272;
    --line: #3a342b;
    --accent: #d89a6c;
    --accent-ink: #1c130b;
    --accent-soft: #3d2d20;
    --ok: #6fb77e;
    --warn: #e0a64a;
    --bad: #e2695c;
    --off: #6f675a;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 var(--sans); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Header: one row ---------- */
.top {
  position: sticky; top: 0; z-index: 30; height: var(--hh);
  display: flex; align-items: center; gap: 8px; padding: 0 14px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font: 600 20px/1 var(--serif); letter-spacing: .2px; margin-right: 6px; color: var(--accent); }
.spacer { flex: 1; min-width: 0; }
.tabs { display: flex; gap: 2px; }
.tabs button {
  background: none; border: 0; border-radius: 8px; padding: 6px 8px; color: var(--ink-2); white-space: nowrap;
}
.tabs button:hover { background: var(--surface-2); }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.n { color: var(--ink-3); font-variant-numeric: tabular-nums; font-weight: 400; }
.tabs button[data-tab="new"] .n:not(:empty) { color: var(--accent); font-weight: 700; }
.tabsel { display: none; }

.btn, .icon {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 11px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
}
.btn:hover, .icon:hover { background: var(--surface-2); }
.btn[aria-expanded="true"], .icon[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); }
.icon { justify-content: center; width: 34px; padding: 0; font-size: 20px; line-height: 1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: none; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 9px; padding: 0 6px; font-size: 11px; font-weight: 700; line-height: 17px; }
.warn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 2px var(--surface); }
.only-compact { display: none; }

.searchbox { display: flex; gap: 6px; }
.searchbox input, .searchbox select, .pop input[type="search"], dialog input[type="text"], dialog select {
  height: 34px; padding: 0 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; min-width: 0;
}
.searchbox input { width: 84px; }
.searchbox select { width: 128px; }
.status { color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: transparent; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }

/* ---------- Popovers ---------- */
.pop {
  position: fixed; z-index: 40; top: calc(var(--hh) + 4px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column;
  max-height: calc(100vh - var(--hh) - 16px); overflow: hidden;
}
.pop-kw { width: 380px; }
.pop-src { width: 420px; }
.pop-menu { width: 260px; padding: 6px; }
.pop-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 6px; }
.pop-head input { flex: 1; }
.pop-list { overflow: auto; padding: 4px 6px; }
.pop-foot { border-top: 1px solid var(--line); padding: 8px 10px; display: flex; gap: 8px; }
.link { background: none; border: 0; color: var(--accent); padding: 4px 6px; border-radius: 6px; }
.link:hover { text-decoration: underline; }
.pop-menu button[role="menuitem"] { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 10px; border-radius: 8px; }
.pop-menu button[role="menuitem"]:hover, .pop-menu button[role="menuitem"]:focus-visible { background: var(--surface-2); }
.menu-status { padding: 6px 10px 8px; color: var(--ink-2); font-size: 13px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 0; }
.menu-note { padding: 4px 10px; color: var(--ink-3); font-size: 12px; }

.kw-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.kw-row, .src-row { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 8px; position: relative; }
.kw-row:hover, .src-row:hover { background: var(--surface-2); }
.kw-row label { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer; }
.kw-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kw-row.paused .name { color: var(--ink-3); font-style: italic; }
.cnt { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cnt b { color: var(--accent); font-weight: 700; }
.row-menu-btn { width: 28px; height: 28px; border: 0; background: none; border-radius: 6px; font-size: 18px; line-height: 1; color: var(--ink-2); }
.row-menu-btn:hover { background: var(--line); }
.row-menu { position: absolute; right: 4px; top: 100%; z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; min-width: 190px; }
.row-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; }
.row-menu button:hover { background: var(--surface-2); }
.row-menu button.bad { color: var(--bad); }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; flex: none; }

.src-row { flex-wrap: wrap; padding: 7px 6px; }
.src-row .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex: none; }
.dot.ok { background: var(--ok); } .dot.partial { background: var(--warn); }
.dot.blocked, .dot.disallowed, .dot.error { background: var(--bad); }
.src-row .sname { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-row .smeta { color: var(--ink-3); font-size: 12px; white-space: nowrap; }
.src-row .serr { flex-basis: 100%; padding-left: 18px; color: var(--bad); font-size: 12.5px; }
.src-row .serr.soft { color: var(--ink-3); }
.sw { position: relative; width: 32px; height: 18px; flex: none; }
.sw input { appearance: none; -webkit-appearance: none; width: 32px; height: 18px; border-radius: 9px; background: var(--off); border: 0; margin: 0; cursor: pointer; transition: background .15s; }
.sw input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.sw input:checked { background: var(--ok); }
.sw input:checked::after { transform: translateX(14px); }

/* ---------- Content ---------- */
main { padding: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.card.is-new { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card.is-dismissed { opacity: .6; }
.pic { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); display: block; overflow: hidden; }
.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.pic .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); }
.pic .ph svg { width: 34px; height: 34px; stroke-width: 1.4; }
.pic img + .ph { display: none; }
.pic.noimg .ph { display: grid; }
.card .body { padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.meta { display: flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: 12px; }
.meta { white-space: nowrap; min-width: 0; }
.meta .src { color: var(--ink-2); font-weight: 600; flex: none; max-width: 60%; overflow: hidden; text-overflow: ellipsis; }
.meta .when { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.newdot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.meta .sp { flex: 1; }
.card h3 { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card h3 a { color: inherit; text-decoration: none; }
.card h3 a:hover { text-decoration: underline; }
.price { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.price small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-2); }
.price .est { font-weight: 400; font-size: 12.5px; color: var(--ink-2); }
.price .none { color: var(--ink-3); font-weight: 400; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--accent-soft); color: var(--ink); border-radius: 10px; padding: 1px 8px; font-size: 11.5px; line-height: 18px; }
.chip.loose { background: transparent; border: 1px dashed var(--line); color: var(--ink-3); }
.note { font-size: 12px; color: var(--ink-2); background: var(--surface-2); padding: 3px 8px; border-radius: 6px; }
.acts { display: flex; border-top: 1px solid var(--line); }
.acts button { flex: 1; background: none; border: 0; padding: 8px 4px; color: var(--ink-2); display: flex; justify-content: center; align-items: center; gap: 5px; font-size: 12.5px; }
.acts button + button { border-left: 1px solid var(--line); }
.acts button:hover { background: var(--surface-2); color: var(--ink); }
.acts button[aria-pressed="true"] { color: var(--accent); font-weight: 600; }
.acts button[aria-pressed="true"] svg { fill: currentColor; }
.more { display: flex; justify-content: center; padding: 18px 0 8px; }
.empty { max-width: 460px; margin: 12vh auto 0; text-align: center; color: var(--ink-2); }
.empty strong { display: block; font: 600 20px/1.3 var(--serif); color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 12px; }

/* ---------- Dialogs, toast ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 18px 20px; width: min(520px, calc(100vw - 24px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(20, 14, 6, .45); }
dialog h2 { margin: 0 0 12px; font: 600 20px/1.2 var(--serif); }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-weight: 600; font-size: 13px; }
.field small, .hint, dialog small { font-weight: 400; color: var(--ink-3); font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.row-2 { display: flex; gap: 16px; align-items: flex-end; }
.row-2 .row { margin-bottom: 14px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.err { color: var(--bad); margin: 0 0 8px; }
.chips-edit { display: flex; flex-wrap: wrap; gap: 5px; padding: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; min-height: 40px; align-items: center; }
.chips-edit .chip { display: inline-flex; align-items: center; gap: 4px; padding-right: 3px; font-weight: 400; }
.chips-edit .chip button { border: 0; background: none; padding: 0 4px; line-height: 16px; border-radius: 8px; color: var(--ink-2); }
.chips-edit input { flex: 1; min-width: 90px; border: 0; background: none; outline: 0; height: 24px; padding: 0 4px; font-weight: 400; }
.links { display: flex; flex-direction: column; max-height: 55vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.links a { display: flex; gap: 8px; padding: 8px 10px; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.links a:last-child { border-bottom: 0; }
.links a:hover { background: var(--surface-2); }
.links .ln { font-weight: 600; min-width: 110px; }
.links .lq { color: var(--ink-2); flex: 1; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); max-width: calc(100vw - 24px); }
.toast .link { color: var(--accent-soft); font-weight: 600; }

/* ---------- Narrower: same header, compacted ---------- */
@media (max-width: 1439px) {
  .tabs { display: none; }
  .tabsel { display: block; height: 34px; padding: 0 8px; background: var(--accent-soft); border: 1px solid var(--line); border-radius: 8px; font-weight: 600; max-width: 190px; min-width: 0; }
  .only-compact { display: inline-flex; }
  .searchbox { display: none; position: fixed; z-index: 40; top: calc(var(--hh) + 4px); right: 10px; left: auto; width: min(380px, calc(100vw - 20px)); padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
  .searchbox.open { display: flex; }
  .searchbox input { flex: 1; width: auto; }
  .status { max-width: 150px; }
}
@media (max-width: 760px) {
  .status { display: none; }
  .btn .lbl { display: none; }
  .btn { padding: 0 7px; width: auto; justify-content: center; }
  .top { gap: 4px; padding: 0 6px; }
  .tabsel { font-size: 13px; padding: 0 4px; }
  .btn, .icon { min-width: 32px; }
  .icon { width: 32px; }
  .brand { font-size: 17px; margin-right: 2px; }
  .tabsel { max-width: none; flex: 1 1 auto; }
  .pop-kw, .pop-src { left: 8px; right: 8px; width: auto; }
  .pop-menu { right: 8px; }
  main { padding: 10px 8px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
}
@media (max-width: 440px) {
  .brand { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- v2 : compte, ajout de recherche, utilisateurs, pages publiques ---------- */
.btn.accent { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.btn.accent:hover { background: var(--accent-soft); }
.avatar { border-radius: 50%; background: var(--accent-soft); border-color: var(--accent); font: 700 14px/1 var(--sans); color: var(--ink); text-transform: uppercase; }
.only-narrow { display: none; }
.pop-add { width: 400px; padding: 12px; overflow: visible; }
.add-l { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.add-row { display: flex; gap: 6px; }
.add-row input { flex: 1; height: 36px; padding: 0 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.add-row .btn { height: 36px; }
.add-more { margin-top: 8px; }
.add-more summary { cursor: pointer; color: var(--ink-2); font-size: 13px; padding: 4px 0; }
.add-more .field { margin: 8px 0 0; }
.pop-add .err { margin: 8px 0 0; }
.pop-add { overflow: auto; }
.sec { margin: 4px 0 8px; font: 600 12px/1.2 var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.sec small { text-transform: none; letter-spacing: 0; }
#setGlobal { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.users { border: 1px solid var(--line); border-radius: 10px; max-height: 45vh; overflow: auto; margin-bottom: 10px; }
.user-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.user-row .u-main { flex: 1; min-width: 0; }
.user-row .u-mail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.user-row .u-sub { color: var(--ink-3); font-size: 12px; }
.user-row select { height: 30px; padding: 0 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.user-row .btn { height: 30px; padding: 0 9px; }
.user-add { display: flex; gap: 6px; }
.user-add input { flex: 1; min-width: 0; height: 34px; padding: 0 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.user-add select { height: 34px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 26px 24px; box-shadow: var(--shadow); }
.auth-card .brand { display: block; font-size: 26px; margin: 0 0 6px; }
.auth-card h1 { font: 600 20px/1.3 var(--serif); margin: 0 0 6px; }
.auth-card p { color: var(--ink-2); margin: 0 0 14px; }
.auth-card input[type="email"] { width: 100%; height: 40px; padding: 0 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; }
.auth-card .btn { width: 100%; height: 40px; justify-content: center; }
.auth-card .err { margin: 0 0 12px; }
.auth-card .ok { color: var(--ink); background: var(--accent-soft); padding: 10px 12px; border-radius: 8px; }
@media (max-width: 1439px) { .searchbox input { width: auto; } }
@media (max-width: 760px) {
  .avatar { display: none; }
  .only-narrow { display: block; }
  .pop-add { left: 8px; right: 8px; width: auto; }
  .btn.accent { padding: 0 9px; }
  .user-row { flex-wrap: wrap; }
}
