:root {
  color-scheme: light;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: #f6f8fa;
  color: #1f2933;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f6f8fa;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: #1f2933;
  color: #fff;
}

.version-display {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.button.small {
  font-size: 0.85rem;
  padding: 0.2rem 0.55rem;
}

.brand {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
}

.header-user-name {
  font-weight: 600;
  color: #e2e8f0;
}

.logout-link {
  color: #f8fafc;
  text-decoration: none;
  border: 1px solid rgba(248, 250, 252, 0.4);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.logout-link:hover,
.logout-link:focus {
  background: rgba(248, 250, 252, 0.18);
  border-color: rgba(248, 250, 252, 0.6);
  outline: none;
}

.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  flex-wrap: wrap;
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.app-nav .nav-link {
  color: #1f2933;
  text-decoration: none;
  font-size: 0.95rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease;
}

.app-nav .nav-link:hover,
.app-nav .nav-link:focus {
  background: #e2e8f0;
  outline: none;
}

.app-nav .nav-link.is-active,
.app-nav .nav-link[aria-current="page"] {
  background: #2563eb;
  color: #fff;
}

.app-main {
  padding: 1.5rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  border: 1px solid transparent;
  background: #2563eb;
  color: #fff;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s ease;
}

.button:hover {
  background: #1d4ed8;
}

.button.primary {
  background: #2563eb;
  color: #fff;
}

.button.danger {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.button.danger:hover {
  background: #b91c1c;
}

.button.ghost {
  background: transparent;
  color: #2563eb;
  border-color: #2563eb;
}

.button.small {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

.panel {
  background: #fff;
  border-radius: 10px;
  padding: 2rem;
  max-width: 640px;
  margin: 0 auto;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
}

.panel.narrow {
  max-width: 480px;
}

.login-wrapper {
  max-width: 420px;
  margin: 4rem auto;
}

.login-form h1 {
  margin-top: 0;
  margin-bottom: 0.35rem;
}

.login-form .muted {
  margin-bottom: 1.5rem;
}

.alert {
  padding: 0.65rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.import-form label,
.rule-form label,
.modal-content label,
.login-form label {
  display: block;
  margin-bottom: 1rem;
  font-weight: 600;
}

.import-form input,
.rule-form input,
.rule-form select,
.rule-form textarea,
.filters input,
.filters select,
.modal-content input,
.modal-content select,
.modal-content textarea,
.sidebar input,
.sidebar select,
.login-form input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  font-size: 0.95rem;
  margin-top: 0.35rem;
  box-sizing: border-box;
}

.form-actions,
.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.hint,
.muted {
  color: #6b7280;
  font-size: 0.9rem;
}

.studies-listing {
  max-width: 960px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.page-title-block {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-start;
}

.study-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1rem;
}

.study-tile {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 1.2rem;
  background: #fff;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.study-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.study-name {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.study-header .count {
  color: #2563eb;
  font-weight: 600;
}

.study-meta {
  margin-top: 0.35rem;
  color: #475569;
  font-size: 0.9rem;
}

.study-meta span {
  display: block;
}

.study-list .empty {
  text-align: center;
  color: #6b7280;
  background: #f8fafc;
  border-radius: 10px;
  padding: 2rem;
  border: 1px dashed #cbd5e1;
}

.study-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.study-link:hover .study-name {
  color: #2563eb;
}

.workspace {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.5rem;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.sidebar-button {
  align-self: flex-start;
  min-width: 0;
  justify-content: flex-start;
  gap: 0.6rem;
  font-weight: 600;
  padding-inline: 0.8rem;
}

.sidebar-button .button-icon {
  font-size: 1.1rem;
}

.builder-callout {
  align-self: flex-start;
  gap: 0.6rem;
  padding-inline: 0.8rem;
  font-weight: 600;
}

.builder-callout .button-icon {
  font-size: 1.1rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1.25rem 0;
}

.mapping-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1rem 0 0.5rem;
  padding: 0.85rem 1rem;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

.mapping-panel h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.mapping-panel p {
  margin: 0;
}

.mapping-panel .mapping-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.mapping-panel .mapping-form {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.mapping-panel .mapping-icon {
  border: none;
  background: rgba(37, 99, 235, 0.1);
  color: #1f2933;
  padding: 0.4rem;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.mapping-panel .mapping-icon:hover,
.mapping-panel .mapping-icon:focus {
  background: rgba(37, 99, 235, 0.18);
  outline: none;
}

.mapping-panel .mapping-file-name {
  font-size: 0.9rem;
  color: #6b7280;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mapping-panel .mapping-form .button {
  white-space: nowrap;
}

.filters .filter-select {
  width: auto;
  min-width: 10ch;
  flex-shrink: 0;
}

.filters .filter-search {
  width: calc(12ch * 1.5);
  max-width: calc(12ch * 1.5);
  flex: 0 0 auto;
}

.filters .filter-group {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
}

.table-wrapper {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  padding: 1rem;
  max-height: 560px;
  overflow-y: auto;
}

.bulk-footer {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
}

.button.button-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.rules-layout {
  display: grid;
  gap: 1.5rem;
}

.rules-table {
  max-height: 600px;
}

.rules-table .data-table td:nth-child(4),
.rules-table .data-table td:nth-child(7) {
  width: 24rem;
  white-space: normal;
}

.rules-table .data-table td:last-child {
  vertical-align: middle;
  min-width: 4.5rem;
  padding: 0;
  border-top: 1px solid #e2e8f0;
  border-bottom: 1px solid #ffffff;
}

.rules-table .data-table tr:first-child td:last-child {
  border-top-color: transparent;
}

.rules-table .rule-actions {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem;
  box-sizing: border-box;
}

.rules-table .rule-actions .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  padding: 0;
  font-size: 1rem;
}

.toolbar-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.toolbar-actions input[type="search"] {
  min-width: 240px;
}

.export-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.export-controls select {
  min-width: 14rem;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  font-size: 0.95rem;
  color: #1f2933;
}

.export-controls select:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.export-controls .export-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.copy-modal-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.copy-modal-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.copy-source-field select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
}

.copy-message {
  text-align: center;
  color: #475569;
}

.copy-table-wrapper {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  max-height: 420px;
  overflow-y: auto;
}

.copy-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.copy-table th,
.copy-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
}

.copy-table thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 1;
}

.copy-filter-row input,
.copy-filter-row select {
  width: 100%;
  box-sizing: border-box;
  padding: 0.3rem 0.4rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.85rem;
}

.copy-filter-row th {
  background: #f1f5f9;
}

.copy-select-cell {
  width: 36px;
  text-align: center;
}

.copy-empty {
  padding: 0.75rem;
  text-align: center;
  color: #475569;
}

.copy-selection-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.copy-selection-bar strong {
  font-size: 1.1rem;
}

.compatibility-modal-content {
  width: min(520px, 92vw);
}

.compatibility-body {
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.compatibility-list {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  color: #1f2933;
}

.compatibility-list li {
  margin-bottom: 0.35rem;
}

.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;
}

.modal-content.wide {
  width: min(1100px, 95vw);
}

.preview-body {
  max-height: 60vh;
  overflow-y: auto;
  display: block;
  padding: 0;
}

.preview-group-heading {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #1f2933;
}

.preview-group:first-of-type {
  margin-top: 0.35rem;
}

.preview-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: flex-start;
  padding: 0.85rem 0;
  border-bottom: 1px solid #e2e8f0;
}

.preview-item:first-child {
  padding-top: 0.35rem;
}

.preview-item:last-child {
  border-bottom: none;
}

.preview-info {
  flex: 1 1 calc(50% - 1.5rem);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0;
  align-self: center;
}

.preview-info input[type="checkbox"] {
  margin-top: 0.15rem;
  width: 1rem;
  height: 1rem;
}

.preview-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  background: transparent;
  padding: 0;
  line-height: 1.2;
}

.preview-label {
  font-weight: 600;
  color: #1f2933;
  margin: 0;
}

.preview-meta {
  color: #6b7280;
  font-size: 0.85rem;
  margin: 0;
  text-align: left;
}

.preview-control {
  flex: 1 1 calc(50% - 1.5rem);
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  background: transparent;
  padding: 0;
}

.preview-control > * {
  max-width: min(26rem, 100%);
  width: 100%;
  margin: 0;
}

.preview-control input,
.preview-control textarea {
  width: min(20rem, 100%);
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  box-sizing: border-box;
}

.preview-control .preview-options {
  width: auto;
  max-width: 100%;
}

.preview-control select {
  width: auto;
  max-width: 100%;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
}

.preview-control textarea {
  min-height: 2.6rem;
}


.preview-options {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.preview-options-vertical {
  display: grid;
  gap: 0.4rem;
}

.preview-option {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.95rem;
}

.preview-option input[type="radio"],
.preview-option input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
}

.preview-group {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 1.5rem;
}

.preview-group-standard {
  gap: 0.75rem;
}

.preview-group-standard > .preview-item {
  margin: 0;
}

.preview-group-repeating {
  gap: 1rem;
}

.repeating-preview-table {
  width: 100%;
  border: 1px solid #d4dbe5;
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.repeating-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #eef2ff;
  border-bottom: 1px solid #d4dbe5;
}

.repeating-preview-title {
  font-weight: 600;
  color: #1f2933;
}

.repeating-column-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.repeating-column-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin-top: 0.15rem;
}

.repeating-column-label .label-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.repeating-column-label .label-primary {
  font-weight: 600;
  color: #1f2933;
}

.repeating-column-label .label-secondary {
  font-size: 0.75rem;
  color: #6b7280;
  font-weight: 400;
}

.repeating-preview-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.repeating-preview-table th,
.repeating-preview-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
}

.repeating-preview-table th:first-child,
.repeating-preview-table td:first-child {
  width: 5rem;
  text-align: center;
  font-weight: 600;
}

.repeating-preview-table th:last-child,
.repeating-preview-table td:last-child {
  width: 4rem;
  text-align: center;
}

.repeating-preview-table tbody tr:last-child td {
  border-bottom: none;
}

.repeating-preview-table .button.repeating-add {
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  border-radius: 6px;
  border: 1px solid #4c51bf;
  color: #4c51bf;
  background: #ffffff;
}

.repeating-preview-table .button.repeating-add:hover {
  background: #4c51bf;
  color: #ffffff;
}

.repeating-delete {
  color: #ef4444;
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
}

.data-table tr.repeating-group td {
  background: #f8fafc;
}

.meta-seq {
  text-align: center;
  font-weight: 600;
  color: #0f172a;
}

.data-table thead th {
  background: #f8fafc;
  text-align: left;
  font-weight: 600;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-pill.status-active {
  background: #dcfce7;
  color: #166534;
}

.status-pill.status-draft {
  background: #fee2e2;
  color: #991b1b;
}

.field-help {
  display: block;
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 0.25rem;
}

.sort-header {
  background: none;
  border: none;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
  color: inherit;
}

.sort-arrow[data-direction="asc"]::after {
  content: '▲';
}

.sort-arrow[data-direction="desc"]::after {
  content: '▼';
}

.sort-arrow[data-direction="none"]::after {
  content: '↕';
}

.data-table tbody tr:hover {
  background: #f1f5f9;
}

.empty {
  text-align: center;
  padding: 1rem;
  color: #64748b;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.35);
  z-index: 50;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem;
  width: min(480px, 90vw);
  box-shadow: 0 30px 50px rgba(15, 23, 42, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.icon-button {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #1f2933;
  color: #fff;
  padding: 0.8rem 1.2rem;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-error {
  background: #dc2626;
}

.toast-info {
  background: #1f2933;
}

.horizontal {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.picker {
  display: grid;
  gap: 0.5rem;
}

#target-variable {
  height: 140px;
}

.tabs {
  display: inline-flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.tab {
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  cursor: pointer;
  font-size: 0.85rem;
}

.tab.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.tab-panel {
  display: none;
}

.tab-panel-active {
  display: block;
}

.preview {
  background: #f8fafc;
  border-radius: 8px;
  padding: 0.75rem;
  border: 1px solid #e2e8f0;
}

.builder-layout {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: minmax(320px, 2fr) minmax(240px, 1fr);
}

.stack-panel {
  background: #fff;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.stack-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.actions .link {
  border: none;
  background: none;
  color: #2563eb;
  cursor: pointer;
  padding: 0;
}

.actions .icon-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.1rem;
  font-size: 1.1rem;
  line-height: 1;
}

@media (max-width: 980px) {
  .dashboard,
  .workspace,
  .builder-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .filters {
    flex-direction: column;
  }

  #target-variable {
    height: 100px;
  }
}

.modal.builder-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: transparent;
  z-index: 1200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal.builder-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.builder-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.builder-modal .modal-dialog {
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
  width: min(1100px, 96vw);
  background: #fff;
  border-radius: 16px;
  padding: 1.75rem 2rem;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18);
  transform: translateY(18px);
  transition: transform 0.2s ease;
}

.modal.builder-modal.open .modal-dialog {
  transform: translateY(0);
}

.builder-modal .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.builder-modal .modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
  color: #1f2937;
  padding: 0.2rem;
}

.builder-modal .modal-close:hover {
  color: #111827;
}

body.builder-modal-active {
  overflow: hidden;
}
body.modal-open {
  overflow: hidden;
}
.builder-config {
  margin-bottom: 1.5rem;
}

.config-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  align-items: center;
}

.config-grid .field {
  display: grid;
  gap: 0.3rem;
}

.config-grid .field-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: #1f2933;
}

.target-variable-field {
  display: grid;
  gap: 0.25rem;
  grid-template-columns: 1fr;
}

.target-variable-field select,
.target-variable-field input {
  width: 100%;
  height: 1.9rem;
  padding: 0.25rem 0.5rem;
}

.config-grid .span-2 {
  grid-column: span 2;
}

.logic-section {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.logic-tree {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 540px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.logic-node {
  border: 1px solid #dbeafe;
  border-radius: 12px;
  background: #fff;
  padding: 1rem;
  position: relative;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.logic-node.group {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.logic-node.is-selected {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.logic-node.is-readonly {
  opacity: 0.65;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.group-title {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.group-meta {
  font-size: 0.8rem;
  color: #64748b;
}

.group-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.group-controls select {
  margin-top: 0.35rem;
}

.group-children {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.condition-body {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(4, minmax(190px, 1fr));
  align-items: start;
}

@media (max-width: 900px) {
  .condition-body {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

.condition-field {
  display: grid;
  gap: 0.25rem;
}

.condition-field .field-label {
  font-size: 0.8rem;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.condition-field input,
.condition-field select {
  width: 100%;
  padding: 0.3rem 0.5rem;
  height: 2rem;
}

.rhs-field {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.6rem;
  row-gap: 0.3rem;
  align-items: center;
  align-self: start;
}

.rhs-header {
  display: contents;
}

.rhs-header .field-label {
  grid-column: 1;
}

.rhs-header .rhs-toggle {
  grid-column: 2;
  justify-self: end;
  display: inline-flex;
  gap: 0.6rem;
}

.rhs-input-slot {
  grid-column: 1 / span 2;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
}

.rhs-input-slot input[type="text"],
.rhs-input-slot input[type="search"],
.rhs-choice-wrapper select {
  width: 100%;
  height: 2rem;
  padding: 0.3rem 0.5rem;
}

.rhs-choice-wrapper {
  flex: 1;
  width: 100%;
}

.rhs-variable-wrapper {
  flex: 1;
  width: 100%;
}

.rhs-variable-scopes {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.35rem;
}

.rhs-variable-scopes .rhs-scope {
  flex: 1;
  display: grid;
  gap: 0.25rem;
}

.rhs-variable-scopes .rhs-scope select {
  width: 100%;
  height: 2rem;
  padding: 0.3rem 0.5rem;
}

.rhs-choice-wrapper[hidden],
.rhs-variable-wrapper[hidden],
.rhs-value-input[hidden] {
  display: none !important;
}

.datatype-hint {
  font-size: 0.8rem;
  color: #64748b;
}

.rhs-toggle {
  display: inline-flex;
  gap: 0.6rem;
  font-size: 0.8rem;
}

.rhs-toggle input[type="radio"] {
  width: 14px;
  height: 14px;
}

.rhs-input-wrapper input[type="text"],
.rhs-input-wrapper input[type="search"] {
  height: 2rem;
  padding: 0.3rem 0.5rem;
}

.condition-field[data-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.logic-empty {
  margin-top: 1rem;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  text-align: center;
  padding: 1rem;
  color: #64748b;
}

.builder-errors {
  margin-top: 1rem;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  color: #991b1b;
}

.builder-errors ul {
  margin: 0;
  padding-left: 1.2rem;
}

.logic-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.message-section {
  margin-bottom: 1.5rem;
}

.preview-section {
  margin-bottom: 1.5rem;
}

.preview-tabs {
  margin-bottom: 0.75rem;
}

.preview-text {
  width: 100%;
  min-height: 120px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  padding: 0.75rem;
  background: #f8fafc;
  font-family: ui-monospace, SFMono-Regular, SFMono, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.85rem;
  color: #0f172a;
}

.preview-text[hidden] {
  display: none;
}

.logic-node .node-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.logic-node .node-actions .icon-button {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  font-size: 0.8rem;
  padding: 0.25rem 0.45rem;
  cursor: pointer;
}

.logic-node .node-actions .icon-button[disabled] {
  cursor: not-allowed;
  opacity: 0.4;
}

.logic-node.custom {
  background: #fffaf0;
  border-color: #fbbf24;
}

.custom-expression {
  font-family: ui-monospace, SFMono-Regular, SFMono, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.85rem;
  color: #92400e;
}
.rule-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}

.rule-actions .icon-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

.rule-actions .icon-button:hover {
  transform: translateY(-1px);
  background: #e2e8f0;
  border-radius: 50%;
}

@media (max-width: 900px) {
  .preview-item {
    gap: 0.75rem;
  }
  .preview-info {
    flex: 1 1 100%;
  }
  .preview-control {
    flex: 1 1 100%;
  }
}
