/* =============================================================
   UX Gym Comms Tool — stylesheet
   Design targets: Apple product pages, Things 3, Linear.
   Neutral-first. Color is a signal, not decoration.
   ============================================================= */

/* ---------- Tokens ---------- */

:root {
  /* Neutral scale */
  --gray-50:  #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #ebebeb;
  --gray-300: #d4d4d4;
  --gray-400: #a3a3a3;
  --gray-500: #737373;
  --gray-600: #525252;
  --gray-700: #404040;
  --gray-800: #262626;
  --gray-900: #171717;
  --gray-950: #0a0a0a;

  /* Brand — used sparingly */
  --primary:       #FF6229;
  --primary-press: #E8521C;
  --gold:          #FFB71A;
  --red:           #FF450F;

  /* Semantic (light) */
  --bg:            #ffffff;
  --bg-muted:      var(--gray-50);
  --surface:       #ffffff;
  --surface-hover: var(--gray-50);
  --surface-tint:  rgba(255, 98, 41, 0.06);

  --border:        rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.10);
  --border-focus:  var(--primary);

  --text:          #1a1a1a;
  --text-muted:    var(--gray-500);
  --text-subtle:   var(--gray-400);
  --text-on-primary: #ffffff;

  --success:       #0f7c3d;
  --success-bg:    rgba(15, 124, 61, 0.08);
  --warning:       #a56300;
  --warning-bg:    rgba(255, 183, 26, 0.12);
  --error:         #c1331a;
  --error-bg:      rgba(255, 69, 15, 0.08);

  /* Type */
  --font-sans: 'Satoshi', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Spacing — 4px base */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;
  --s-9: 96px;

  /* Radius */
  --r-badge: 4px;
  --r-input: 6px;
  --r-btn:   6px;
  --r-card:  8px;
  --r-modal: 12px;

  /* Elevation — soft, multi-layer */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md:
    0 1px 3px rgba(0, 0, 0, 0.04),
    0 8px 24px rgba(0, 0, 0, 0.04);
  --shadow-lg:
    0 2px 4px rgba(0, 0, 0, 0.04),
    0 16px 48px rgba(0, 0, 0, 0.08);

  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px rgba(255, 98, 41, 0.5);

  /* Motion */
  --t-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --t:      200ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset & base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.6;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 {
  margin: 0;
  font-family: var(--font-sans);
  line-height: 1.2;
  color: var(--text);
}
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
h4 { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }

p { margin: 0; }

code, pre, .mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--t);
}
a:hover { color: var(--primary-press); }

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

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  border: 0;
}

::selection { background: var(--surface-tint); color: var(--text); }

/* Focus — keyboard only */
:focus { outline: none; }
:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--r-input); }

/* ---------- Login ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-muted);
  padding: var(--s-4);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s-7);
  box-shadow: var(--shadow-md);
}

.login-logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.login-logo span { color: var(--primary); }

.login-subtitle {
  margin: var(--s-1) 0 var(--s-6);
  font-size: 14px;
  color: var(--text-muted);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.shake { animation: shake 0.32s cubic-bezier(0.4, 0, 0.2, 1); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 var(--s-4);
  border: 1px solid transparent;
  border-radius: var(--r-btn);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  user-select: none;
  transition:
    background var(--t),
    border-color var(--t),
    color var(--t),
    opacity var(--t);
  white-space: nowrap;
}
.btn:disabled { cursor: not-allowed; opacity: 0.4; }

.btn-block { width: 100%; }
.btn-sm    { height: 32px; padding: 0 var(--s-3); font-size: 13px; }

.btn-primary {
  background: var(--primary);
  color: var(--text-on-primary);
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-press);
  border-color: var(--primary-press);
}
.btn-primary:disabled { background: var(--gray-300); border-color: var(--gray-300); opacity: 1; color: var(--bg); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger {
  background: var(--red);
  color: #ffffff;
  border-color: var(--red);
}
.btn-danger:hover:not(:disabled) { background: #d33a0d; border-color: #d33a0d; }

.btn-link {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--t);
}
.btn-link:hover { color: var(--text); }

/* Icon button (used for modal close). Text inside is hidden; glyph is CSS-drawn. */
.btn-icon {
  position: relative;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--r-btn);
  background: transparent;
  color: var(--text-muted);
  font-size: 0;
  cursor: pointer;
  transition: background var(--t), color var(--t);
}
.btn-icon::before,
.btn-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 1.5px;
  background: currentColor;
  border-radius: 1px;
}
.btn-icon::before { transform: translate(-50%, -50%) rotate(45deg); }
.btn-icon::after  { transform: translate(-50%, -50%) rotate(-45deg); }
.btn-icon:hover   { background: var(--surface-hover); color: var(--text); }

/* ---------- Form controls ---------- */

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 0 var(--s-3);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  transition:
    border-color var(--t),
    background var(--t);
  -webkit-appearance: none;
  appearance: none;
}
textarea {
  min-height: 200px;
  padding: 12px var(--s-3);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  resize: vertical;
}
select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 17px,
    calc(100% - 13px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: var(--s-7);
  cursor: pointer;
}
input:hover:not(:disabled):not(:focus),
select:hover:not(:disabled):not(:focus),
textarea:hover:not(:disabled):not(:focus) {
  border-color: var(--gray-400);
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 98, 41, 0.15);
}
input::placeholder,
textarea::placeholder { color: var(--text-subtle); }

.error-message {
  padding: 10px var(--s-3);
  background: var(--error-bg);
  color: var(--error);
  border-radius: var(--r-input);
  font-size: 13px;
  font-weight: 500;
}

/* Checkbox */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  min-height: 0;
  background: var(--bg);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-badge);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: background var(--t), border-color var(--t);
}
input[type="checkbox"]:hover:not(:disabled) { border-color: var(--gray-400); }
input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 4px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(42deg);
  animation: check-in var(--t);
}
@keyframes check-in {
  0%   { opacity: 0; transform: rotate(42deg) scale(0.4); }
  100% { opacity: 1; transform: rotate(42deg) scale(1); }
}

/* Radio */
input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  min-height: 0;
  background: var(--bg);
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: border-color var(--t);
}
input[type="radio"]:hover:not(:disabled) { border-color: var(--gray-400); }
input[type="radio"]:checked { border-color: var(--primary); }
input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: radio-in var(--t);
}
@keyframes radio-in {
  0%   { transform: translate(-50%, -50%) scale(0); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* ---------- App header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 var(--s-5);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
}

.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.brand span { color: var(--primary); }
.brand small {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
}

.app-header-meta {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.health-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
}
.health-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}
.health-pill.ok    { background: var(--success-bg); color: var(--success); }
.health-pill.warn  { background: var(--warning-bg); color: var(--warning); }
.health-pill.error { background: var(--error-bg);   color: var(--error); }

/* ---------- Main layout ---------- */

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--s-7) var(--s-5) var(--s-9);
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
}

.zone {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s-5);
}

.zone-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-4);
  gap: var(--s-3);
}
.zone-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0;
}
.zone-actions {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

/* ---------- Diagram ---------- */

.diagram-container {
  position: relative;
  max-height: 350px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  background: var(--bg-muted);
  padding: var(--s-4);
}

.diagram-loading {
  display: flex;
  gap: var(--s-4);
  flex-wrap: wrap;
}
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-hover) 0%,
    var(--border-strong) 50%,
    var(--surface-hover) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--r-input);
}
.skeleton-node { width: 180px; height: 64px; }
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.refresh-indicator {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

.mermaid-host svg { max-width: none; }

.empty-state {
  padding: var(--s-6) var(--s-4);
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

/* Mermaid node color overrides */
.node-green rect,    .node-green polygon    { fill: var(--success-bg) !important; stroke: var(--success) !important; }
.node-yellow rect,   .node-yellow polygon   { fill: var(--warning-bg) !important; stroke: var(--warning) !important; }
.node-red rect,      .node-red polygon      { fill: var(--error-bg) !important;   stroke: var(--error) !important; }
.node-inprogress rect, .node-inprogress polygon {
  fill: var(--surface-tint) !important;
  stroke: var(--primary) !important;
  animation: pulse-border 1.8s ease-in-out infinite;
}
@keyframes pulse-border {
  0%, 100% { stroke-width: 1.5; }
  50%      { stroke-width: 3; }
}

/* ---------- Fields ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.field label,
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
.field-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}
.req { color: var(--red); font-weight: 400; }

.composer {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

/* Chip checkbox group (channels) */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.chip-check {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: 36px;
  padding: 0 var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background var(--t), border-color var(--t), color var(--t);
}
.chip-check:hover { background: var(--surface-hover); }
.chip-check:has(input:checked) {
  background: var(--surface-tint);
  border-color: var(--primary);
  color: var(--primary);
}

/* Inline toggle */
.toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.toggle-inline:hover { color: var(--text); }
.toggle-inline input[type="checkbox"] { width: 14px; height: 14px; }

/* Radio row */
.radio-row {
  display: flex;
  gap: var(--s-5);
  flex-wrap: wrap;
}
.radio {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

/* ---------- Tag picker ---------- */

.tag-picker {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-3);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
}
.tag-search { background: var(--bg); }
.tag-list {
  max-height: 192px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0;
}
.tag-list-loading {
  padding: var(--s-3);
  font-size: 13px;
  color: var(--text-muted);
}
.tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: 8px 10px;
  border-radius: var(--r-input);
  cursor: pointer;
  transition: background var(--t);
}
.tag-row:hover { background: var(--surface-hover); }
.tag-row.selected { background: var(--surface-tint); }
.tag-row > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.tag-row .tag-name {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.005em;
}
.tag-row.selected .tag-name { color: var(--primary); }
.tag-row .tag-count {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}
.tag-row.pinned .tag-name::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold);
  margin-right: 8px;
  vertical-align: middle;
  transform: translateY(-1px);
}

.tag-selected {
  padding-top: var(--s-3);
  border-top: 1px solid var(--border);
}
.tag-selected-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-right: var(--s-2);
  letter-spacing: 0.02em;
}
.tag-selected-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  vertical-align: middle;
}
.tag-selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  background: var(--primary);
  color: #ffffff;
  border-radius: var(--r-badge);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.005em;
}
.tag-selected-chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  background: rgba(255, 255, 255, 0.18);
  border: none;
  border-radius: 3px;
  color: #ffffff;
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  transition: background var(--t);
}
.tag-selected-chip button:hover { background: rgba(255, 255, 255, 0.3); }

.lead-count {
  padding: 10px var(--s-3);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  font-size: 13.5px;
  color: var(--text-muted);
}
.lead-count strong {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.lead-count code {
  padding: 1px 6px;
  background: var(--surface-hover);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Channel blocks ---------- */

.channel-block {
  margin: 0;
  padding: var(--s-4);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}
.channel-block legend {
  padding: 0 var(--s-2);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field-with-sidebar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px;
  gap: var(--s-4);
  align-items: start;
}
.field-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-width: 0;
}

.variable-picker {
  position: sticky;
  top: 72px;
  max-height: 340px;
  overflow: auto;
  padding: var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
}
.variable-picker-title {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: var(--s-2);
}
.variable-picker-group-title {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-subtle);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: var(--s-3);
  margin-bottom: 4px;
}
.variable-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.variable-item {
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: var(--r-badge);
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--t), color var(--t);
  width: 100%;
}
.variable-item:hover {
  background: var(--surface-tint);
  color: var(--primary);
}

.wa-template-preview {
  margin: 0;
  padding: var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 240px;
  overflow: auto;
  color: var(--text);
}
.wa-variable-fields {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

/* ---------- CSV ---------- */

.csv-row {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  flex-wrap: wrap;
}
.csv-status {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}
.csv-status strong {
  color: var(--text);
  font-weight: 600;
}
.csv-status code {
  padding: 1px 6px;
  background: var(--surface-hover);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---------- Checkpoint row ---------- */

.checkpoint-row {
  display: flex;
  gap: var(--s-3);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.checkpoint-row .btn {
  flex: 1 1 0;
  min-width: 140px;
}

/* ---------- Queue ---------- */

.queue-group {
  margin-bottom: var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow: hidden;
}
.queue-group:last-child { margin-bottom: 0; }

.queue-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--s-4);
  list-style: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: background var(--t);
}
.queue-group summary::-webkit-details-marker { display: none; }
.queue-group summary:hover { background: var(--surface-hover); }

/* Chevron drawn with CSS borders */
.queue-group summary > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.queue-group summary > span:first-child::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform var(--t);
  margin-right: 2px;
}
.queue-group[open] summary > span:first-child::before {
  transform: rotate(45deg);
}

.queue-count {
  padding: 2px 8px;
  background: var(--surface-hover);
  color: var(--text-muted);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.queue-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}
.queue-list > .empty-state { padding: var(--s-5) var(--s-4); }

.queue-row {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--t);
}
.queue-row:first-child { border-top: none; }
.queue-row:hover { background: var(--surface-hover); }
.queue-row > div:first-child {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.queue-row > div:not(:first-child) {
  flex: 0 0 auto;
}
.campaign-slug {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
.campaign-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.campaign-meta code {
  padding: 1px 6px;
  background: var(--surface-hover);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.channel-icon {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  background: var(--surface-hover);
  color: var(--text-muted);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metric-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.metric-inline span {
  color: var(--text);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--r-badge);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.status-badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}
.status-badge.scheduled { background: var(--warning-bg); color: var(--warning); }
.status-badge.sending   { background: var(--surface-tint); color: var(--primary); }
.status-badge.sent      { background: var(--success-bg); color: var(--success); }
.status-badge.killed,
.status-badge.failed    { background: var(--error-bg); color: var(--error); }
.status-badge.draft     { background: var(--surface-hover); color: var(--text-muted); }

/* ---------- Modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-4);
  z-index: 50;
  animation: modal-fade var(--t-fast);
}
.modal[hidden] { display: none; }
@keyframes modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-modal);
  box-shadow: var(--shadow-lg);
  animation: modal-pop var(--t);
}
.modal-dialog-wide { max-width: 780px; }

@keyframes modal-pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-body {
  padding: var(--s-5);
  overflow: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  background: var(--bg-muted);
  border-top: 1px solid var(--border);
}

/* Dry-run stats */
.dry-run-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-2);
  margin-bottom: var(--s-5);
}
.dry-run-stat {
  padding: var(--s-3) var(--s-4);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
}
.dry-run-stat .label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.dry-run-stat .value {
  margin-top: 4px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.dry-run-stat.warn {
  background: var(--warning-bg);
  border-color: rgba(255, 183, 26, 0.3);
}
.dry-run-stat.warn .value { color: var(--warning); }
.dry-run-stat.error {
  background: var(--error-bg);
  border-color: rgba(255, 69, 15, 0.3);
}
.dry-run-stat.error .value { color: var(--error); }

.dry-run-sample {
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-2);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
}
.dry-run-sample-header {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}
.dry-run-sample-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.dry-run-sample-body strong { font-weight: 600; }

/* Campaign detail */
.campaign-detail-section { margin-bottom: var(--s-5); }
.campaign-detail-section:last-child { margin-bottom: 0; }
.campaign-detail-section h4 { margin-bottom: var(--s-2); }

.campaign-copy {
  padding: var(--s-3);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 260px;
  overflow: auto;
  color: var(--text);
  margin: 0;
}

.reply-row,
.failure-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.reply-row:last-child,
.failure-row:last-child { border-bottom: none; }
.reply-row strong,
.failure-row strong { font-weight: 600; color: var(--text); }

/* ---------- Toast ---------- */

.toast-root {
  position: fixed;
  bottom: var(--s-5);
  right: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  z-index: 60;
  pointer-events: none;
}
.toast {
  padding: 10px 14px;
  background: var(--gray-900);
  color: #ffffff;
  border-radius: var(--r-input);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  pointer-events: auto;
  animation: toast-in var(--t);
}
.toast.success {
  background: var(--success);
  color: #ffffff;
}
.toast.error {
  background: var(--red);
  color: #ffffff;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .app-header { padding: 0 var(--s-4); }
  .app-main {
    padding: var(--s-5) var(--s-4) var(--s-8);
    gap: var(--s-5);
  }
  .zone { padding: var(--s-4); }
  .field-with-sidebar {
    grid-template-columns: 1fr;
  }
  .variable-picker {
    position: static;
    max-height: 200px;
  }
  .checkpoint-row {
    flex-direction: column;
  }
  .checkpoint-row .btn {
    width: 100%;
  }
  .dry-run-summary {
    grid-template-columns: 1fr 1fr;
  }
  .queue-row {
    flex-wrap: wrap;
  }
}
