/* Variable font (weight axis 400–700) — lets us use 450 for normal text. */
@font-face { font-family: "Instrument Sans"; font-style: normal; font-weight: 400 700; font-display: swap; src: url("/fonts/instrument-sans-var.woff2") format("woff2"); }

* { box-sizing: border-box; }
:root {
  --font: "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --accent: #5b53e8;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --line: #e7e8ef;
  --ink: #1c1d28;
  --muted: #8a8c99;
  --soft: #f1f1f5;
}
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-weight: 450; /* normal text sits at 450 instead of 400 */
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--ink); }
a { color: var(--accent); }

/* ---------- Login ---------- */
.login-wrap {
  height: 100vh; display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px; width: 340px; box-shadow: 0 12px 40px rgba(17,18,28,.08);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .sub { color: var(--muted); margin: 0 0 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 12px; margin-bottom: 6px; color: #54566280; text-transform: uppercase; letter-spacing: .05em; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; background: #fff;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.btn { background: var(--accent); color: #fff; border: 0; padding: 10px 16px; border-radius: 9px; font-weight: 600; }
.btn:hover { filter: brightness(.95); }
.btn.full { width: 100%; }
.btn.ghost { background: transparent; color: #54566; border: 1px solid var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--soft); filter: none; }
.btn.danger { background: #fff; color: #d23b3b; border: 1px solid #f3c9c9; }
.btn.danger:hover { background: #fdf0f0; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.err { color: #d23b3b; font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- App shell ---------- */
.app { display: none; height: 100vh; flex-direction: column; }
.app.on { display: flex; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.brand { font-weight: 800; color: var(--accent); font-size: 16px; }
.project-select { display: flex; align-items: center; gap: 8px; }
.project-select select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; min-width: 180px; }
.spacer { margin-left: auto; }
.status-chip { font-size: 12px; padding: 4px 10px; border-radius: 20px; font-weight: 600; }
.status-chip.dirty { background: #fff5e6; color: #b7791f; }
.status-chip.clean { background: #e9f7ee; color: #2a8a4a; }
.status-chip.none { background: var(--soft); color: var(--muted); }
.muted { color: var(--muted); }

.cols { flex: 1 1 auto; display: grid; grid-template-columns: 260px 1fr; min-height: 0; }

/* editor + preview stacked vertically, 50:50, filling the area beside the sidebar */
.main-stack { display: grid; grid-template-rows: 1fr 1fr; min-height: 0; min-width: 0; }

/* ---------- Sidebar ---------- */
.sidebar { border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; }
.side-section { padding: 14px 14px 6px; }
.side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.side-head h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0; }
.icon-btn { width: 24px; height: 24px; border: 1px solid var(--line); background: #fff; border-radius: 7px; color: var(--ink); line-height: 1; }
.icon-btn:hover { background: var(--soft); }
.item-list { list-style: none; margin: 0; padding: 0 8px 8px; }
.item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 9px; cursor: pointer; margin-bottom: 2px;
}
.item:hover { background: var(--soft); }
.item.active { background: #eeedfd; }
.item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.item .name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.item .badge { font-size: 11px; color: var(--muted); }
.item.inactive .dot, .item.inactive .name { opacity: 0.5; }
.item.inactive .badge { color: #b7791f; text-transform: uppercase; font-weight: 700; letter-spacing: .04em; }
.empty { color: var(--muted); font-size: 13px; padding: 6px 10px 14px; }

/* Active/Inactive switch */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; position: relative; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { width: 34px; height: 20px; border-radius: 20px; background: #cfd0da; position: relative; transition: background .15s; flex: 0 0 auto; }
.switch .slider::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: #2a8a4a; }
.switch input:checked + .slider::after { transform: translateX(14px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-label { font-size: 13px; font-weight: 600; color: var(--muted); min-width: 54px; }
.switch input:checked ~ .switch-label { color: #2a8a4a; }

/* editor header row */
.editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.editor-head-right { display: flex; align-items: center; gap: 16px; flex: 0 0 auto; }

/* ---------- Editor ---------- */
.editor { overflow-y: auto; padding: 22px 26px; }
.editor-empty { color: var(--muted); display: flex; height: 100%; align-items: center; justify-content: center; text-align: center; padding: 40px; }
.editor h1.title { font-size: 18px; margin: 0 0 2px; }
.editor .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.card-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card-box > h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.selector-row { display: flex; gap: 8px; align-items: flex-end; }
.selector-row .field { flex: 1 1 auto; margin-bottom: 0; }
.found { font-size: 12px; margin-top: 6px; }
.found.yes { color: #2a8a4a; }
.found.no { color: #b7791f; }

/* steps */
.step { border: 1px solid var(--line); border-radius: 11px; margin-bottom: 12px; background: #fcfcfe; }
.step-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; }
.step-head .num { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: 0 0 auto; }
.step-head .stitle { flex: 1 1 auto; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-head .step-ctrls { display: flex; gap: 4px; }
.step-body { padding: 0 12px 12px; display: none; }
.step.open .step-body { display: block; }
.add-step { width: 100%; border: 1px dashed var(--line); background: #fff; border-radius: 10px; padding: 10px; color: var(--accent); font-weight: 600; }
.add-step:hover { background: #faf9ff; }

/* targeting */
.rule { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.rule select { width: 110px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; background: #fff; }
.rule input { flex: 1 1 auto; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.rule .icon-btn { flex: 0 0 auto; }
.add-rule { background: transparent; border: 0; color: var(--accent); font-weight: 600; padding: 4px 0; }
.summary { background: #f4f4fb; border-radius: 9px; padding: 10px 12px; font-size: 13px; color: #41434f; margin-top: 8px; }
.summary b { color: var(--ink); }
.mode-toggle { display: flex; gap: 6px; margin-bottom: 12px; }
.mode-toggle button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; font-size: 13px; }
.mode-toggle button.on { background: var(--accent); color: #fff; border-color: transparent; }

/* ---------- Preview pane ---------- */
.preview { border-top: 1px solid var(--line); background: #eef0f6; display: flex; flex-direction: column; min-height: 0; }
.preview-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.preview-bar .ttl { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.preview-frame-wrap { flex: 1 1 auto; padding: 14px; min-height: 0; }
.preview iframe { width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fff; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(17,18,28,.45); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal-back.on { display: flex; }
.modal { background: #fff; border-radius: 16px; padding: 24px; width: 460px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,.3); max-height: 86vh; overflow-y: auto; }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.snippet { background: #15161f; color: #e7e7ef; border-radius: 10px; padding: 14px; font: 12px/1.5 ui-monospace, Menlo, monospace; overflow-x: auto; white-space: pre; }
.copy-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.key-display { font: 13px ui-monospace, Menlo, monospace; background: var(--soft); padding: 8px 10px; border-radius: 8px; word-break: break-all; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: #15161f; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px; opacity: 0; transition: all .2s ease; z-index: 100; pointer-events: none; }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.help { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.swatch { width: 26px; height: 26px; border-radius: 7px; border: 2px solid transparent; cursor: pointer; }
.swatch.on { border-color: var(--ink); }
.inline-actions { display: flex; gap: 8px; align-items: center; margin: 10px 0 20px; flex-wrap: wrap; }
