:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel2: #eef0f4; --border: #dde1e8;
  --text: #1d2433; --muted: #667082; --accent: #e8632e; --accent2: #b34617;
  --good: #1e9e66; --bad: #d64545; --warn: #b07708; --info: #2f6fd0;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
#app { display: flex; min-height: 100vh; }
a { color: var(--info); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 15px; margin: 20px 0 8px; color: var(--accent2); font-weight: 700; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.sidebar { width: 210px; background: var(--panel); border-right: 1px solid var(--border); padding: 16px 0; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.logo { font-size: 18px; font-weight: 700; padding: 4px 18px 14px; color: var(--accent); }
.logo span { color: var(--text); }
.nav a { display: block; padding: 8px 18px; color: var(--muted); border-left: 3px solid transparent; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--panel2); border-left-color: var(--accent); }
.sidebar .foot { position: absolute; bottom: 12px; left: 0; right: 0; padding: 0 18px; font-size: 12px; color: var(--muted); }
.sidebar .foot button { margin-top: 6px; }

.main { flex: 1; padding: 22px 26px; max-width: 1200px; }

.cards { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; min-width: 130px; }
.card .num { font-size: 24px; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 12px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(29,36,51,.05); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--panel2); }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: var(--panel2); cursor: pointer; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.active, .badge.sent, .badge.ok { background: rgba(30,158,102,.12); color: var(--good); }
.badge.paused, .badge.deferred, .badge.dry_run, .badge.draft { background: rgba(176,119,8,.12); color: var(--warn); }
.badge.blocked, .badge.failed, .badge.needs_review { background: rgba(214,69,69,.1); color: var(--bad); }
.badge.stopped, .badge.completed, .badge.skipped, .badge.archived { background: rgba(102,112,130,.12); color: var(--muted); }
.badge.email, .badge.sms, .badge.wait, .badge.branch, .badge.exit, .badge.brief { background: rgba(47,111,208,.1); color: var(--info); }

button { background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #ffffff; font-weight: 700; }
button.danger { background: rgba(214,69,69,.08); border-color: var(--bad); color: var(--bad); }
button.small { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: .45; cursor: default; }

input, select, textarea { background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; font-size: 13px; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { width: 100%; min-height: 110px; resize: vertical; }
label { display: block; color: var(--muted); font-size: 12px; margin: 10px 0 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex-shrink: 0; }
.grow { flex: 1; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(29,36,51,.05); }
.muted { color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

.kill { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); margin-bottom: 18px; }
.kill.on { border-color: var(--bad); background: rgba(214,69,69,.06); }
.switch { position: relative; width: 46px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--panel2); border: 1px solid var(--border); border-radius: 24px; transition: .15s; }
.switch .slider:before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: var(--muted); border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(22px); background: #ffffff; }

.login-wrap { margin: auto; width: 340px; padding-top: 12vh; }
.login-wrap input { width: 100%; margin-bottom: 10px; }
.err { color: var(--bad); font-size: 13px; margin: 8px 0; }
.okmsg { color: var(--good); font-size: 13px; margin: 8px 0; }

.step-row { display: grid; grid-template-columns: 26px 90px 1fr 64px 64px 64px 64px 78px 90px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.step-row .pos { color: var(--muted); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--border); margin-left: 6px; position: relative; }
.timeline li:before { content: ""; position: absolute; left: -5px; top: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.timeline li.kind-sent:before, .timeline li.kind-enrolled:before { background: var(--good); }
.timeline li.kind-blocked:before, .timeline li.kind-error:before, .timeline li.kind-send_failed:before, .timeline li.kind-needs_review:before { background: var(--bad); }
.timeline li.kind-dry_run:before, .timeline li.kind-deferred:before, .timeline li.kind-paused:before { background: var(--warn); }
.timeline .when { color: var(--muted); font-size: 11px; }
.modal-bg { position: fixed; inset: 0; background: rgba(29,36,51,.4); display: flex; z-index: 50; }
.modal { margin: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(720px, 92vw); max-height: 86vh; overflow: auto; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--good); border-radius: 8px; padding: 10px 16px; z-index: 99; box-shadow: 0 6px 24px rgba(29,36,51,.14); }
.toast.bad { border-left-color: var(--bad); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button.on { background: var(--accent); color: #ffffff; border-color: var(--accent); font-weight: 700; }
.pill-mode { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 4px; }
.pill-mode.mock { background: rgba(176,119,8,.12); color: var(--warn); }
.pill-mode.live { background: rgba(30,158,102,.12); color: var(--good); }

/* ---------------------------------------------------------- responsive ---- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 860px) {
  #app { flex-direction: column; }
  .sidebar {
    position: sticky; top: 0; height: auto; width: 100%; z-index: 40;
    display: flex; align-items: center; gap: 4px;
    padding: 8px 10px; border-right: none; border-bottom: 1px solid var(--border);
  }
  .logo { padding: 0 10px 0 4px; font-size: 16px; white-space: nowrap; }
  .nav {
    display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch;
    flex: 1; scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    padding: 8px 10px; border-left: none; border-bottom: 3px solid transparent;
    white-space: nowrap; font-size: 13px;
  }
  .nav a.active, .nav a:hover { border-left: none; border-bottom-color: var(--accent); }
  .sidebar .foot { position: static; padding: 0 4px; display: flex; align-items: center; gap: 8px; }
  .sidebar .foot br { display: none; }
  .sidebar .foot button { margin-top: 0; }
  .foot-meta { display: none; }

  .main { padding: 14px 12px; max-width: 100%; }
  h1 { font-size: 18px; }
  .cards { gap: 8px; }
  .card { min-width: calc(33% - 8px); flex: 1; padding: 10px 12px; }
  .card .num { font-size: 20px; }

  /* tables scroll sideways instead of crushing */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { white-space: nowrap; }

  /* step editor: stack each step into a wrapping row */
  .step-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 0; }
  .step-row .pos { width: 100%; font-weight: 700; }
  .step-row input[type="number"] { width: 64px; }
  .step-row input[data-f="at_time"] { width: 80px; }

  .row > div { flex: 1 1 45%; min-width: 140px; }
  .row input, .row select { max-width: 100%; }
  input, select, textarea { font-size: 16px; } /* prevents iOS zoom-on-focus */
  .kill { flex-wrap: wrap; }
  .modal { padding: 14px; }
  .login-wrap { width: min(340px, 92vw); padding-top: 8vh; }
  .toast { left: 12px; right: 12px; text-align: center; }
}

@media (max-width: 480px) {
  .card { min-width: calc(50% - 8px); }
  .main { padding: 12px 8px; }
}
