:root {
    --ink: #17151f;
    --muted: #777383;
    --line: #e9e7ee;
    --panel: #ffffff;
    --workspace: #f4f3f7;
    --purple: #6757ff;
    --purple-dark: #4d3ee8;
    --purple-soft: #eeebff;
    --danger: #dd3f55;
    --shadow: 0 18px 60px rgba(27, 22, 49, .16);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; }
body {
    margin: 0;
    overflow: hidden;
    color: var(--ink);
    background: var(--workspace);
    font: 14px/1.45 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid rgba(103, 87, 255, .22);
    outline-offset: 2px;
}
.sr-only {
    position: absolute !important; width: 1px !important; height: 1px !important;
    padding: 0 !important; margin: -1px !important; overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important;
}
.app-shell { height: 100vh; display: grid; grid-template-rows: 64px minmax(0, 1fr); }

.topbar {
    position: relative; z-index: 20; display: grid; grid-template-columns: 300px 1fr 300px;
    align-items: center; gap: 20px; padding: 0 18px; color: white;
    background: linear-gradient(100deg, #17131f 0%, #29213d 58%, #34275b 100%);
    box-shadow: 0 2px 12px rgba(16, 12, 28, .18);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
    width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px;
    color: white; font-size: 19px; font-weight: 900; font-style: italic;
    background: linear-gradient(145deg, #8b7fff, #5847f2); box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}
.brand div { display: grid; line-height: 1.15; }
.brand strong { font-size: 14px; letter-spacing: .01em; }
.brand span { margin-top: 4px; color: #a9a2b8; font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.document-name { justify-self: center; width: min(390px, 100%); }
.document-name input {
    width: 100%; padding: 8px 14px; border: 1px solid transparent; border-radius: 8px;
    color: #f8f7fb; background: transparent; text-align: center; font-weight: 600;
}
.document-name input:hover, .document-name input:focus { border-color: rgba(255,255,255,.18); background: rgba(255,255,255,.07); }
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }
.history-actions { display: flex; gap: 2px; padding-right: 8px; border-right: 1px solid rgba(255,255,255,.12); }
.topbar .icon-button { color: #ded9e8; }
.save-status { display: flex; align-items: center; gap: 7px; color: #b8b2c4; font-size: 12px; }
.save-status i { width: 6px; height: 6px; border-radius: 50%; background: #56d39b; box-shadow: 0 0 0 3px rgba(86,211,155,.12); }

.button {
    display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 38px;
    padding: 0 16px; border: 0; border-radius: 9px; cursor: pointer; font-weight: 700; transition: .18s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button-primary { color: white; background: linear-gradient(135deg, #7869ff, #5a47ed); box-shadow: 0 8px 20px rgba(65,49,193,.26); }
.button-primary:hover { background: linear-gradient(135deg, #897cff, #6553f4); box-shadow: 0 10px 24px rgba(65,49,193,.36); }
.button-dark { color: white; background: #24202e; }
.button-soft { color: #3f374d; background: #f3f1f6; }
.button-soft:hover { background: #ebe8f1; }
.button-block { width: 100%; }
.icon-button {
    width: 34px; height: 34px; display: inline-grid; place-items: center; padding: 0;
    border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: 17px;
}
.icon-button:hover:not(:disabled) { background: rgba(128, 116, 150, .12); }
.icon-button:disabled { opacity: .32; cursor: default; }
.icon-button.danger { color: var(--danger); }
.text-button { border: 0; padding: 2px; color: var(--purple); background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; }
.text-button.danger { color: var(--danger); }

.editor { min-height: 0; display: grid; grid-template-columns: 76px 306px minmax(420px, 1fr) 248px; }
.tool-rail {
    position: relative; z-index: 12; display: flex; flex-direction: column; gap: 5px;
    padding: 14px 8px; color: #cbc6d5; background: #201b2b; box-shadow: 4px 0 18px rgba(24,18,36,.08);
}
.rail-button {
    height: 66px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
    border: 0; border-radius: 10px; color: #aaa4b6; background: transparent; cursor: pointer; font-size: 11px;
}
.rail-button span { display: grid; place-items: center; min-height: 24px; color: #ddd8e7; font-size: 21px; font-weight: 800; }
.rail-button:hover { color: white; background: rgba(255,255,255,.06); }
.rail-button.active { color: white; background: #373047; }
.rail-button.active span { color: #9e93ff; }

.side-panel, .properties-panel { min-width: 0; overflow: auto; background: var(--panel); }
.side-panel { position: relative; z-index: 10; border-right: 1px solid var(--line); box-shadow: 5px 0 20px rgba(29,22,43,.035); }
.mobile-panel-close { display: none; }
.panel-page { display: none; padding: 24px 20px 30px; }
.panel-page.active { display: block; animation: panel-in .18s ease-out; }
@keyframes panel-in { from { opacity: 0; transform: translateX(-5px); } }
.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.panel-heading h1 { margin: 2px 0 0; font-size: 21px; line-height: 1.25; letter-spacing: -.025em; }
.eyebrow { color: #9993a4; font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .16em; }
.search-field {
    display: flex; align-items: center; gap: 8px; height: 39px; padding: 0 11px; margin-bottom: 24px;
    border: 1px solid var(--line); border-radius: 9px; color: #8d8798; background: #faf9fb;
}
.search-field span { font-size: 21px; line-height: 1; transform: rotate(-15deg); }
.search-field input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 13px; }
.panel-section { margin-top: 24px; }
.panel-section.separated { padding-top: 22px; border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 11px; }
.section-heading h2, .section-heading h3 { margin: 0; font-size: 12px; letter-spacing: .01em; }
.format-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.format-card {
    min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
    padding: 10px 8px 9px; border: 1px solid var(--line); border-radius: 10px; background: white; cursor: pointer;
}
.format-card:hover { border-color: #b9b2d2; }
.format-card.active { border-color: var(--purple); box-shadow: 0 0 0 2px var(--purple-soft); }
.format-card span { margin-top: 3px; font-size: 11px; font-weight: 700; }
.format-card small { color: var(--muted); font-size: 9px; }
.ratio { display: block; border: 1.5px solid #756d84; border-radius: 2px; }
.format-card.active .ratio { border-color: var(--purple); background: var(--purple-soft); }
.ratio-wide { width: 28px; height: 13px; }
.ratio-landscape { width: 25px; height: 17px; }
.ratio-portrait { width: 17px; height: 21px; }
.custom-size {
    grid-template-columns: 1fr auto 1fr; align-items: end; gap: 7px; padding: 12px; margin-top: 9px;
    border-radius: 10px; background: #f7f6f9;
}
.custom-size label { color: var(--muted); font-size: 10px; font-weight: 700; }
.custom-size input { width: 100%; margin-top: 4px; padding: 7px; border: 1px solid var(--line); border-radius: 7px; }
.custom-size .button { grid-column: 1 / -1; min-height: 34px; }
.swatch-list { display: flex; gap: 9px; }
.palette { width: 36px; height: 36px; padding: 3px; border: 1px solid transparent; border-radius: 50%; background: transparent; cursor: pointer; }
.palette i { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(135deg, var(--a), var(--b)); }
.palette.active { border-color: var(--purple); }
.color-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.color-row label { display: flex; align-items: center; justify-content: space-between; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); font-size: 11px; }
.color-row input { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 6px; background: none; }

.text-preset {
    width: 100%; display: block; padding: 14px 3px; border: 0; border-bottom: 1px solid var(--line);
    background: transparent; text-align: left; cursor: pointer;
}
.text-preset:hover { color: var(--purple); }
.title-preset { margin-top: 14px; font-size: 24px; font-weight: 800; letter-spacing: -.03em; }
.subtitle-preset { font-size: 17px; font-weight: 700; }
.body-preset { color: #4c4853; font-size: 13px; }
.commerce-card {
    width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 14px;
    border: 1px solid #f2d9dc; border-radius: 12px; background: linear-gradient(135deg, #fff9f7, #fff0f2); cursor: pointer; text-align: left;
}
.commerce-card span { display: grid; }
.commerce-card small { color: #d5475b; font-size: 8px; font-weight: 900; letter-spacing: .1em; }
.commerce-card strong { font-size: 23px; line-height: 1.1; }
.commerce-card del { color: #928895; font-size: 11px; }
.commerce-card b { padding: 7px 6px; border-radius: 7px; color: white; background: #e0465c; transform: rotate(4deg); }
.upload-dropzone {
    min-height: 132px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
    padding: 18px; border: 1.5px dashed #c9c3d2; border-radius: 13px; color: var(--ink); background: #faf9fc; cursor: pointer; text-align: center;
}
.upload-dropzone:hover { border-color: var(--purple); background: var(--purple-soft); }
.upload-dropzone > span { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 10px; color: white; background: var(--purple); font-size: 21px; }
.upload-dropzone small { color: var(--muted); font-size: 10px; }
.upload-dropzone.compact { min-height: 62px; flex-direction: row; margin-top: 10px; }
.upload-dropzone.compact > span { width: 28px; height: 28px; font-size: 16px; }
.media-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.media-preview img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 9px; border: 1px solid var(--line); }
.empty-state { grid-column: 1 / -1; margin: 8px 0; color: #aaa5b2; font-size: 11px; text-align: center; }
.range-field > span { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.range-field output { color: var(--ink); font-weight: 700; }
input[type="range"] { accent-color: var(--purple); }
.template-list, .layer-list { display: grid; gap: 6px; }
.template-item, .layer-item {
    display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px;
    border: 1px solid var(--line); border-radius: 9px; background: white; cursor: pointer; text-align: left;
}
.template-item:hover, .layer-item:hover, .layer-item.active { border-color: #c6bedf; background: #f8f6ff; }
.template-item span, .layer-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 700; }
.template-item small { color: var(--muted); font-size: 9px; }
.layer-thumb { flex: 0 0 31px !important; width: 31px; height: 31px; display: grid; place-items: center; border-radius: 7px; color: white; background: #40394d; font-size: 13px !important; }
.layer-item.reference { border-color: var(--purple); box-shadow: inset 3px 0 0 var(--purple); }
.layer-reference { flex: 0 0 auto !important; color: var(--purple); font-size: 8px !important; font-weight: 900; text-transform: uppercase; }
.template-card { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: white; }
.template-preview { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 8; overflow: hidden; background: linear-gradient(135deg, #eeeaff, #dcd6ff); }
.template-preview img { width: 100%; height: 100%; object-fit: cover; }
.template-preview > span { color: #7869ff; font-size: 24px; font-weight: 900; }
.template-meta { padding: 10px 11px 8px; }
.template-meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.template-meta p { min-height: 28px; margin: 4px 0 7px; color: var(--muted); font-size: 9px; }
.template-badges { display: flex; gap: 5px; }
.template-badges span { padding: 3px 5px; border-radius: 5px; color: #686172; background: #f2f0f5; font-size: 8px; font-weight: 700; }
.template-actions { display: grid; grid-template-columns: 1fr auto; gap: 5px; padding: 0 10px 10px; }
.template-actions .button { min-height: 32px; font-size: 10px; }
.template-actions .icon-button { width: 32px; height: 32px; color: var(--danger); background: #fff1f3; }
.variable-intro { display: flex; gap: 10px; padding: 12px; border-radius: 11px; color: #5e576a; background: var(--purple-soft); }
.variable-intro > span { flex: 0 0 auto; color: var(--purple); font-weight: 900; }
.variable-intro p { margin: 0; font-size: 10px; }
.variable-form { display: grid; gap: 10px; margin-top: 18px; }
.variable-field { padding: 11px; border: 1px solid var(--line); border-radius: 10px; background: #fbfafc; }
.variable-field > label { display: grid; gap: 6px; color: #4b4554; font-size: 10px; font-weight: 800; }
.variable-field input[type="text"] { width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: white; }
.variable-field small { display: block; margin-top: 5px; color: #9993a3; font-size: 8px; }
.variable-image-control { display: grid; grid-template-columns: 46px 1fr; align-items: center; gap: 9px; }
.variable-image-control img, .variable-image-placeholder { width: 46px; height: 46px; display: grid; place-items: center; object-fit: cover; border-radius: 8px; color: var(--purple); background: var(--purple-soft); }
.variable-image-control .button { min-height: 34px; font-size: 10px; }

.workspace { min-width: 0; min-height: 0; display: grid; grid-template-rows: 52px minmax(0, 1fr) 42px; background: var(--workspace); }
.context-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 14px;
    border-bottom: 1px solid #e3e1e8; background: rgba(255,255,255,.86); backdrop-filter: blur(12px);
}
#noSelectionHint { display: flex; align-items: center; gap: 8px; color: #8c8793; font-size: 11px; }
.hint-dot { width: 6px; height: 6px; border-radius: 50%; background: #bbb5c6; }
.text-controls { display: flex; align-items: center; gap: 6px; min-width: 0; }
.alignment-controls { display: flex; align-items: center; gap: 2px; }
.alignment-controls .icon-button { width: 30px; height: 30px; color: #5f5869; font-size: 15px; }
.toolbar-divider { width: 1px; height: 22px; margin: 0 6px 0 2px; background: var(--line); }
.text-controls select, .size-control {
    height: 34px; border: 1px solid var(--line); border-radius: 7px; color: #403b48; background: white; font-size: 11px;
}
.text-controls select { padding: 0 8px; }
.text-controls .icon-button.active { color: var(--purple); background: var(--purple-soft); }
.size-control { display: flex; align-items: center; }
.size-control input { width: 48px; border: 0; padding: 0 3px 0 8px; outline: 0; }
.size-control span { padding-right: 7px; color: var(--muted); font-size: 9px; }
.color-control { position: relative; width: 34px; height: 34px; padding: 5px; border-radius: 7px; cursor: pointer; }
.color-control:hover { background: #f1eff4; }
.color-control input { position: absolute; opacity: 0; pointer-events: none; }
.color-control i { display: block; width: 24px; height: 24px; border: 2px solid white; border-radius: 6px; background: var(--picked, #fff); box-shadow: 0 0 0 1px #c9c5cf; }
.object-actions { display: flex; margin-left: auto; }
.stage { min-width: 0; min-height: 0; overflow: auto; display: grid; place-items: center; padding: 54px; }
.canvas-shell { position: relative; transition: transform .18s ease; }
.canvas-wrapper {
    position: relative; line-height: 0; background: white; box-shadow: var(--shadow);
    transition: width .2s ease, height .2s ease;
}
.canvas-wrapper .canvas-container { line-height: initial; }
.canvas-size {
    position: absolute; left: 50%; bottom: -29px; transform: translateX(-50%); padding: 4px 8px;
    border-radius: 5px; color: #89838f; background: rgba(255,255,255,.85); font-size: 9px; line-height: 1;
    white-space: nowrap; box-shadow: 0 2px 8px rgba(35,28,45,.06);
}
.workspace-footer { display: flex; align-items: center; justify-content: space-between; padding: 0 13px; border-top: 1px solid #e3e1e8; color: #8e8995; background: white; font-size: 10px; }
.zoom-control { display: flex; align-items: center; gap: 4px; }
.zoom-control .icon-button { width: 28px; height: 28px; font-size: 14px; }
.zoom-control input { width: 80px; }
.zoom-control output { width: 35px; color: #5c5663; text-align: right; }

.properties-panel { border-left: 1px solid var(--line); padding: 22px 17px; }
.properties-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #9994a0; text-align: center; }
.properties-empty > span { width: 46px; height: 46px; display: grid; place-items: center; margin-bottom: 13px; border-radius: 15px; color: var(--purple); background: var(--purple-soft); font-size: 23px; }
.properties-empty strong { color: #4d4854; font-size: 12px; }
.properties-empty p { max-width: 180px; margin: 6px 0; font-size: 10px; }
.properties-heading { padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.properties-heading h2 { margin: 3px 0 0; font-size: 18px; }
.property-section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.property-section > label { display: grid; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 700; }
.property-help { margin: -3px 0 10px; color: #9892a0; font-size: 9px; }
#dynamicPropertyFields { display: grid; gap: 10px; }
#dynamicPropertyFields label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 700; }
.property-section textarea, .property-section input {
    width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fbfafc; resize: vertical;
}
.property-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.property-grid label { color: var(--muted); font-size: 10px; }
.property-grid input { margin-top: 5px; }
.property-section .button + .button { margin-top: 7px; }
.alignment-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.alignment-grid .button { min-height: 34px; padding: 0 5px; font-size: 9px; }
.alignment-grid .button + .button { margin-top: 0; }
.switch { position: relative; width: 34px; height: 20px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { display: block; width: 34px; height: 20px; border-radius: 999px; background: #d8d4de; transition: .18s ease; }
.switch i::after { content: ""; display: block; width: 16px; height: 16px; margin: 2px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(20,15,30,.2); transition: .18s ease; }
.switch input:checked + i { background: var(--purple); }
.switch input:checked + i::after { transform: translateX(14px); }

.toast-stack { position: fixed; z-index: 100; right: 18px; bottom: 18px; display: grid; gap: 9px; pointer-events: none; }
.toast {
    min-width: 260px; padding: 12px 14px; border: 1px solid rgba(255,255,255,.1); border-radius: 11px;
    color: white; background: #292432; box-shadow: 0 14px 35px rgba(22,17,30,.24); font-size: 12px;
    animation: toast-in .22s ease-out;
}
.toast.error { background: #a62f45; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.export-dialog { width: min(420px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 28px 90px rgba(25,18,43,.3); }
.export-dialog::backdrop { background: rgba(22,17,31,.54); backdrop-filter: blur(3px); }
.export-dialog form { position: relative; padding: 30px; text-align: center; }
.dialog-close { position: absolute; top: 10px; right: 10px; }
.dialog-icon { width: 52px; height: 52px; display: grid; place-items: center; margin: 0 auto 14px; border-radius: 16px; color: white; background: var(--purple); font-size: 25px; }
.export-dialog h2 { margin: 0; font-size: 21px; }
.export-dialog p { color: var(--muted); font-size: 12px; }
.export-summary { display: flex; justify-content: space-between; gap: 14px; padding: 12px; margin: 18px 0; border-radius: 9px; background: #f5f3f8; font-size: 11px; text-align: left; }
.export-summary span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-field { display: grid; gap: 5px; margin-top: 12px; color: #6e6876; font-size: 10px; font-weight: 700; text-align: left; }
.dialog-field input, .dialog-field textarea { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #faf9fb; resize: vertical; }
.template-variable-summary { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; margin: 14px 0; border-radius: 9px; color: #625b6c; background: var(--purple-soft); font-size: 11px; }
.template-variable-summary strong { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 7px; color: white; background: var(--purple); }
.template-dialog .button + .button { margin-top: 7px; }

@media (max-width: 1180px) {
    .editor { grid-template-columns: 70px 280px minmax(390px, 1fr); }
    .properties-panel { display: none; }
    .topbar { grid-template-columns: 260px 1fr 260px; }
}
@media (max-width: 820px) {
    .topbar { grid-template-columns: 1fr auto; }
    .document-name, .save-status, .history-actions { display: none; }
    .editor { grid-template-columns: 62px minmax(240px, 1fr); }
    .side-panel { position: absolute; z-index: 11; left: 62px; top: 64px; bottom: 0; width: 286px; transform: translateX(-105%); transition: transform .2s ease; }
    .side-panel.open { transform: translateX(0); }
    .mobile-panel-close {
        position: sticky; z-index: 4; top: 10px; float: right; display: grid; margin: 10px 10px -44px 0;
        color: #5f5968; background: #f1eff4; box-shadow: 0 2px 8px rgba(32,27,43,.08);
    }
    .workspace { grid-column: 2; }
    .stage { padding: 35px 24px 50px; }
    .context-toolbar {
        justify-content: flex-start; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
        overscroll-behavior-x: contain;
    }
    .text-controls, .alignment-controls, .object-actions { flex: 0 0 auto; }
    .object-actions { margin-left: 0; padding-right: 5px; }
}
