@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;600;700&family=Share+Tech+Mono&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #080B14;
    --surface:  #0f1220;
    --surface2: #171b2e;
    --border:   #252840;
    --accent:   #7027CF;
    --accent2:  #A368FF;
    --indigo:   #2D4FCC;
    --text:     #DDE8FF;
    --muted:    #5a6080;
    --danger:   #e05050;
    --btn24:    #2D4FCC;
    --btn30:    #7027CF;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Rajdhani', sans-serif; font-size: 14px; }

/* ── APP ── */
.app { display: flex; flex-direction: column; height: 100vh; }
.app__body { display: flex; flex: 1; overflow: hidden; }

/* ── SIDEBAR ── */
.sidebar {
    width: 18%; min-width: 210px;
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; overflow-y: auto; flex-shrink: 0;
}
.sidebar__footer {
    margin-top: auto;
    padding: 6px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;

}
.sidebar__footer .logo-svg { height: 20px; width: auto; display: block; }

/* ── CANVAS AREA ── */
.canvas-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.canvas-wrap {
    flex: 1; position: relative; overflow: hidden;
    background: var(--bg);
    cursor: default;
    touch-action: none;
    background-image: radial-gradient(circle at 1px 1px, #1a1d2e 1px, transparent 0);
    background-size: 24px 24px;
}
#canvas-bg {
position: absolute; top: 0; left: 0;
width: 100%; height: 100%;
pointer-events: none;
}
#canvas-bg img {
position: absolute;
opacity: 0.9;
}
#canvas-buttons { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

/* ── GRID OVERLAY ── */
.grid-active .canvas-wrap {
    background-image:
    linear-gradient(to right, #1e2235 1px, transparent 1px),
    linear-gradient(to bottom, #1e2235 1px, transparent 1px);
    background-size: 20px 20px;
}

/* ── PROPS POPOVER (flottant) ── */
.props-popover {
    position: absolute;
    z-index: 1000;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    min-width: 170px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    display: none;
}
.props-popover.is-visible {
    display: block;
}
.props-popover__title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--accent2);
    text-transform: uppercase;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    cursor: move;
    user-select: none;
}
.props-popover.is-dragging {
    opacity: 0.9;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}
.props-popover.is-dragging .props-popover__title {
    cursor: grabbing;
}

/* ── TOOLBAR ── */
.toolbar {
    display: flex; align-items: center; gap: 5px;
    height: 38px; padding: 0 10px;
    background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.toolbar__sep { width: 1px; height: 16px; background: var(--border); margin: 0 3px; }
.toolbar__spacer { flex: 1; }

/* ── RESPONSIVE ── */
@media (max-width: 1000px) {
    .sidebar {
        min-width: 170px;
    }
    .sidebar .panel {
        padding: 8px 10px;
    }
    .panel--column .row-5 {
        flex-direction: column;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 260px; min-width: 0;
        z-index: 1500;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.5);
    }
    .app.sidebar-visible .sidebar {
        transform: translateX(0);
    }
    .app.sidebar-hidden .sidebar {
        display: block;
        transform: translateX(-100%);
    }
    .ui-menu__toggle {
        opacity: 0.7;
        width: 48px;
        height: 48px;
        font-size: 44px;
    }
    .props-popover {
        max-width: calc(100vw - 16px);
        min-width: 150px;
    }
    .toolbar {
        gap: 3px;
        padding: 0 6px;
        height: 34px;
    }
    .toolbar .btn {
        font-size: 11px;
        padding: 0 6px;
        height: 26px;
    }
    .statusbar {
        font-size: 9px;
        gap: 8px;
        padding: 0 8px;
    }
}

@media (max-width: 480px) {
    .toolbar .btn {
        font-size: 10px;
        padding: 0 4px;
        height: 24px;
    }
    .statusbar {
        font-size: 8px;
        gap: 4px;
        padding: 0 4px;
    }
    .statusbar #status-pos {
        display: none;
    }
}

/* ── STATUS BAR ── */
.statusbar {
    display: flex; align-items: center; gap: 16px;
    height: 28px; padding: 0 12px;
    background: var(--surface); border-top: 1px solid var(--border);
    font-family: 'Share Tech Mono', monospace; font-size: 10px; color: var(--muted);
    flex-shrink: 0;
}
.statusbar span { color: var(--accent2); }
.statusbar__spacer { flex: 1; }

/* ── MENU FLOTTANT ── */
.ui-menu {
    position: fixed;
    bottom: 30px;
    right: 12px;
    z-index: 2000;
}
.ui-menu__toggle {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 40px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    opacity: 0.4;
    transition: opacity 0.2s;
    font-family: inherit;
}
.ui-menu:hover .ui-menu__toggle,
.ui-menu.is-open .ui-menu__toggle {
    opacity: 1;
}
.ui-menu__dropdown {
    display: none;
    position: absolute;
    bottom: 40px;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    white-space: nowrap;
}
.ui-menu.is-open .ui-menu__dropdown {
    display: flex;
}
.ui-menu__dropdown .btn {
    font-size: 14px;
    padding: 4px 10px;
    text-align: left;
}

.app.sidebar-hidden .sidebar { display: none; }
.app.sidebar-hidden .toolbar { display: none; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1400;
}
.app.sidebar-visible .sidebar-overlay {
    display: block;
}
@media (min-width: 769px) {
    .sidebar-overlay {
        display: none !important;
    }
}

/* ── PANEL ROW (Gauche + Droite côte à côte) ── */
.panel-row {
    display: flex;
}
.panel--half {
    flex: 1;
    border-bottom: none;   /* le parent gère la bordure basse */
    min-width: 0;          /* permet le shrink dans flex */
}
.panel--half:first-child {
    border-right: 1px solid var(--border);
}

/* ── PANEL ── */
.panel { border-bottom: 1px solid var(--border); padding: 10px 12px; }
.panel__title { font-size: 12px; font-weight: 700; letter-spacing: 2px; color: var(--accent2); text-transform: uppercase; text-align: center; margin-bottom: 8px; cursor: pointer; user-select: none; display: flex; align-items: center; justify-content: center; gap: 6px; }
.panel__title::after { content: '▾'; font-size: 9px; color: var(--muted); transition: transform 0.2s ease; }
.panel.is-collapsed .panel__title::after { transform: rotate(-90deg); }
.panel__title:hover { color: #fff; }
.panel__body { overflow: hidden; max-height: 500px; transition: max-height 0.3s ease, opacity 0.2s ease; opacity: 1; }
.panel.is-collapsed .panel__body { max-height: 0; opacity: 0; }

/* ── BUTTONS UI ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    height: 28px; padding: 0 9px;
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); font-family: 'Rajdhani', sans-serif;
    font-size: 12px; font-weight: 600; letter-spacing: 0.5px;
    cursor: pointer; transition: border-color .12s, color .12s;
    border-radius: 3px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent2); color: var(--accent2); }
.btn.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.is-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.is-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn.is-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.is-disabled { opacity: .3; pointer-events: none; }
.btn--full { width: 100%; }

/* ── FORM ── */
select, input[type="text"] {
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); font-family: 'Rajdhani', sans-serif;
    font-size: 12px; padding: 5px 7px; border-radius: 3px; width: 100%; outline: none;
}
select:focus, input[type="text"]:focus { border-color: var(--accent); }
.sidebar select {
    width: 100%;
    margin-top: 4px;
    cursor: pointer;
    appearance: auto;
}
input[type="color"] { width: 100%; height: 26px; border: 1px solid var(--border); border-radius: 3px; cursor: pointer; padding: 2px; background: var(--surface2); }

/* ── PROP ROWS ── */
.prop-row { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.prop-label { font-size: 10px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
.hint { font-size: 11px; color: var(--muted); text-align: center; padding: 14px 10px; line-height: 1.6; }
.gap-4 { display: flex; flex-direction: column; gap: 4px; }
.row-5 { display: flex; gap: 5px; }
.mt-6 { margin-top: 6px; }

/* ── LAYOUT LIST ── */
.layout-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 8px; border: 1px solid var(--border); border-radius: 3px;
    background: var(--surface2); cursor: pointer; transition: border-color .12s;
    font-size: 12px; font-weight: 600; margin-bottom: 4px;
}
.layout-item:hover { border-color: var(--accent); }
.layout-item.is-active { border-color: var(--accent); color: var(--accent2); background: #120d1e; }
.layout-item__id { font-size: 10px; color: var(--muted); font-family: 'Share Tech Mono', monospace; }

/* ── BOUTONS CANVAS ── */
.cbutton {
    position: absolute;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: grab;
    font-family: 'Rajdhani', sans-serif;
    font-weight: 700;
    overflow: visible;
    font-size: 11px;
    color: #fff;
    border: 2px solid rgba(255,255,255,0.25);
    user-select: none;
    transition: box-shadow .12s, border-color .12s;
    text-align: center;
    line-height: 1.1;
}
/* background géré dynamiquement par applyButtonColor() dans app.js */
.cbutton.is-selected {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--accent2), 0 0 16px var(--accent);
    z-index: 100;
    cursor: grabbing;
}
.cbutton:hover { border-color: rgba(255,255,255,0.6); z-index: 50; }
.cbutton.is-dragging { cursor: grabbing; z-index: 200; transition: none; }

/* ── CROIX SUPPRESSION SUR BOUTON ── */
.cbutton__label { pointer-events: none; }
.cbutton__delete {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--danger);
    border: 1.5px solid #ff9090;
    color: #fff;
    font-size: 8px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity .15s, transform .15s;
    z-index: 300;
    padding: 0;
    font-family: sans-serif;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
    pointer-events: none;
}
.cbutton.is-selected .cbutton__delete {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}
.cbutton__delete:hover {
    background: #ff2020;
    border-color: #fff;
    transform: scale(1.15) !important;
}

/* ── TAILLE SELECTOR ── */
.size-selector { display: flex; gap: 5px; }
.size-btn {
    flex: 1; height: 28px; border-radius: 3px; border: 1px solid var(--border);
    background: var(--surface2); color: var(--text);
    font-family: 'Rajdhani', sans-serif; font-size: 12px; font-weight: 600;
    cursor: pointer; transition: all .12s;
    display: flex; align-items: center; justify-content: center; gap: 5px;
}
.size-btn .dot { border-radius: 50%; background: currentColor; flex-shrink: 0; }
.size-btn:hover { border-color: var(--accent2); color: var(--accent2); }
.size-btn.is-active { border-color: var(--accent); background: #120d1e; color: var(--accent2); }

.size-slider {
    width: 100%; margin: 10px 0;
    -webkit-appearance: none; appearance: none;
    height: 8px; background: var(--border); border-radius: 4px;
    outline: none; cursor: pointer;
}
.size-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 22px; height: 22px;
    border-radius: 50%; background: var(--accent);
    border: 2px solid var(--accent2); cursor: pointer;
}
.size-slider::-moz-range-thumb {
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--accent); border: 2px solid var(--accent2);
    cursor: pointer;
}
