:root {
    color-scheme: dark;
    --bg: #0c1018;
    --panel: #121824;
    --panel-2: #171f2e;
    --panel-3: #202a3b;
    --border: #293449;
    --border-bright: #3b4962;
    --text: #edf2f7;
    --muted: #8e9ab0;
    --yellow: #ffd166;
    --orange: #ff9f43;
    --red: #ef476f;
    --green: #62d6a7;
    --blue: #64b5f6;
    --radius: 12px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 900px; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.app-header {
    min-height: 76px;
    padding: 12px 22px;
    display: grid;
    grid-template-columns: minmax(250px, 1fr) auto minmax(440px, 1fr);
    align-items: center;
    gap: 22px;
    background: rgba(18, 24, 36, .96);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 18px; line-height: 1.15; margin: 2px 0 0; }
.eyebrow { margin: 0; color: var(--yellow); letter-spacing: .14em; font-size: 10px; font-weight: 800; }
.egg-mark, .empty-egg {
    width: 38px;
    height: 47px;
    border-radius: 52% 48% 48% 52% / 62% 62% 38% 38%;
    background: linear-gradient(145deg, #fff5c4 0 54%, var(--yellow) 55%);
    transform: rotate(8deg);
    box-shadow: 0 0 28px rgba(255, 209, 102, .16);
}

.tabs { display: flex; flex-wrap: wrap; justify-content: center; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 11px; }
.tab { border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 700; }
.tab span { margin-left: 5px; padding: 1px 7px; border-radius: 99px; background: var(--panel-3); font-size: 11px; }
.tab.active { color: #17120a; background: var(--yellow); }
.tab.active span { background: rgba(0, 0, 0, .15); }

.header-actions { display: flex; justify-content: flex-end; align-items: center; gap: 9px; }
.button { border: 1px solid transparent; border-radius: 9px; padding: 9px 13px; cursor: pointer; font-weight: 750; transition: .16s ease; }
.button:hover { transform: translateY(-1px); filter: brightness(1.06); }
.button:disabled { cursor: wait; opacity: .55; transform: none; }
.button.primary { background: var(--yellow); color: #17120a; }
.button.secondary { background: var(--panel-3); border-color: var(--border-bright); }
.button.danger { color: #ff92aa; background: rgba(239, 71, 111, .1); border-color: rgba(239, 71, 111, .35); }
.button.square { padding: 7px 13px; font-size: 22px; line-height: 1; background: var(--yellow); color: #17120a; }
.text-button { border: 0; padding: 3px; background: transparent; color: var(--muted); cursor: pointer; text-align: left; }
.text-button:hover { color: var(--text); }

.save-state { min-width: 118px; display: flex; gap: 7px; align-items: center; color: var(--muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 4px rgba(142, 154, 176, .08); }
.save-state[data-state="saved"] .status-dot { background: var(--green); }
.save-state[data-state="saving"] .status-dot { background: var(--yellow); animation: pulse .8s infinite alternate; }
.save-state[data-state="error"] .status-dot { background: var(--red); }
@keyframes pulse { to { opacity: .35; } }

.workspace { display: grid; grid-template-columns: 310px minmax(590px, 1fr); min-height: calc(100vh - 77px); }
.collection-panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--border); }
.collection-tools { display: grid; grid-template-columns: 1fr auto; gap: 9px; padding: 14px; border-bottom: 1px solid var(--border); }
.search-box input, input, select, textarea {
    width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); padding: 9px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 209, 102, .10); }
textarea { resize: vertical; }
.collection-list { padding: 8px; overflow-y: auto; height: calc(100vh - 181px); }
.collection-card { width: 100%; border: 1px solid transparent; border-radius: 10px; background: transparent; padding: 10px; margin-bottom: 3px; cursor: pointer; text-align: left; display: grid; grid-template-columns: 34px 1fr; gap: 10px; }
.collection-card:hover { background: var(--panel-2); }
.collection-card.active { border-color: var(--border-bright); background: var(--panel-3); }
.swatch { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: #131722; font-weight: 900; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.dish-swatch { background: #f5e4bb; border-radius: 50%; box-shadow: inset 0 0 0 5px #c8b283, inset 0 0 0 7px #fff4d8; }
.collection-card strong, .collection-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collection-card strong { font-size: 13px; }
.collection-card small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.aside-footer { margin-top: auto; padding: 13px 16px; display: flex; flex-direction: column; gap: 7px; border-top: 1px solid var(--border); font-size: 12px; }

.editor-panel { padding: 24px clamp(24px, 4vw, 64px) 70px; overflow-y: auto; }
.editor-shell { max-width: 1120px; margin: 0 auto; }
.editor-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 20px; }
.editor-heading h2 { font-size: 29px; margin: 2px 0 5px; }
.technical-id { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.editor-actions { display: flex; gap: 8px; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 310px; align-items: start; gap: 18px; }
.form-stack { display: grid; gap: 15px; }
.section-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 17px; }
.section-card h3 { margin: 0 0 14px; font-size: 13px; letter-spacing: .04em; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: block; color: #bec7d6; font-size: 12px; font-weight: 650; }
label input, label select { display: block; margin-top: 6px; font-weight: 500; }
label small { display: block; margin-top: 5px; color: var(--muted); font-weight: 400; line-height: 1.35; }
.wide-field { margin-top: 14px; }
.wide-field textarea { display: block; margin-top: 6px; }
.color-field { display: grid; grid-template-columns: 48px 1fr; gap: 8px; margin-top: 6px; }
.color-field input[type="color"] { height: 39px; padding: 3px; }

.preview-card { position: sticky; top: 100px; }
.preview-stage { height: 260px; position: relative; overflow: hidden; border-radius: 10px; background: radial-gradient(circle at center, #243047 0 2px, transparent 3px), #0e1420; background-size: 24px 24px; }
.preview-stage svg { width: 100%; height: 100%; }
.swipe-preview { transform-origin: 150px 130px; animation: swipe-preview-spin 2s linear infinite; }
@keyframes swipe-preview-spin { to { transform: rotate(360deg); } }
.preview-caption { margin-top: 12px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.metric { padding: 9px; background: var(--panel-2); border-radius: 8px; }
.metric span, .metric strong { display: block; }
.metric span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.metric strong { font-size: 14px; margin-top: 2px; }
.plate-preview { display: grid; place-items: center; }
.plate { width: 175px; height: 175px; border-radius: 50%; background: #f8eac9; box-shadow: inset 0 0 0 17px #d5c093, inset 0 0 0 21px #fff7e3, 0 17px 35px rgba(0,0,0,.35); display: flex; flex-wrap: wrap; gap: 5px; align-content: center; justify-content: center; padding: 45px; }
.food-dot { width: 24px; height: 24px; border-radius: 44% 56% 52% 48%; box-shadow: inset -3px -4px 5px rgba(0,0,0,.2); }
.material-preview { display: grid; place-items: center; }
.material-orb { width: 142px; height: 142px; border-radius: 46% 54% 58% 42% / 52% 44% 56% 48%; box-shadow: inset -18px -22px 28px rgba(0,0,0,.24), inset 12px 12px 20px rgba(255,255,255,.18), 0 20px 44px rgba(0,0,0,.38); transform: rotate(-8deg); }
.usage-list { display: grid; gap: 7px; }
.usage-pill { padding: 8px 10px; border-radius: 8px; background: var(--panel-2); color: var(--muted); font-size: 12px; }
.usage-pill strong { color: var(--text); }
.upgrade-swatch { border: 2px solid var(--yellow); color: #fff; font-size: 9px; border-radius: 50%; }
.upgrade-swatch.shape-square { border-radius: 5px; }
.upgrade-swatch.shape-diamond { border-radius: 0; clip-path: polygon(50% 0,100% 50%,50% 100%,0 50%); }
.upgrade-swatch.shape-hexagon { clip-path: polygon(25% 5%,75% 5%,100% 50%,75% 95%,25% 95%,0 50%); border-radius: 0; }

.upgrade-editor-shell { max-width: 1480px; }
.tree-card { margin-bottom: 18px; padding: 0; overflow: hidden; }
.tree-card-heading { display: flex; justify-content: space-between; align-items: center; padding: 15px 17px; border-bottom: 1px solid var(--border); }
.tree-card-heading h3 { margin-bottom: 4px; }
.tree-card-heading p, .section-help { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.upgrade-tree-preview { height: min(47vh, 520px); min-height: 330px; background-color: #0e1420; background-image: linear-gradient(rgba(100,181,246,.06) 1px, transparent 1px), linear-gradient(90deg, rgba(100,181,246,.06) 1px, transparent 1px); background-size: 24px 24px; overflow: hidden; }
.upgrade-tree-preview svg { width: 100%; height: 100%; }
.web-tree-lines line { stroke: #758196; stroke-width: 4; stroke-dasharray: 8 6; }
.web-tree-node { cursor: pointer; }
.web-tree-node path { stroke-width: 5; transition: .15s ease; }
.web-tree-node:hover path, .web-tree-node.selected path { filter: brightness(1.25); stroke-width: 8; }
.web-tree-node text { text-anchor: middle; dominant-baseline: middle; font-size: 11px; font-weight: 900; pointer-events: none; }
.upgrade-editor-grid { display: grid; grid-template-columns: minmax(620px, 1.65fr) minmax(330px, .8fr); gap: 18px; align-items: start; }
.nested-list { display: grid; gap: 8px; margin-top: 12px; }
.nested-row { display: grid; align-items: end; gap: 8px; padding: 9px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; }
.nested-row.modifier-row { grid-template-columns: 1.2fr 1fr 1fr .7fr auto; }
.nested-row.condition-row { grid-template-columns: .9fr 1.1fr 1.1fr .9fr .8fr auto; }
/* L'aperçu d'adresse occupe toute la largeur sous les listes en cascade. */
.address-preview { grid-column: 1 / -1; margin: 2px 0 0; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; opacity: .75; }
.address-preview.address-invalid { color: #ff9f43; opacity: 1; }
.nested-row input, .nested-row select { margin-top: 4px; padding: 7px; }
.nested-remove { min-width: 37px; padding: 7px 10px; }
.nested-add { margin-top: 10px; width: 100%; }
.empty-nested { margin-top: 11px; border: 1px dashed var(--border-bright); border-radius: 8px; padding: 12px; color: var(--muted); text-align: center; font-size: 11px; }
.node-live-preview { min-height: 150px; display: grid; place-items: center; margin-top: 15px; border-radius: 9px; background: var(--bg); }
.live-node { width: 94px; height: 94px; display: grid; place-items: center; padding: 10px; border: 5px solid; border-radius: 50%; text-align: center; font-size: 13px; font-weight: 900; overflow: hidden; }
.live-node.shape-square { border-radius: 9px; }
.live-node.shape-diamond { border-radius: 0; clip-path: polygon(50% 0,100% 50%,50% 100%,0 50%); }
.live-node.shape-hexagon { border-radius: 0; clip-path: polygon(25% 4%,75% 4%,100% 50%,75% 96%,25% 96%,0 50%); }
.state-style-row { display: grid; grid-template-columns: 1fr repeat(3, 55px); gap: 7px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.state-style-row strong { font-size: 11px; }
.state-style-row label { font-size: 9px; text-align: center; color: var(--muted); }
.state-style-row input { height: 30px; padding: 2px; margin-top: 3px; }
.state-legend > div { display: flex; align-items: center; gap: 9px; margin-top: 8px; font-size: 11px; }
.state-index { width: 23px; height: 23px; display: grid; place-items: center; border-radius: 50%; background: var(--panel-3); color: var(--yellow); font-weight: 800; }
.toggle-label { display: flex; align-items: center; gap: 9px; margin-top: 20px; }
.toggle-label input { width: auto; margin: 0; accent-color: var(--yellow); }
.value-preview { text-align: center; }
.value-preview .value-kind { display: inline-block; color: var(--yellow); font-weight: 900; letter-spacing: .12em; font-size: 10px; }
.value-preview > strong, .value-preview > b { display: block; margin-top: 12px; }
.value-preview > strong { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.value-preview > b { font-size: 46px; color: var(--blue); overflow-wrap: anywhere; }
.value-preview p { color: var(--muted); line-height: 1.5; font-size: 12px; }

.amount-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.amount-row { min-height: 52px; display: grid; grid-template-columns: auto 1fr 64px; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); }
.amount-row[data-enabled="false"] { opacity: .52; }
.amount-row input[type="checkbox"] { width: 17px; margin: 0; accent-color: var(--yellow); }
.amount-row input[type="number"] { margin: 0; padding: 6px; }
.ingredient-label { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.ingredient-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }

.empty-state { min-height: 65vh; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--text); margin: 18px 0 4px; }
.empty-state p { margin: 0; }
.empty-egg { width: 54px; height: 67px; opacity: .28; filter: grayscale(1); }
.empty-list { padding: 30px 12px; color: var(--muted); text-align: center; font-size: 13px; }

.error-drawer { position: fixed; z-index: 40; right: 16px; bottom: 16px; width: min(560px, calc(100vw - 32px)); max-height: 50vh; overflow: auto; padding: 16px; border: 1px solid rgba(239,71,111,.65); border-radius: 12px; background: #25151d; box-shadow: 0 18px 60px rgba(0,0,0,.55); display: flex; justify-content: space-between; gap: 16px; }
.error-drawer[hidden] { display: none; }
.error-drawer ul { padding-left: 20px; margin: 9px 0 0; color: #ffc1cf; font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translate(-50%, 20px); padding: 10px 15px; border-radius: 9px; background: var(--text); color: #111722; font-weight: 750; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

dialog { width: min(440px, calc(100vw - 40px)); border: 1px solid var(--border-bright); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; box-shadow: 0 30px 90px rgba(0,0,0,.7); }
dialog::backdrop { background: rgba(4,7,12,.76); backdrop-filter: blur(3px); }
dialog form { padding: 22px; display: grid; gap: 16px; }
dialog h2 { margin: -9px 0 2px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 5px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 1100px) {
    .app-header { grid-template-columns: 240px auto 1fr; }
    .save-state { display: none; }
    .editor-grid { grid-template-columns: 1fr; }
    .preview-card { position: static; order: -1; }
    .preview-stage { height: 220px; }
    .upgrade-editor-grid { grid-template-columns: 1fr; }
    .nested-row.condition-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1380px) {
    .app-header { grid-template-columns: 1fr auto; }
    .tabs { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
    .header-actions { grid-column: 2; grid-row: 1; }
}

/* --- Page Textes --------------------------------------------------------- */
.loc-table { display: flex; flex-direction: column; gap: 4px; }
.loc-head, .loc-row { display: grid; grid-template-columns: minmax(220px, 1.4fr) repeat(var(--loc-langs, 2), minmax(160px, 1fr)); gap: 10px; align-items: center; }
.loc-head { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; opacity: .6; padding: 0 0 6px; border-bottom: 1px solid rgba(255,255,255,.12); }
.loc-row { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.loc-source { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.loc-source code { font-size: 11px; opacity: .55; word-break: break-all; }
.loc-source span { font-size: 13px; font-weight: 600; }
.loc-row input { width: 100%; }
.loc-row input.loc-empty { border-color: rgba(255,159,67,.55); background: rgba(255,159,67,.07); }
.lang-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.lang-chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 6px 5px 12px; border: 1px solid rgba(255,255,255,.14); border-radius: 999px; font-size: 13px; }
.lang-chip span { opacity: .7; }
.lang-chip .lang-remove { padding: 0 7px; line-height: 1.5; font-size: 12px; }
.lang-add { display: inline-flex; gap: 8px; margin-left: auto; }
.lang-add input { width: 180px; }
.loc-filter { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }

/* --- Gestionnaire de salles ---------------------------------------------- */
/* La grille montre la progression telle qu'elle se joue: une colonne par
   dimension, une case par salle, de haut en bas. */
.room-editor-grid { display: grid; grid-template-columns: minmax(330px, .85fr) minmax(520px, 1.4fr); gap: 18px; align-items: start; }
.room-grid-card { position: sticky; top: 0; max-height: calc(100vh - 130px); display: flex; flex-direction: column; }
.room-grid-shell { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.room-grid { display: flex; gap: 8px; overflow: auto; padding-bottom: 6px; min-height: 0; }
.room-column { display: flex; flex-direction: column; gap: 6px; min-width: 104px; }
.room-column-special { border-left: 1px dashed var(--border); padding-left: 8px; }
.room-column-head { display: flex; flex-direction: column; gap: 1px; padding: 4px 2px; border-bottom: 1px solid var(--border); }
.room-column-head strong { font-size: 13px; letter-spacing: .06em; }
.room-column-head span { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-column-head small { font-size: 10px; color: var(--muted); }
.room-cells { display: flex; flex-direction: column; gap: 5px; overflow-y: auto; }
.room-cell { position: relative; display: flex; flex-direction: column; gap: 1px; padding: 6px 7px; border: 2px solid; border-radius: 8px; cursor: pointer; text-align: left; color: #f4f6fb; }
.room-cell strong { font-size: 11px; letter-spacing: .05em; }
.room-cell span { font-size: 10px; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-cell small { font-size: 10px; opacity: .7; }
.room-cell.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.room-cell-badge { position: absolute; top: 4px; right: 5px; font-size: 9px; font-style: normal; padding: 1px 4px; border-radius: 6px; background: rgba(0, 0, 0, .45); }
.room-column-tools { display: flex; gap: 8px; padding-top: 4px; border-top: 1px solid var(--border); }
.room-empty { font-size: 11px; color: var(--muted); padding: 8px 2px; }
.element-grid { display: flex; flex-direction: column; gap: 7px; }
.element-row { display: grid; grid-template-columns: auto 1fr 78px 66px 66px; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); }
.element-row[data-enabled="false"] { opacity: .5; }
.element-row label { font-size: 10px; color: var(--muted); }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.check-row { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.nested-row.replace-row { grid-template-columns: 1.4fr .7fr .8fr auto; }

@media (max-width: 1500px) {
    .room-editor-grid { grid-template-columns: 1fr; }
    .room-grid-card { position: static; max-height: none; }
}

/* La page Salles porte sa grille au centre: le panneau de gauche se replie
   plutôt que de redire la même chose. */
/* Le panneau masqué sort du flux de la grille: il ne reste qu'un enfant, donc
   une seule piste. Déclarer deux pistes ici enverrait le panneau d'édition dans
   la première et l'écraserait à zéro. */
.workspace.no-list { grid-template-columns: minmax(0, 1fr); }
.workspace.no-list .collection-panel { display: none; }
.room-column-head { width: 100%; border: 1px solid transparent; border-radius: 8px; background: transparent; cursor: pointer; text-align: left; }
.room-column-head.active { border-color: var(--accent); background: var(--panel-2); }

/* Bandeau de péremption: un onglet resté ouvert longtemps travaille peut-être
   sur une version dépassée. Il occupe sa propre bande pour ne pas se glisser
   dans la grille du plan de travail, qui compte ses enfants. */
.stale-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0 24px 12px;
    padding: 12px 18px;
    border-radius: 10px;
    border: 1px solid #c8973f;
    background: #3a2f18;
    color: #ffe8c2;
}
.stale-banner[hidden] { display: none; }
.stale-banner span { flex: 1 1 320px; }
