:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f4f3;
  --text: #1f2933;
  --muted: #65707c;
  --border: #dde3ea;
  --line: #06c755;
  --red: #ff6b6f;
  --blue: #4f83ff;
  --shadow: 0 12px 36px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
  padding: 10px 14px;
}

button:hover {
  filter: brightness(1.05);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

code {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 2px 6px;
}

.hidden {
  display: none !important;
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  margin: 12vh auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.login-card p {
  margin: 0 0 24px;
  color: var(--muted);
}

.login-card form {
  display: grid;
  gap: 14px;
}

.login-card label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 650;
}

.error {
  color: #c92a2a !important;
  margin-top: 14px !important;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: #111827;
  color: #fff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--line);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: #9ca3af;
  font-size: 13px;
}

nav {
  display: grid;
  gap: 8px;
}

.nav-button,
.logout {
  background: transparent;
  color: #d1d5db;
  text-align: left;
  border: 1px solid transparent;
}

.nav-button.active,
.nav-button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.08);
}

.logout {
  margin-top: auto;
  color: #fecaca;
}

.workspace {
  min-width: 0;
  background: #fbfcfd;
}

.topbar {
  height: 88px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 28px;
}

.topbar h2 {
  margin: 0;
  font-size: 24px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.tab-panel {
  padding: 28px;
  display: grid;
  gap: 20px;
}

#flowsTab {
  padding: 0;
  height: calc(100vh - 88px);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.metrics article,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 18px;
}

.metrics span {
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

.panel {
  padding: 20px;
}

.panel h3,
.panel h4 {
  margin: 0;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header.tight {
  justify-content: flex-start;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr auto;
  gap: 10px;
  align-items: center;
}

.account-manager {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.2fr);
  gap: 20px;
  align-items: start;
}

.account-form {
  display: grid;
  gap: 13px;
}

.account-form label {
  display: grid;
  gap: 6px;
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

.account-form input,
.account-form textarea,
.account-form select {
  font-size: 13px;
  font-weight: 500;
}

.checkbox-field {
  grid-template-columns: auto 1fr;
  align-items: center;
  justify-content: start;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
}

.copy-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.copy-row button {
  min-width: 78px;
}

.copy-row button:disabled {
  background: #e5e7eb;
  color: #6b7280;
  cursor: not-allowed;
  filter: none;
}

.webhook-status {
  display: block;
  line-height: 1.45;
  font-size: 12px;
  font-weight: 650;
}

.webhook-status.ok {
  color: #078a40;
}

.webhook-status.warning {
  color: #c2410c;
}

.media-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.media-input-row button,
.media-card button {
  min-height: 36px;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12px;
  white-space: nowrap;
  background: #eef2f7;
  color: #334155;
}

.inline-media-picker {
  max-height: 240px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.inline-media-picker span {
  color: var(--muted);
  font-size: 12px;
}

.inline-media-option {
  min-height: 0;
  display: grid;
  gap: 5px;
  align-content: start;
  border: 1px solid #e5edf5;
  border-radius: 7px;
  background: #fbfcfd;
  color: #334155;
  padding: 6px;
  text-align: left;
}

.inline-media-option img {
  width: 100%;
  aspect-ratio: 20 / 13;
  object-fit: cover;
  border-radius: 5px;
  background: #eef2f7;
}

.inline-media-option span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inline-upload-control {
  display: grid;
  gap: 8px;
}

.inline-upload-preview {
  min-height: 150px;
  border: 1px solid #e5edf5;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.inline-upload-preview.empty {
  border-style: dashed;
  background: #f8fafc;
  color: var(--muted);
}

.inline-upload-preview img {
  width: 100%;
  aspect-ratio: 20 / 13;
  object-fit: cover;
}

.inline-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.upload-button {
  width: fit-content;
  min-height: 36px;
  display: inline-flex !important;
  align-items: center;
  border-radius: 7px;
  padding: 8px 10px;
  background: #111827;
  color: #fff !important;
  cursor: pointer;
  font-size: 12px !important;
  font-weight: 700 !important;
}

.upload-button input {
  display: none;
}

.inline-upload-actions button {
  min-height: 36px;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12px;
  background: #eef2f7;
  color: #334155;
}

.size-hint {
  color: #ef4444;
  font-size: 12px;
  font-weight: 650;
}

pre {
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  min-height: 160px;
}

.list {
  display: grid;
  gap: 10px;
}

.list.compact {
  gap: 8px;
}

.row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 6px;
}

.row.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79, 131, 255, 0.12);
}

.row-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

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

.row-actions button,
.danger-button {
  min-height: 30px;
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 12px;
}

.danger-button {
  background: #fff1f1;
  color: #c92a2a;
}

.row-title strong {
  font-size: 15px;
}

.row small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 7px;
  padding: 3px 8px;
  background: #ffe5e6;
  color: #c92a2a;
  font-size: 12px;
  font-weight: 700;
}

.node-type-keyword_trigger {
  border-color: #ffb3b6;
  background: #fff1f1;
}

.node-type-line_message {
  border-color: #dbe7f8;
}

.builder-layout {
  min-height: calc(100vh - 88px);
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 300px;
  background: #f8fafc;
}

.flow-sidebar,
.inspector {
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow: auto;
}

.inspector {
  border-right: 0;
  border-left: 1px solid var(--border);
}

.inspector h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.inspector-empty {
  min-height: 120px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 16px;
  margin-bottom: 22px;
}

.builder-stage {
  min-width: 0;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
}

.builder-toolbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
}

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

.tool-button {
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 7px;
  background: #111827;
  color: #fff;
  font-size: 13px;
}

.tool-button.red {
  background: var(--red);
}

.tool-button.ghost {
  background: #eef2f7;
  color: #334155;
}

.canvas-search {
  width: 190px;
  border: 2px solid #ff6b6f;
  border-radius: 14px;
  color: #1f2937;
  padding: 9px 14px;
  font-size: 13px;
  background: #fff;
}

.flow-canvas {
  position: relative;
  overflow: auto;
  background:
    radial-gradient(circle at 1px 1px, rgba(148, 163, 184, 0.22) 1px, transparent 0),
    #ffffff;
  background-size: 24px 24px;
}

.edge-layer,
.node-layer {
  position: absolute;
  inset: 0;
  min-width: 1400px;
  min-height: 820px;
}

.edge-layer {
  pointer-events: auto;
  z-index: 1;
}

.node-layer {
  z-index: 2;
  pointer-events: none;
}

.canvas-empty {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 48px));
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  display: grid;
  gap: 6px;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: #475467;
}

.canvas-empty strong {
  color: #1f2937;
}

.canvas-empty span {
  color: var(--muted);
  font-size: 13px;
}

.flow-node {
  position: absolute;
  width: 230px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.11);
  border: 1px solid #e5edf5;
  overflow: visible;
  cursor: grab;
  user-select: none;
  pointer-events: auto;
}

.flow-node.selected {
  box-shadow: 0 0 0 3px rgba(79, 131, 255, 0.18), 0 10px 28px rgba(15, 23, 42, 0.12);
  border-color: #7aa2ff;
}

.flow-node:active {
  cursor: grabbing;
}

.flow-node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 6px;
}

.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #070707;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 7px;
  font-weight: 900;
}

.flow-node-title {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.flow-node-title strong {
  font-size: 13px;
  line-height: 1.1;
}

.flow-node-title span {
  color: #667085;
  font-size: 9px;
  text-transform: uppercase;
}

.keyword-node {
  width: 260px;
  background: #ffb4b8;
  border-color: #ffa0a5;
  padding: 12px;
}

.keyword-node .flow-node-header {
  padding: 0 0 8px;
}

.keyword-node .avatar {
  background: #ef4444;
}

.keyword-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.keyword-tags .tag {
  background: #ff6b6f;
  color: #fff;
}

.message-body {
  padding: 0 12px 12px;
  display: grid;
  gap: 8px;
}

.line-text-bubble {
  border: 1px solid #edf1f5;
  background: #fff;
  border-radius: 7px;
  padding: 8px 10px;
  color: #475467;
  font-size: 11px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.line-image-preview {
  height: 118px;
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(10, 199, 85, 0.85), rgba(10, 65, 42, 0.95)),
    linear-gradient(45deg, #16a34a, #0f172a);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  overflow: hidden;
}

.line-image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-preview {
  border: 1px solid #edf1f5;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  min-width: 0;
}

.card-hero {
  aspect-ratio: 20 / 13;
  height: auto;
  min-height: 0;
  background:
    linear-gradient(135deg, rgba(17, 24, 39, 0.1), rgba(0, 0, 0, 0.25)),
    linear-gradient(135deg, #111827, #0bb657);
  color: #fff;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 900;
  font-size: 15px;
  line-height: 1.2;
  padding: 0;
  overflow: hidden;
}

.card-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-copy {
  padding: 8px 10px;
  min-width: 0;
}

.card-copy strong {
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-copy p {
  margin: 0;
  color: #667085;
  font-size: 10px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-buttons {
  display: grid;
  gap: 1px;
  border-top: 1px solid #edf1f5;
}

.card-buttons button,
.quick-reply-chip {
  position: relative;
  background: #f8fafc;
  color: #344054;
  border-radius: 0;
  min-height: 28px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-action-preview {
  position: relative;
}

.button-port {
  position: absolute;
  right: -7px;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #d7dee8;
  background: #fff;
  transform: translateY(-50%);
  cursor: crosshair;
  z-index: 5;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.button-port:hover {
  transform: translateY(-50%) scale(1.35);
  border-color: var(--blue);
  box-shadow: 0 0 0 5px rgba(79, 131, 255, 0.14);
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 2px;
}

.quick-reply-chip {
  border: 1px solid #edf1f5;
  border-radius: 8px;
  background: #fff;
  color: #59708f;
}

.node-port {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #d7dee8;
  background: #fff;
  top: 50%;
  transform: translateY(-50%);
  cursor: crosshair;
  z-index: 4;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.node-port.in {
  left: -7px;
}

.node-port.out {
  right: -7px;
}

.node-port:hover {
  transform: translateY(-50%) scale(1.35);
  border-color: var(--blue);
  box-shadow: 0 0 0 5px rgba(79, 131, 255, 0.14);
}

.edge-path {
  fill: none;
  stroke: #98a2b3;
  stroke-width: 1.5;
  stroke-dasharray: 4 5;
  pointer-events: none;
}

.temp-edge {
  stroke: var(--blue);
  stroke-width: 2;
  stroke-dasharray: 7 5;
  pointer-events: none;
}

.edge-dot {
  fill: #cbd5e1;
  stroke: #fff;
  stroke-width: 2;
}

.edge-delete {
  pointer-events: auto;
  cursor: pointer;
}

.edge-delete-hit {
  fill: transparent;
}

.edge-delete-circle {
  fill: #cbd5e1;
  stroke: #fff;
  stroke-width: 2;
  transition: fill 0.12s ease, transform 0.12s ease;
}

.edge-delete-text {
  fill: #ffffff;
  font-size: 14px;
  font-weight: 800;
  pointer-events: none;
  user-select: none;
}

.edge-delete:hover .edge-delete-circle {
  fill: #ef4444;
  transform: scale(1.14);
}

.inspector-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.inspector-card pre {
  min-height: 120px;
  font-size: 11px;
  margin: 0;
}

.editor-field {
  display: grid;
  gap: 6px;
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

.editor-field input,
.editor-field textarea,
.editor-field select {
  font-size: 13px;
  font-weight: 500;
}

.editor-section {
  display: grid;
  gap: 10px;
}

.editor-section-header,
.message-edit-head,
.editor-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.editor-section-header strong {
  font-size: 13px;
}

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-end;
}

.mini-actions button,
.message-edit-head button {
  min-height: 28px;
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 11px;
  background: #eef2f7;
  color: #334155;
}

.message-editor-list {
  display: grid;
  gap: 10px;
}

.message-edit-item {
  display: grid;
  gap: 9px;
  border: 1px solid #e5edf5;
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfd;
}

.message-edit-head strong {
  font-size: 12px;
}

.message-edit-head button {
  color: #c92a2a;
  background: #fff1f1;
}

.card-button-editor,
.quick-reply-editor {
  display: grid;
  gap: 8px;
}

.card-button-row,
.quick-reply-row {
  display: grid;
  gap: 8px;
  border: 1px solid #e5edf5;
  border-radius: 8px;
  padding: 9px;
  background: #fff;
}

.card-button-row label,
.quick-reply-row label {
  display: grid;
  gap: 5px;
  color: #667085;
  font-size: 11px;
  font-weight: 700;
}

.card-button-row-head,
.quick-reply-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.card-button-row-head strong,
.quick-reply-row-head strong {
  font-size: 12px;
}

.card-button-row-head button,
.quick-reply-row-head button,
.add-card-button {
  min-height: 30px;
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 11px;
  background: #eef2f7;
  color: #334155;
}

.card-button-row-head button,
.quick-reply-row-head button {
  color: #c92a2a;
  background: #fff1f1;
}

.editor-empty {
  min-height: 68px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.editor-actions {
  display: grid;
  grid-template-columns: 1fr auto;
}

.editor-actions button:first-child {
  background: var(--line);
}

.editor-actions .danger-button {
  background: #fff1f1;
  color: #c92a2a;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.media-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.media-card img {
  display: block;
  width: 100%;
  aspect-ratio: 20 / 13;
  object-fit: cover;
  background: var(--surface-2);
}

.media-card div {
  padding: 10px;
  display: grid;
  gap: 8px;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar,
  .inline-form,
  .metrics,
  .account-manager,
  .builder-layout {
    grid-template-columns: 1fr;
  }

  #flowsTab,
  .builder-layout {
    height: auto;
  }

  .builder-stage {
    min-height: 640px;
  }

  .topbar {
    height: auto;
    align-items: flex-start;
    padding: 20px;
  }
}
