/* ===== Back-office Tuina Loygue ===== */
:root{--ink:#20262b;--ink2:#535d65;--blue:#1f4e79;--blue-d:#163a5c;--paper:#f6f2ea;
  --line:#e2dccd;--jade:#4f7d6e;--gold:#b08d57;--bg:#f3f1ea;--card:#fff;--ok:#3a7d4f;--err:#a8402f;--sidebar:#1b2530}
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:system-ui,-apple-system,"Segoe UI",sans-serif;background:var(--bg);color:var(--ink);line-height:1.5}
a{color:inherit;text-decoration:none}

/* layout */
.layout{display:grid;grid-template-columns:240px 1fr;min-height:100vh}
.sidebar{background:var(--sidebar);color:#cdd5de;padding:1.4rem 0;position:sticky;top:0;height:100vh;overflow-y:auto}
.sidebar .brand{padding:0 1.4rem 1.2rem;border-bottom:1px solid rgba(255,255,255,.08);margin-bottom:1rem}
.sidebar .brand b{color:#fff;font-size:1.05rem;letter-spacing:.04em}
.sidebar .brand span{display:block;font-size:.72rem;color:#8c97a3;letter-spacing:.18em;text-transform:uppercase;margin-top:.2rem}
.sidebar nav a{display:flex;align-items:center;gap:.7rem;padding:.7rem 1.4rem;font-size:.92rem;color:#aab4bf;transition:.2s;border-left:3px solid transparent}
.sidebar nav a:hover{background:rgba(255,255,255,.05);color:#fff}
.sidebar nav a.active{background:rgba(255,255,255,.07);color:#fff;border-left-color:var(--gold)}
.sidebar nav .grp{padding:.9rem 1.4rem .3rem;font-size:.68rem;letter-spacing:.16em;text-transform:uppercase;color:#5f6b78}
.main{padding:2rem 2.4rem}
.topbar{display:flex;justify-content:space-between;align-items:center;margin-bottom:2rem}
.topbar h1{font-size:1.5rem;font-weight:600}
.topbar .user{font-size:.9rem;color:var(--ink2)}
.topbar .user a{color:var(--blue);margin-left:1rem}

/* cards / grilles */
.cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:1rem;margin-bottom:2rem}
.stat{background:var(--card);border:1px solid var(--line);border-radius:8px;padding:1.3rem}
.stat .n{font-size:2rem;font-weight:700;color:var(--blue)}
.stat .l{font-size:.85rem;color:var(--ink2);margin-top:.2rem}
.panel{background:var(--card);border:1px solid var(--line);border-radius:8px;padding:1.6rem;margin-bottom:1.5rem}
.panel h2{font-size:1.1rem;margin-bottom:1rem}

/* boutons */
.btn{display:inline-block;background:var(--blue);color:#fff;border:none;border-radius:5px;padding:.6rem 1.2rem;
  font-size:.9rem;cursor:pointer;transition:.2s}
.btn:hover{background:var(--blue-d)}
.btn.j{background:var(--jade)}.btn.j:hover{filter:brightness(1.1)}
.btn.r{background:var(--err)}.btn.ghost{background:transparent;color:var(--blue);border:1px solid var(--line)}
.btn.sm{padding:.4rem .8rem;font-size:.82rem}

/* médiathèque */
.media-toolbar{display:flex;gap:1rem;align-items:center;margin-bottom:1.3rem;flex-wrap:wrap}
#mdrop{border:2px dashed var(--line);border-radius:8px;background:var(--card);padding:1.6rem;text-align:center;flex:1;min-width:260px;transition:.2s;cursor:pointer}
#mdrop.over{border-color:var(--jade);background:#f0f6f3}
#mdrop .big{font-size:.98rem}#mdrop .small{font-size:.82rem;color:var(--ink2);margin-top:.2rem}
#mdrop kbd{background:var(--bg);border:1px solid var(--line);border-radius:4px;padding:.05rem .35rem;font-size:.8rem}
.mgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(160px,1fr));gap:1rem}
.mitem{background:var(--card);border:1px solid var(--line);border-radius:8px;overflow:hidden;display:flex;flex-direction:column}
.mitem .imgwrap{aspect-ratio:1;background:#eee url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="20" height="20"%3E%3Crect width="10" height="10" fill="%23f4f4f4"/%3E%3Crect x="10" y="10" width="10" height="10" fill="%23f4f4f4"/%3E%3C/svg%3E');display:flex;align-items:center;justify-content:center}
.mitem img{width:100%;height:100%;object-fit:cover}
.mitem .meta{padding:.6rem}
.mitem .nm{font-size:.72rem;color:var(--ink2);word-break:break-all;margin-bottom:.4rem;max-height:2.4em;overflow:hidden}
.mitem .acts{display:flex;gap:.3rem}
.mitem .acts button{flex:1;font-size:.74rem;padding:.35rem;border:none;border-radius:4px;cursor:pointer;background:var(--jade);color:#fff;transition:.2s}
.mitem .acts button.del{background:var(--err)}
.mitem .acts button.copied{background:var(--ok)}
#mstatus{margin:.6rem 0;font-size:.88rem;min-height:1.2em}
#mstatus.ok{color:var(--ok)}#mstatus.err{color:var(--err)}

/* login */
.login-wrap{min-height:100vh;display:flex;align-items:center;justify-content:center;background:var(--sidebar)}
.login-box{background:#fff;border-radius:10px;padding:2.4rem;width:340px;box-shadow:0 30px 60px -20px rgba(0,0,0,.4)}
.login-box img{height:64px;display:block;margin:0 auto 1.2rem}
.login-box h1{font-size:1.2rem;text-align:center;margin-bottom:1.4rem;font-weight:600}
.login-box label{display:block;font-size:.82rem;color:var(--ink2);margin-bottom:.3rem;margin-top:.8rem}
.login-box input{width:100%;padding:.7rem;border:1px solid var(--line);border-radius:6px;font-size:.95rem}
.login-box .btn{width:100%;margin-top:1.4rem;padding:.8rem}
.login-box .err{background:#fbeae8;color:var(--err);padding:.6rem;border-radius:6px;font-size:.85rem;margin-top:1rem;text-align:center}

/* tables */
table{width:100%;border-collapse:collapse;font-size:.9rem}
th,td{text-align:left;padding:.7rem;border-bottom:1px solid var(--line)}
th{font-size:.74rem;letter-spacing:.06em;text-transform:uppercase;color:var(--ink2)}
.badge{font-size:.72rem;padding:.2rem .6rem;border-radius:999px}
.badge.pub{background:#e3f0e8;color:var(--ok)}.badge.draft{background:#eee;color:var(--ink2)}

@media(max-width:760px){.layout{grid-template-columns:1fr}.sidebar{position:static;height:auto}}

/* ===== ÉDITEUR WYSIWYG (articles) ===== */
.wysiwyg-toolbar{display:flex;flex-wrap:wrap;gap:.28rem;align-items:center;
  background:#1d2730;border-radius:8px 8px 0 0;padding:.45rem .55rem;border:1px solid #1d2730}
.wysiwyg-toolbar button{background:none;border:none;color:#e7eef5;min-width:34px;height:34px;
  border-radius:6px;cursor:pointer;font-size:.92rem;font-family:'Manrope',sans-serif;padding:0 .55rem;
  display:inline-flex;align-items:center;justify-content:center;transition:background .15s,color .15s}
.wysiwyg-toolbar button:hover{background:rgba(255,255,255,.16)}
.wysiwyg-toolbar button:active{background:var(--gold);color:#1d2730}
.wysiwyg-toolbar button[data-cmd='bold']{font-weight:700}
#btnInsertImg{font-size:.82rem;letter-spacing:.02em;gap:.3rem}
.wt-sep{width:1px;height:22px;background:rgba(255,255,255,.18);margin:0 .3rem}
/* pastilles couleur éditeur article */
.wt-colors{display:inline-flex;align-items:center;gap:.28rem;padding:0 .15rem}
.wtcolor{width:20px;height:20px;min-width:20px!important;border-radius:50%;
  border:2px solid rgba(255,255,255,.4)!important;cursor:pointer;padding:0!important}
.wtcolor:hover{transform:scale(1.18);border-color:#fff!important;background:inherit}
.wtcolor-pick{position:relative;width:26px;height:26px;display:inline-flex;align-items:center;justify-content:center;cursor:pointer}
.wtcolor-pick span{font-size:1rem;pointer-events:none}
.wtcolor-pick input[type=color]{position:absolute;inset:0;opacity:0;width:100%;height:100%;cursor:pointer;border:none;padding:0}

.wysiwyg{min-height:340px;border:1px solid var(--line);border-radius:0 0 7px 7px;
  padding:1.2rem 1.4rem;background:#fff;font-size:1.02rem;line-height:1.7;color:var(--ink);
  overflow-y:auto;max-height:600px}
.wysiwyg:focus{outline:none;box-shadow:inset 0 0 0 2px rgba(31,78,121,.25)}
.wysiwyg h2{font-family:'Marcellus',serif;font-size:1.5rem;margin:1.4rem 0 .7rem;color:var(--ink)}
.wysiwyg h3{font-family:'Marcellus',serif;font-size:1.2rem;margin:1.1rem 0 .5rem;color:var(--ink)}
.wysiwyg p{margin:0 0 1rem}
.wysiwyg img{max-width:100%;height:auto;border-radius:8px;margin:1rem 0}
.wysiwyg ul,.wysiwyg ol{margin:0 0 1rem 1.4rem}
.wysiwyg a{color:var(--blue);text-decoration:underline}

/* lien permanent vers l'article depuis l'éditeur */
.edit-toplink{display:flex;align-items:center;gap:1rem;flex-wrap:wrap;margin:0 0 1.2rem}
.btn-voir-article{display:inline-flex;align-items:center;gap:.4rem;background:var(--blue);color:#fff;
  text-decoration:none;padding:.6rem 1.1rem;border-radius:7px;font-size:.92rem;font-weight:500;font-family:'Manrope',sans-serif}
.btn-voir-article:hover{filter:brightness(1.1)}
.edit-toplink-note{color:#8a8475;font-size:.82rem;font-style:italic}

/* ====== éditeur : alignement & redim. images ====== */
.wysiwyg img{max-width:100%;height:auto;cursor:pointer}
.wysiwyg img.img-selected{outline:3px solid var(--blue);outline-offset:2px}
.img-toolbar{position:absolute;z-index:9999;display:flex;align-items:center;gap:.25rem;
  background:#1d2730;border-radius:8px;padding:.35rem .45rem;box-shadow:0 10px 30px -10px rgba(0,0,0,.5)}
.img-toolbar button{background:none;border:none;color:#e7eef5;width:32px;height:32px;border-radius:6px;
  cursor:pointer;font-size:.95rem;display:inline-flex;align-items:center;justify-content:center}
.img-toolbar button:hover{background:rgba(255,255,255,.16)}
.img-toolbar .ib-sep{width:1px;height:20px;background:rgba(255,255,255,.2);margin:0 .25rem}
.img-resize-handle{position:absolute;z-index:9999;width:16px;height:16px;background:#fff;
  border:3px solid var(--blue);border-radius:50%;cursor:nwse-resize;box-shadow:0 2px 6px rgba(0,0,0,.3)}

/* aperçu des alignements DANS l'éditeur */
.wysiwyg img.img-left{float:left;margin:.3rem 1.2rem .8rem 0;max-width:50%}
.wysiwyg img.img-right{float:right;margin:.3rem 0 .8rem 1.2rem;max-width:50%}
.wysiwyg img.img-center{display:block;margin:1rem auto}
.wysiwyg img.img-full{display:block;width:100%;margin:1rem 0}