* { box-sizing: border-box; }
html, body, #app { margin: 0; padding: 0; height: 100%; }

:root {
  --bg: #f7f9f6;
  --bg-alt: #eef3ee;
  --panel: #ffffff;
  --panel-border: #dfe6de;
  --panel-shadow: none;
  --text: #1c2420;
  --muted: #6c7b72;
  --line: #dfe6de;
  --accent: #45d17a;
  --accent-contrast: #0b120e;
  --pill: #f2f6f1;
  --pill-border: #d5e0d3;
  --input-bg: #f9fbf8;
  --input-border: #dfe6de;
  --card: #ffffff;
  --code-bg: #f4f7f4;
  --code-border: #e4ece3;
  --drag: rgba(69, 209, 122, 0.12);
  --success: #45d17a;
}

body.theme-dark {
  --bg: #0f1113;
  --bg-alt: #11161c;
  --panel: #151a1f;
  --panel-border: #1f262d;
  --panel-shadow: none;
  --text: #e6edf5;
  --muted: #9aa8b8;
  --line: #1f262d;
  --accent: #45d17a;
  --accent-contrast: #0b0f12;
  --pill: #1a2026;
  --pill-border: #232b33;
  --input-bg: #12181f;
  --input-border: #1f262d;
  --card: #151a1f;
  --code-bg: #0d1319;
  --code-border: #1b242d;
  --drag: rgba(69, 209, 122, 0.18);
  --success: #45d17a;
}

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
}

.page {
  min-height: 100vh;
  background: var(--bg);
  display: grid;
  grid-template-columns: auto 1fr;
}

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 20px 32px;
  gap: 20px;
  min-height: 100vh;
}

.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 20px 10px;
  position: sticky;
  top: 0;
  background: #000000;
  border-bottom: 1px solid var(--line);
  z-index: 10;
  width: calc(100% + 40px);
  margin-left: -20px;
}
.workspace-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
}
.preset-links {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.preset-links .text-link {
  background: transparent;
  border: none;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 4px;
  border-radius: 6px;
}
.preset-links .text-link:hover {
  color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
}
.preset-links .text-link:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}
.preset-links-sidebar {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin: 2px 0 6px;
}

.workspace-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.workspace-breadcrumb {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.workspace-breadcrumb .sep { opacity: 0.6; }

.ghost-link {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 1px;
}
.ghost-link:hover {
  color: var(--text);
  border-color: var(--text);
}

.btn-textual {
  width: auto;
  min-width: unset;
  padding: 6px 12px;
  font-weight: 600;
}
.btn-textual span {
  font-size: 12px;
  letter-spacing: 0.03em;
}
.btn-textual.danger {
  border-color: #ba473a;
  color: #ba473a;
  background: rgba(186, 71, 58, 0.08);
}

.workspace-header-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex: 0 0 auto;
  justify-content: flex-end;
}
.header-status {
  font-size: 12px;
  color: var(--success);
  white-space: nowrap;
}
.workspace-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.image-base-field {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}
.image-base-input {
  width: 100%;
  min-width: 260px;
  max-width: none;
  height: auto;
  padding: 4px 2px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
}
.image-base-input:focus {
  outline: none;
  border: none;
  box-shadow: none;
}
.workspace-header-actions .btn[aria-pressed="true"],
.workspace-header-actions .btn.toggled {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.workspace-header-actions .btn[aria-pressed="true"]:hover,
.workspace-header-actions .btn.toggled:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.workspace-header .pug-actions {
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  gap: 3px;
}

.workspace-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.workspace-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.workspace-subtitle {
  font-size: 14px;
  color: var(--muted);
}

.workspace-grid {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(560px, 820px) minmax(360px, 460px);
  gap: 10px;
  align-items: start;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.panel-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.panel-subtitle { font-size: 12px; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.theme-toggle-inner { display: flex; align-items: center; gap: 6px; }
.theme-icon { display: none; }
.theme-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.theme-slider {
  position: absolute; inset: 0;
  cursor: pointer;
  background: var(--pill);
  border-radius: 999px;
  transition: 0.2s;
  border: none;
}
.theme-slider::before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 5px;
  top: 5px;
  background: #fefefe;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: none;
}
.theme-slider::after {
  content: none;
}
.theme-switch input:checked + .theme-slider { background: #3e444c; border-color: #3e444c; }
.theme-switch input:checked + .theme-slider::before { transform: translateX(20px); background: #fefefe; }
.theme-switch input:checked + .theme-slider::after {
  right: 26px;
  background: var(--accent-contrast);
}

.theme-slider::after {
  content: none;
}

.panel-left { max-width: 780px; width: 100%; }
.panel-right { width: 100%; max-width: 460px; }

.id-manager-panel {
  width: 100%;
  margin-bottom: 14px;
  padding: 10px 8px;
  border: none;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--panel-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.id-manager-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.id-manager-title { font-weight: 700; font-size: 14px; letter-spacing: 0.02em; }
.id-manager-count { font-size: 12px; color: var(--muted); }

.id-manager-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-start;
}

.id-manager-input {
  width: 100%;
  min-height: 60px;
  padding: 6px 6px;
  border-radius: 10px;
  border: none;
  background: transparent;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  font-size: 13px;
  color: var(--text);
  resize: vertical;
}

.id-manager-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  max-height: 110px;
  overflow-y: auto;
}

.id-manager-preview .id-chip {
  padding: 2px 6px;
  border-radius: 8px;
  background: var(--pill);
  border: 1px solid var(--pill-border);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--text);
  outline: none;
  min-width: 0;
  max-width: none;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: max-content;
  width: fit-content;
  flex: 0 0 auto;
  white-space: nowrap;
}
.id-manager-preview .id-chip:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.id-manager-preview .id-chip.free {
  background: rgba(52, 211, 153, 0.08);
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--text);
}
.id-manager-preview .id-chip.used {
  text-decoration: line-through;
  color: var(--muted);
  opacity: 0.6;
  background: transparent;
}

.id-manager-hint {
  font-size: 12px;
  color: var(--muted);
}

.tabs { display: inline-flex; gap: 8px; margin-bottom: 0; }
.tabs button {
  padding: 4px 8px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  transition: all 140ms ease;
  font-weight: 600;
  min-height: 26px;
}
.tabs button:hover { background: var(--pill); color: var(--text); }
.tabs button.tab-active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); font-weight: 700; }
.tabs-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sidebar-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.sidebar-separator {
  width: 100%;
  height: 1px;
  background: var(--panel-border);
  margin: 4px 0 8px;
}
.tabs-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tabs-actions .btn.toggled {
  outline: 1px solid var(--accent);
  box-shadow: none;
}
.price-toggle {
  min-width: 32px;
  min-height: 30px;
  padding: 0;
  justify-content: center;
  font-weight: 700;
  border-radius: 6px;
}
.price-toggle[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  color: var(--text);
  border-radius: 12px;
  box-shadow: var(--panel-shadow);
}

.control-panel {
  width: 320px;
  padding: 15px 20px 20px;
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: none;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  gap: 16px;
}

.control-panel-title {
  font-size: 28px;
  font-weight: 100;
  letter-spacing: 0.02em;
  color: var(--text);
  margin-bottom: 10px;
}

.meta-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 1px;
}
.meta-panel label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.meta-panel input {
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
}

.sidebar-separator {
  height: 2px;
  background: var(--line);
  opacity: 0.75;
  margin: 1px 0;
}

.quick-preset-panel label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.preset-preview {
  padding: 10px;
  border-radius: 10px;
  border: 1px dashed var(--input-border);
  background: var(--input-bg);
}
.preset-preview-title {
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}
.preset-preview-desc {
  font-size: 12px;
  color: var(--muted);
}

.note-templates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.change-log {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  background: var(--panel);
  box-shadow: var(--panel-shadow);
  gap: 6px;
}
.change-log ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.change-log li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text);
}
.change-log li time {
  font-size: 11px;
  color: var(--muted);
}
.change-log-empty {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.7;
}

.id-manager-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-start;
}
.id-manager-panel .btn {
  padding: 5px 10px;
  min-height: 28px;
}
.id-manager-panel .btn.icon-square {
  width: 28px;
  min-width: 28px;
  height: 28px;
}

.dot-loader {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ba473a;
  display: inline-block;
  animation: dotPulse 0.8s infinite alternate;
  margin-right: 4px;
}

@keyframes dotPulse {
  to {
    transform: scale(0.6);
    opacity: 0.4;
  }
}
.panel.panel-left,
.panel.panel-right {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  border-radius: 0;
}
.panel.panel-left .blocks-container {
  padding: 10px 8px 14px;
}
.panel-sidebar {
  align-self: stretch;
  gap: 8px;
}
.panel-sidebar .sidebar-group { display: flex; flex-direction: column; gap: 6px; }
.panel-sidebar .sidebar-title { font-size: 12px; color: var(--muted); font-weight: 700; }
details.sidebar-group > summary.sidebar-title {
  cursor: pointer;
  user-select: none;
}
.sidebar-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}
.control-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-start;
}
.notes-area {
  width: 100%;
  min-height: 110px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  resize: vertical;
  font-size: 12px;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
}

.panel h1, .panel h2 { margin: 0 0 6px; font-weight: 700; color: var(--text); letter-spacing: 0.01em; }
.panel h1 { font-size: 16px; }
.panel h2 { font-size: 14px; }

.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px 10px;
  align-items: end;
  margin-bottom: 8px;
  position: sticky;
  top: 10px;
  z-index: 5;
  background: var(--panel);
  padding: 4px 0 4px;
}
.toolbar-field { display: flex; flex-direction: column; gap: 6px; }
.folder-field {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
.folder-field .folder-btn { align-self: flex-start; width: 32px; }
.folder-field .field-control { width: 100%; min-width: 360px; }
.folder-actions { display: flex; align-items: center; gap: 4px; }
.btn.icon-square {
  width: 32px;
  min-width: 32px;
  height: 30px;
  padding: 0;
  justify-content: center;
  font-size: 13px;
}
.btn.icon-square.btn-textual {
  width: auto;
  min-width: 0;
  height: 32px;
  padding: 6px 8px;
  justify-content: flex-start;
}
.btn.icon-square.triangle { font-size: 13px; }
.btn.icon-square.danger {
  border-color: #ba473a;
  color: #ba473a;
}
.btn.icon-square.danger:hover { background: rgba(186, 71, 58, 0.14); border-color: #ba473a; }
.small-actions { display: flex; align-items: center; gap: 6px; }

.sidebar-row .folder-actions { flex: 0 0 auto; justify-content: flex-start; flex-wrap: nowrap; }
.folder-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  min-height: 40px;
  flex: 0 0 auto;
}

.field-label { font-size: 12px; color: var(--muted); letter-spacing: 0.01em; }
.field-control {
  padding: 7px 9px;
  font-size: 13px;
  min-width: 240px;
  height: 34px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: 8px;
  box-shadow: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field-control:focus { outline: none; border-color: #d1ccbf; box-shadow: none; }

.hint { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

.btn {
  padding: 7px 12px;
  font-size: 13px;
  border: 1px solid var(--pill-border);
  background: var(--pill);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 10px;
  transition: all 140ms ease;
  font-weight: 600;
  min-height: 32px;
}
.btn:hover { border-color: var(--accent); background: var(--panel); }
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.25);
}
.btn.reset-btn {
  border-color: #ba473a;
  color: #ba473a;
  background: rgba(186, 71, 58, 0.08);
  font-weight: 600;
}
.btn.reset-btn:hover {
  background: rgba(186, 71, 58, 0.16);
  border-color: #ba473a;
  color: #ba473a;
}
.btn.reset-btn:disabled {
  opacity: 0.35;
  color: rgba(186, 71, 58, 0.55);
  border-color: rgba(186, 71, 58, 0.4);
  background: rgba(186, 71, 58, 0.08);
}
.btn.ghost { background: transparent; border-style: dashed; border-color: var(--panel-border); color: var(--muted); }
.btn.ghost:hover { background: var(--pill); border-color: var(--accent); color: var(--text); }
.folder-btn { font-weight: 600; }
.folder-btn { min-width: 38px; min-height: 32px; padding: 0; justify-content: center; }
#copy-btn.btn-primary, #copy-btn-top.btn-primary, #export-btn.btn-primary, #export-btn-top.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
#copy-btn.btn-primary:hover, #copy-btn-top.btn-primary:hover, #export-btn.btn-primary:hover, #export-btn-top.btn-primary:hover {
  box-shadow: none;
}
.pug-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 0;
}
.pug-actions .btn {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.pug-actions .btn:hover {
  border-color: var(--accent);
  background: var(--pill);
}
.pug-actions .btn.danger {
  color: #ba473a;
  border: none;
  background: transparent;
}
.pug-actions .btn.danger:hover {
  border: none;
  background: rgba(186, 71, 58, 0.12);
}

.blocks-container {
  margin-top: 6px;
  border-top: none;
  padding-top: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.segment-divider {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 2px 0;
}
.segment-divider::before,
.segment-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
  opacity: 0.4;
}
.segment-divider span {
  font-weight: 600;
  color: var(--muted);
}

.block-card {
  border: 1px solid var(--panel-border);
  padding: 9px 10px 10px 14px;
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  box-shadow: none;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
  position: relative;
}
.block-card:hover {
  background: var(--pill);
  border-color: var(--accent);
  box-shadow: none;
}
.block-card.dragging {
  border-color: var(--accent);
  background: var(--pill);
  transform: scale(0.99);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.26), 0 0 0 1px rgba(69, 209, 122, 0.35);
  cursor: grabbing;
}
.block-card.dragging * { cursor: grabbing; }
.block-card.collapsed {
  padding: 6px 10px 6px 14px;
  min-height: 26px;
}
.block-card.collapsed .block-title { opacity: 0.92; }
.block-card.collapsed .block-header { margin-bottom: 0; }
.block-card::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 999px;
  background: transparent;
  opacity: 0.85;
}
.block-card.marker-female::before { background: #ba473a; }
.block-card.marker-male::before { background: #2a6cc6; }
.block-card.marker-common::before { background: #6b7b70; opacity: 0.4; }
.block-card.marker-center::before { background: #6ac18f; opacity: 1; }

.block-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; gap: 6px; }
.block-title { font-weight: 700; font-size: 12px; color: var(--text); display: flex; align-items: center; gap: 4px; letter-spacing: 0.01em; }
.block-title.clickable { cursor: pointer; }
.block-actions { display: inline-flex; align-items: center; gap: 3px; margin-left: auto; }

.collapse-btn {
  border: 1px solid var(--panel-border);
  background: var(--pill);
  color: var(--text);
  border-radius: 8px;
  width: 26px;
  height: 24px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 12px;
  transition: background 120ms ease, border-color 120ms ease;
}
.collapse-btn:hover { background: #ebe8e0; border-color: #dcd6c9; }

.segment-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 0 3px;
  margin-right: 2px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: var(--text);
  font-weight: 700;
  font-size: 10px;
  line-height: 1.1;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
}

.segment-switch { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; }
.segment-toggle {
  display: inline-flex;
  border: none;
  border-radius: 10px;
  overflow: visible;
  background: transparent;
  gap: 2px;
}
.segment-toggle button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0 5px;
  height: 24px;
  min-width: 22px;
  font-size: 11px;
  cursor: pointer;
  line-height: 1.2;
  border-radius: 6px;
  transition: all 120ms ease;
}
.segment-toggle button:focus,
.segment-toggle button:focus-visible {
  outline: none;
  box-shadow: none;
  border-radius: 8px;
}
.segment-toggle button + button { border-left: none; }
.segment-toggle button.active {
  font-weight: 700;
  border-radius: 8px;
}
.segment-toggle button:nth-child(1).active { color: #4b4c46; border-color: #4b4c46; }
.segment-toggle button:nth-child(2).active { color: #ba473a; border-color: #ba473a; }
.segment-toggle button:nth-child(3).active { color: #2a6cc6; border-color: #2a6cc6; }
.segment-toggle.compact { transform: none; }

.block-actions button {
  margin-left: 2px;
  padding: 0 6px;
  height: 24px;
  min-height: 24px;
  font-size: 11px;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 120ms ease;
}
.block-actions button:hover { background: rgba(69, 209, 122, 0.12); color: var(--text); border-color: var(--accent); }
.block-actions .segment-toggle button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0 6px;
  height: 24px;
  min-width: 22px;
  font-size: 11px;
  border-radius: 6px;
}
.block-actions .segment-toggle button:hover { background: transparent; color: var(--text); }
.block-actions .segment-toggle button:focus,
.block-actions .segment-toggle button:focus-visible {
  outline: none;
  box-shadow: none;
  border-radius: 8px;
}
.block-actions .segment-toggle button:nth-child(1).active { background: transparent; color: #4b4c46; border-color: #4b4c46; border-radius: 8px; }
.block-actions .segment-toggle button:nth-child(2).active { background: transparent; color: #ba473a; border-color: #ba473a; border-radius: 8px; }
.block-actions .segment-toggle button:nth-child(3).active { background: transparent; color: #2a6cc6; border-color: #2a6cc6; border-radius: 8px; }
.block-actions .icon-btn {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  justify-content: center;
  align-items: center;
  padding: 0;
  border: none;
  background: transparent;
}
.block-actions .icon-btn svg { display: block; }
.block-actions .icon-btn.danger { color: #ba473a; }
.block-actions .icon-btn.danger:hover { background: rgba(186,71,58,0.18); color: #ba473a; }

.block-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 4px;
}
.block-summary {
  flex: 0 1 220px;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  font-size: 10px;
  color: var(--muted);
  opacity: 0.9;
}
.block-issues {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
}
.issue-badge {
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid rgba(186, 71, 58, 0.35);
  color: #ba473a;
}

.drag-placeholder { height: 8px; margin: 8px 0; background: var(--drag); border-radius: 999px; }
.block-drag-handle { display: inline-flex; align-items: center; justify-content: center; width: 18px; cursor: grab; color: #9b9b97; user-select: none; }
.block-drag-handle:active { cursor: grabbing; }

.block-body { font-size: 13px; display: grid; gap: 6px; }
.block-body label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }

.block-body input[type="checkbox"],
.block-body input[type="radio"],
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

.block-body input[type="text"],
.block-body input[type="number"],
.block-body textarea,
select.field-control {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  margin-top: 2px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: 10px;
  box-shadow: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.block-body input[type="text"]:focus,
.block-body input[type="number"]:focus,
.block-body textarea:focus,
select.field-control:focus {
  outline: none;
  border-color: #d1ccbf;
  box-shadow: none;
}

.block-body textarea { min-height: 70px; resize: vertical; }
.block-body .singleline-textarea { min-height: 36px; height: 36px; resize: none; }
.block-body .inline { display: flex; align-items: center; gap: 10px; margin: 2px 0; }
.block-body .inline label { display: flex; align-items: center; gap: 6px; margin: 0; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(43,47,52,0.35);
  outline-offset: 2px;
}

.code-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--panel-border);
  margin-bottom: 8px;
}
.code-panel-title { font-size: 18px; font-weight: 600; letter-spacing: 0.01em; }
.code-panel-subtitle { font-size: 12px; color: var(--muted); }
.code-panel-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.code-panel-actions .btn {
  font-size: 12px;
  padding: 5px 10px;
  min-height: 28px;
  border-style: solid;
  border-color: var(--panel-border);
  background: var(--pill);
}

textarea#pug-output {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  font-family: "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  border: none;
  background: transparent;
  color: var(--text);
  resize: none;
  white-space: pre;
  min-height: calc(100vh - 120px);
  max-height: calc(100vh - 120px);
  height: calc(100vh - 120px);
  overflow: auto;
  border-radius: 12px;
  box-shadow: none;
}

.copy-status { margin-top: 4px; font-size: 12px; color: var(--success); }
.code-collapsed-hint {
  border: 1px dashed var(--panel-border);
  border-radius: 12px;
  padding: 16px;
  font-size: 13px;
  color: var(--muted);
  background: var(--panel);
}

.footer-note { margin: 8px 0 16px; text-align: left; font-size: 11px; color: var(--muted); opacity: 0.85; }
.footer-link { color: var(--text); text-decoration: none; border-bottom: 1px dashed var(--muted); }
.footer-link:hover { color: var(--accent); }

@media (max-width: 1200px) {
  .workspace { padding: 0 20px 24px; }
  .workspace-grid { grid-template-columns: 1fr; }
  .panel-right { max-width: 100%; }
}

@media (max-width: 960px) {
  .notion-layout { flex-direction: column; }
  .control-panel {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
    border-radius: 0 0 12px 12px;
  }
  .workspace { padding-top: 20px; }
  .workspace-header { position: relative; }
  .field-control { min-width: 240px; }
}

.preset-list { display: grid; gap: 10px; }
.preset-card {
  border: 1px solid var(--line);
  background: var(--card);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-radius: 12px;
  box-shadow: none;
}
.preset-title { font-weight: 700; color: var(--text); letter-spacing: 0.01em; }
.preset-desc { font-size: 13px; color: var(--muted); }
.preset-fields { display: grid; gap: 10px; margin: 4px 0; }
.html-pug-fields {
  margin: 8px 0 10px;
}
.html-pug-fields .html-pug-label {
  display: block;
  font-weight: 100;
  font-size: 11px;
  color: var(--muted);
}
.html-pug-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.html-pug-path {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#html-pug-path {
  margin-top: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
}
#html-pug-path:focus {
  border-bottom-color: var(--accent);
  box-shadow: none;
}
#html-pug-preheader {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
}
#html-pug-preheader:focus {
  border-bottom-color: var(--accent);
  box-shadow: none;
}
.html-pug-grow {
  flex: 1 1 auto;
}
.html-pug-actions {
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}
.save-status {
  margin-top: 4px;
  font-size: 12px;
  color: var(--success);
}
.html-pug-actions .btn-inline-row {
  margin-top: 10;
}
.html-pug-actions .btn-inline {
  height: 26px;
  min-height: 26px;
  line-height: 1;
}
.html-pug-gender .btn-inline:hover {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}
.html-pug-copy.btn.icon-square.btn-textual {
  margin-left: auto;
  height: 26px;
  min-height: 26px;
  padding: 4px 8px;
  line-height: 1;
}
.html-pug-gender .btn-inline.female.active,
.html-pug-gender .btn-inline.female.active:hover {
  color: #ba473a;
  border-color: #ba473a;
}
.html-pug-gender .btn-inline.male.active,
.html-pug-gender .btn-inline.male.active:hover {
  color: #2a6cc6;
  border-color: #2a6cc6;
}
.autosave-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  margin-left: 6px;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.4s ease, background 0.4s ease, border-color 0.4s ease, transform 0.4s ease, box-shadow 0.4s ease;
}
.autosave-dot.active {
  opacity: 1;
  background: var(--success);
  border-color: var(--success);
  transform: scale(1);
  box-shadow: 0 0 6px rgba(69, 209, 122, 0.6);
}
.preset-fields textarea {
  min-height: 70px;
  resize: vertical;
  padding: 8px 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  min-width: 320px;
  width: 100%;
  border-radius: 1px;
}
.preset-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preset-row label { width: 100%; }
.preset-advanced { margin-top: 6px; }

.custom-presets { display: grid; gap: 8px; }
.custom-preset-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
.custom-preset-name { font-weight: 600; color: var(--text); }
.custom-preset-actions button { margin-left: 6px; }

.btn-inline {
  margin-top: 2px;
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid var(--line);
  background: var(--pill);
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  width: auto;
  align-self: flex-start;
  justify-self: flex-start;
  grid-column: auto;
  max-width: 80px;
}
.btn-inline:hover {
  background: #2f8f55;
  border-color: #2f8f55;
  color: var(--accent-contrast);
}
.btn-inline.active {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-inline.active:hover {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-inline.push-right { margin-left: auto; }
.btn-inline-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.btn-inline.vk-btn {
  box-sizing: border-box;
  height: 34px;
  padding: 0 4px;
  min-width: 24px;
  background: transparent;
  border: none;
  line-height: 1;
}
.btn-inline.vk-btn:hover {
  background: transparent;
  border: none;
  color: var(--text);
}
.btn-inline.vk-btn.active,
.btn-inline.vk-btn.active:hover {
  background: transparent;
  border: none;
  color: var(--accent);
}

.advanced-wrapper { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.btn-advanced-toggle {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 11px;
  padding: 0;
  cursor: pointer;
  text-decoration: underline dotted;
  margin-bottom: 4px;
}
.btn-advanced-toggle.is-open { color: var(--text); }
.advanced-panel label { margin-bottom: 6px; font-size: 11px; }

.block-preview {
  margin: 6px auto 10px;
  padding: 10px;
  border: 1px dashed var(--line);
  background: var(--card);
  color: var(--text);
  min-height: 40px;
  width: 540px;
  max-width: 100%;
  text-align: center;
}
.paragraph-textarea {
  font-size: 18px;
  line-height: 27px;
  font-family: Helvetica, Arial, sans-serif;
}
.paragraph-preview {
  font-size: 18px;
  line-height: 27px;
  font-family: Helvetica, Arial, sans-serif;
}

.theme-light textarea#pug-output,
.theme-light .field-control,
.theme-light .preset-fields textarea,
.theme-light .block-body input[type="text"],
.theme-light .block-body input[type="number"],
.theme-light .block-body textarea { background: var(--input-bg); color: var(--text); }
.block-card:focus-within { outline: 2px solid rgba(43,47,52,0.16); outline-offset: 2px; }
.icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 0.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
