*{box-sizing:border-box;margin:0}
body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:#f8f7f5;color:#1a1a1a;min-height:100vh;overflow:hidden}

.app-shell{display:flex;min-height:100vh;position:relative}
.workspace{min-width:0;flex:1;display:flex;flex-direction:column}
.notes-backdrop{display:none}

/* ── sidebar ── */
.sidebar{width:300px;flex-shrink:0;background:#fcfbf9;border-right:1px solid #ece8e1;display:flex;flex-direction:column;position:relative;z-index:30;height:100vh;overflow:hidden}
.sidebar-header{padding:22px 20px 14px;border-bottom:1px solid #ece8e1;display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
.sidebar-kicker{font-size:11px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:#b28a67;margin-bottom:6px}
.sidebar-header h1{font-size:20px;line-height:1.2}
.sidebar-nav{padding:10px 10px 18px;overflow-y:auto;flex:1;min-height:0;display:flex;flex-direction:column;gap:4px}

/* ── accordion groups ── */
.sidebar-group{}
.sidebar-group-toggle{width:100%;border:none;background:transparent;text-align:left;padding:10px 12px;cursor:pointer;display:flex;align-items:center;justify-content:space-between;gap:8px;border-radius:10px;transition:background .15s}
.sidebar-group-toggle:hover{background:#f3eee7}
.sidebar-group-label{font-size:12px;font-weight:700;color:#8c847a;text-transform:uppercase;letter-spacing:.05em}
.sidebar-group-chevron{width:16px;height:16px;color:#b0a898;transition:transform .2s ease;flex-shrink:0}
.sidebar-group.is-open .sidebar-group-chevron{transform:rotate(90deg)}
.sidebar-group-items{display:none;flex-direction:column;gap:2px;padding:2px 0 6px 8px}
.sidebar-group.is-open .sidebar-group-items{display:flex}

/* ── nested sub-groups (S1, S2, S3) ── */
.sidebar-subgroup{}
.sidebar-subgroup-toggle{width:100%;border:none;background:transparent;text-align:left;padding:7px 10px;cursor:pointer;display:flex;align-items:center;justify-content:space-between;gap:6px;border-radius:8px;transition:background .15s}
.sidebar-subgroup-toggle:hover{background:#f3eee7}
.sidebar-subgroup-label{font-size:12px;font-weight:600;color:#a09890;letter-spacing:.02em}
.sidebar-subgroup-chevron{width:14px;height:14px;color:#c0b8ae;transition:transform .2s ease;flex-shrink:0}
.sidebar-subgroup.is-open .sidebar-subgroup-chevron{transform:rotate(90deg)}
.sidebar-subgroup-items{display:none;flex-direction:column;gap:1px;padding:1px 0 4px 10px}
.sidebar-subgroup.is-open .sidebar-subgroup-items{display:flex}

.sidebar-item{width:100%;border:none;background:transparent;text-align:left;padding:9px 12px;border-radius:10px;cursor:pointer;display:flex;align-items:center;justify-content:space-between;gap:8px;transition:background .15s,color .15s}
.sidebar-item:hover{background:#f3eee7}
.sidebar-item.is-active{background:#1a1a1a;color:#fff}
.sidebar-item-title{font-size:13px;font-weight:600;line-height:1.25;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.sidebar-item-aside{display:flex;align-items:center;gap:6px;flex-shrink:0}
.sidebar-status-dot{width:8px;height:8px;border-radius:50%;background:#d6d0c7}
.sidebar-status-dot.todo{background:#d6d0c7}
.sidebar-status-dot.changes-requested{background:#d59b5f}
.sidebar-status-dot.approved{background:#66a96d}
.sidebar-backdrop{display:none}
.sidebar-open,.sidebar-close{display:none}

/* ── bars ── */
.bar{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 20px;background:#fff;border-bottom:1px solid #eee;flex-shrink:0;z-index:10}
.bottom-bar{border-bottom:none;border-top:1px solid #eee}
.nav-group{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.nav-left{min-width:0;flex:1}
.current-mail{display:flex;flex-direction:column;min-width:0}
.current-mail strong{font-size:15px;line-height:1.2;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.current-mail span{font-size:12px;color:#8d857b;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* ── buttons ── */
.btn-icon{display:inline-flex;align-items:center;justify-content:center;width:36px;height:36px;border:1px solid #e0e0e0;border-radius:10px;background:#fff;color:#555;cursor:pointer;transition:all .15s;position:relative}
.btn-icon:hover{border-color:#bbb;color:#1a1a1a}
.btn-icon:disabled{opacity:.25;pointer-events:none}
.btn-action{width:auto;min-width:36px;height:36px;padding:0 12px;gap:8px}
.btn-action span:not(.badge){font-size:13px;font-weight:600}

.badge{position:absolute;top:-4px;right:-4px;min-width:18px;height:18px;border-radius:9px;background:#c4956a;color:#fff;font-size:11px;font-weight:700;display:flex;align-items:center;justify-content:center;padding:0 5px}
.badge:empty{display:none}

.btn-primary{display:inline-flex;align-items:center;gap:6px;padding:8px 14px;border:none;border-radius:10px;background:#1a1a1a;color:#fff;font-size:13px;font-weight:600;cursor:pointer;transition:opacity .15s}
.btn-primary:hover{opacity:.8}

/* ── toggle ── */
.toggle-group{display:inline-flex;border:1px solid #e0e0e0;border-radius:10px;overflow:hidden}
.toggle{border:none;background:#fff;padding:7px 14px;font-size:12px;font-weight:600;color:#999;cursor:pointer;transition:all .15s}
.toggle.is-active{background:#1a1a1a;color:#fff}

/* ── status chips ── */
.status-group{display:flex;gap:4px}
.status-radio{cursor:pointer}
.status-radio input{position:absolute;opacity:0;width:0;height:0}
.chip{display:inline-block;padding:6px 12px;border-radius:8px;font-size:12px;font-weight:600;border:1px solid #e0e0e0;background:#fff;color:#999;transition:all .15s}
.status-radio input:checked+.chip.todo{background:#f5f5f5;color:#666;border-color:#ccc}
.status-radio input:checked+.chip.changes{background:#fff3e6;color:#b96a3b;border-color:#f0d0a8}
.status-radio input:checked+.chip.approved{background:#e8f5e9;color:#2e7d32;border-color:#a5d6a7}

/* ── preview ── */
.preview{flex:1;display:flex;align-items:flex-start;justify-content:center;overflow:auto;padding:24px;background:#f3f2f0}
#frame{width:680px;height:100%;min-height:640px;border:none;border-radius:12px;background:#fff;box-shadow:0 8px 40px rgba(0,0,0,.08)}
.preview.mobile #frame{width:390px}

/* ── overlay + panels ── */
.overlay{position:fixed;inset:0;z-index:100;background:rgba(0,0,0,.3);display:flex;align-items:center;justify-content:center;backdrop-filter:blur(4px)}
.overlay.hidden{display:none}

.panel{background:#fff;border-radius:16px;width:100%;max-width:520px;max-height:85vh;display:flex;flex-direction:column;box-shadow:0 20px 60px rgba(0,0,0,.15)}
.panel-header{display:flex;justify-content:space-between;align-items:center;padding:20px 24px 16px;border-bottom:1px solid #eee}
.panel-header h2{font-size:18px}

/* ── notes panel ── */
.notes-sidebar{width:360px;flex-shrink:0;background:#fff;border-left:1px solid #ece8e1;display:flex;flex-direction:column;min-height:100vh}
.notes-sidebar:not(.is-open){display:none}
.notes-sidebar-header{padding:22px 20px 14px;border-bottom:1px solid #ece8e1;display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
.notes-kicker{font-size:11px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:#b28a67;margin-bottom:6px}
.notes-sidebar-header h2{font-size:20px;line-height:1.2}
.notes-context{margin-top:6px;font-size:12px;color:#8d857b;line-height:1.4}
.notes-sync-status{margin-top:8px;font-size:12px;color:#6c7a6e;line-height:1.4}
.notes-sidebar-body{display:flex;flex-direction:column;min-height:0;flex:1}
.note-form{padding:16px 24px;border-bottom:1px solid #eee;display:flex;flex-direction:column;gap:10px}
.note-form textarea,.note-form input{width:100%;border:1px solid #e0e0e0;border-radius:10px;padding:10px 14px;font-size:14px;background:#fafafa;resize:none}
.note-form textarea:focus,.note-form input:focus{outline:none;border-color:#c4956a}
.note-form-row{display:flex;gap:8px;align-items:center}
.note-form-row input{flex:1}
.note-form-actions{justify-content:space-between;align-items:flex-start}
.field-label{font-size:12px;font-weight:700;color:#8c847a;text-transform:uppercase;letter-spacing:.04em}
.notes-hint{font-size:12px;line-height:1.45;color:#8d857b;max-width:220px}
.notes-sync-status.is-error{color:#b9583b}
.notes-sync-status.is-local{color:#8d857b}
.notes-sync-status.is-sync{color:#4b7d53}

.notes-list{overflow:auto;padding:16px 24px;display:flex;flex-direction:column;gap:10px}
.notes-list:empty::after{content:'Aucune note pour le moment.';color:#bbb;font-size:14px}

.note-item{padding:12px;border-radius:10px;background:#fafaf8;border:1px solid #f0f0ee}
.note-item.is-remote{background:#f4f8f2;border-color:#dfead9}
.note-item-header{display:flex;justify-content:space-between;gap:8px;margin-bottom:6px;font-size:12px;color:#999}
.note-item-header strong{color:#1a1a1a}
.note-item p{font-size:14px;line-height:1.5;color:#444;white-space:pre-wrap}
.note-item .delete-note{border:none;background:none;color:#ccc;cursor:pointer;font-size:12px;padding:2px 6px;border-radius:4px}
.note-item .delete-note:hover{background:#fee;color:#c44}
.note-item-source{display:inline-flex;align-items:center;padding:2px 6px;border-radius:999px;background:#edf4ea;color:#4b7d53;font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.03em}

/* ── refs panel ── */
.refs-body{overflow:auto;padding:20px 24px;display:flex;flex-direction:column;gap:16px}
.refs-empty{color:#bbb;font-size:14px}
.refs-section h3{font-size:13px;font-weight:700;text-transform:uppercase;letter-spacing:.04em;color:#8c847a;margin-bottom:8px}
.refs-grid{display:flex;flex-wrap:wrap;gap:8px}
.refs-link{display:inline-flex;align-items:center;gap:6px;padding:8px 12px;border:1px solid #e8e4de;border-radius:10px;background:#faf8f5;color:#555;font-size:13px;text-decoration:none;transition:all .15s}
.refs-link:hover{border-color:#c4956a;color:#1a1a1a;background:#fff}
.refs-note{font-size:14px;color:#555;line-height:1.5;padding:10px 14px;background:#faf8f5;border-radius:10px;border:1px solid #efe9e0}
.refs-help{font-size:13px;color:#8d857b;line-height:1.5;padding:12px 14px;background:#f7f4ef;border:1px solid #ece5d8;border-radius:10px}
.refs-media-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px}
.refs-media-card{display:flex;flex-direction:column;gap:8px;padding:10px;border:1px solid #e8e4de;border-radius:12px;background:#faf8f5;color:#555;text-decoration:none;transition:all .15s}
.refs-media-card:hover{border-color:#c4956a;background:#fff}
.refs-media-thumb{width:100%;aspect-ratio:4/3;object-fit:contain;border-radius:8px;background:#fff;border:1px solid #eee8de}
.refs-media-name{font-size:12px;font-weight:600;line-height:1.35;word-break:break-word}
.refs-media-url{font-size:11px;color:#8d857b;word-break:break-all}
.refs-loading{color:#8d857b;font-size:14px}

/* ── version label ── */
.version-stack{display:flex;flex-direction:column;gap:2px;min-width:220px}
.version-label{font-size:13px;font-weight:700;color:#1a1a1a;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.version-meta{font-size:12px;color:#8d857b;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* ── responsive ── */
@media(max-width:980px){
    body{overflow:auto}
    .app-shell{display:block}
    .sidebar{position:fixed;top:0;bottom:0;left:0;transform:translateX(-100%);transition:transform .2s ease;box-shadow:0 20px 50px rgba(0,0,0,.18)}
    .sidebar.is-open{transform:translateX(0)}
    .sidebar-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.28);z-index:20}
    .sidebar-backdrop:not(.hidden){display:block}
    .sidebar-open,.sidebar-close{display:inline-flex}
    .notes-sidebar{position:fixed;top:0;right:0;bottom:0;transform:translateX(100%);transition:transform .2s ease;box-shadow:0 20px 50px rgba(0,0,0,.18);width:min(92vw,380px);z-index:40;display:flex}
    .notes-sidebar.is-open{transform:translateX(0)}
    .notes-sidebar:not(.is-open){display:flex}
    .notes-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.28);z-index:35}
    .notes-backdrop:not(.hidden){display:block}
}

@media(max-width:768px){
    .bar{padding:8px 12px;gap:8px}
    .current-mail{max-width:170px}
    .preview{padding:8px}
    #frame,.preview.mobile #frame{width:100%;border-radius:8px;height:calc(100vh - 130px)}
    .status-group{gap:2px}
    .chip{padding:5px 8px;font-size:11px}
    .panel{max-width:100%;max-height:100vh;border-radius:0}
    .btn-action span:not(.badge){display:none}
    .btn-action{padding:0;width:36px}
    .version-stack{min-width:0;max-width:150px}
    .notes-sidebar-header,.note-form,.notes-list{padding-left:16px;padding-right:16px}
    .note-form-actions{flex-direction:column;align-items:stretch}
    .notes-hint{max-width:none}
}

@media(max-width:480px){
    .toggle-group{display:none}
    .sidebar{width:88vw}
    .bottom-bar{align-items:flex-start}
    .version-stack{max-width:120px}
}
