/* ============================================================
   DDV Studio — interface de l'éditeur
   ============================================================ */

:root {
    --bg: #14161c;
    --bg-2: #1b1e26;
    --bg-3: #232733;
    --bg-4: #2c3140;
    --line: #333a4a;
    --txt: #e8eaf0;
    --txt-dim: #98a0b3;
    --txt-mute: #6c7488;
    --accent: #6c5ce7;
    --accent-2: #8b7cf6;
    --accent-soft: rgba(108, 92, 231, .18);
    --danger: #ef4b6b;
    --ok: #24c58a;
    --stage: #3a3f4d;
    --radius: 10px;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --rail-w: 76px;
    --panel-w: 296px;
    --props-w: 268px;
    --top-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--txt);
    font: 14px/1.45 Inter, -apple-system, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 18px; height: 18px; display: block; }

.app { display: flex; flex-direction: column; height: 100vh; }

/* ---------------- Barre supérieure ---------------- */

.topbar {
    /* Hauteur libre : la barre s'adapte à un logo plus grand que sa hauteur de base. */
    min-height: var(--top-h);
    padding-top: 6px;
    padding-bottom: 6px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 12px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--line);
    z-index: 40;
}

.topbar-left, .topbar-center, .topbar-right { display: flex; align-items: center; gap: 6px; }
.topbar-left { min-width: 0; flex: 1; }
.topbar-right { flex: 0 0 auto; }

.brand { display: flex; align-items: center; gap: 6px; text-decoration: none; color: var(--txt); margin-right: 6px; flex: 0 0 auto; }
.brand-logo { width: auto; max-width: 280px; object-fit: contain; display: block; }
.brand-mark {
    background: linear-gradient(135deg, var(--accent), #45b7ff);
    color: #fff; font-weight: 800; font-size: 12px; letter-spacing: .5px;
    padding: 5px 7px; border-radius: 7px;
}
.brand-name { font-weight: 600; font-size: 14px; }

.title-input {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--txt);
    padding: 6px 10px;
    font-size: 14px;
    font-weight: 500;
    max-width: 280px;
    min-width: 80px;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; border-color: var(--accent); background: var(--bg-3); }

.save-state { font-size: 12px; color: var(--txt-mute); white-space: nowrap; }
.save-state.is-saving { color: var(--accent-2); }
.save-state.is-error { color: var(--danger); }

.tb {
    background: transparent; border: 0; border-radius: 8px;
    padding: 7px; color: var(--txt-dim);
    display: flex; align-items: center; justify-content: center;
}
.tb:hover:not(:disabled) { background: var(--bg-3); color: var(--txt); }
.tb:disabled { opacity: .32; cursor: default; }
.tb.is-active { background: var(--accent-soft); color: var(--accent-2); }
.tb-zoom { min-width: 62px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.btn {
    display: inline-flex; align-items: center; gap: 7px;
    border: 1px solid transparent; border-radius: 9px;
    padding: 8px 14px; font-size: 13.5px; font-weight: 550;
    background: var(--bg-3); color: var(--txt);
    white-space: nowrap;
}
.btn:hover { background: var(--bg-4); }
.btn-primary { background: linear-gradient(135deg, var(--accent), #5b8cff); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--txt-dim); }
.btn-ghost:hover { background: var(--bg-3); color: var(--txt); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn svg { width: 16px; height: 16px; }

/* ---------------- Structure ---------------- */

.workspace { flex: 1; display: flex; min-height: 0; }

.rail {
    width: var(--rail-w); flex: 0 0 auto;
    background: var(--bg-2); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; align-items: center;
    padding: 8px 0; gap: 2px; overflow-y: auto;
}
.rail-btn {
    width: 62px; padding: 9px 2px; border: 0; border-radius: 10px;
    background: transparent; color: var(--txt-dim);
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    font-size: 10.5px; line-height: 1;
}
.rail-btn svg { width: 21px; height: 21px; }
.rail-btn:hover { background: var(--bg-3); color: var(--txt); }
.rail-btn.is-active { background: var(--accent-soft); color: var(--accent-2); }

.panel {
    width: var(--panel-w); flex: 0 0 auto; position: relative;
    background: var(--bg-2); border-right: 1px solid var(--line);
    overflow-y: auto; overflow-x: hidden; padding: 16px 14px 40px;
}
.panel.is-collapsed { display: none; }
.panel-collapse {
    position: absolute; top: 10px; right: 8px;
    background: transparent; border: 0; color: var(--txt-mute); padding: 4px; border-radius: 6px;
}
.panel-collapse:hover { background: var(--bg-3); color: var(--txt); }
.panel-page { display: none; }
.panel-page.is-active { display: block; }
.panel-title { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--txt-mute); margin: 18px 0 9px; font-weight: 600; }
.panel-page > .panel-title:first-child { margin-top: 0; }
.panel-hint { font-size: 12px; color: var(--txt-mute); margin: -4px 0 10px; }

.props {
    width: var(--props-w); flex: 0 0 auto;
    background: var(--bg-2); border-left: 1px solid var(--line);
    overflow-y: auto; padding: 14px 14px 40px;
}
.props-empty { color: var(--txt-mute); font-size: 12.5px; padding: 24px 6px; text-align: center; }

/* ---------------- Zone de travail ---------------- */

.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--stage); position: relative; }
.stage-scroll { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 46px 40px; }
.stage-scroll.is-panning { cursor: grabbing; }

.page-wrap { position: relative; flex: 0 0 auto; transform-origin: top center; }
.page {
    position: relative; overflow: hidden;
    background: #fff; box-shadow: 0 6px 26px rgba(0, 0, 0, .38);
}
.page.show-grid::after {
    content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 999;
    background-image: linear-gradient(rgba(108, 92, 231, .16) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(108, 92, 231, .16) 1px, transparent 1px);
    background-size: 40px 40px;
}

.el { position: absolute; transform-origin: center center; }
.el-inner { width: 100%; height: 100%; position: relative; }
.el img { width: 100%; height: 100%; display: block; }
.el svg { width: 100%; height: 100%; }
.el-text { white-space: pre-wrap; word-break: break-word; display: flex; flex-direction: column; }
.el-text[contenteditable="true"] { outline: 2px solid var(--accent); cursor: text; user-select: text; }
.el.is-hidden { display: none; }

.overlay { position: absolute; inset: 0; pointer-events: none; z-index: 1000; }

.selection { position: absolute; pointer-events: none; }
.sel-box { position: absolute; inset: 0; border: 1.5px solid var(--accent-2); box-shadow: 0 0 0 1px rgba(255, 255, 255, .35); }
.selection.is-multi .sel-box { border-style: dashed; }

.handle {
    position: absolute; width: 11px; height: 11px; margin: -6px 0 0 -6px;
    background: #fff; border: 1.5px solid var(--accent-2); border-radius: 3px;
    pointer-events: auto; z-index: 2;
}
.h-nw { left: 0; top: 0; cursor: nwse-resize; }
.h-n  { left: 50%; top: 0; cursor: ns-resize; }
.h-ne { left: 100%; top: 0; cursor: nesw-resize; }
.h-e  { left: 100%; top: 50%; cursor: ew-resize; }
.h-se { left: 100%; top: 100%; cursor: nwse-resize; }
.h-s  { left: 50%; top: 100%; cursor: ns-resize; }
.h-sw { left: 0; top: 100%; cursor: nesw-resize; }
.h-w  { left: 0; top: 50%; cursor: ew-resize; }
.selection.is-multi .handle { display: none; }

.rotator {
    position: absolute; left: 50%; top: -32px; margin-left: -13px;
    width: 26px; height: 26px; border-radius: 50%;
    background: #fff; color: #333; border: 1px solid var(--line);
    display: flex; align-items: center; justify-content: center;
    pointer-events: auto; cursor: grab; z-index: 2;
}
.rotator svg { width: 14px; height: 14px; }
.selection.is-multi .rotator { display: none; }

.marquee { position: absolute; border: 1px solid var(--accent-2); background: rgba(108, 92, 231, .12); }

.guide { position: absolute; background: #ff3d8b; z-index: 3; }
.guide.v { width: 1px; top: 0; bottom: 0; }
.guide.h { height: 1px; left: 0; right: 0; }

.size-badge {
    position: absolute; left: 50%; transform: translateX(-50%);
    bottom: -26px; background: var(--accent); color: #fff;
    font-size: 11px; padding: 2px 7px; border-radius: 5px; white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ---------------- Barre contextuelle ---------------- */

.context-bar {
    position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
    background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px;
    padding: 6px; box-shadow: var(--shadow); z-index: 30; max-width: calc(100% - 40px);
}
.context-bar .tb { color: var(--txt); }
.context-bar select.mini, .context-bar input.mini {
    background: var(--bg-3); border: 1px solid var(--line); color: var(--txt);
    border-radius: 7px; padding: 5px 7px; font-size: 12.5px;
}
.context-bar input.mini { width: 56px; }
.ctx-color { width: 26px; height: 26px; border-radius: 6px; border: 2px solid var(--line); padding: 0; overflow: hidden; }

/* ---------------- Bande de pages ---------------- */

.pages-bar {
    flex: 0 0 auto; height: 92px; background: var(--bg-2); border-top: 1px solid var(--line);
    display: flex; align-items: center; gap: 10px; padding: 0 12px;
}
.pages-strip { flex: 1; display: flex; gap: 10px; overflow-x: auto; padding: 8px 0; align-items: center; }
.page-thumb {
    flex: 0 0 auto; position: relative; border: 2px solid transparent; border-radius: 8px;
    background: #fff; overflow: hidden; cursor: pointer; height: 62px;
}
.page-thumb.is-active { border-color: var(--accent-2); }
.page-thumb-inner { transform-origin: top left; position: relative; }
.page-thumb-num {
    position: absolute; left: 3px; bottom: 3px; background: rgba(0, 0, 0, .6); color: #fff;
    font-size: 10px; padding: 1px 5px; border-radius: 4px; z-index: 5;
}
.page-thumb-tools { position: absolute; top: 3px; right: 3px; display: none; gap: 2px; z-index: 5; }
.page-thumb:hover .page-thumb-tools { display: flex; }
.page-thumb-tools button {
    background: rgba(0, 0, 0, .62); border: 0; color: #fff; border-radius: 4px; padding: 3px;
}
.page-thumb-tools svg { width: 12px; height: 12px; }

/* ---------------- Champs de formulaire ---------------- */

.field {
    width: 100%; background: var(--bg-3); border: 1px solid var(--line);
    color: var(--txt); border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.field:focus { outline: none; border-color: var(--accent); }
select.field { cursor: pointer; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.row > * { min-width: 0; }
.lbl { flex: 1; font-size: 11.5px; color: var(--txt-mute); display: block; }
.lbl .field { margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--txt-dim); cursor: pointer; }
.color-input { width: 38px; height: 34px; padding: 2px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; flex: 0 0 auto; }

.prop-group { border-top: 1px solid var(--line); padding: 12px 0; }
.prop-group:first-child { border-top: 0; padding-top: 0; }
.prop-group h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--txt-mute); margin: 0 0 10px; font-weight: 600; }
.slider-row { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.slider-row label { flex: 0 0 74px; font-size: 11.5px; color: var(--txt-mute); }
.slider-row input[type=range] { flex: 1; accent-color: var(--accent); min-width: 0; }
.slider-row output { flex: 0 0 38px; text-align: right; font-size: 11.5px; color: var(--txt-dim); font-variant-numeric: tabular-nums; }
.btn-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.btn-grid button {
    background: var(--bg-3); border: 1px solid var(--line); border-radius: 7px;
    padding: 7px 0; display: flex; align-items: center; justify-content: center; color: var(--txt-dim);
}
.btn-grid button:hover { background: var(--bg-4); color: var(--txt); }
.btn-grid button.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
.btn-grid button svg { width: 15px; height: 15px; }
.btn-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.btn-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.btn-grid .txt { font-size: 11.5px; }

/* ---------------- Panneaux ---------------- */

.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.tpl-card { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--bg-3); cursor: pointer; padding: 0; text-align: left; }
.tpl-card:hover { border-color: var(--accent); }
.tpl-preview { position: relative; background: #fff; overflow: hidden; width: 100%; }
.tpl-preview-inner { transform-origin: top left; position: relative; }
.tpl-name { font-size: 11px; color: var(--txt-dim); padding: 6px 7px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.shape-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.shape-btn {
    aspect-ratio: 1; background: var(--bg-3); border: 1px solid var(--line); border-radius: 9px;
    display: flex; align-items: center; justify-content: center; color: var(--txt-dim); padding: 9px;
}
.shape-btn:hover { border-color: var(--accent); color: var(--txt); }
.shape-btn svg { width: 100%; height: 100%; }
.icon-grid .shape-btn { padding: 11px; }

.text-preset {
    display: block; width: 100%; text-align: left; background: var(--bg-3);
    border: 1px solid var(--line); border-radius: 9px; padding: 11px 13px; margin-bottom: 8px; color: var(--txt);
}
.text-preset:hover { border-color: var(--accent); }
.text-preset[data-preset=title] { font-size: 21px; font-weight: 700; }
.text-preset[data-preset=subtitle] { font-size: 15px; font-weight: 600; }
.text-preset[data-preset=body] { font-size: 13px; }

.combo-list { display: grid; gap: 8px; }
.combo-card { background: var(--bg-3); border: 1px solid var(--line); border-radius: 9px; padding: 12px; text-align: center; color: var(--txt); }
.combo-card:hover { border-color: var(--accent); }
.combo-card b { display: block; }
.combo-card small { color: var(--txt-mute); }

.uploader {
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    border: 1.5px dashed var(--line); border-radius: 11px; padding: 20px 12px; cursor: pointer;
    color: var(--txt-dim); text-align: center; margin-bottom: 12px;
}
.uploader:hover, .uploader.is-over { border-color: var(--accent); color: var(--txt); background: var(--accent-soft); }
.uploader small { color: var(--txt-mute); font-size: 11px; }
.uploader svg { width: 22px; height: 22px; }

.asset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.asset-grid-sm { grid-template-columns: repeat(4, 1fr); }
.asset-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg-3); border: 1px solid var(--line); padding: 0; }
.asset-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.asset-item:hover { border-color: var(--accent); }
.asset-del {
    position: absolute; top: 3px; right: 3px; background: rgba(0, 0, 0, .65); border: 0; color: #fff;
    border-radius: 5px; padding: 3px; display: none;
}
.asset-item:hover .asset-del { display: block; }
.asset-del svg { width: 12px; height: 12px; }

.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; margin-bottom: 10px; }
.swatch { aspect-ratio: 1; border-radius: 6px; border: 1px solid rgba(255, 255, 255, .14); padding: 0; }
.swatch:hover { transform: scale(1.12); }
.gradient-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.gradient-swatch { aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line); padding: 0; }

.layer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.layer-item {
    display: flex; align-items: center; gap: 8px; padding: 7px 8px;
    background: var(--bg-3); border: 1px solid transparent; border-radius: 8px; cursor: grab; font-size: 12.5px;
}
.layer-item.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.layer-item.is-drag { opacity: .4; }
.layer-item .layer-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--txt-dim); }
.layer-item.is-selected .layer-name { color: var(--txt); }
.layer-thumb { width: 24px; height: 24px; border-radius: 5px; background: var(--bg-4); flex: 0 0 auto; display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--txt-mute); }
.layer-thumb img { width: 100%; height: 100%; object-fit: cover; }
.layer-thumb svg { width: 13px; height: 13px; }
.layer-act { background: transparent; border: 0; color: var(--txt-mute); padding: 3px; border-radius: 5px; }
.layer-act:hover { background: var(--bg-4); color: var(--txt); }
.layer-act svg { width: 14px; height: 14px; }

/* ---------------- Modales ---------------- */

.modal {
    position: fixed; inset: 0; background: rgba(8, 10, 14, .68);
    display: flex; align-items: center; justify-content: center; z-index: 200; padding: 24px;
    backdrop-filter: blur(2px);
}
.modal[hidden] { display: none; }
.modal-card {
    background: var(--bg-2); border: 1px solid var(--line); border-radius: 15px;
    width: 100%; max-width: 460px; box-shadow: var(--shadow); display: flex; flex-direction: column;
    max-height: calc(100vh - 48px);
}
.modal-lg { max-width: 800px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 15.5px; font-weight: 600; }
.modal-close { background: transparent; border: 0; color: var(--txt-mute); padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--bg-3); color: var(--txt); }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--line); }
.modal-foot .export-status { margin-right: auto; font-size: 12px; color: var(--txt-mute); }

.export-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; padding: 16px 18px 6px; }
.export-mode {
    background: var(--bg-3); border: 1.5px solid var(--line); border-radius: 10px;
    padding: 11px 12px; text-align: left; display: flex; flex-direction: column; gap: 3px;
}
.export-mode strong { font-size: 13px; }
.export-mode small { font-size: 11px; color: var(--txt-mute); line-height: 1.35; }
.export-mode.is-active { border-color: var(--accent); background: var(--accent-soft); }

.export-options { padding: 8px 18px; display: flex; flex-wrap: wrap; gap: 14px; }
.export-report { margin: 4px 18px 0; padding: 10px 12px; border-radius: 9px; font-size: 12.2px; line-height: 1.5; }
.export-report.is-ok { background: rgba(36, 197, 138, .12); color: #7ce0bb; }
.export-report.is-warn { background: rgba(255, 176, 32, .12); color: #ffc861; }
.export-report ul { margin: 6px 0 0; padding-left: 18px; }
.export-preview { padding: 12px 18px 0; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.export-preview-head { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--txt-mute); margin-bottom: 6px; }
.export-code {
    width: 100%; flex: 1; min-height: 190px; resize: none;
    background: #10131a; border: 1px solid var(--line); border-radius: 9px;
    color: #a9d8b8; font: 11.5px/1.5 "Roboto Mono", Consolas, monospace; padding: 11px;
}

.export-help {
    margin: 12px 18px 0; padding: 10px 12px;
    background: var(--bg-3); border-radius: 9px;
    font-size: 12px; line-height: 1.6; color: var(--txt-mute);
}
.export-help strong { color: var(--txt-dim); }

.dl-list { padding: 14px 18px 6px; display: grid; gap: 8px; }
.dl-item { background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; text-align: left; display: flex; flex-direction: column; gap: 2px; }
.dl-item:hover { border-color: var(--accent); }
.dl-item small { color: var(--txt-mute); font-size: 11.5px; }
.dl-scale { padding: 8px 18px 4px; }
.dl-scale label { font-size: 11.5px; color: var(--txt-mute); display: block; margin-bottom: 5px; }
.resize-body { padding: 16px 18px; display: grid; gap: 12px; }

/* ---------------- Toast ---------------- */

.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--bg-4); border: 1px solid var(--line); color: var(--txt);
    padding: 11px 18px; border-radius: 10px; box-shadow: var(--shadow);
    z-index: 300; font-size: 13px; max-width: 80vw;
}
.toast[hidden] { display: none; }
.toast.is-ok { border-color: var(--ok); }
.toast.is-error { border-color: var(--danger); }

/* ---------------- Écrans étroits ---------------- */

@media (max-width: 1180px) {
    :root { --props-w: 232px; --panel-w: 260px; }
}
@media (max-width: 900px) {
    .props { display: none; }
    .topbar-center .tb-sep:last-of-type, #btn-grid, #btn-resize { display: none; }
}

/* Impression du canevas exclue : l'app est un outil d'écran */
@media print { body { display: none; } }
