:root {
  --bg: #f7f2ec;
  --surface: #fffdfa;
  --ink: #2a1e24;
  --muted: #8a7b80;
  --line: #e8ddd3;
  --plum: #5b2a43;
  --plum-soft: #efe3e8;
  --gold: #b88a44;
  --gold-soft: #f5ead7;
  --green: #3f7a5a;
  --green-soft: #e3f0e8;
  --red: #b23b3b;
  --red-soft: #f8e3e1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(42, 30, 36, .06), 0 6px 20px rgba(42, 30, 36, .06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 Inter, system-ui, sans-serif; }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 600; margin: 0; }
h2 { font-size: 22px; } h3 { font-size: 17px; }
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; }
.grow { flex: 1; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--plum); }
.btn.primary { background: var(--plum); border-color: var(--plum); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .5; cursor: progress; }

.brand-mark { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--plum); color: var(--gold-soft); font: 600 26px Fraunces, serif; margin: 0 auto 12px; }
.brand-mark.sm { width: 30px; height: 30px; font-size: 16px; margin: 0; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); padding: 32px 28px; border-radius: 20px; box-shadow: var(--shadow); width: min(380px, 100%); text-align: center; display: grid; gap: 12px; }
.login-card input { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: rgba(247, 242, 236, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font: 600 18px Fraunces, serif; }
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tab { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab.active { background: var(--plum-soft); color: var(--plum); }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
main { padding: 20px; max-width: 1300px; margin: 0 auto; }

.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-head h2 { min-width: 190px; text-align: center; text-transform: capitalize; }
.legend { margin-left: auto; display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot.scheduled { background: var(--gold); } .dot.published { background: var(--green); } .dot.failed { background: var(--red); } .dot.draft { background: var(--muted); }
.cal-layout { display: grid; grid-template-columns: 1fr 280px; gap: 18px; align-items: start; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-weekdays span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 6px 4px; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; min-height: 118px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.day.other { opacity: .45; }
.day.today { border-color: var(--plum); box-shadow: inset 0 0 0 1px var(--plum); }
.day.drag-over { background: var(--gold-soft); }
.day-num { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.day-add { opacity: 0; border: 0; background: none; cursor: pointer; color: var(--plum); font-size: 16px; line-height: 1; padding: 0 2px; }
.day:hover .day-add { opacity: 1; }
.item { display: flex; gap: 6px; align-items: center; padding: 3px; border-radius: 7px; cursor: pointer; font-size: 12px; border-left: 3px solid transparent; background: #fbf7f2; }
.item:hover { background: var(--plum-soft); }
.item img, .item .ph { width: 30px; height: 30px; border-radius: 5px; object-fit: cover; flex: none; background: var(--line); }
.item.scheduled { border-left-color: var(--gold); } .item.published { border-left-color: var(--green); } .item.failed { border-left-color: var(--red); } .item.draft { border-left-color: var(--muted); }
.item .t { font-weight: 600; } .item .k { color: var(--muted); }
.item[draggable="true"] { cursor: grab; }

.side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; position: sticky; top: 76px; }
.side-list { display: grid; gap: 8px; margin-top: 10px; }
.side-list .item { padding: 6px; font-size: 13px; }
.side-list .empty { color: var(--muted); font-size: 13px; }

.sheet { border: 0; border-radius: 20px; padding: 0; width: min(640px, calc(100% - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); background: var(--surface); }
.sheet.small { width: min(460px, calc(100% - 24px)); }
.sheet::backdrop { background: rgba(42, 30, 36, .45); }
.sheet form, #detail > * { padding: 0 22px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 10px !important; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sheet form > .sheet-head { margin: 0 -22px; }
#detail-body { padding-bottom: 22px; }
.sheet label { display: block; font-weight: 600; font-size: 13px; margin: 16px 0 6px; }
.sheet textarea, .sheet input[type=datetime-local] { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; resize: vertical; }
.seg { display: inline-flex; background: var(--plum-soft); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--plum); }
.seg button.active { background: var(--surface); box-shadow: var(--shadow); }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.drop { display: grid; place-items: center; margin-top: 14px; padding: 22px; border: 2px dashed var(--line); border-radius: 14px; cursor: pointer; color: var(--muted); text-align: center; font-weight: 400 !important; font-size: 14px !important; }
.drop.over { border-color: var(--plum); background: var(--plum-soft); }
.media-list { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.mtile { position: relative; width: 104px; height: 130px; border-radius: 10px; overflow: hidden; background: var(--line); }
.mtile img { width: 100%; height: 100%; object-fit: cover; }
.mtile .badge { position: absolute; left: 6px; top: 6px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 6px; }
.mtile .state { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255, 253, 250, .8); font-size: 12px; text-align: center; padding: 6px; }
.mtile .state.err { color: var(--red); }
.mtile .ctrl { position: absolute; right: 4px; bottom: 4px; display: flex; gap: 3px; }
.mtile .ctrl button { width: 24px; height: 24px; border-radius: 6px; border: 0; background: rgba(255, 255, 255, .92); cursor: pointer; font-size: 12px; }
.caption-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.caption-meta .over { color: var(--red); font-weight: 600; }
.preview { font-size: 13px; background: #fbf7f2; border-radius: 10px; padding: 8px 10px; margin-top: 8px; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 16px 0 22px; position: sticky; bottom: 0; background: var(--surface); }

.stats-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.profile { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.profile img { width: 44px; height: 44px; border-radius: 50%; }
.profile b { font-family: Fraunces, serif; font-size: 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font: 600 26px Fraunces, serif; margin-top: 2px; }
.kpi .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .s { font-size: 12px; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h3 { margin-bottom: 12px; }
.chart svg { width: 100%; height: 190px; display: block; }
.chart .bar { fill: var(--plum); opacity: .85; }
.chart .bar:hover { opacity: 1; fill: var(--gold); }
.chart text { font-size: 10px; fill: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: right; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { text-align: right; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td.post { display: flex; align-items: center; gap: 10px; white-space: normal; min-width: 240px; }
td.post img { width: 44px; height: 55px; object-fit: cover; border-radius: 6px; flex: none; }
td.post a { color: var(--ink); text-decoration: none; }
td.post a:hover { color: var(--plum); text-decoration: underline; }
.typetag { font-size: 11px; color: var(--gold); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.loading { color: var(--muted); padding: 20px 0; }

.detail-media { width: 100%; max-height: 360px; object-fit: contain; border-radius: 12px; background: #000; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.detail-grid div { background: #fbf7f2; border-radius: 10px; padding: 8px; text-align: center; }
.detail-grid b { display: block; font: 600 18px Fraunces, serif; }
.detail-grid span { font-size: 11px; color: var(--muted); }
.detail-caption { white-space: pre-wrap; font-size: 13px; max-height: 160px; overflow: auto; background: #fbf7f2; padding: 10px; border-radius: 10px; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(30px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .25s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 900px) {
  .cal-layout { grid-template-columns: 1fr; }
  .side { position: static; }
  .legend { display: none; }
}
@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand span:last-child { display: none; }
  .tabs { margin-left: 0; gap: 2px; order: 3; width: 100%; }
  .tab { flex: 1; padding: 7px 4px; font-size: 14px; }
  #new-post { padding: 8px 10px; }
  .top-actions { gap: 4px; }
  #logout { padding: 6px 8px; font-size: 12px; }
  #charte-text { font-size: 13px; padding: 12px; }
  .cal-weekdays, .cal-grid { gap: 3px; }
  .cal-weekdays span { font-size: 10px; padding: 0 2px 4px; }
  .day { min-height: 70px; padding: 3px; border-radius: 7px; }
  .item { padding: 1px; background: none; border-left-width: 2px; }
  .item .t, .item .k { display: none; }
  .cal-grid .item img, .cal-grid .item .ph { width: 100%; height: 34px; }
  .side-list .item { background: #fbf7f2; padding: 6px; border-left-width: 3px; }
  .side-list .item .t, .side-list .item .k { display: inline; }
  .hide-sm { display: none; }
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .brand span:last-child { display: inline; font-size: 16px; }
  .day-add { display: none; }
  .cal-head h2 { min-width: 0; font-size: 18px; }
  .sheet-actions .btn { flex: 1; }
}

/* Charte */
.charte-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; }
.charte-head p { margin: 4px 0 0; font-size: 14px; }
#charte-text { width: 100%; min-height: 70vh; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }

/* Légendes IA */
.ai-box { margin-top: 16px; background: var(--gold-soft); border-radius: 14px; padding: 12px; }
.ai-row { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-row input { flex: 1; min-width: 200px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.ai-btn { background: var(--plum); color: #fff; border-color: var(--plum); }
.ai-btn:hover { filter: brightness(1.1); }
.ai-prop { background: var(--surface); border-radius: 12px; padding: 12px; margin-top: 10px; border: 1px solid var(--line); }
.ai-prop .ai-angle { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--gold); }
.ai-prop p { white-space: pre-wrap; margin: 6px 0 10px; font-size: 14px; }
.ai-prop .ai-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.ai-prop .ai-foot .btn { margin-left: auto; }
.ai-note { font-size: 13px; color: var(--plum); margin-top: 8px; }
.ai-loading { margin-top: 10px; font-size: 13px; color: var(--muted); }
.guide-tip { font-size: 13px; background: var(--plum-soft); color: var(--plum); border-radius: 10px; padding: 8px 10px; margin-top: 8px; }

/* Commentaires */
.badge-count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 2px; border-radius: 9px; background: var(--plum); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; }
.cm-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.cm-head #cm-refresh { margin-left: auto; }
.cm-head #cm-info { font-size: 13px; }
.cm-list { display: grid; gap: 10px; max-width: 860px; }
.cm { display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.cm.is-hidden { opacity: .65; }
.cm-media { flex: none; width: 56px; height: 70px; border-radius: 8px; overflow: hidden; background: var(--line); }
.cm-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cm-body { flex: 1; min-width: 0; }
.cm-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.cm-top .muted { font-size: 12px; }
.cm-on { font-size: 12px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-text { margin: 6px 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.cm-tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--line); color: var(--muted); font-weight: 500; }
.cm-tag.ok { background: var(--green-soft); color: var(--green); }
.cm-replies { border-left: 2px solid var(--line); padding-left: 10px; margin: 0 0 8px; display: grid; gap: 4px; font-size: 13px; }
.cm-reply { overflow-wrap: anywhere; }
.cm-reply.mine b { color: var(--plum); }
.cm-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cm-compose { margin-top: 10px; background: var(--gold-soft); border-radius: 12px; padding: 10px; }
.cm-compose textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; resize: vertical; margin-top: 6px; }
.cm-sugg { display: grid; gap: 6px; }
.cm-sugg .ai-loading, .cm-sugg .ai-note, .cm-sugg .guide-tip { margin: 0; }
.cm-chip { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; cursor: pointer; font-size: 14px; }
.cm-chip:hover, .cm-chip.on { border-color: var(--plum); box-shadow: inset 3px 0 0 var(--plum); }
.cm-send { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.cm-send .error { margin: 0; font-size: 13px; }
@media (max-width: 640px) {
  .cm { padding: 10px; gap: 10px; }
  .cm-media { width: 44px; height: 55px; }
  .cm-actions .grow { display: none; }
  .tab .badge-count { margin-left: 1px; }
}
.show-sm { display: none; }
.tab { white-space: nowrap; }
@media (max-width: 640px) {
  .show-sm { display: inline; }
  .cm-actions { gap: 5px; }
  .cm-actions .btn.small { padding: 5px 8px; }
}

/* Meilleurs horaires */
.best-sugg { font-size: 14px; margin-bottom: 10px; line-height: 1.6; }
.best-sub { font-size: 12px; margin: 12px 0 6px; color: var(--muted); }
.heat { display: grid; grid-template-columns: 34px repeat(var(--cols), 1fr); gap: 2px; font-size: 10px; color: var(--muted); }
.heat .hh { text-align: left; white-space: nowrap; }
.heat .hd { font-size: 11px; align-self: center; }
.heat i { display: block; height: 18px; border-radius: 3px; background: color-mix(in srgb, var(--plum) calc(var(--v) * 100%), var(--plum-soft)); }
.best-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 28px; }
.bp { display: grid; grid-template-columns: 96px 1fr 120px; align-items: center; gap: 8px; font-size: 13px; padding: 2px 0; }
.bpbar { height: 8px; border-radius: 4px; background: var(--plum-soft); position: relative; overflow: hidden; }
.bpbar i { position: absolute; inset: 0 auto 0 0; background: var(--plum); border-radius: 4px; }
.bpbar::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--gold); }
.bp .muted { font-size: 12px; text-align: right; }
.best-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: 13px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 10px; cursor: pointer; font-size: 13px; }
.chip:hover, .chip.on { border-color: var(--plum); background: var(--plum-soft); color: var(--plum); }

/* Aperçu de la grille */
.cal-head.grid-mode #cal-prev, .cal-head.grid-mode #cal-next, .cal-head.grid-mode #cal-today, .cal-head.grid-mode #cal-title, .cal-head.grid-mode .legend { display: none; }
.grid-view { max-width: 560px; }
.grid-note { font-size: 13px; margin: 0 0 10px; }
.ig-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.gcell { position: relative; aspect-ratio: 3 / 4; border: 0; padding: 0; background: var(--line); cursor: pointer; overflow: hidden; }
.gcell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gcell.planned { outline: 2px dashed var(--gold); outline-offset: -2px; }
.gcell.planned img { opacity: .85; }
.gicon { position: absolute; top: 6px; right: 7px; color: #fff; font-size: 13px; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.gwhen { position: absolute; left: 6px; bottom: 6px; background: var(--gold); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 6px; }
@media (max-width: 640px) {
  .best-cols { grid-template-columns: 1fr; }
  .bp { grid-template-columns: 84px 1fr 104px; }
  .heat { grid-template-columns: 28px repeat(var(--cols), 1fr); gap: 1px; }
  .heat i { height: 14px; }
  .heat .hh { font-size: 9px; }
}
@media (max-width: 640px) {
  .tabs .tab { flex: 1 1 auto; padding: 7px 3px; font-size: 13px; }
  .tab .badge-count { min-width: 16px; line-height: 16px; font-size: 10px; padding: 0 4px; }
}
