:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1b1f24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --ok: #059669;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: #0f1115;
  color: #c7cbd1;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: #fff;
  font-size: 15px;
  padding: 6px 8px 18px;
}
.logo {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-weight: 800;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6b7280;
  padding: 16px 10px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  color: #aeb4bd;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: #1a1d23; color: #fff; }
.nav-link.active { background: #22262e; color: #fff; }
.nav-link.disabled { color: #565b64; cursor: default; }
.nav-link.disabled em { font-style: normal; font-size: 10px; margin-left: auto; opacity: .7; }
.nav-link .ico { width: 16px; text-align: center; opacity: .8; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 4px; }
.sidebar-toggle {
  position: absolute; top: 16px; right: -13px; z-index: 6;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; line-height: 1;
  background: #1a1d23; color: #c7cbd1; border: 1px solid #2c313a;
  cursor: pointer; font-size: 15px; padding: 0;
}
.sidebar-toggle:hover { background: #22262e; color: #fff; }
.brand-name { white-space: nowrap; }

@media (min-width: 721px) {
  .sidebar { transition: width .15s ease, flex-basis .15s ease, padding .15s ease; }
  .sidebar .brand, .nav-link, .nav-text, .brand-name, .nav-label, .sidebar-foot { transition: opacity .12s ease; }
  body.sidebar-collapsed .sidebar { width: 64px; flex: 0 0 64px; padding: 18px 10px; }
  body.sidebar-collapsed .brand-name,
  body.sidebar-collapsed .nav-text,
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .nav-link em,
  body.sidebar-collapsed .sidebar-foot { display: none; }
  body.sidebar-collapsed .brand { justify-content: center; padding: 6px 0 18px; }
  body.sidebar-collapsed .nav-link { justify-content: center; padding: 9px 0; }
  body.sidebar-collapsed .nav-link .ico { width: auto; }
}
@media (max-width: 720px) {
  .sidebar-toggle { display: none; }
}

/* Content */
.content { flex: 1; min-width: 0; max-width: 100%; padding: 22px 28px 60px; overflow-x: clip; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.topbar { align-items: flex-start; }
.topbar h1 { font-size: 20px; min-width: 0; overflow-wrap: anywhere; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* Project identity sits above the page title: the project is the workspace, the
   page is just where you are inside it. */
.topbar-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.project-crumb {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  align-self: flex-start;
  max-width: 100%;
  padding: 3px 9px 3px 10px;
  margin-bottom: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 120ms, box-shadow 120ms;
}
.project-crumb:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.project-crumb-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.project-crumb-name {
  font-size: 13px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-crumb-switch { color: var(--muted); font-size: 10px; }
.project-crumb.is-empty { border-color: #fde68a; background: #fffbeb; }
.project-crumb.is-empty .project-crumb-name { color: #92400e; }

/* Project tiles: the card is the button. */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 18px;
}
.project-tile {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.project-tile.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
/* The form that turns a tile into a link. It is a plain block wrapper in both
   the picker and the manage page, so the button styling lives in one place. */
.project-tile-form { display: block; margin: 0; }
.project-tile-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 18px 18px 14px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.project-tile-btn:hover { background: #fafbff; }
.project-tile-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.project-tile-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}
.project-tile-desc {
  font-size: 13px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.project-tile-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--muted);
}
.project-tile-stats strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.project-tile-cta { font-size: 12px; font-weight: 600; color: var(--accent); margin-top: 2px; }
.project-tile-tools {
  display: flex;
  gap: 8px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}
.project-tile-tools form { margin: 0; }

.project-edit-panel { grid-column: 1 / -1; }
.project-edit-panel[hidden] { display: none; }

/* Collapsible "New project" form */
.project-new { margin-bottom: 6px; }
.project-new > summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
}
.project-new > summary::-webkit-details-marker { display: none; }
.project-new > summary::before { content: '+'; color: var(--accent); font-weight: 700; }
.project-new[open] > summary::before { content: '\2212'; }
.project-new > summary:hover { border-color: var(--accent); }
.project-new .form-card { margin-top: 12px; }
.env-badge {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: #fff;
  padding: 3px 9px;
  border-radius: 999px;
}

.btn:disabled { opacity: .5; cursor: default; }
.btn:disabled:hover { background: var(--accent); }
.btn.tiny:disabled:hover { background: #fff; }

.hero { margin-bottom: 22px; }
.hero h2 { font-size: 18px; margin-bottom: 4px; }

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
a.card { transition: transform .1s, box-shadow .1s; }
a.card:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(16,24,40,.08), 0 12px 28px rgba(16,24,40,.07); }
.card.ghost { background: transparent; box-shadow: none; border-style: dashed; }
.card-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.card-value { font-size: 28px; font-weight: 700; margin: 6px 0 2px; }
.card-foot { color: var(--muted); font-size: 12px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 9px 14px; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Section */
.section-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 14px;
}
.section-head h2 { font-size: 16px; margin-bottom: 2px; }

.notice {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  padding: 9px 12px; border-radius: 9px; font-size: 12px; margin-bottom: 14px;
}
.notice-warn { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.notice code { font-size: 11px; }
.setup-checks { margin-bottom: 18px; }
.setup-checks .notice:last-child { margin-bottom: 0; }

/* Tables */
.table-wrap {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { white-space: nowrap; }
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbff; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
td.row-actions { text-align: right; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 7px 12px; border-radius: 9px; font-size: 13px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.tiny { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn.icon { padding: 4px 8px; line-height: 1; }

/* Pills */
.pill {
  border: 1px solid var(--line); background: #fff; cursor: pointer;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.pill.on { background: #ecfdf5; border-color: #a7f3d0; color: var(--ok); }
.pill.off { background: #f3f4f6; border-color: var(--line); color: var(--muted); }

/* Forms */
.form-card, .card { background: var(--panel); }
.form-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.form-card h3, .card-head h3 { font-size: 15px; margin-bottom: 12px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; min-width: 0; }
input, select, textarea {
  font: inherit; color: var(--ink);
  border: 1px solid var(--line); background: #fff;
  border-radius: 9px; padding: 8px 10px; width: 100%;
  min-width: 0; max-width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }
.alert { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: 8px 11px; border-radius: 9px; margin-bottom: 12px; font-size: 13px; }

/* Empty + status */
.empty {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 28px; text-align: center; color: var(--muted); background: #fff;
}
.status { font-size: 12px; font-weight: 600; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }
.status.muted { color: var(--muted); font-weight: 500; }

/* Flow detail */
.detail-head { margin-bottom: 10px; }
.back { color: var(--muted); font-size: 13px; }
.back:hover { color: var(--ink); }
.title-row { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; flex-wrap: wrap; }
.title-input {
  border: 1px solid transparent; background: transparent;
  font-size: 20px; font-weight: 700; padding: 4px 8px; border-radius: 8px;
  flex: 1 1 240px; width: 100%; min-width: 0; max-width: 100%;
}
.title-input:hover { border-color: var(--line); background: #fff; }
.title-input:focus { border-color: var(--accent); background: #fff; }

/* Steps */
.steps-card { padding: 18px; margin-top: 16px; }
.steps { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.step {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fafbfc;
  min-width: 0; max-width: 100%; flex-wrap: wrap;
}
.step-num {
  width: 22px; height: 22px; flex: 0 0 22px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; font-size: 12px; font-weight: 700;
}
.drag-handle {
  cursor: grab; color: #b8bcc4; user-select: none;
  font-size: 15px; line-height: 1; padding: 0 2px;
}
.drag-handle:hover { color: var(--muted); }
.drag-handle:active { cursor: grabbing; }
.step-ghost { opacity: .5; background: var(--accent-soft); border-style: dashed; }
.step-form { display: flex; gap: 8px; flex: 1 1 200px; min-width: 0; flex-wrap: wrap; }
.step-form select { flex: 0 1 180px; width: auto; min-width: 0; }
.step-form input { flex: 1 1 160px; min-width: 0; text-overflow: ellipsis; }
.step-tools { display: flex; gap: 4px; flex: 0 0 auto; }
.step-add { display: flex; gap: 8px; border-top: 1px dashed var(--line); padding-top: 14px; }
.step-add select { flex: 0 1 180px; width: auto; min-width: 0; }
.step-add input { flex: 1 1 160px; min-width: 0; text-overflow: ellipsis; }

@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-label, .sidebar-foot { display: none; }
  .content { padding: 16px; }
  .topbar { flex-wrap: wrap; }
  .project-crumb-name { max-width: 45vw; }
}

/* Builder branches */
.canvas { padding: 16px; min-width: 0; max-width: 100%; overflow-x: clip; }
.step-main { display: flex; align-items: center; gap: 10px; flex: 1 1 200px; min-width: 0; flex-wrap: wrap; }
.step.is-condition { flex-direction: column; align-items: stretch; background: #fff; }
.step.is-condition > .step-main { padding-bottom: 6px; }
.branches { display: flex; gap: 12px; flex-wrap: wrap; min-width: 0; }
.branch { flex: 1 1 220px; min-width: 0; border-left: 2px solid var(--line); padding: 6px 0 6px 12px; }
.branch.yes { border-left-color: #a7f3d0; }
.branch.no { border-left-color: #fecaca; }
.branch-tag { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.branch.yes .branch-tag { color: var(--ok); }
.branch.no .branch-tag { color: var(--danger); }
.step-add.mini { padding-top: 8px; flex-wrap: wrap; }
.step-add.mini input, .step-add.mini select { flex: 1; min-width: 90px; }
.step-add { flex-wrap: wrap; }

/* Chart */
#chart { padding: 4px; min-width: 0; max-width: 100%; }
.chart-trigger, .cbox {
  display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border: 1px solid var(--line); background: #fff;
  border-radius: 10px; padding: 9px 12px; box-shadow: var(--shadow);
  min-width: 0; max-width: 100%;
}
.chart-trigger { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.ctype { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; flex: 0 0 auto; }
.clabel { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.cval { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; word-break: break-word; min-width: 0; }
.clist { list-style: none; margin: 10px 0 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.clist.root { border-left: 0; padding-left: 0; margin-top: 14px; }
.cnode { position: relative; min-width: 0; }
.cnode::before { content: ''; position: absolute; left: -18px; top: 18px; width: 14px; height: 2px; background: var(--line); }
.clist.root > .cnode::before { display: none; }
.cnode.cond > .cbox { border-color: #c7d2fe; background: #f5f3ff; }
.cbranches { display: flex; gap: 14px; margin-top: 10px; flex-wrap: wrap; min-width: 0; }
.cbranch { flex: 1 1 200px; min-width: 0; }
.ctag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; }
.ctag.yes { background: #ecfdf5; color: var(--ok); }
.ctag.no { background: #fef2f2; color: var(--danger); }
.cempty { color: var(--muted); font-size: 12px; padding: 6px 0; }

/* Graphical flow canvas */
.flow-canvas { position: relative; }
.flow-col { position: relative; padding-left: 26px; }
.flow-col::before {
  content: ''; position: absolute; left: 9px; top: 8px; bottom: 8px;
  width: 2px; background: linear-gradient(var(--accent), var(--line));
  border-radius: 2px;
}
.flow-col > .step { position: relative; }
.flow-col > .step::before {
  content: ''; position: absolute; left: -24px; top: 22px;
  width: 15px; height: 2px; background: var(--line);
}
.node { border-radius: 12px; border: 1px solid var(--line); background: #fff; box-shadow: var(--shadow); }
.node-send_email { border-top: 3px solid var(--accent); }
.node-condition { border-top: 3px solid #8b5cf6; background: #fdfeff; }
.node-delay { border-top: 3px solid #f59e0b; }
.node-webhook { border-top: 3px solid #0ea5e9; }
.node-stop { border-top: 3px solid var(--danger); }
.node-tag { border-top: 3px solid var(--ok); }
.node-untag { border-top: 3px solid #f97316; }
.node-set_field { border-top: 3px solid #6366f1; }
.node-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.node-head select { max-width: 230px; font-weight: 600; }
/* Node form hardening: column layout, natural control heights, no stretch */
.node-form { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-width: 0; }
.step-form.node-form input, .step-form.node-form select, .step-form.node-form textarea { flex: none; width: 100%; max-width: none; height: auto; }
.node-form .node-head select { max-width: none; }
.node-fields { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.node-fields textarea { resize: vertical; min-height: 44px; }
.node-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.node-row > label { flex: 1 1 160px; min-width: 0; }
.needs {
  display: inline-block; font-size: 11px; font-weight: 700;
  background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.node-problems { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.node-problems li { font-size: 12px; color: #92400e; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 2px 8px; }
.step-add.palette { border: 2px dashed #c7d2fe; border-radius: 12px; padding: 12px; background: #fbfbff; margin-top: 14px; }

/* Step collapse/expand */
.canvas-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.step-toggle {
  font-size: 12px;
  line-height: 1;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  flex: 0 0 24px;
}
.step.is-collapsed {
  padding-top: 7px;
  padding-bottom: 7px;
}
.step.is-collapsed .step-main {
  flex-wrap: nowrap;
}
.step.is-collapsed .node-form {
  flex-direction: row;
  align-items: center;
}
.step.is-collapsed .node-head {
  margin-bottom: 0;
  flex: 1 1 auto;
}
.step.is-collapsed .node-head select {
  width: auto;
  min-width: 150px;
  max-width: 240px;
}
.step.is-collapsed .node-fields,
.step.is-collapsed .node-problems,
.step.is-collapsed .branches {
  display: none !important;
}
.step-summary {
  display: none;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 8px;
  background: #f3f4f6;
  border-radius: 6px;
  cursor: pointer;
}
.step-summary:hover {
  background: #e5e7eb;
  color: var(--ink);
}
.step.is-collapsed .step-summary {
  display: inline-block;
}

/* Trigger-first setup */
.flow-setup { margin: 16px 0; }
.trigger-node { border-top: 3px solid var(--accent); }
.trigger-node.trigger-highlight {
  box-shadow: 0 0 0 4px var(--accent-soft), 0 0 0 2px var(--accent);
  transition: box-shadow 0.2s ease;
}
.node-tag {
  display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent); background: var(--accent-soft);
  padding: 2px 10px; border-radius: 999px; margin-bottom: 8px;
}
.fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 12px; background: #fafbff; }
.fieldset .grid { margin-bottom: 8px; }
.issues { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.issues li { font-size: 13px; color: #92400e; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 6px 10px; }
.issues li::before { content: '⚠ '; }
.ready { color: var(--ok); font-weight: 600; }
.full { grid-column: 1 / -1; }

/* Run & events */
.run-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
@media (max-width: 900px) { .run-grid { grid-template-columns: 1fr; } }
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow: auto; }
.event { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 12px; background: #fff; }
.ev-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.ev-type { font-weight: 700; }
.ev-clicked .ev-type, .ev-opened .ev-type { color: var(--ok); }
.ev-sent .ev-type { color: var(--accent); }
.ev-condition_true .ev-type { color: var(--ok); }
.ev-condition_false .ev-type { color: var(--muted); }
.ev-run_error .ev-type, .ev-webhook_error .ev-type { color: var(--danger); }
.ev-contact { color: var(--muted); }
.ev-detail { color: var(--ink); word-break: break-word; }
.run-links ul { margin: 8px 0 0; padding-left: 18px; font-size: 12px; word-break: break-all; }
.contact-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .contact-cols { grid-template-columns: 1fr; } }
textarea {
  font: inherit; color: var(--ink);
  border: 1px solid var(--line); background: #fff;
  border-radius: 9px; padding: 8px 10px; width: 100%;
}
textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.inline-add { margin-bottom: 16px; }
code { background: #f3f4f6; border-radius: 5px; padding: 1px 5px; font-size: 12px; }

/* Diagram (Drawflow) */
.graph-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.graph-tools select, .graph-tools input {
  height: 30px;
  padding: 4px 8px;
  font-size: 13px;
  line-height: normal;
  width: auto;
  box-sizing: border-box;
}
.graph-tools select { width: 190px; }
.graph-tools input { width: 230px; }
.graph-add-label { display: inline; font-size: 12px; color: var(--muted); font-weight: 600; }
.drawflow-host {
  height: 580px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  background-color: #fbfcff;
  background-image: radial-gradient(#dde4ef 1px, transparent 1px);
  background-size: 22px 22px;
}
#drawflow .drawflow-node {
  width: 235px; min-height: 0; padding: 10px 12px; background: #fff;
  border: 1px solid var(--line); border-top: 3px solid var(--accent);
  border-radius: 12px; color: var(--ink); box-shadow: var(--shadow);
}
#drawflow .drawflow-node:hover { cursor: move; }
#drawflow .drawflow-node.selected { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
#drawflow .drawflow-node.gnode-trigger { border-top-color: #0ea5e9; background: #f0f9ff; }
#drawflow .drawflow-node.gnode-condition { border-top-color: #8b5cf6; }
#drawflow .drawflow-node.gnode-delay { border-top-color: #f59e0b; }
#drawflow .drawflow-node.gnode-webhook { border-top-color: #0ea5e9; }
#drawflow .drawflow-node.gnode-stop { border-top-color: var(--danger); }
#drawflow .drawflow-node.gnode-tag { border-top-color: var(--ok); }
#drawflow .drawflow-node .input, #drawflow .drawflow-node .output {
  width: 12px; height: 12px; margin-bottom: 8px; border-width: 2px; border-color: #94a3b8; background: #fff;
}
#drawflow .drawflow-node .input { left: -6px; border-color: var(--accent); }
#drawflow .drawflow-node .output { right: -6px; }
#drawflow .drawflow-node .output::after {
  content: attr(data-label); position: absolute; right: 17px; top: -3px;
  font-size: 10px; font-weight: 700; color: var(--muted); white-space: nowrap; pointer-events: none;
}
#drawflow .drawflow-node .output.port-yes { border-color: var(--ok); }
#drawflow .drawflow-node .output.port-no { border-color: var(--danger); }
#drawflow .drawflow-node .output.port-next, #drawflow .drawflow-node .output.port-start { border-color: var(--accent); }
#drawflow .connection .main-path { stroke: #93a6c4; stroke-width: 2.5px; }
#drawflow .connection .main-path:hover { stroke: var(--accent); cursor: pointer; }
#drawflow .connection .main-path.selected { stroke: var(--ok); }
#drawflow .drawflow-delete { background: var(--danger); border-color: #fff; }

.gnode-inner { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.gnode-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gnode-label { font-weight: 700; font-size: 13px; overflow-wrap: anywhere; }
.gnode-sum { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.gnode-needs { font-size: 10px; font-weight: 700; background: #fef3c7; color: #92400e; border: 1px solid #fde68a; padding: 1px 6px; border-radius: 999px; white-space: nowrap; }
.gnode-tools { display: flex; gap: 6px; justify-content: flex-end; }
.gnode-btn { font-size: 11px; padding: 1px 8px; border-radius: 6px; border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--muted); }
.gnode-btn:hover { color: var(--ink); border-color: var(--accent); }
.gnode-del:hover { color: var(--danger); border-color: var(--danger); }
.draft-zone { margin-top: 18px; border-top: 2px dashed var(--line); padding-top: 10px; }
.drafts-col { padding-left: 22px; }
.drafts-col::before { background: repeating-linear-gradient(180deg, var(--line) 0 6px, transparent 6px 12px); }
.chart-drafts { margin-top: 16px; border-top: 2px dashed var(--line); padding-top: 10px; }

/* MCP settings */
.copy-row { display: flex; gap: 6px; align-items: center; }
.copy-row input { flex: 1 1 auto; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.copy-row .btn { flex: 0 0 auto; }
.mcp-tools { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mcp-tools li { display: flex; gap: 10px; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.mcp-tools li:last-child { border-bottom: 0; padding-bottom: 0; }
.mcp-tools code { flex: 0 0 auto; font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 7px; }
.mcp-tools span { font-size: 13px; color: var(--muted); }

/* Email previews — the frame is sized by the content it reports, so long
   emails do not need an inner scrollbar. */
.preview-frame {
  display: block;
  width: 100%;
  height: 120px;
  min-height: 80px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  transition: height 120ms ease-out;
}
.preview-stage { width: 100%; }
.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.preview-toolbar .tabs { margin-bottom: 0; }
.preview-toolbar .tab { padding: 4px 10px; font-size: 12px; }
.preview-grow { flex: 1 1 auto; }
.preview-origin code { font-size: 11px; }
.preview-origin-warn { color: #b45309; }
.preview-origin-warn code { color: #b45309; }
.preview-links {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.preview-links ul { margin: 6px 0; padding-left: 18px; }
.preview-links li { word-break: break-all; margin-bottom: 2px; }
.preview-links code { font-size: 11px; }
.preview-subject {
  margin: 0 0 10px 0;
  font-size: 14px;
  word-break: break-word;
}
.preview-card .card-head { align-items: flex-start; }
.preview-live-hint { color: var(--muted); font-size: 12px; }

/* Broadcast detail action row */
.action-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.action-row form { display: flex; gap: 8px; align-items: center; margin: 0; }
.action-row form.inline-input input { width: 200px; }

/* Analytics */
.analytics-page { display: flex; flex-direction: column; }
.period-switcher .tabs { margin-bottom: 0; }
.period-switcher .tab { padding: 6px 12px; font-size: 13px; }
.kpi-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.kpi-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.kpi-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--line);
}
.kpi-card:nth-child(1)::after { background: #4f46e5; }
.kpi-card:nth-child(2)::after { background: #059669; }
.kpi-card:nth-child(3)::after { background: #d97706; }
.kpi-card:nth-child(4)::after { background: #8b5cf6; }
.kpi-card:nth-child(5)::after { background: #0ea5e9; }

.chart-card {
  border-radius: var(--radius);
  background: var(--panel);
}
.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.legend-sent { background: #4f46e5; }
.legend-open { background: #059669; }
.legend-click { background: #d97706; }

.analytics-chart-svg rect {
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.analytics-chart-svg rect:hover {
  opacity: 0.85;
  cursor: pointer;
}

/* Template preview and live editors */
.template-preview-pane {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 14px;
}
.template-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 17, 21, 0.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.template-modal-card {
  background: #fff;
  border-radius: var(--radius);
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}

/* Drip-style Workflows & Subscriber Management */
.node-untag { border-top: 3px solid #e11d48; }
#drawflow .drawflow-node.gnode-untag { border-top-color: #e11d48; }

.tag-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(79, 70, 229, 0.15);
  transition: all 0.15s ease;
}
.tag-badge.filter-active {
  background: var(--accent);
  color: #fff;
}
.tag-badge .tag-remove {
  background: none;
  border: none;
  color: inherit;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  margin: 0 0 0 2px;
  cursor: pointer;
  opacity: 0.6;
}
.tag-badge .tag-remove:hover {
  opacity: 1;
  color: var(--danger);
}

.contacts-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 12px 0;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.contacts-filter-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.contacts-filter-controls input,
.contacts-filter-controls select {
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  padding-left: 24px;
  margin-top: 12px;
}
.timeline-list::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 11px;
  width: 2px;
  background: var(--line);
}
.timeline-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  position: relative;
}
.timeline-marker {
  position: absolute;
  left: -24px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  z-index: 1;
}
.timeline-content {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
}
.timeline-title {
  font-size: 13px;
  margin-bottom: 3px;
}
.timeline-detail {
  font-weight: normal;
  color: var(--ink);
  margin-left: 6px;
}
.timeline-meta {
  font-size: 11px;
}

.custom-field-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-subtle);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
}
.custom-field-badge strong {
  font-weight: 600;
}

#drawflow .drawflow-node.gnode-set_field {
  border-top-color: #6366f1;
}


/* Template editor: form and live preview side by side */
.template-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 1100px) {
  .template-editor { grid-template-columns: 1fr; }
}
.template-editor-form { margin: 0; }
.template-editor-preview {
  position: sticky;
  top: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.preview-loading { color: var(--muted); font-size: 13px; padding: 18px 4px; }

/* CSV import */
.import-card .import-advanced { margin: 10px 0 0 0; }
.import-card .import-advanced summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.import-card .import-advanced[open] summary { margin-bottom: 8px; }
.import-card input[type="file"] { font-size: 12px; }
.import-preview code { font-size: 11px; }
.import-preview details { margin-top: 10px; }
.import-preview details summary { cursor: pointer; font-size: 12px; color: var(--muted); }

.preview-standalone .preview-frame { min-height: 200px; }

/* ---------- login ---------- */
.login-shell {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login-brand h1 { font-size: 18px; margin: 0; }
.login-brand p { margin: 0; }
.login-submit { width: 100%; justify-content: center; }
.login-foot { margin: 0; text-align: center; }
.login-foot code { font-size: 11px; word-break: break-all; }

/* When logged out the page chrome is noise — the layout hides it. */
body.auth-login .sidebar,
body.auth-login .topbar-id { display: none; }

.logout-form { margin: 0; display: flex; }
