/* =====================================================================
   Outil IZIKARD — feuille de style unifiee (thème clair / sombre auto)
   Design aligne sur le simulateur : neutres travailles, panneaux,
   accents de marque, boutons degrades.
   ===================================================================== */

:root {
    color-scheme: light dark;

    /* Neutres (clair par defaut) */
    --bg: #f5f5fb;
    --panel: #ffffff;
    --panel-2: #f0f0f6;
    --ink: #1b1a24;
    --ink-soft: #55536a;
    --line: #e2e1ee;

    /* Marque + accents */
    --brand-a: #6a11cb;
    --brand-b: #2575fc;
    --action-a: #ff8a00;
    --action-b: #e52e71;
    --green: #22a06b;
    --red: #e5484d;

    /* Editeur */
    --guide: #00b7d4;
    --grid: rgba(20,18,30,.28);
    --grid-center: #e52e71;
    --stage-a: #e9e9f2;
    --stage-b: #f6f6fb;

    --shadow: 0 10px 30px rgba(30,20,60,.12);
    --radius: 14px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #131119; --panel: #1c1a25; --panel-2: #232130;
        --ink: #efeef6; --ink-soft: #a9a6bd; --line: #302d3f;
        --green: #3ecf8e; --red: #ff6b6b;
        --guide: #00e0ff; --grid: rgba(255,255,255,.3);
        --stage-a: #201e2b; --stage-b: #26232f;
        --shadow: 0 10px 30px rgba(0,0,0,.45);
    }
}

* { box-sizing: border-box; }

/* L'attribut HTML [hidden] doit toujours l'emporter sur un display: flex/grid. */
[hidden] { display: none !important; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    padding: 28px 18px 64px;
}

a { color: var(--brand-b); text-decoration: none; }

/* ---------- Structure ---------- */
.container {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}
.container--wide { max-width: 1120px; }

.logo {
    height: 84px;
    margin-bottom: 6px;
    background: #ffffff;
    padding: 10px 16px;
    border-radius: 14px;
    box-shadow: var(--shadow);
}

h1 {
    margin: 8px 0 4px;
    font-size: clamp(1.5rem, 3.4vw, 2.05rem);
    line-height: 1.12;
    letter-spacing: -.01em;
    text-wrap: balance;
    background: linear-gradient(90deg, var(--brand-a), var(--brand-b));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
h2 {
    margin: 0 0 6px;
    font-weight: 500;
    font-size: 1.05rem;
    color: var(--ink-soft);
}

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: none; cursor: pointer; font: inherit; font-weight: 700;
    padding: 13px 26px; border-radius: 10px; color: #fff;
    background: linear-gradient(120deg, var(--action-a), var(--action-b));
    transition: filter .2s, transform .12s, box-shadow .2s;
    box-shadow: var(--shadow);
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; box-shadow: none; }
.btn:focus-visible { outline: 3px solid var(--brand-b); outline-offset: 2px; }

.btn--ghost { background: var(--panel-2); color: var(--ink); box-shadow: none; border: 1px solid var(--line); }
.btn--ghost:hover { filter: none; background: var(--line); }
.btn--danger { background: var(--red); }

.actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 22px; }

/* ---------- Panneaux ---------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    width: 100%;
    max-width: 460px;
    margin: 16px auto;
    text-align: left;
}

/* ---------- Dashboard ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
    width: 100%;
    margin-top: 22px;
}
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 20px 18px;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ink);
    transition: transform .14s, border-color .2s;
}
.card:hover { transform: translateY(-2px); border-color: var(--brand-b); }
.card--custom {
    grid-column: 1 / -1;
    background: linear-gradient(120deg, var(--action-a), var(--action-b));
    color: #fff; border: none;
}
.card--custom:hover { filter: brightness(1.06); }

/* ---------- Formulaires ---------- */
label { font-weight: 600; }
form.panel label, .panel label { display: block; margin: 14px 0 6px; }
form.panel label:first-of-type { margin-top: 0; }

input[type=text], input[type=password], input[type=file], select {
    width: 100%;
    padding: 11px;
    font-size: 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--ink);
}
input[type=file]::file-selector-button {
    font: inherit; font-weight: 600; margin-right: 10px; padding: 8px 12px;
    border: 1px solid var(--line); border-radius: 7px; background: var(--panel);
    color: var(--ink); cursor: pointer;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--brand-b); outline-offset: 1px; }

.hint { font-size: .85rem; color: var(--ink-soft); margin: 6px 0 10px; }
.hint b { color: var(--ink); }

/* Option identifiant izikard */
.check-row { display: flex; align-items: center; gap: 9px; font-weight: 700; margin: 16px 0 6px; cursor: pointer; }
.check-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand-b); }
.id-fields, #idFields { display: flex; flex-direction: column; gap: 6px; }
.id-row { display: flex; align-items: center; gap: 10px; font-weight: normal; }
.id-row span { flex: 1; font-size: .85rem; word-break: break-all; }
.id-row input { width: 130px; text-transform: uppercase; letter-spacing: .12em; }

/* ---------- Messages ---------- */
.alert { border-radius: 10px; padding: 12px 16px; margin: 14px auto; max-width: 620px; font-weight: 600; }
.alert--error { background: color-mix(in srgb, var(--red) 16%, var(--panel)); color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 40%, transparent); }
.alert--ok { background: color-mix(in srgb, var(--green) 16%, var(--panel)); color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 40%, transparent); }

/* ---------- Galerie ---------- */
.gallery { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; margin-top: 20px; }
.gallery figure { margin: 0; width: 180px; }
.thumb { background: #fff; border-radius: 12px; padding: 6px; box-shadow: var(--shadow); }
.thumb img { width: 100%; display: block; border-radius: 8px; }
.gallery figcaption { font-size: .8rem; word-break: break-all; margin-top: 6px; color: var(--ink-soft); }

/* =====================================================================
   Editeur "sur mesure"
   ===================================================================== */

.sm-layout {
    display: grid; grid-template-columns: 340px 1fr; gap: 18px;
    align-items: start; width: 100%; text-align: left; margin-top: 10px;
}
@media (max-width: 860px) { .sm-layout { grid-template-columns: 1fr; } }
.panel.sm-controls, .panel.sm-editor { max-width: none; margin: 0; }

.sm-controls label { display: block; font-weight: 700; margin: 16px 0 6px; }
.sm-controls label:first-of-type { margin-top: 0; }
.sm-editor .hint { margin: 0 0 12px; }
.stage-host { display: flex; justify-content: center; }

.stage {
    position: relative; margin: 0 auto; max-width: 100%;
    background: repeating-conic-gradient(var(--stage-a) 0 25%, var(--stage-b) 0 50%) 0 0 / 26px 26px;
    box-shadow: var(--shadow); user-select: none; touch-action: none; overflow: hidden;
    border-radius: 8px;
}
.stage.empty {
    width: 100%; max-width: 560px; aspect-ratio: 4 / 5;
    display: grid; place-items: center;
}
.stage.empty::after {
    content: "Chargez une image de fond, ou choisissez un modèle";
    color: var(--ink-soft); font-size: .95rem; text-align: center; padding: 24px; max-width: 30ch;
}
.stage > img { display: block; width: 100%; height: 100%; pointer-events: none; }

/* Grille reglee (regle des tiers + croix centrale) */
.grid-overlay { position: absolute; inset: 0; z-index: 4; pointer-events: none; display: none; }
.grid-overlay.on { display: block; }
.grid-overlay .gl { position: absolute; background: var(--grid); }
.grid-overlay .gl.v { top: 0; bottom: 0; width: 1px; }
.grid-overlay .gl.h { left: 0; right: 0; height: 1px; }
.grid-overlay .gl.center { background: var(--grid-center); opacity: .85; }

/* Guides magnetiques dynamiques */
.guides { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.guides .guide { position: absolute; background: var(--guide); box-shadow: 0 0 4px var(--guide); }
.guides .guide.v { top: 0; bottom: 0; width: 1px; }
.guides .guide.h { left: 0; right: 0; height: 1px; }

/* Elements deplacables */
.item {
    position: absolute; z-index: 5; cursor: move; touch-action: none;
    border: 1.5px dashed var(--brand-b); box-shadow: 0 0 0 1px rgba(255,255,255,.55);
}
.item.sel { border-color: var(--action-b); }
.item > img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; display: block; }
.item--qr > img { object-fit: fill; }
.item .handle {
    position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px;
    background: var(--brand-b); border: 2px solid #fff; border-radius: 50%; cursor: nwse-resize;
}
.item .badge {
    position: absolute; top: 0; left: 0; transform: translateY(-100%);
    font-size: .64rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
    background: var(--brand-b); color: #fff; padding: 2px 7px; border-radius: 6px 6px 6px 0; white-space: nowrap;
}
.item--qr .badge { background: var(--action-b); }
.item .id-preview {
    position: absolute; left: 50%; top: 100%; transform: translateX(-50%);
    margin-top: 5px; font: 700 13px/1 Arial, sans-serif; color: #000; white-space: nowrap;
    text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
}

/* Controles de l'editeur */
.editor-controls { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; margin-top: 14px; }
.editor-controls .inline { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.editor-controls input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand-b); }
.editor-controls select { width: auto; }

/* Tableau des coordonnees reelles */
.readout { margin-top: 18px; overflow-x: auto; }
.readout table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.readout caption {
    text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .1em;
    color: var(--ink-soft); font-weight: 700; margin-bottom: 8px;
}
.readout th, .readout td {
    text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line);
    font-variant-numeric: tabular-nums;
}
.readout th:first-child, .readout td:first-child { text-align: left; }
.readout thead th { color: var(--ink-soft); font-weight: 600; }
.readout .muted td { color: var(--ink-soft); }

/* Selecteur de modeles de fond (vignettes) */
.model-picker {
    max-height: 260px; overflow-y: auto; margin: 6px 0 10px; padding: 8px;
    background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
}
.model-group { margin-bottom: 10px; }
.model-group-title {
    display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
    color: var(--ink-soft); margin: 4px 2px 6px;
}
.model-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.model-thumb {
    padding: 0; border: 2px solid transparent; border-radius: 8px; cursor: pointer;
    background: #fff; overflow: hidden; aspect-ratio: 1; line-height: 0;
}
.model-thumb img { width: 100%; height: 100%; object-fit: contain; }
.model-thumb:hover { border-color: var(--brand-b); }
.model-thumb.sel { border-color: var(--action-b); box-shadow: 0 0 0 2px var(--action-b); }
