/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body.pd-editor-body {
    background: #111;
    color: #f0f0f0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ── Layout ───────────────────────────────────────────────────── */
#pd-app {
    display: grid;
    grid-template-rows: 56px 1fr;
    grid-template-columns: 260px 1fr;
    grid-template-areas:
        "topbar topbar"
        "sidebar canvas";
    height: 100vh;
    width: 100vw;
}

/* ── Top bar ──────────────────────────────────────────────────── */
#pd-topbar {
    grid-area: topbar;
    background: #1a1a1a;
    border-bottom: 1px solid #2e2e2e;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 100;
}

#pd-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: 8px;
    color: #aaa;
    text-decoration: none;
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
#pd-close-btn:hover { background: #2e2e2e; color: #fff; }

#pd-product-title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#pd-topbar-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
#pd-sidebar {
    grid-area: sidebar;
    background: #1a1a1a;
    border-right: 1px solid #2e2e2e;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#pd-tabs {
    display: flex;
    border-bottom: 1px solid #2e2e2e;
    flex-shrink: 0;
}

.pd-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px;
    background: none;
    border: none;
    color: #777;
    cursor: pointer;
    font-size: 11px;
    transition: color .15s, background .15s;
    border-bottom: 2px solid transparent;
}
.pd-tab:hover { color: #ccc; background: #222; }
.pd-tab.active { color: #6c9fff; border-bottom-color: #6c9fff; }

.pd-tab-panel {
    display: none;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}
.pd-tab-panel.active { display: flex; }

.pd-tab-panel h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #888;
    margin-bottom: -4px;
}

.pd-tab-panel h4 {
    font-size: 13px;
    color: #ccc;
    margin-bottom: -4px;
}

.pd-tab-panel label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: #bbb;
    font-size: 13px;
}

.pd-tab-panel input[type="number"],
.pd-tab-panel input[type="text"],
.pd-tab-panel input[type="color"],
.pd-tab-panel select {
    background: #262626;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #f0f0f0;
    padding: 7px 10px;
    font-size: 13px;
    outline: none;
    transition: border-color .15s;
    width: 100%;
}
.pd-tab-panel input:focus,
.pd-tab-panel select:focus { border-color: #6c9fff; }

.pd-tab-panel input[type="color"] {
    padding: 3px 6px;
    height: 36px;
    cursor: pointer;
}

.pd-tab-panel hr {
    border: none;
    border-top: 1px solid #2e2e2e;
    margin: 4px 0;
}

/* Size presets */
#pd-size-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pd-size-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #222;
    border: 1px solid #333;
    border-radius: 8px;
    cursor: pointer;
    color: #ccc;
    transition: border-color .15s, background .15s;
    font-size: 13px;
}
.pd-size-option:hover { background: #2a2a2a; border-color: #555; }
.pd-size-option.selected { border-color: #6c9fff; background: #1c2b45; color: #9fc4ff; }

.pd-size-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#pd-size-custom {
    padding: 12px;
    background: #1e1e1e;
    border-radius: 8px;
    border: 1px solid #2e2e2e;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* BG presets */
#pd-bg-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pd-bg-swatch {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .15s, transform .1s;
}
.pd-bg-swatch:hover { transform: scale(1.1); }
.pd-bg-swatch.selected { border-color: #6c9fff; }

/* Upload */
#pd-bg-upload-area { }

.pd-upload-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: #222;
    border: 2px dashed #444;
    border-radius: 8px;
    cursor: pointer;
    color: #aaa;
    transition: border-color .15s, background .15s;
    font-size: 13px;
}
.pd-upload-label:hover { border-color: #6c9fff; background: #1c2b45; color: #9fc4ff; }

/* Text toolbar */
#pd-text-toolbar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    background: #1e1e1e;
    border-radius: 8px;
    border: 1px solid #2e2e2e;
}

.pd-format-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.pd-format-btn,
.pd-align-btn {
    width: 36px; height: 36px;
    background: #262626;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #ccc;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, border-color .15s, color .15s;
}
.pd-format-btn:hover,
.pd-align-btn:hover { background: #333; border-color: #555; }
.pd-format-btn.active,
.pd-align-btn.active { background: #1c2b45; border-color: #6c9fff; color: #9fc4ff; }

/* ── Canvas area ──────────────────────────────────────────────── */
#pd-canvas-area {
    grid-area: canvas;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #111;
    position: relative;
    overflow: hidden;
}

#pd-canvas-wrapper {
    position: relative;
    box-shadow: 0 8px 48px rgba(0,0,0,.6);
}

#pd-canvas-wrapper canvas {
    display: block;
}

#pd-canvas-hint {
    position: absolute;
    color: #555;
    font-size: 15px;
    text-align: center;
    pointer-events: none;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.pd-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background .15s, opacity .15s;
    white-space: nowrap;
    text-decoration: none;
}
.pd-btn:disabled { opacity: .45; cursor: not-allowed; }

.pd-btn-primary {
    background: #3b7dff;
    color: #fff;
}
.pd-btn-primary:hover:not(:disabled) { background: #2c6aee; }

.pd-btn-outline {
    background: transparent;
    color: #9fc4ff;
    border: 1px solid #3b5a8f;
}
.pd-btn-outline:hover:not(:disabled) { background: #1c2b45; }

.pd-btn-ghost {
    background: #222;
    color: #aaa;
    border: 1px solid #333;
}
.pd-btn-ghost:hover:not(:disabled) { background: #2a2a2a; color: #ccc; }

.pd-btn-danger { color: #ff6b6b; border-color: #5c2222; }
.pd-btn-danger:hover { background: #2c1818; }

.pd-btn-full { width: 100%; justify-content: center; }

/* ── Toast ────────────────────────────────────────────────────── */
#pd-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #23c563;
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 24px rgba(0,0,0,.4);
    pointer-events: none;
    opacity: 0;
    transition: transform .3s, opacity .3s;
    z-index: 9999;
}
#pd-toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
#pd-toast.error { background: #e74c3c; }

/* ── Modal ────────────────────────────────────────────────────── */
.pd-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    backdrop-filter: blur(4px);
}
.pd-modal-box {
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 14px;
    padding: 28px;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 12px 48px rgba(0,0,0,.5);
}
.pd-modal-box h3 { font-size: 18px; color: #f0f0f0; }
.pd-modal-box label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #bbb;
    font-size: 13px;
}
.pd-modal-box input[type="text"] {
    background: #262626;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #f0f0f0;
    padding: 9px 12px;
    font-size: 14px;
    outline: none;
}
.pd-modal-box input:focus { border-color: #6c9fff; }
.pd-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ── Account designs page ─────────────────────────────────────── */
.pd-account-designs h2 { margin-bottom: 20px; }

.pd-designs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.pd-design-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
    transition: box-shadow .2s;
}
.pd-design-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.12); }

.pd-design-thumb {
    aspect-ratio: 4/3;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.pd-design-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pd-design-thumb--empty { color: #ccc; }

.pd-design-info {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.pd-design-info strong { font-size: 14px; }
.pd-design-meta { font-size: 12px; color: #888; }

.pd-design-actions {
    padding: 8px 12px 12px;
    display: flex;
    gap: 8px;
}

.pd-empty-state {
    text-align: center;
    padding: 40px;
    color: #666;
    line-height: 2;
}

/* ── Undo / redo ─────────────────────────────────────────────── */
.pd-btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
    border-radius: 8px;
}
.pd-btn-icon:disabled { opacity: .3; cursor: not-allowed; }

.pd-topbar-sep {
    width: 1px;
    height: 22px;
    background: #2e2e2e;
    flex-shrink: 0;
}

/* ── Predefined backgrounds grid ─────────────────────────────── */
#pd-predefined-bgs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

#pd-predefined-bgs:empty::after {
    content: 'Aucun fond prédéfini configuré.';
    font-size: 11px;
    color: #555;
    font-style: italic;
    grid-column: 1 / -1;
}

.pd-predef-bg {
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .15s, transform .1s;
    background: #222;
    position: relative;
}
.pd-predef-bg:hover { border-color: #555; transform: scale(1.04); }
.pd-predef-bg.active { border-color: #6c9fff; }
.pd-predef-bg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}
.pd-predef-bg-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 3px 4px;
    font-size: 9px;
    background: rgba(0,0,0,.55);
    color: #ddd;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
}

/* ── Toggle switch ────────────────────────────────────────────── */
.pd-switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
    cursor: pointer;
    flex-shrink: 0;
}
.pd-switch input { display: none; }
.pd-switch-track {
    position: absolute;
    inset: 0;
    background: #3a3a3a;
    border-radius: 10px;
    transition: background .2s;
}
.pd-switch-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
}
.pd-switch input:checked + .pd-switch-track { background: #3b7dff; }
.pd-switch input:checked + .pd-switch-track::after { transform: translateX(14px); }

/* ── Shadow controls ──────────────────────────────────────────── */
.pd-shadow-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: #bbb;
}

#pd-shadow-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: #1a1a1a;
    border: 1px solid #2e2e2e;
    border-radius: 6px;
}

.pd-range-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.pd-range-row input[type="range"] {
    flex: 1;
    accent-color: #6c9fff;
    cursor: pointer;
    height: 4px;
    padding: 0;
    border: none;
    background: none;
}

/* ── QR Code tab ─────────────────────────────────────────────── */
.pd-qr-price-banner {
    background: linear-gradient(135deg, #1a261a, #1f301f);
    border: 1px solid #2d4a2d;
    border-radius: 6px;
    padding: 9px 12px;
    font-size: 12px;
    color: #8fbc8f;
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.4;
}
.pd-qr-price-banner strong { color: #5cb85c; }

#pd-qr-preview-wrap {
    display: flex;
    justify-content: center;
    min-height: 40px;
}

#pd-qr-preview-canvas {
    width: 148px;
    height: 148px;
    image-rendering: pixelated;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    display: block;
}

.pd-qr-hint {
    font-size: 11px;
    color: #666;
    line-height: 1.5;
    margin: 0;
}

/* ── Background transform panel ──────────────────────────────── */
#pd-bg-transform {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pd-transform-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pd-transform-label {
    font-size: 12px;
    color: #888;
    width: 52px;
    flex-shrink: 0;
}

.pd-transform-val {
    font-size: 12px;
    color: #ccc;
    min-width: 38px;
    text-align: center;
}

.pd-transform-rot input[type="range"] {
    flex: 1;
    accent-color: #6c9fff;
    cursor: pointer;
    height: 4px;
}

/* ── Holes overlay ───────────────────────────────────────────── */
#pd-holes-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    overflow: visible;
}

.pd-hole-marker {
    position: absolute;
    /* border-radius set in JS from radius_mm */
    border: 1.5px dashed #ff6b6b;
    background: linear-gradient(135deg, rgba(0,0,0,0.7) 0%, rgba(30,0,0,0.5) 100%);
    box-sizing: border-box;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.8), 0 0 0 1px rgba(255,107,107,0.15);
}

.pd-hole-label {
    position: absolute;
    left: calc(100% + 5px);
    top: 50%;
    transform: translateY(-50%);
    font-size: 9px;
    font-family: sans-serif;
    color: rgba(255, 107, 107, 0.9);
    white-space: nowrap;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

#pd-holes-legend {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 107, 107, 0.12);
    border: 1px solid rgba(255, 107, 107, 0.35);
    color: rgba(255, 130, 130, 0.95);
    padding: 5px 16px;
    border-radius: 20px;
    font-size: 11.5px;
    pointer-events: none;
    white-space: nowrap;
    display: none;
    z-index: 10;
}

#pd-bg-hint {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(108, 159, 255, 0.12);
    border: 1px solid rgba(108, 159, 255, 0.3);
    color: rgba(159, 196, 255, 0.9);
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 11px;
    pointer-events: none;
    white-space: nowrap;
    display: none;
    z-index: 10;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    #pd-app {
        grid-template-columns: 1fr;
        grid-template-rows: 56px 1fr 260px;
        grid-template-areas:
            "topbar"
            "canvas"
            "sidebar";
    }
    #pd-sidebar {
        border-right: none;
        border-top: 1px solid #2e2e2e;
        flex-direction: row;
    }
    #pd-tabs {
        flex-direction: column;
        border-bottom: none;
        border-right: 1px solid #2e2e2e;
        min-width: 60px;
    }
    .pd-tab { flex: none; padding: 12px 8px; }
    .pd-tab-panel { overflow-x: auto; flex-direction: row; flex-wrap: nowrap; }
}
