:root{
  --paper:#F6F2E9;
  --paper-page:#FFFEFB;
  --ink:#2A2520;
  --ink-soft:#7A7266;
  --gold:#A6803C;
  --gold-deep:#8C6A2A;
  --burgundy:#7B2E3A;
  --sage:#5E6E52;
  --slate:#3B5268;
  --rose:#B06276;
  --muted:#8A8272;
  --line:#E6DCC4;
  --sidebar-bg:#EFE8D8;
  --shadow: 0 18px 50px rgba(50,36,10,.20), 0 2px 8px rgba(50,36,10,.10);
  --radius: 10px;
}
*{box-sizing:border-box;}
html,body{height:100%;}
body{ margin:0; background:var(--paper); color:var(--ink); font-family:'Inter',sans-serif; overflow:hidden; }
.app{ display:flex; flex-direction:column; height:100vh; }

.topbar{ display:flex; align-items:center; gap:14px; padding:10px 20px; background:var(--ink); color:#F3EEDF; border-bottom:3px solid var(--gold); flex-shrink:0; position:relative; z-index:50; }
.brand{ display:flex; align-items:center; gap:8px; font-family:'Cormorant Garamond',serif; font-size:22px; font-weight:600; color:#F3EEDF; white-space:nowrap; }
.nom-livret{ background:transparent; border:1px solid rgba(243,238,223,.25); color:#F3EEDF; font-family:'EB Garamond', serif; font-size:16px; font-style:italic; padding:6px 12px; border-radius:6px; min-width:160px; flex:1; max-width:280px; }
.nom-livret:focus{ outline:none; border-color:var(--gold); background:rgba(255,255,255,.05); }
.topbar-spacer{flex:1;}
.btn{ font-family:'Inter',sans-serif; font-size:13px; font-weight:600; border:none; border-radius:7px; padding:9px 14px; cursor:pointer; display:inline-flex; align-items:center; gap:7px; white-space:nowrap; }
.btn:active{ transform:translateY(1px); }
.btn-ghost{ background:rgba(243,238,223,.08); color:#F3EEDF; }
.btn-ghost:hover{ background:rgba(243,238,223,.16); }
.btn-gold{ background:linear-gradient(180deg,var(--gold),var(--gold-deep)); color:#2A2007; }
.btn-gold:hover{ filter:brightness(1.07); }
.btn-gold:disabled{ opacity:.55; cursor:progress; }

.dropdown-wrap{ position:relative; }
.dropdown-panel{ position:absolute; top:calc(100% + 8px); right:0; width:280px; background:var(--paper-page); color:var(--ink); border-radius:10px; box-shadow:var(--shadow); padding:8px; display:none; max-height:360px; overflow-y:auto; border:1px solid var(--line); }
.dropdown-panel.open{ display:block; }
.dd-item{ display:flex; align-items:center; gap:8px; padding:9px 10px; border-radius:7px; cursor:pointer; }
.dd-item:hover{ background:var(--sidebar-bg); }
.dd-item .dd-title{ flex:1; font-size:13.5px; font-weight:600; }
.dd-item .dd-date{ font-size:11px; color:var(--ink-soft); }
.dd-item .dd-actions{ display:none; gap:4px; }
.dd-item:hover .dd-actions{ display:flex; }
.dd-icon-btn{ border:none; background:transparent; color:var(--ink-soft); cursor:pointer; padding:3px; border-radius:4px; }
.dd-icon-btn:hover{ background:var(--line); color:var(--burgundy); }
.dd-new{ font-weight:700; color:var(--gold-deep); border-bottom:1px solid var(--line); margin-bottom:6px; padding-bottom:10px; }

.body{ flex:1; display:flex; min-height:0; }
.sidebar{ width:280px; flex-shrink:0; background:var(--sidebar-bg); border-right:1px solid var(--line); display:flex; flex-direction:column; min-height:0; }
.sidebar-head{ padding:14px 14px 8px; }
.add-page-wrap{ position:relative; }
.add-page-btn{ width:100%; background:var(--ink); color:#F3EEDF; border:none; border-radius:8px; padding:11px; font-size:13px; font-weight:700; cursor:pointer; }
.add-page-btn:hover{ background:#3a332a; }
.template-menu{ position:absolute; top:calc(100% + 6px); left:0; right:0; z-index:40; background:var(--paper-page); border:1px solid var(--line); border-radius:9px; box-shadow:var(--shadow); padding:6px; display:none; max-height:340px; overflow-y:auto; }
.template-menu.open{ display:block; }
.tpl-item{ display:flex; align-items:center; gap:9px; padding:8px 9px; border-radius:6px; cursor:pointer; font-size:13px; }
.tpl-item:hover{ background:var(--sidebar-bg); }
.tpl-dot{ width:8px; height:8px; border-radius:50%; flex-shrink:0; }

.page-list{ flex:1; overflow-y:auto; padding:6px 10px 20px; }
.page-item{ display:flex; align-items:center; gap:8px; background:var(--paper-page); border:1px solid var(--line); border-left:5px solid var(--muted); border-radius:7px; padding:9px 8px; margin-bottom:7px; cursor:grab; position:relative; }
.page-item.selected{ box-shadow:0 0 0 2px var(--gold-deep) inset; border-color:var(--gold-deep); }
.page-item.dragging{ opacity:.4; }
.page-item.drag-over{ box-shadow:0 -3px 0 var(--gold-deep) inset; }
.page-num{ font-family:'Cormorant Garamond',serif; font-weight:700; font-size:15px; color:var(--ink-soft); width:20px; text-align:center; flex-shrink:0; }
.page-info{ flex:1; min-width:0; }
.page-info .pt{ font-size:13px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.page-info .pc{ font-size:10.5px; color:var(--ink-soft); text-transform:uppercase; letter-spacing:.4px; }
.page-actions{ display:flex; gap:2px; opacity:0; transition:opacity .1s; }
.page-item:hover .page-actions{ opacity:1; }
.pi-btn{ border:none; background:transparent; color:var(--ink-soft); cursor:pointer; padding:4px; border-radius:5px; }
.pi-btn:hover{ background:var(--sidebar-bg); color:var(--burgundy); }
.drag-handle{ color:var(--ink-soft); cursor:grab; flex-shrink:0; }

.canvas-wrap{ flex:1; display:flex; flex-direction:column; min-width:0; background:var(--paper); }
.format-toolbar{ display:flex; align-items:center; gap:4px; padding:9px 16px; background:var(--paper-page); border-bottom:1px solid var(--line); flex-wrap:wrap; }
.fmt-btn{ border:1px solid var(--line); background:#fff; color:var(--ink); border-radius:6px; width:32px; height:32px; cursor:pointer; }
.fmt-btn:hover{ background:var(--sidebar-bg); }
.fmt-sep{ width:1px; height:22px; background:var(--line); margin:0 6px; }
.fmt-label{ font-size:11px; color:var(--ink-soft); margin-right:4px; }

.page-stage{ flex:1; overflow:auto; display:flex; justify-content:center; padding:36px 24px; }
.page{ width:480px; height:682px; background:var(--paper-page); box-shadow:var(--shadow); flex-shrink:0; position:relative; font-family:'EB Garamond',serif; padding:56px 46px 50px; display:flex; flex-direction:column; overflow:hidden; }
.page::before{ content:''; position:absolute; left:0; top:0; bottom:0; width:2px; background:repeating-linear-gradient(to bottom, var(--line) 0 6px, transparent 6px 12px); }
.page-badge{ position:absolute; top:14px; right:18px; font-family:'Inter',sans-serif; font-size:10px; color:var(--ink-soft); letter-spacing:.5px; }
.page-title{ font-family:'Cormorant Garamond',serif; font-weight:600; font-size:23px; color:var(--burgundy); margin:0 0 16px; outline:none; border-bottom:1px solid var(--line); padding-bottom:10px; }
.page-content{ flex:1; outline:none; line-height:1.65; color:var(--ink); }
.page-content p{ margin:0 0 12px; }
.page-content .refrain{ font-style:italic; font-weight:600; color:var(--gold-deep); }
.page-content .divider{ text-align:center; color:var(--gold-deep); margin:18px 0; font-size:17px; }
.page-content:empty::before{ content:'Écrivez ici…'; color:#c9c0a8; }
.page-overflow-warning{ position:absolute; left:46px; right:46px; bottom:16px; background:#FBEAEA; border:1px solid #E8C7C7; color:#7B2E3A; font-family:'Inter',sans-serif; font-size:11.5px; text-align:center; padding:7px 10px; border-radius:6px; display:none; box-shadow:0 4px 14px rgba(0,0,0,.12); }
.page.has-overflow .page-overflow-warning{ display:block; }

.page.cover{ align-items:center; text-align:center; justify-content:center; padding:50px 42px; }
.cover-ornament{ margin-bottom:18px; color:var(--gold-deep); }
.cover-title{ font-family:'Cormorant Garamond',serif; font-weight:600; font-size:34px; color:var(--ink); outline:none; line-height:1.2; margin-bottom:10px; max-width:100%; }
.cover-subtitle{ font-family:'EB Garamond',serif; font-style:italic; font-size:18px; color:var(--burgundy); outline:none; margin-bottom:22px; }
.cover-image-box{ width:220px; height:220px; border-radius:6px; border:1px solid var(--line); background:var(--sidebar-bg); display:flex; align-items:center; justify-content:center; overflow:hidden; margin-bottom:22px; cursor:pointer; position:relative; }
.cover-image-box img{ width:100%; height:100%; object-fit:cover; }
.cover-image-box .cib-label{ font-size:11.5px; color:var(--ink-soft); text-align:center; padding:10px; }
.cover-image-box .cib-remove{ position:absolute; top:4px; right:4px; background:rgba(20,15,5,.55); color:#fff; border:none; border-radius:4px; width:22px; height:22px; cursor:pointer; display:none; font-size:12px; }
.cover-image-box:hover .cib-remove{ display:block; }
.cover-meta-row{ display:flex; gap:18px; font-size:13.5px; color:var(--ink-soft); margin-bottom:6px; }
.cover-meta-row span[contenteditable]{ outline:none; border-bottom:1px dotted var(--line); }
.cover-ornament-picker{ display:flex; gap:10px; margin-top:22px; }
.orn-choice{ width:34px; height:34px; border-radius:50%; border:1.5px solid var(--line); background:#fff; display:flex; align-items:center; justify-content:center; cursor:pointer; color:var(--ink-soft); }
.orn-choice.active{ border-color:var(--gold-deep); color:var(--gold-deep); box-shadow:0 0 0 2px rgba(166,128,60,.15); }

.empty-state{ margin:auto; text-align:center; color:var(--ink-soft); max-width:320px; }
.empty-state .es-icon{ margin-bottom:14px; color:var(--gold-deep); }
.empty-state h3{ font-family:'Cormorant Garamond',serif; font-size:22px; color:var(--ink); margin:0 0 6px; }

::-webkit-scrollbar{ width:9px; height:9px; }
::-webkit-scrollbar-thumb{ background:#D8CBA4; border-radius:5px; }
::-webkit-scrollbar-track{ background:transparent; }

.toast{ position:fixed; bottom:20px; left:50%; transform:translateX(-50%) translateY(20px); background:var(--ink); color:#F3EEDF; padding:10px 18px; border-radius:8px; font-size:13px; opacity:0; pointer-events:none; transition:all .25s ease; z-index:200; box-shadow:var(--shadow); }
.toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }

.paid-banner{ background:#EEF3EA; border:1px solid #CFE0C6; color:var(--sage); font-size:12.5px; padding:8px 14px; text-align:center; }

@media (max-width:900px){
  .sidebar{ width:230px; }
  .page{ width:400px; height:568px; padding:44px 34px 40px; }
}
