:root {
    --ink: #18201f;
    --muted: #66716e;
    --line: #dfe5e2;
    --soft-line: #edf1ef;
    --paper: #ffffff;
    --canvas: #f3f5f3;
    --accent: #176b5d;
    --accent-hover: #0f574c;
    --accent-soft: #e5f3ef;
    --amber: #dc8c35;
    --danger: #b94b4b;
    --shadow: 0 12px 34px rgba(24, 32, 31, 0.12);
    --topbar-height: 66px;
    --toolbar-height: 54px;
    --status-height: 30px;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
    color: var(--ink);
    background: var(--canvas);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }

.app-shell { display: grid; grid-template-rows: var(--topbar-height) var(--toolbar-height) 1fr var(--status-height); height: 100%; }

.topbar {
    position: relative;
    z-index: 20;
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(280px, 560px) minmax(240px, 1fr);
    align-items: center;
    padding: 0 22px;
    color: #f6faf8;
    background: #172321;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
}

.brand { display: inline-flex; align-items: center; gap: 12px; width: fit-content; color: inherit; text-decoration: none; }
.brand strong { display: block; font-size: 15px; letter-spacing: 0.01em; }
.brand small { display: block; margin-top: 2px; color: #94a8a3; font-size: 10px; letter-spacing: 0.12em; }
.brand-mark { position: relative; display: block; width: 34px; height: 34px; border: 1px solid #51736b; border-radius: 10px; }
.brand-mark i { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: #71c4b2; }
.brand-mark i:nth-child(1) { left: 7px; top: 14px; }
.brand-mark i:nth-child(2) { right: 7px; top: 7px; }
.brand-mark i:nth-child(3) { right: 7px; bottom: 7px; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; left: 12px; width: 11px; height: 1px; background: #71c4b2; transform-origin: left center; }
.brand-mark::before { top: 16px; transform: rotate(-32deg); }
.brand-mark::after { top: 17px; transform: rotate(32deg); }

.topbar-center { display: flex; align-items: center; justify-content: center; min-width: 0; }
.document-dot { flex: 0 0 auto; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: #65bca9; box-shadow: 0 0 0 4px rgba(101, 188, 169, 0.12); }
.document-dot.dirty { background: var(--amber); box-shadow: 0 0 0 4px rgba(220, 140, 53, 0.14); }
.document-name { min-width: 120px; max-width: 300px; padding: 6px 9px; overflow: hidden; color: #f6faf8; background: transparent; border: 1px solid transparent; border-radius: 6px; font-weight: 600; text-align: center; text-overflow: ellipsis; }
.document-name:hover, .document-name:focus { outline: none; border-color: #3c504c; background: rgba(255, 255, 255, 0.04); }
.save-state { flex: 0 0 auto; margin-left: 8px; color: #80938e; font-size: 11px; }

.topbar-meta { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.console-link { padding: 6px 9px; color: #c7d5d1; border: 1px solid #344844; border-radius: 7px; font-size: 11px; font-weight: 650; text-decoration: none; transition: 150ms ease; }
.console-link:hover { color: white; border-color: #617b75; background: rgba(255, 255, 255, 0.04); }
.engine-badge { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; color: #c7d5d1; border: 1px solid #344844; border-radius: 99px; font-size: 11px; font-weight: 650; letter-spacing: 0.04em; }
.engine-badge span { width: 6px; height: 6px; border-radius: 50%; background: #6ac3af; box-shadow: 0 0 8px #6ac3af; }
.icon-button { width: 30px; height: 30px; padding: 0; color: #aabbb7; background: transparent; border: 1px solid #344844; border-radius: 8px; cursor: pointer; }
.icon-button:hover { color: white; border-color: #617b75; }

.toolbar { position: relative; z-index: 15; display: flex; align-items: center; gap: 12px; padding: 0 18px; background: var(--paper); border-bottom: 1px solid var(--line); }
.toolbar-group { display: flex; align-items: center; gap: 7px; }
.toolbar-group label { color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: 0.02em; white-space: nowrap; }
.toolbar-divider { width: 1px; height: 24px; background: var(--line); }
.toolbar-spacer, .statusbar-spacer { flex: 1; }

.tool-button, .tool-icon, .primary-button { display: inline-flex; align-items: center; justify-content: center; border-radius: 7px; cursor: pointer; transition: 150ms ease; }
.tool-button { gap: 6px; min-height: 34px; padding: 0 11px; color: #35413f; background: white; border: 1px solid var(--line); font-size: 12px; font-weight: 600; }
.tool-button:hover { border-color: #aebbb7; background: #f8faf9; }
.tool-button:active, .tool-icon:active, .primary-button:active { transform: translateY(1px); }
.tool-button.compact { min-height: 30px; padding: 0 9px; }
.tool-button span { color: var(--accent); font-size: 16px; line-height: 1; }
.tool-icon { width: 32px; height: 32px; padding: 0; color: #53605d; background: transparent; border: 1px solid transparent; font-size: 18px; }
.tool-icon:hover { color: var(--accent); background: var(--accent-soft); }
.tool-icon:disabled { opacity: 0.35; cursor: default; }
.primary-button { gap: 7px; min-height: 36px; padding: 0 15px; color: white; background: var(--accent); border: 1px solid var(--accent); box-shadow: 0 3px 10px rgba(23, 107, 93, 0.18); font-size: 12px; font-weight: 700; }
.primary-button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.primary-button:disabled { opacity: 0.6; cursor: wait; }
.deploy-icon { font-size: 16px; }

.deployed-group select { width: min(26vw, 300px); height: 32px; padding: 0 30px 0 10px; color: #34403e; background: #f8faf9; border: 1px solid var(--line); border-radius: 7px; font-size: 12px; outline: none; }
.deployed-group select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 318px; min-height: 0; }
.canvas-panel { position: relative; min-width: 0; min-height: 0; overflow: hidden; background-color: var(--canvas); background-image: radial-gradient(#ccd3d0 0.7px, transparent 0.7px); background-size: 18px 18px; }
.canvas { width: 100%; height: 100%; }
.canvas .djs-container, .canvas svg { background: transparent !important; }
.canvas .djs-palette { top: 20px; left: 20px; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(34, 46, 43, 0.1); overflow: hidden; }
.canvas .djs-palette .entry:hover { color: var(--accent); }
.canvas .djs-context-pad { filter: drop-shadow(0 5px 8px rgba(24, 32, 31, 0.14)); }
.canvas .djs-outline { stroke: var(--accent) !important; }
.canvas .djs-element.selected .djs-outline { stroke-width: 2px !important; }

.canvas-controls { position: absolute; right: 18px; bottom: 18px; display: flex; overflow: hidden; background: white; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 18px rgba(24, 32, 31, 0.1); }
.canvas-controls button { height: 34px; padding: 0 11px; background: white; border: 0; border-right: 1px solid var(--line); cursor: pointer; font-size: 12px; font-weight: 600; }
.canvas-controls button:last-child { border-right: 0; }
.canvas-controls button:hover { color: var(--accent); background: var(--accent-soft); }
.canvas-guide { position: absolute; left: 82px; bottom: 18px; display: flex; align-items: center; gap: 8px; padding: 8px 11px; color: #697370; background: rgba(255, 255, 255, 0.88); border: 1px solid rgba(223, 229, 226, 0.9); border-radius: 8px; backdrop-filter: blur(6px); font-size: 11px; }
.guide-key { padding: 2px 5px; color: var(--accent); background: var(--accent-soft); border-radius: 4px; font-size: 9px; font-weight: 800; letter-spacing: 0.08em; }

.drop-hint { position: absolute; inset: 14px; z-index: 30; display: none; place-items: center; background: rgba(229, 243, 239, 0.92); border: 2px dashed var(--accent); border-radius: 14px; pointer-events: none; }
.drop-hint.visible { display: grid; }
.drop-hint div { display: grid; gap: 6px; text-align: center; }
.drop-hint strong { color: var(--accent); font-size: 18px; }
.drop-hint span { color: var(--muted); font-size: 12px; }

.properties-panel { min-width: 0; overflow-y: auto; background: var(--paper); border-left: 1px solid var(--line); }
.properties-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; min-height: 78px; padding: 16px 18px; background: rgba(255, 255, 255, 0.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px); }
.eyebrow { display: block; color: #88938f; font-size: 9px; font-weight: 800; letter-spacing: 0.14em; }
.properties-header h2, .dialog-heading h2 { margin: 4px 0 0; font-size: 16px; line-height: 1.25; }
.element-type { max-width: 118px; padding: 4px 7px; overflow: hidden; color: var(--accent); background: var(--accent-soft); border-radius: 5px; font-size: 9px; font-weight: 800; letter-spacing: 0.08em; text-overflow: ellipsis; white-space: nowrap; }
.property-section { padding: 18px; border-bottom: 1px solid var(--soft-line); }
.property-section h3 { margin: 0 0 14px; font-size: 11px; letter-spacing: 0.04em; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading span { padding: 3px 5px; color: #7b5b28; background: #faefd9; border-radius: 4px; font-size: 8px; font-weight: 800; letter-spacing: 0.1em; }
.field { display: grid; gap: 6px; margin-top: 12px; color: #4e5a57; font-size: 11px; font-weight: 650; }
.field input, .field textarea { width: 100%; padding: 9px 10px; color: var(--ink); background: #fbfcfb; border: 1px solid var(--line); border-radius: 7px; outline: none; font-size: 12px; font-weight: 450; resize: vertical; transition: 150ms ease; }
.field input:focus, .field textarea:focus { background: white; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field small { color: #8a9491; font-size: 9px; font-weight: 450; line-height: 1.45; }
.field.invalid input { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(185, 75, 75, 0.08); }
.empty-properties { display: grid; justify-items: center; padding: 70px 28px; color: #7a8582; text-align: center; }
.empty-properties span { margin-bottom: 14px; color: #a6b0ad; font-size: 30px; }
.empty-properties strong { color: #4c5855; font-size: 13px; }
.empty-properties p { max-width: 220px; margin: 8px 0 0; font-size: 11px; line-height: 1.6; }

.statusbar { display: flex; align-items: center; gap: 18px; padding: 0 16px; color: #68726f; background: #eef1ef; border-top: 1px solid #d8dedb; font-size: 10px; }
.online-dot { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: #3aaa84; }

.toast-region { position: fixed; z-index: 100; right: 22px; bottom: 50px; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 260px; max-width: 390px; padding: 12px 14px; color: #f7fbf9; background: #21302d; border: 1px solid #3c504b; border-radius: 9px; box-shadow: var(--shadow); font-size: 12px; line-height: 1.5; animation: toast-in 180ms ease-out; }
.toast.error { background: #502d2d; border-color: #794242; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.dialog { width: min(440px, calc(100vw - 32px)); padding: 0; color: var(--ink); background: white; border: 0; border-radius: 14px; box-shadow: 0 24px 70px rgba(18, 30, 27, 0.25); }
.dialog::backdrop { background: rgba(18, 28, 26, 0.56); backdrop-filter: blur(3px); }
.dialog form, .help-dialog { position: relative; padding: 26px; }
.dialog-icon { position: absolute; top: 26px; right: 26px; display: grid; place-items: center; width: 38px; height: 38px; color: var(--accent); background: var(--accent-soft); border-radius: 10px; font-size: 21px; }
.dialog-heading { padding-right: 48px; }
.dialog-heading p { margin: 8px 0 20px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.shortcut-list { display: grid; gap: 0; margin: 20px 0 0; }
.shortcut-list div { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--soft-line); }
.shortcut-list dt { color: #45514e; font-size: 12px; }
.shortcut-list dd { margin: 0; padding: 4px 7px; color: #58635f; background: #f1f3f2; border: 1px solid var(--line); border-radius: 5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }

@media (max-width: 1050px) {
    .topbar { grid-template-columns: 230px 1fr auto; }
    .save-state, .toolbar-group label, #export-svg-button { display: none; }
    .deployed-group select { width: 190px; }
    .workspace { grid-template-columns: minmax(0, 1fr) 286px; }
}

@media (max-width: 760px) {
    :root { --topbar-height: 58px; --toolbar-height: 104px; }
    .topbar { grid-template-columns: auto 1fr auto; padding: 0 12px; }
    .brand small, .engine-badge, .topbar-center .document-dot { display: none; }
    .brand strong { font-size: 12px; }
    .brand-mark { width: 30px; height: 30px; }
    .document-name { max-width: 150px; font-size: 12px; }
    .toolbar { align-content: center; flex-wrap: wrap; gap: 7px; padding: 8px 10px; }
    .toolbar-divider { display: none; }
    .toolbar-spacer { display: none; }
    .deployed-group { order: 3; width: 100%; }
    .deployed-group select { flex: 1; width: auto; }
    .workspace { grid-template-columns: 1fr; }
    .properties-panel { position: absolute; z-index: 25; right: 0; bottom: var(--status-height); width: min(318px, 90vw); height: calc(100% - var(--topbar-height) - var(--toolbar-height) - var(--status-height)); box-shadow: -10px 0 30px rgba(24, 32, 31, 0.12); }
    .canvas-guide { display: none; }
}
