:root {
  color-scheme: dark;
  --theme-bg: #11161d;
  --theme-bg-grid: #18212c;
  --theme-surface: #181f28;
  --theme-surface-2: #202936;
  --theme-surface-3: #293544;
  --theme-input: #101720;
  --theme-canvas: #303946;
  --theme-sheet: #c9cdd2;
  --theme-line: #3b4757;
  --theme-line-strong: #536277;
  --theme-text: #e5e9ef;
  --theme-muted: #a7b0bd;
  --theme-accent: #5b9cff;
  --theme-accent-strong: #2f72db;
  --theme-accent-soft: #203a5f;
  --theme-success: #39b872;
  --theme-warning: #f0b429;
  --theme-danger: #e34d59;
  --theme-overlay: rgba(4, 8, 14, .76);
  --theme-shadow: 0 24px 70px rgba(0, 0, 0, .48);

  /* Совместимость существующих оболочек до завершения унификации компонентов. */
  --bg: var(--theme-bg);
  --surface: var(--theme-surface);
  --surface2: var(--theme-surface-2);
  --line: var(--theme-line);
  --text: var(--theme-text);
  --muted: var(--theme-muted);
  --blue: var(--theme-accent);
  --blue2: var(--theme-accent-strong);
  --shadow: var(--theme-shadow);
  --panel: var(--theme-surface);
  --panel-2: var(--theme-surface-2);
  --accent: var(--theme-accent);
  --server: var(--theme-warning);
  --client: var(--theme-success);
  --danger: var(--theme-danger);
  --studio-bg: var(--theme-bg);
  --studio-surface: var(--theme-surface);
  --studio-surface-2: var(--theme-surface-2);
  --studio-surface-3: var(--theme-surface-3);
  --studio-line: var(--theme-line);
  --studio-text: var(--theme-text);
  --studio-muted: var(--theme-muted);
  --studio-blue: var(--theme-accent);
  --studio-blue-strong: var(--theme-accent-strong);
  --studio-danger: var(--theme-danger);
}

.studio-inline-help {
  margin: 10px 0;
  padding: 8px 10px;
  border: 1px solid var(--theme-line);
  border-radius: 6px;
  color: var(--theme-muted);
  background: var(--theme-surface);
  font-size: 13px;
}
.studio-inline-help > summary { cursor: pointer; color: var(--theme-text); }
.studio-inline-help > p { margin: 10px 0 0; line-height: 1.5; }

:root[data-theme="light"] {
  color-scheme: light;
  --theme-bg: #e7ebf0;
  --theme-bg-grid: #d7dde5;
  --theme-surface: #f7f8fa;
  --theme-surface-2: #edf0f4;
  --theme-surface-3: #e1e6ec;
  --theme-input: #ffffff;
  --theme-canvas: #c8ced6;
  --theme-sheet: #f7f8fa;
  --theme-line: #b8c0cb;
  --theme-line-strong: #8995a5;
  --theme-text: #202833;
  --theme-muted: #566273;
  --theme-accent: #246fce;
  --theme-accent-strong: #1e5eae;
  --theme-accent-soft: #d8e7fa;
  --theme-success: #237c4b;
  --theme-warning: #946200;
  --theme-danger: #b52f3d;
  --theme-overlay: rgba(32, 40, 51, .45);
  --theme-shadow: 0 20px 55px rgba(39, 49, 63, .2);
}

.theme-toggle {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 5000;
  display: inline-grid;
  width: 38px;
  height: 38px;
  min-width: 38px;
  margin: 0;
  padding: 0;
  place-items: center;
  color: var(--theme-text);
  background: var(--theme-surface-2);
  border: 1px solid var(--theme-line-strong);
  border-radius: 9px;
  box-shadow: var(--theme-shadow);
  cursor: pointer;
  font: 700 17px/1 ui-sans-serif, system-ui, sans-serif;
}

.theme-toggle:hover {
  color: #fff;
  background: var(--theme-accent-strong);
  border-color: var(--theme-accent);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--theme-accent);
  outline-offset: 2px;
}

/* Общие служебные классы для генерируемого интерфейса редактора. */
.is-hidden { display: none !important; }
.is-invisible { visibility: hidden !important; }
.is-disabled-ui { pointer-events: none; opacity: .5; }
.ui-stack { display: flex; flex-direction: column; gap: 6px; }
.ui-row { display: flex; align-items: center; gap: 8px; }
.ui-row-wrap { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.ui-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.ui-full-width { width: 100%; }
.ui-muted { color: var(--theme-muted); }
.ui-scroll-x { overflow-x: auto; }
.ui-section { margin-bottom: 12px; padding: 10px; border: 1px solid var(--theme-line); border-radius: 5px; background: var(--theme-surface-2); }
.ui-section-title { margin-bottom: 6px; font-weight: 600; }
.ui-compact-button { padding: 4px 10px; font-size: 12px; }
.ui-color-input { width: 50px; height: 30px; }
.ui-small-number { width: 60px; }
.ui-table-input { width: 100%; }

/* Studio */
body,
.dialog-page,
.tag-config-page {
  color: var(--theme-text);
  background-color: var(--theme-bg);
}

.start-page {
  background: radial-gradient(circle at 50% 0, color-mix(in srgb, var(--theme-accent) 22%, transparent) 0, transparent 42%), var(--theme-bg);
}

.start-card,
.form-card,
.panel,
.context-menu,
.editor-header {
  color: var(--theme-text);
  background: var(--theme-surface);
  border-color: var(--theme-line);
  box-shadow: var(--theme-shadow);
}

.topbar,
.sidebar {
  color: var(--theme-text);
  background: var(--theme-surface);
  border-color: var(--theme-line);
}

.workspace,
.dialog-page,
.tag-config-page {
  background-color: var(--theme-bg);
  background-image:
    linear-gradient(var(--theme-bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--theme-bg-grid) 1px, transparent 1px);
}

.project-row,
.symbol-card,
.object-row,
.deployment-list > div,
.alarm-master,
.alarm-boundary-card,
.settings-card {
  color: var(--theme-text);
  background: var(--theme-surface-2);
  border-color: var(--theme-line);
}

.button,
.context-menu button,
input,
textarea,
select {
  color: var(--theme-text);
  background: var(--theme-input);
  border-color: var(--theme-line);
}

.context-menu button {
  background: transparent;
}

.context-menu button:hover,
.context-menu button:focus-visible {
  color: var(--theme-text);
  background: var(--theme-accent-soft);
}

.template-tree-instance:hover,
.template-tree-instance.active,
.template-tree-instance:focus-visible,
.model-tree-instance:hover,
.model-tree-instance.active,
.model-tree-instance:focus-visible {
  color: var(--theme-text);
  background: var(--theme-accent-soft);
}

.button.primary,
.logo {
  color: #fff;
  background: var(--theme-accent-strong);
  border-color: var(--theme-accent);
}

.topbar .logo {
  background: transparent;
  border-color: transparent;
}

.tab-button:hover,
.tree > a:hover,
.tree > a.active,
.template-tree-item:hover,
.template-tree-item.active,
.object-row:hover {
  color: var(--theme-text);
  background: var(--theme-surface-3);
}

.muted,
.panel-hint,
.blank-state,
.symbol-preview-empty,
.list-empty,
.tree p,
.tree > a small,
.object-row small {
  color: var(--theme-muted);
}

label,
.helptext,
.top-link,
.eyebrow,
.tree > a,
.tree p,
.template-tree-item,
.template-tree-toggle,
.tool-tabs a,
.runtime-header p,
.runtime-instance-label,
.runtime-section-actions span {
  color: var(--theme-muted);
}

.back,
.sidebar-title a,
.add-template,
.object-icon,
.object-name:hover,
.object-name:focus,
.tab-button.active,
.alarm-boundary-card h3,
.settings-card h3 {
  color: var(--theme-accent);
}

.role,
.inheritance-badge {
  color: var(--theme-accent);
  background: var(--theme-accent-soft);
}

.tool-tabs,
.deployment-list > div,
.object-row,
.tag-row.inherited-tag,
.object-row.inherited-symbol,
.alarm-master,
.alarm-boundary-card,
.settings-card {
  background: var(--theme-surface-2);
  border-color: var(--theme-line);
}

.tool-tabs a:hover,
.tab-button:hover,
.config-panel-toggle:hover {
  color: var(--theme-text);
  background: var(--theme-surface-3);
}

.tool-tabs a.active,
.object-row.selectable-object.selected {
  color: var(--theme-text);
  background: var(--theme-accent-soft);
  border-color: var(--theme-accent);
}

.config-panel-toggle {
  color: var(--theme-text);
  background: var(--theme-input);
  border-color: var(--theme-line-strong);
}

.list-empty,
.symbol-preview-empty,
.canvas-empty {
  border-color: var(--theme-line);
}

#symbol-preview-frame,
.symbol-card svg {
  background: var(--theme-sheet);
}

/* Runtime */
.runtime-header {
  color: var(--theme-text);
  background: var(--theme-surface);
  border-color: var(--theme-line);
}

.runtime-frame-panel {
  background: var(--theme-canvas);
  border-color: var(--theme-line);
}

.runtime-frame-panel iframe {
  background: var(--theme-sheet);
}

.runtime-control-section,
.runtime-value-row {
  color: var(--theme-text);
  background: var(--theme-surface-2);
  border-color: var(--theme-line);
}

/* SVG editor */
#toolbar,
#alignment-toolbar,
#inspector,
.modal-content,
.tutorial-modal {
  color: var(--theme-text);
  background: var(--theme-surface);
  border-color: var(--theme-line);
}

#canvas {
  background-color: var(--theme-canvas);
}

#background[data-no-bg="1"] {
  fill: var(--theme-sheet);
}

#toolbar button,
#alignment-toolbar button,
#inspector button,
.modal-content button,
.tutorial-modal button {
  color: var(--theme-text);
  background: var(--theme-surface-2);
  border-color: var(--theme-line);
}

#toolbar button:hover,
#alignment-toolbar button:hover,
#inspector button:hover,
.modal-content button:hover,
.tutorial-modal button:hover {
  color: var(--theme-text);
  background: var(--theme-surface-3);
  border-color: var(--theme-line-strong);
}

#studio-save-symbol,
.animation-type-button.active,
.tutorial-tab.active {
  color: #fff !important;
  background: var(--theme-accent-strong) !important;
  border-color: var(--theme-accent) !important;
}

#animation-delete-btn,
.button.danger {
  color: #fff !important;
  background: var(--theme-danger) !important;
  border-color: color-mix(in srgb, var(--theme-danger) 72%, #000) !important;
}

#inspector input,
#inspector textarea,
#inspector select,
.modal-content input,
.modal-content textarea,
.modal-content select {
  color: var(--theme-text);
  background: var(--theme-input);
  border-color: var(--theme-line);
}

.tool-number,
.studio-symbol-owner,
.tutorial-tabs,
.tutorial-tab,
#ce-left-panel,
#ce-preview,
#cc-preview,
#pa-points,
.animation-mode-table th,
.animation-mode-table td {
  color: var(--theme-text) !important;
  background: var(--theme-surface-2) !important;
  border-color: var(--theme-line) !important;
}

.modal,
.tutorial-overlay {
  background: var(--theme-overlay);
}
