:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --line: #e3e6eb;
  --line-strong: #cfd4dc;
  --text: #171a21;
  --muted: #677084;
  --accent: #3b5bfd;
  --accent-soft: #eef1ff;
  --danger: #d43c3c;
  --success: #17875a;
  --sidebar: #12151c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 14px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

#root {
  height: 100%;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.25;
}

h1 {
  font-size: 20px;
  font-weight: 600;
}

h2 {
  font-size: 16px;
  font-weight: 600;
}

h3 {
  font-size: 14px;
  font-weight: 600;
}

h4 {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.spacer {
  flex: 1;
}

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

input,
select,
textarea {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  min-width: 0;
  padding: 8px 10px;
  width: 100%;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

input:disabled {
  background: var(--bg);
  color: var(--muted);
}

input[type="checkbox"] {
  accent-color: var(--accent);
  width: auto;
}

.button {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  padding: 8px 14px;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  white-space: nowrap;
}

.button:hover {
  background: var(--bg);
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: #2f4be0;
}

.button.ghost {
  background: transparent;
}

.button.ghost:hover {
  background: rgba(16, 24, 40, 0.05);
}

.button.danger {
  color: var(--danger);
}

.button.small {
  font-size: 13px;
  padding: 5px 10px;
}

.button.block {
  width: 100%;
}

.button:disabled {
  cursor: default;
  opacity: 0.5;
}

.link {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}

.icon-button {
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  flex: none;
  font-size: 18px;
  height: 30px;
  line-height: 1;
  width: 30px;
}

.icon-button:hover {
  background: var(--bg);
  color: var(--danger);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  font-weight: 500;
}

.field-help {
  color: var(--muted);
  font-size: 12px;
}

.row {
  align-items: center;
  display: flex;
  gap: 8px;
}

.badge {
  background: var(--bg);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 2px 9px;
}

.badge.forwarded {
  background: #e6f6ee;
  color: var(--success);
}

.badge.voicemail {
  background: #fff3df;
  color: #a86400;
}

.badge.assistant {
  background: var(--accent-soft);
  color: var(--accent);
}

.notice {
  background: var(--bg);
  border-radius: 8px;
  color: var(--muted);
  padding: 12px 14px;
}

.notice.error {
  background: #fdecec;
  color: var(--danger);
}

.empty {
  color: var(--muted);
  margin: 80px auto;
  text-align: center;
}

.empty h3 {
  color: var(--text);
  font-size: 16px;
  margin-bottom: 6px;
}

#toast {
  background: var(--sidebar);
  border-radius: 8px;
  bottom: 24px;
  color: #fff;
  left: 50%;
  opacity: 0;
  padding: 10px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s, transform 0.18s;
  z-index: 50;
}

#toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toast[data-tone="error"] {
  background: var(--danger);
}

#toast[data-tone="success"] {
  background: var(--success);
}

.centered {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
}

.auth-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 380px;
  padding: 28px;
  width: 100%;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  align-items: center;
  display: flex;
  font-size: 15px;
  font-weight: 700;
  gap: 10px;
  letter-spacing: -0.01em;
}

.brand-mark {
  height: 26px;
  width: 26px;
}

.live {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  gap: 7px;
}

.live::before {
  animation: pulse 1.8s ease-in-out infinite;
  background: var(--success);
  border-radius: 50%;
  content: "";
  height: 8px;
  width: 8px;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.checks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.checks h4 {
  margin-bottom: 2px;
}

.check-item {
  background: #fff8ea;
  border: 1px solid #f3dfb4;
  border-radius: 8px;
  color: #7a4b00;
  cursor: pointer;
  font-size: 13px;
  padding: 8px 10px;
  text-align: left;
}

.check-item:hover {
  background: #fff1d4;
}

.checks-clear {
  color: var(--success);
  font-size: 13px;
}

.node.flagged .node-head::after {
  background: #e09b12;
  border-radius: 50%;
  content: "";
  height: 8px;
  margin-left: auto;
  width: 8px;
}

.shell {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  height: 100%;
}

.sidebar {
  background: var(--sidebar);
  color: #c5cad6;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px 12px;
}

.sidebar .brand {
  color: #fff;
  padding: 2px 8px 18px;
}

.sidebar a {
  align-items: center;
  border-radius: 8px;
  color: inherit;
  display: flex;
  font-weight: 500;
  justify-content: space-between;
  padding: 8px 10px;
  text-decoration: none;
}

.sidebar a:hover {
  background: rgba(255, 255, 255, 0.06);
}

.sidebar a.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar .count {
  background: var(--accent);
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  padding: 0 7px;
}

.sidebar-foot {
  color: #fff;
  overflow: hidden;
  padding: 0 10px 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar .link {
  color: #8f97a8;
  padding: 0 10px;
  text-align: left;
}

main {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  overflow: auto;
  padding: 22px 26px;
}

main.view-flows {
  overflow: hidden;
  padding-bottom: 0;
  padding-right: 0;
}

.toolbar {
  align-items: center;
  display: flex;
  flex: none;
  gap: 10px;
}

.view-flows .toolbar {
  padding-right: 26px;
}

.toolbar h1 {
  margin-right: 8px;
}

.flow-picker {
  width: 200px;
}

.save-status {
  color: var(--muted);
  font-size: 13px;
}

.save-status.dirty {
  color: #a86400;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stack.narrow {
  max-width: 720px;
}

.stack .card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stack .card > .button {
  align-self: flex-start;
}

.stack ol {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.number-list {
  display: flex;
  flex-direction: column;
}

.number-row {
  align-items: center;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) 180px auto;
  padding: 12px 0;
}

.number-row > div {
  align-items: center;
  display: flex;
  gap: 10px;
}

.split {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.table-card {
  padding: 0;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 16px;
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.active {
  background: var(--accent-soft);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.drawer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  position: sticky;
  top: 0;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.step {
  border-left: 2px solid var(--line-strong);
  color: var(--muted);
  font-size: 13px;
  padding-left: 10px;
}

.bubble {
  border-radius: 12px;
  max-width: 88%;
  padding: 8px 12px;
}

.bubble.caller {
  align-self: flex-start;
  background: var(--bg);
}

.bubble.agent {
  align-self: flex-end;
  background: var(--accent-soft);
}

.voicemail header,
.voicemail footer {
  align-items: center;
  display: flex;
  gap: 10px;
}

.voicemail header {
  justify-content: space-between;
}

.voicemail.unheard {
  border-left: 3px solid var(--accent);
}

.transcript {
  font-size: 15px;
}

.player audio {
  display: block;
  height: 34px;
}

.builder {
  border-top: 1px solid var(--line);
  display: grid;
  flex: 1;
  grid-template-columns: 204px minmax(0, 1fr) 304px;
  margin-left: -26px;
  min-height: 0;
}

.palette {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  padding: 16px 12px;
}

.palette h4 {
  padding: 0 6px 6px;
}

.palette-item {
  align-items: flex-start;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  padding: 8px;
  text-align: left;
}

.palette-item:hover {
  background: var(--bg);
  border-color: var(--line);
}

.palette-item strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.palette-item small {
  color: var(--muted);
  display: block;
  font-size: 12px;
  line-height: 1.35;
}

.palette-item .node-dot {
  margin-top: 4px;
}

.canvas {
  background-color: var(--bg);
  background-image: radial-gradient(var(--line-strong) 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: grab;
  overflow: hidden;
  position: relative;
  touch-action: none;
  user-select: none;
}

.canvas.panning {
  cursor: grabbing;
}

.world {
  left: 0;
  position: absolute;
  top: 0;
  transform-origin: 0 0;
}

.zoom {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  bottom: 14px;
  box-shadow: var(--shadow);
  cursor: default;
  display: flex;
  left: 14px;
  padding: 3px;
  position: absolute;
}

.zoom button {
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  min-width: 28px;
  padding: 4px 8px;
}

.zoom button:hover {
  background: var(--bg);
}

.zoom-level {
  color: var(--muted);
  font-size: 12px;
  min-width: 40px;
  text-align: center;
}

.edges {
  height: 1px;
  left: 0;
  overflow: visible;
  pointer-events: none;
  position: absolute;
  top: 0;
  width: 1px;
}

.edge {
  fill: none;
  stroke: #98a1b3;
  stroke-width: 2;
}

.edge-preview {
  stroke: var(--accent);
  stroke-dasharray: 5 4;
}

.edge-hit {
  cursor: pointer;
  fill: none;
  pointer-events: stroke;
  stroke: transparent;
  stroke-width: 14;
}

.edge-hit:hover {
  stroke: rgba(212, 60, 60, 0.25);
}

.node-start {
  --tone: #171a21;
}

.node-say {
  --tone: #0e9aa7;
}

.node-ai {
  --tone: #7a4dff;
}

.node-menu {
  --tone: #3b5bfd;
}

.node-hours {
  --tone: #d98a00;
}

.node-forward {
  --tone: #17875a;
}

.node-voicemail {
  --tone: #d6457a;
}

.node-hangup {
  --tone: #677084;
}

.node-dot {
  background: var(--tone);
  border-radius: 50%;
  flex: none;
  height: 9px;
  width: 9px;
}

.node {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: grab;
  position: absolute;
  width: 220px;
}

.node.selected {
  border-color: var(--tone);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 18%, transparent), var(--shadow);
}

.node-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  font-size: 13px;
  font-weight: 600;
  gap: 8px;
  padding: 9px 12px;
}

.node-summary {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  padding: 9px 12px;
}

.node-ports {
  border-top: 1px solid var(--line);
  padding: 6px 0;
}

.port-row {
  align-items: center;
  display: flex;
  font-size: 12px;
  font-weight: 500;
  justify-content: flex-end;
  padding: 3px 0 3px 12px;
  position: relative;
}

.port-label {
  overflow: hidden;
  padding-right: 14px;
  text-overflow: ellipsis;
  white-space: pre;
}

.port-out,
.port-in {
  background: var(--surface);
  border: 2px solid var(--tone);
  border-radius: 50%;
  height: 14px;
  position: absolute;
  width: 14px;
}

.port-out {
  cursor: crosshair;
  margin-top: -7px;
  right: -8px;
  top: 50%;
}

.port-out.linked {
  background: var(--tone);
}

.port-out:hover {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--tone) 22%, transparent);
}

.port-in {
  border-color: var(--line-strong);
  left: -8px;
  top: 12px;
}

.inspector {
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: auto;
  padding: 18px;
}

.inspector-head {
  align-items: center;
  display: flex;
  gap: 8px;
}

.inspector-head h3 {
  font-size: 15px;
}

.inspector-empty {
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inspector-empty h3 {
  color: var(--text);
}

.inspector .button.ghost.small {
  align-self: flex-start;
}

.inspector .button.danger {
  margin-top: auto;
}

.inspector .digit {
  flex: none;
  width: 62px;
}

.route {
  background: var(--bg);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
}

.day .check {
  align-items: center;
  display: flex;
  flex: none;
  gap: 6px;
  width: 62px;
}

.day input[type="time"] {
  padding: 5px 8px;
}

.canvas-actions,
.sheet-close {
  display: none;
}

[hidden] {
  display: none !important;
}

.segmented {
  background: #e6e9ef;
  border-radius: 9px;
  display: flex;
  flex: none;
  padding: 3px;
}

.segmented button {
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
  padding: 5px 14px;
}

.segmented button.active {
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
  color: var(--text);
}

.toolbar[data-mode="simple"] .advanced-only {
  display: none;
}

.simple-stage {
  flex: 1;
  margin-left: -26px;
  min-height: 0;
  overflow: auto;
  padding: 4px 26px 48px;
}

.simple {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0 auto;
  max-width: 640px;
}

.simple-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.simple-card header {
  align-items: center;
  display: flex;
  gap: 10px;
}

.step-number {
  align-items: center;
  background: var(--accent-soft);
  border-radius: 50%;
  color: var(--accent);
  display: flex;
  flex: none;
  font-size: 13px;
  font-weight: 700;
  height: 26px;
  justify-content: center;
  width: 26px;
}

.choice {
  align-items: flex-start;
  border: 1.5px solid var(--line-strong);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  gap: 12px;
  padding: 12px 14px;
}

.choice.chosen {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.choice input {
  accent-color: var(--accent);
  flex: none;
  height: 18px;
  margin: 2px 0 0;
  width: 18px;
}

.choice strong {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  font-size: 15px;
  font-weight: 600;
  gap: 8px;
}

.choice em {
  background: var(--accent);
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-style: normal;
  font-weight: 600;
  padding: 1px 8px;
}

.choice small {
  color: var(--muted);
  display: block;
  font-size: 13.5px;
  margin-top: 2px;
}

.toggle {
  align-items: center;
  cursor: pointer;
  display: flex;
  font-weight: 500;
  gap: 10px;
}

.toggle input {
  height: 18px;
  width: 18px;
}

.hours-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) auto minmax(0, 1fr);
}

.notice.warn {
  background: #fff8ea;
  color: #7a4b00;
}

.link-hint {
  align-items: center;
  background: var(--sidebar);
  border-radius: 999px;
  box-shadow: var(--shadow);
  color: #fff;
  cursor: default;
  display: flex;
  font-size: 13px;
  gap: 12px;
  left: 50%;
  padding: 8px 16px;
  position: absolute;
  top: 14px;
  transform: translateX(-50%);
  white-space: nowrap;
}

.link-hint[hidden] {
  display: none;
}

.link-hint .link {
  color: #a9b8ff;
}

.port-out::after {
  content: "";
  inset: -11px;
  position: absolute;
}

.port-out.arming {
  background: var(--tone);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--tone) 30%, transparent);
}

@media (max-width: 900px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }

  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    height: 100dvh;
  }

  .sidebar {
    flex-direction: row;
    gap: 0;
    order: 2;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }

  .sidebar .brand,
  .sidebar .spacer,
  .sidebar-foot,
  .sidebar > .link {
    display: none;
  }

  .sidebar a {
    flex: 1;
    font-size: 12.5px;
    gap: 6px;
    justify-content: center;
    padding: 11px 4px;
  }

  main {
    gap: 14px;
    padding: 16px 14px 24px;
  }

  main.view-flows {
    padding: 10px 0 0;
  }

  #toast {
    bottom: calc(76px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 32px);
    text-align: center;
  }

  .view-flows .toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 12px;
  }

  .view-flows .toolbar h1,
  .view-flows .toolbar .spacer {
    display: none;
  }

  .segmented {
    flex: 1;
    order: 1;
  }

  .segmented button {
    flex: 1;
    padding: 8px 10px;
  }

  .view-flows .toolbar .button.primary {
    order: 2;
  }

  .flow-picker {
    flex: 1 1 100%;
    order: 3;
    width: auto;
  }

  .view-flows .toolbar .button.ghost {
    font-size: 13px;
    order: 4;
    padding: 6px 10px;
  }

  .save-status {
    margin-left: auto;
    order: 5;
  }

  .simple-stage {
    margin-left: 0;
    padding: 4px 12px 40px;
  }

  .simple-card {
    padding: 16px;
  }

  .hours-row {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .hours-row select {
    grid-column: 1 / -1;
  }

  .split,
  .number-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .drawer {
    position: static;
  }

  th,
  td {
    padding: 10px 12px;
  }

  th:nth-child(3),
  td:nth-child(3) {
    display: none;
  }

  .voicemail header {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .voicemail footer {
    flex-wrap: wrap;
  }

  .builder {
    display: block;
    margin-left: 0;
    position: relative;
  }

  .canvas {
    height: 100%;
  }

  .canvas-actions {
    display: flex;
    gap: 8px;
    position: absolute;
    right: 12px;
    top: 12px;
  }

  .canvas-actions .button {
    box-shadow: var(--shadow);
    font-size: 14px;
    padding: 8px 14px;
  }

  .checks-button {
    background: #fff8ea;
    border-color: #f3dfb4;
    color: #7a4b00;
  }

  .checks-button[hidden] {
    display: none;
  }

  .link-hint {
    top: 60px;
  }

  .zoom {
    bottom: 12px;
    left: 12px;
  }

  .palette,
  .inspector {
    border: 0;
    border-radius: 16px 16px 0 0;
    bottom: 0;
    box-shadow: 0 -10px 34px rgba(16, 24, 40, 0.22);
    left: 0;
    max-height: 74dvh;
    padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    transform: translateY(105%);
    transition: transform 0.22s ease;
    z-index: 30;
  }

  .builder[data-sheet="palette"] .palette,
  .builder[data-sheet="inspector"] .inspector {
    transform: none;
  }

  .sheet-close {
    align-self: flex-end;
    background: var(--accent-soft);
    border: 0;
    border-radius: 999px;
    color: var(--accent);
    cursor: pointer;
    display: block;
    flex: none;
    font-weight: 600;
    margin-bottom: -6px;
    padding: 6px 14px;
  }

  .palette-item {
    padding: 10px 8px;
  }

  .inspector .button.danger {
    margin-top: 8px;
  }

  .auth-card {
    padding: 22px;
  }
}
