:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --line: #d9dee5;
  --text: #1d252d;
  --muted: #64717f;
  --green: #127c56;
  --blue: #2457a6;
  --red: #b42318;
  --amber: #936316;
}

* {
  box-sizing: border-box;
}

html {
  max-width: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 60px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  white-space: nowrap;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.nav a,
.logout {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
}

.nav a:hover,
.logout:hover {
  background: #edf1f5;
  color: var(--text);
}

.shell {
  width: min(1220px, calc(100% - 32px));
  margin: 28px auto 56px;
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 28px;
  margin-bottom: 4px;
}

h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.help {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-left: 4px;
  border-radius: 999px;
  background: #edf1f5;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
  z-index: 2;
}

.help::after {
  content: attr(data-tip);
  display: none;
}

.help-tooltip {
  position: fixed;
  z-index: 5000;
  width: min(320px, calc(100vw - 24px));
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.35;
  pointer-events: none;
  white-space: normal;
  overflow-wrap: anywhere;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.quick-flow {
  margin-bottom: 18px;
}

.flow-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.flow-steps a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.flow-steps strong {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
}

.metric,
.panel,
.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  font-size: 30px;
}

.panel {
  padding: 18px;
  min-width: 0;
  overflow: visible;
}

@supports selector(:has(*)) {
  .panel:has(table) {
    overflow-x: auto;
  }
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin-bottom: 0;
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.list {
  display: grid;
  gap: 16px;
}

.form-panel,
.stack,
.step-form {
  display: grid;
  gap: 12px;
}

.field-title,
.section-title {
  color: var(--muted);
  font-weight: 700;
}

.hint,
.button-help {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

textarea {
  resize: vertical;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--green);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.95);
}

button.secondary {
  background: #edf1f5;
  color: var(--text);
}

button.danger {
  color: var(--red);
}

.inline-actions,
.item-actions,
.step-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.item-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 340px);
  gap: 16px;
  align-items: start;
}

.edit-details {
  width: 100%;
}

.edit-details summary {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border-radius: 6px;
  padding: 9px 12px;
  background: #edf1f5;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.edit-details[open] summary {
  margin-bottom: 12px;
}

.compact-form {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.badge,
.chip,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 6px;
  padding: 3px 8px;
  background: #edf1f5;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}

.status-active,
.status-sent,
.status-queued {
  background: #e4f5ed;
  color: var(--green);
}

.status-draft,
.status-pending {
  background: #fff3d8;
  color: var(--amber);
}

.status-stopped,
.status-blocked,
.status-failed {
  background: #ffe8e5;
  color: var(--red);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.media-preview {
  width: min(260px, 100%);
  margin: 8px 0 10px;
}

.media-preview img,
.media-preview video {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #edf1f5;
}

.item {
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.item:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.sequence {
  display: grid;
  gap: 14px;
}

.sequence-create-row {
  margin-bottom: 18px;
}

.sequence-view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.sequence-view-toggle button {
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.sequence-view-toggle button.is-active {
  background: var(--green);
  color: #ffffff;
}

.sequence-mode-panel[hidden] {
  display: none;
}

.sequence-create-form {
  grid-template-columns: minmax(220px, 1.4fr) minmax(220px, 1fr) minmax(160px, 0.7fr) auto;
  align-items: end;
}

.sequence-create-form h2 {
  grid-column: 1 / -1;
}

.sequence-workspaces {
  display: grid;
  gap: 18px;
}

.sequence-workspace {
  display: grid;
  gap: 12px;
}

.sequence-workspace-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.sequence-workspace-head h2 {
  margin-bottom: 8px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.chain-builder {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.chain-builder:fullscreen,
.chain-builder.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  overflow: hidden;
}

.chain-builder:fullscreen .chain-layout,
.chain-builder.is-fullscreen .chain-layout {
  min-height: 0;
  height: 100%;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 360px);
  overflow: hidden;
}

.chain-builder:fullscreen .chain-canvas,
.chain-builder.is-fullscreen .chain-canvas {
  height: 100%;
  min-height: 0;
}

.chain-builder:fullscreen .chain-inspector,
.chain-builder.is-fullscreen .chain-inspector {
  height: 100%;
  max-height: none;
  overflow: hidden;
}

.chain-map-fullscreen-active {
  overflow: hidden;
}

.chain-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.chain-toolbar-info {
  display: grid;
  gap: 3px;
  min-width: min(320px, 100%);
}

.chain-toolbar-info strong {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chain-toolbar-info span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.chain-toolbar-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.chain-tool {
  min-height: 34px;
  padding: 7px 10px;
  white-space: nowrap;
}

.chain-tool.compact {
  width: 36px;
  padding: 7px 0;
  text-align: center;
}

.chain-zoom-value {
  min-width: 52px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.chain-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 640px;
  overflow: hidden;
}

.chain-canvas {
  position: relative;
  min-width: 0;
  min-height: 640px;
  overflow: hidden;
  background-color: #f4f6f8;
  background-image: radial-gradient(#cfd7df 1px, transparent 1px);
  background-size: 22px 22px;
  outline: 0;
  cursor: grab;
}

.chain-canvas.is-panning {
  cursor: grabbing;
}

.chain-world {
  position: absolute;
  inset: 0 auto auto 0;
  width: 2600px;
  height: 980px;
  transform-origin: 0 0;
}

.chain-links {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}

.chain-link {
  fill: none;
  stroke: #7d90a3;
  stroke-width: 2;
}

.chain-node {
  position: absolute;
  width: 252px;
  min-height: 150px;
  padding: 12px;
  border: 1px solid #cdd6df;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  cursor: grab;
  user-select: none;
}

.chain-node:hover {
  border-color: #9bb0c5;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
}

.chain-node.is-dragging {
  cursor: grabbing;
  opacity: 0.88;
  z-index: 3;
}

.chain-node.is-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 87, 166, 0.14), 0 10px 26px rgba(15, 23, 42, 0.12);
}

.chain-node-start {
  border-color: #8bc7ad;
  background: #f0faf4;
}

.chain-node-add {
  border-style: dashed;
  background: #fffaf0;
}

.node-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.node-type {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.node-action {
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  background: #edf1f5;
  color: var(--text);
  font-size: 13px;
}

.chain-node strong {
  display: block;
  margin-bottom: 8px;
  line-height: 1.3;
}

.chain-node p {
  margin-bottom: 10px;
  font-size: 13px;
}

.node-meta,
.node-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.node-meta span,
.node-buttons span {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 6px;
  padding: 2px 7px;
  background: #edf1f5;
  color: #435160;
  font-size: 12px;
}

.node-buttons {
  margin-top: 8px;
}

.node-buttons span {
  border: 1px solid #d8e4ef;
  background: #ffffff;
}

.node-port {
  position: absolute;
  width: 13px;
  height: 13px;
  border: 2px solid #7d90a3;
  border-radius: 50%;
  background: #ffffff;
}

.node-port-in {
  left: -7px;
  top: calc(50% - 7px);
}

.node-port-out {
  right: -7px;
  top: calc(50% - 7px);
}

.chain-minimap {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 170px;
  height: 112px;
  border: 1px solid #c5cfda;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  overflow: hidden;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
}

.chain-minimap-node {
  position: absolute;
  border-radius: 3px;
  background: #8fa3b7;
}

.chain-minimap-node-start {
  background: var(--green);
}

.chain-minimap-node-add {
  background: var(--amber);
}

.chain-minimap-viewport {
  position: absolute;
  border: 1px solid var(--blue);
  background: rgba(36, 87, 166, 0.08);
}

.chain-inspector {
  min-width: 0;
  border-left: 1px solid var(--line);
  background: #fbfcfd;
  padding: 14px;
  overflow: hidden;
}

.chain-inspector *,
.chain-inspector-panel,
.chain-inspector form,
.chain-inspector label {
  min-width: 0;
}

.chain-inspector-empty {
  padding: 12px;
}

.chain-inspector-empty.is-hidden,
.chain-inspector-panel {
  display: none;
}

.chain-inspector-panel.is-active {
  display: grid;
  gap: 12px;
}

.inspector-head {
  display: grid;
  gap: 4px;
}

.inspector-head h3 {
  margin-bottom: 0;
}

.inspector-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.map-step-form {
  grid-template-columns: 1fr;
  align-items: stretch;
}

.chain-inspector .compact-form,
.chain-inspector .map-step-form,
.chain-inspector .smart-step-form.map-step-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}

.map-step-form .condition-preview,
.map-step-form .checkline,
.map-step-form button[type="submit"] {
  grid-column: 1 / -1;
}

.chain-inspector input,
.chain-inspector textarea,
.chain-inspector select,
.chain-inspector button {
  max-width: 100%;
}

.chain-inspector .condition-preview,
.chain-inspector .checkline {
  overflow-wrap: anywhere;
}

.chain-inspector .map-step-form button[type="submit"] {
  width: 100%;
}

.chain-builder:fullscreen .map-step-form,
.chain-builder.is-fullscreen .map-step-form {
  gap: 8px;
}

.chain-builder:fullscreen input,
.chain-builder:fullscreen textarea,
.chain-builder:fullscreen select,
.chain-builder.is-fullscreen input,
.chain-builder.is-fullscreen textarea,
.chain-builder.is-fullscreen select {
  min-height: 36px;
  padding: 7px 9px;
}

.chain-builder:fullscreen .condition-preview,
.chain-builder.is-fullscreen .condition-preview {
  padding: 8px 10px;
}

.sequence-steps {
  display: grid;
  gap: 10px;
}

.step-list,
.button-list {
  display: grid;
  gap: 8px;
}

.button-builder {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.step-card,
.button-row,
.trash-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.step-card {
  min-width: 0;
  grid-template-columns: minmax(92px, auto) minmax(0, 1fr);
}

.step-card > * {
  min-width: 0;
}

.button-row {
  grid-template-columns: minmax(92px, auto) minmax(0, 1fr);
  align-items: start;
  min-width: 0;
  overflow: hidden;
}

.button-row label {
  min-width: 0;
}

.button-row label:nth-of-type(2),
.button-row label:nth-of-type(3),
.button-row .button-help,
.button-row [data-remove-button] {
  grid-column: 1 / -1;
}

.button-row [data-remove-button] {
  justify-self: start;
}

.trash-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.step-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.step-summary strong {
  width: 100%;
}

.step-edit {
  grid-column: 2 / -1;
  min-width: 0;
}

.drag-handle {
  width: auto;
  min-width: 92px;
  min-height: 34px;
  padding: 6px 8px;
  background: #edf1f5;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.1;
  cursor: grab;
}

.dragging {
  opacity: 0.55;
}

.is-disabled {
  opacity: 0.72;
}

.save-order-button {
  justify-self: start;
}

.save-state {
  color: var(--muted);
  font-size: 13px;
}

.step-form {
  grid-template-columns: 1.2fr 120px 110px 110px 130px 90px auto;
  align-items: end;
  min-width: 0;
}

.smart-step-form {
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
}

.smart-step-form label,
.smart-step-form select,
.smart-step-form input,
.smart-step-form button {
  min-width: 0;
  max-width: 100%;
}

.condition-preview {
  grid-column: 1 / -1;
  border: 1px solid #cfe3d7;
  border-radius: 6px;
  background: #f0faf4;
  color: #244b36;
  padding: 10px 12px;
  line-height: 1.45;
  font-size: 14px;
}

.settings-form,
.settings-form section {
  display: grid;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 14px;
}

.checkline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-weight: 700;
}

.checkline input {
  width: auto;
}

.compact-metrics {
  margin-bottom: 16px;
}

.empty {
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.alert {
  border: 1px solid #ffd0ca;
  border-radius: 6px;
  background: #ffe8e5;
  color: var(--red);
  padding: 10px 12px;
}

.notice {
  border: 1px solid #ffe1a6;
  border-radius: 6px;
  background: #fff8e8;
  color: #725019;
  padding: 10px 12px;
  line-height: 1.45;
}

.telegram-preview {
  width: min(360px, 100%);
  margin: 8px 0 10px;
  padding: 10px;
  border-radius: 8px;
  border-bottom-left-radius: 2px;
  background: #d9fdd3;
}

.telegram-preview p {
  margin-bottom: 8px;
  color: var(--text);
  white-space: pre-wrap;
}

.telegram-preview .media-preview {
  width: 100%;
}

.preview-buttons {
  display: grid;
  gap: 6px;
}

.preview-buttons span {
  display: block;
  min-height: 32px;
  padding: 7px 10px;
  border-radius: 6px;
  background: #ffffff;
  color: var(--blue);
  text-align: center;
  font-weight: 700;
}

.code-box {
  min-height: 360px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 24px;
}

@media (max-width: 900px) {
  .topbar,
  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics,
  .flow-steps,
  .split,
  .item-main,
  .button-row,
  .step-card,
  .trash-row,
  .step-form,
  .smart-step-form,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .step-edit {
    grid-column: auto;
  }

  .shell {
    width: min(100% - 20px, 1220px);
    margin-top: 18px;
  }
}

.app-layout {
  min-height: 100vh;
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

.side-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  padding: 16px 12px;
  background: #111827;
  color: #e5edf5;
  border-right: 1px solid #243041;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
}

.side-brand span {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #2f6b57;
  color: #fff;
  font-weight: 700;
}

.side-nav nav {
  display: grid;
  align-content: start;
  gap: 4px;
}

.side-nav nav a,
.side-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 8px 10px;
  border-radius: 7px;
  color: #c7d2df;
}

.side-nav nav a span {
  color: #8ea0b5;
  font-size: 11px;
  min-width: 22px;
}

.side-nav nav a:hover,
.side-nav nav a.active,
.side-logout:hover {
  background: #223047;
  color: #fff;
}

.app-main {
  min-width: 0;
  width: 100%;
}

.workbar {
  position: sticky;
  top: 0;
  z-index: 9;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  min-height: 56px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
}

.workbar div {
  display: grid;
  gap: 2px;
}

.workbar span {
  color: var(--muted);
  font-size: 13px;
}

.workbar a,
.button,
a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  border: 0;
  font-weight: 700;
}

.button.secondary,
a.button.secondary,
button.secondary {
  background: #eef2f6;
  color: var(--text);
}

.app-main .shell {
  width: auto;
  max-width: none;
  margin: 28px 24px 56px;
}

.compact-head {
  align-items: center;
}

.actions-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.notice.danger {
  border-color: #f1b0a8;
  background: #fff4f2;
  color: var(--red);
}

.inbox-layout {
  display: grid;
  grid-template-columns: 170px minmax(220px, 320px) minmax(0, 1fr) minmax(240px, 320px);
  gap: 12px;
  min-height: calc(100vh - 160px);
}

.inbox-sidebar,
.conversation-list,
.conversation-panel,
.client-sidecard {
  min-height: 0;
}

.inbox-sidebar {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 10px;
}

.sidebar-title {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 6px;
  color: var(--muted);
  font-size: 13px;
}

.inbox-sidebar a {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--muted);
}

.inbox-sidebar a.active,
.inbox-sidebar a:hover {
  background: #edf1f5;
  color: var(--text);
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px;
}

.conversation-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.conversation-row.active,
.conversation-row:hover {
  border-color: #8fb0d8;
  background: #f0f6ff;
}

.conversation-row span,
.conversation-row small,
.crm-card p,
.crm-card small {
  color: var(--muted);
}

.conversation-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-row b {
  float: right;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  text-align: center;
}

.conversation-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.conversation-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.conversation-head h2 {
  margin-bottom: 4px;
}

.message-thread {
  display: grid;
  align-content: end;
  gap: 8px;
  overflow: auto;
  padding: 6px;
}

.message-thread.embedded {
  max-height: 520px;
  align-content: start;
}

.chat-bubble {
  width: min(78%, 720px);
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.chat-bubble.outbound {
  justify-self: end;
  background: #eef7f1;
  border-color: #b8dac5;
}

.chat-bubble small,
.activity-list small {
  color: var(--muted);
  font-size: 12px;
}

.chat-bubble p {
  margin: 4px 0 0;
  color: var(--text);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.reply-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.reply-box label {
  min-width: 0;
}

.client-sidecard {
  display: grid;
  align-content: start;
  gap: 14px;
}

.meta-list {
  display: grid;
  grid-template-columns: minmax(90px, auto) minmax(0, 1fr);
  gap: 8px 10px;
  margin: 0;
}

.meta-list dt {
  color: var(--muted);
}

.meta-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.mini-list,
.activity-list {
  display: grid;
  gap: 8px;
}

.mini-list span,
.activity-list article {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
}

.activity-list article.done {
  opacity: 0.68;
}

.activity-list.compact {
  max-height: 420px;
  overflow: auto;
}

.activity-list p {
  margin: 4px 0;
  overflow-wrap: anywhere;
}

.crm-bulk {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) 190px 190px minmax(180px, 240px) auto;
  gap: 12px;
  align-items: end;
}

.crm-bulk > div {
  display: grid;
  gap: 4px;
}

.crm-bulk > div span {
  color: var(--muted);
  font-size: 13px;
}

.crm-board {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(6, minmax(210px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-top: 8px;
}

.crm-column {
  min-width: 210px;
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr);
  gap: 10px;
}

.crm-column header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 2px solid var(--line);
}

.crm-column h2 {
  margin: 0;
  font-size: 15px;
}

.crm-cards {
  display: grid;
  align-content: start;
  gap: 8px;
}

.crm-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.chip-row,
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip.danger {
  background: #fff0ee;
  color: var(--red);
}

.card-actions a,
.table-link {
  color: var(--blue);
  font-weight: 700;
}

.table-link {
  display: grid;
  gap: 2px;
}

.table-link span {
  color: var(--muted);
  font-weight: 400;
}

.subscriber-grid {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.profile-panel {
  grid-row: span 3;
  display: grid;
  gap: 18px;
}

.wide-panel {
  grid-column: span 2;
}

.timeline-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 140px;
  color: var(--muted);
  text-align: center;
}

.empty-state.small {
  min-height: 56px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.period-switch,
.quick-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.quick-filter-title {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  color: var(--muted);
  font-weight: 700;
}

.toolbar-help {
  margin-left: 0;
}

.period-switch button,
.quick-filter-row a {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  padding: 9px 12px;
  font-weight: 700;
}

.period-switch button.active,
.quick-filter-row a.active {
  border-color: var(--blue);
  background: #eef4ff;
  color: var(--blue);
}

.quick-filter-row {
  margin: -4px 0 14px;
}

.stats-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.goal-selector,
.widget-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.goal-selector label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-weight: 700;
}

.goal-selector select {
  min-width: 220px;
}

.goal-selector span {
  color: var(--muted);
  font-weight: 700;
}

.funnel-kpis {
  grid-template-columns: repeat(7, minmax(120px, 1fr));
}

.funnel-map-shell {
  padding: 0;
  overflow: hidden;
}

.funnel-map-shell.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  border-radius: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.funnel-map-toolbar,
.funnel-map-layout {
  min-width: 0;
}

.funnel-map-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.funnel-map-toolbar span,
.funnel-inspector p,
.funnel-inspector small {
  color: var(--muted);
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.toolbar-actions button,
.chain-block-count {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
  padding: 8px 10px;
  font-weight: 700;
}

.funnel-map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  min-height: 620px;
}

.funnel-map-shell.is-fullscreen .funnel-map-layout {
  min-height: 0;
}

.funnel-canvas {
  position: relative;
  overflow: hidden;
  min-height: 620px;
  background-color: #f7fbff;
  background-image: radial-gradient(#c9d8ea 1px, transparent 1px);
  background-size: 20px 20px;
  touch-action: none;
}

.funnel-world {
  position: absolute;
  inset: 0 auto auto 0;
  width: 3520px;
  height: 640px;
  transform-origin: 0 0;
}

.funnel-links {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}

.funnel-link {
  fill: none;
  stroke: #8aa1bf;
  stroke-width: 3;
}

.funnel-link.branch {
  stroke: #d39b52;
  stroke-dasharray: 8 8;
}

.funnel-link-label {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 5;
  stroke-linejoin: round;
}

.funnel-node {
  position: absolute;
  width: 210px;
  min-height: 168px;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(28, 44, 64, 0.08);
  cursor: pointer;
}

.funnel-node.is-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 87, 166, 0.14), 0 14px 30px rgba(28, 44, 64, 0.12);
}

.funnel-node header {
  display: grid;
  gap: 4px;
}

.funnel-node header span,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.funnel-node-number {
  font-size: 30px;
  font-weight: 800;
}

.funnel-node dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
}

.funnel-node dl div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.funnel-node dt,
.funnel-node dd {
  margin: 0;
  font-size: 12px;
}

.funnel-node dt {
  color: var(--muted);
}

.funnel-node dd {
  font-weight: 700;
}

.funnel-node.status-ok {
  border-top: 5px solid var(--green);
}

.funnel-node.status-warning {
  border-top: 5px solid var(--amber);
}

.funnel-node.status-danger {
  border-top: 5px solid var(--red);
}

.funnel-node.status-empty {
  border-top: 5px solid #9aa7b4;
}

.funnel-inspector {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: #fff;
  overflow: hidden;
}

.inspector-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.inspector-metrics div {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
}

.inspector-metrics span {
  color: var(--muted);
  font-size: 12px;
}

.funnel-minimap {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 176px;
  height: 98px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  overflow: hidden;
}

.funnel-minimap-node {
  position: absolute;
  border-radius: 3px;
  background: var(--blue);
  opacity: 0.7;
}

.funnel-minimap-viewport {
  position: absolute;
  border: 2px solid var(--green);
  border-radius: 4px;
  pointer-events: none;
}

.retention-bars {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.retention-bars div {
  display: grid;
  gap: 8px;
  min-height: 86px;
  align-content: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(to top, #edf7f2 var(--bar, 42%), #fff var(--bar, 42%));
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.dashboard-widget {
  min-height: 190px;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.dashboard-widget[hidden] {
  display: none;
}

.dashboard-grid.is-dragging .dashboard-widget {
  cursor: grabbing;
}

.dashboard-widget header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.dashboard-widget h2 {
  margin: 0;
}

.widget-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.widget-drag,
.widget-hide {
  display: none;
  min-height: 30px;
  padding: 5px 8px;
  border-radius: 7px;
  background: #eef2f6;
  color: var(--text);
  font-size: 12px;
  line-height: 1.1;
}

.dashboard-grid.is-configuring .widget-drag,
.dashboard-grid.is-configuring .widget-hide {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.widget-drag {
  cursor: grab;
}

.dashboard-widget > strong {
  font-size: 30px;
}

.widget-help {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.widget-visual {
  display: grid;
  place-items: center;
  min-height: 54px;
}

.widget-visual svg {
  width: 100%;
  height: 48px;
}

.widget-visual path {
  fill: none;
  stroke: #9eb1ca;
  stroke-width: 5;
}

.chart-donut .widget-visual span {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: conic-gradient(var(--blue) 0 34%, #dce5ef 34% 100%);
}

.chart-bar .widget-visual {
  grid-template-columns: repeat(4, 16px);
  align-items: end;
  gap: 7px;
}

.chart-bar .widget-visual i {
  display: block;
  width: 16px;
  border-radius: 4px 4px 0 0;
  background: #9eb1ca;
}

.chart-bar .widget-visual i:nth-child(1) { height: 24px; }
.chart-bar .widget-visual i:nth-child(2) { height: 38px; }
.chart-bar .widget-visual i:nth-child(3) { height: 30px; }
.chart-bar .widget-visual i:nth-child(4) { height: 48px; }

.hidden-widget-panel {
  margin-bottom: 14px;
}

.hidden-widget-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hidden-widget-list button {
  background: #eef4ff;
  color: var(--blue);
}

.sequence-guide {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(0, 1.5fr) minmax(220px, 0.8fr);
  gap: 16px;
  align-items: stretch;
  margin-bottom: 14px;
}

.guide-intro {
  display: grid;
  align-content: start;
  gap: 8px;
}

.guide-intro h2 {
  margin-bottom: 0;
  line-height: 1.25;
}

.guide-intro p {
  margin-bottom: 0;
}

.guide-steps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: guide-step;
}

.guide-steps li {
  counter-increment: guide-step;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 8px;
  align-content: start;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.guide-steps li::before {
  content: counter(guide-step);
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #e4f5ed;
  color: var(--green);
  font-weight: 800;
}

.guide-steps strong,
.guide-steps span {
  grid-column: 2;
}

.guide-steps span,
.guide-note span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.guide-note {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 12px;
  border: 1px dashed #a7b6c8;
  border-radius: 8px;
  background: #f8fbff;
}

.chain-block-count {
  color: var(--muted);
  white-space: nowrap;
}

.funnel-status-box {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.chip.success {
  background: #e9f7ef;
  color: var(--green);
}

.chip.warning {
  background: #fff7e6;
  color: var(--amber);
}

@media (max-width: 1180px) {
  .app-layout {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .side-brand strong,
  .side-nav nav a {
    font-size: 0;
  }

  .side-nav nav a span {
    font-size: 12px;
  }

  .inbox-layout,
  .chain-layout,
  .subscriber-grid,
  .timeline-grid,
  .funnel-map-layout,
  .dashboard-grid,
  .sequence-guide {
    grid-template-columns: 1fr;
  }

  .funnel-inspector {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .funnel-kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats-controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .chain-inspector {
    max-height: none;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .wide-panel,
  .profile-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .client-sidecard {
    order: 4;
  }
}

@media (max-width: 1440px) {
  .sequence-mode-panel[data-sequence-mode-panel="classic"] .split {
    grid-template-columns: 1fr;
  }

  .sequence-mode-panel[data-sequence-mode-panel="classic"] .step-card {
    grid-template-columns: minmax(92px, auto) minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .app-layout {
    display: block;
  }

  .side-nav {
    position: static;
    height: auto;
  }

  .side-nav nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workbar,
  .reply-box,
  .inline-form,
  .sequence-create-form,
  .crm-bulk,
  .funnel-kpis,
  .retention-bars,
  .inspector-metrics,
  .goal-selector,
  .widget-settings,
  .guide-steps {
    display: grid;
    grid-template-columns: 1fr;
  }

  .workbar {
    align-items: start;
    padding: 10px 16px;
  }

  .chat-bubble {
    width: 100%;
  }

  .sequence-workspace-head,
  .chain-toolbar {
    display: grid;
  }

  .chain-canvas {
    min-height: 560px;
  }

  .funnel-canvas {
    min-height: 520px;
  }

  .funnel-map-toolbar,
  .period-switch {
    display: grid;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .chain-minimap {
    width: 132px;
    height: 88px;
  }

  .funnel-minimap {
    width: 132px;
    height: 82px;
  }
}
