:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --border: #e4e1da;
  --border-strong: #cfcac0;
  --text: #1f1d1a;
  --muted: #6d685f;
  --accent: #e8590c;
  --accent-hover: #cc4c08;
  --accent-soft: #fdecdf;
  --ok: #2f7d4f;    --ok-soft: #e3f3e8;
  --warn: #9a6400;  --warn-soft: #fbf0d6;
  --bad: #c0362c;   --bad-soft: #fbe4e1;
  --info: #3b5ccc;  --info-soft: #e5ebfb;
  --code-bg: #f3f1ec;
  --shadow: 0 1px 2px rgba(31, 29, 26, .06), 0 2px 8px rgba(31, 29, 26, .04);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #1f1e1b;
    --surface-2: #252420;
    --border: #34322d;
    --border-strong: #46433c;
    --text: #ece9e3;
    --muted: #a19b90;
    --accent: #f76b1c;
    --accent-hover: #ff8238;
    --accent-soft: #3a2316;
    --ok: #6cc48f;   --ok-soft: #1d3326;
    --warn: #e2b04f; --warn-soft: #3a2f17;
    --bad: #f07a6f;  --bad-soft: #3d1f1c;
    --info: #8ea6f5; --info-soft: #1f2741;
    --code-bg: #191816;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: .4rem 0; }
code, .mono, pre, kbd { font-family: var(--mono); font-size: .86em; }
code { background: var(--code-bg); padding: .08em .35em; border-radius: 4px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.opt { color: var(--muted); font-weight: 400; font-size: .8rem; margin-left: .25rem; }
.kbd { font-family: var(--mono); font-size: .8em; border: 1px solid var(--border-strong); border-radius: 4px; padding: 0 .3em; }

/* ---------- layout ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1040px; margin: 0 auto; padding: 0 16px; height: 56px; display: flex; align-items: center; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after {
  content: ""; position: absolute; inset: 0;
  background: no-repeat center / 14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 8h10M8.5 4l4 4-4 4' stroke='white' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a[aria-current] { color: var(--text); background: var(--accent-soft); }
.signout { margin: 0; }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 6px; }
.link-btn:hover { color: var(--text); }

.wrap { max-width: 1040px; margin: 0 auto; padding: 28px 16px 80px; }
.is-bare .wrap { max-width: 440px; padding-top: 12vh; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.head-actions form { margin: 0; }
.crumbs { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .88rem; margin-bottom: 12px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }

.toast {
  background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 25%, transparent);
  padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; font-weight: 500;
}
.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; color: var(--muted); font-size: .9rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }

/* ---------- controls ---------- */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 11px; width: 100%; min-width: 0;
}
input.mono, textarea.mono, select.mono { font-size: .86rem; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; border-color: var(--accent);
}
input[readonly] { background: var(--surface-2); }
label { font-weight: 600; font-size: .9rem; display: block; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .9rem; white-space: nowrap;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn.is-busy { opacity: .7; pointer-events: none; }
.icon-btn { flex: none; width: 34px; height: 36px; border: 0; background: none; color: var(--muted); font-size: 1.25rem; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); }

.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: .88rem; margin-top: 10px; cursor: pointer; }
.check input { width: auto; margin-top: 3px; accent-color: var(--accent); }

/* on/off switch (checkbox) */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { width: 40px; height: 22px; border-radius: 22px; background: var(--border-strong); position: relative; transition: background .15s; }
.switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; 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 + .switch-ui { background: var(--ok); }
.switch input:checked + .switch-ui::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-on { display: none; color: var(--ok); }
.switch-off { color: var(--muted); }
.switch input:checked ~ .switch-on { display: inline; }
.switch input:checked ~ .switch-off { display: none; }

/* on/off switch (button, on list) */
.toggle-form { margin: 0; }
.switch-btn { width: 40px; height: 22px; border-radius: 22px; border: 0; padding: 0; background: var(--border-strong); position: relative; cursor: pointer; display: block; }
.switch-btn span { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch-btn[aria-checked="true"] { background: var(--ok); }
.switch-btn[aria-checked="true"] span { transform: translateX(18px); }

/* badges */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
a.badge:hover { text-decoration: none; filter: brightness(.97); }
.badge-success { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-failed { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge-retrying { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-pending, .badge-sending { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-test { background: transparent; }

/* ---------- auth ---------- */
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.35rem; margin-bottom: 6px; }
.auth-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; margin-bottom: 26px; }
.stack { display: grid; gap: 8px; margin-top: 18px; }
.stack .btn { margin-top: 6px; }

/* ---------- hook list ---------- */
.create-form { display: flex; gap: 8px; margin: 0; flex: 0 1 420px; }
.hook-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.hook-row { display: flex; align-items: center; gap: 16px; padding: 14px 18px; border-top: 1px solid var(--border); }
.hook-row:first-child { border-top: 0; }
.hook-row:hover { background: var(--surface-2); }
.hook-row.is-off .hook-name { color: var(--muted); }
.hook-main { flex: 1; min-width: 0; color: var(--text); display: grid; gap: 4px; }
.hook-main:hover { text-decoration: none; }
.hook-main:hover .hook-name { color: var(--accent); }
.hook-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hook-flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .8rem; }
.pill { font-family: var(--mono); font-size: .76rem; padding: 1px 8px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill-out { color: var(--text); }
.pill-empty { border-style: dashed; }
.arrow { color: var(--muted); }
.hook-stats { display: flex; align-items: center; gap: 12px; font-size: .84rem; white-space: nowrap; }

.empty { text-align: center; padding: 56px 24px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.empty h2 { margin-bottom: 6px; }
.empty p { max-width: 440px; margin: 0 auto; }
.flow-art { display: inline-flex; align-items: center; gap: 0; margin-bottom: 18px; font-family: var(--mono); font-size: .8rem; }
.flow-art span { border: 1px solid var(--border-strong); background: var(--surface-2); padding: 6px 12px; border-radius: 8px; }
.flow-art i { width: 40px; height: 2px; background: var(--accent); position: relative; }
.flow-art i::after { content: ""; position: absolute; right: -1px; top: -4px; border: 5px solid transparent; border-left-color: var(--accent); border-right: 0; }

/* ---------- editor ---------- */
#hook-form { max-width: 760px; }
.editor-head { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.title-input { font-size: 1.45rem; font-weight: 700; border-color: transparent; background: transparent; padding: 4px 8px; margin-left: -9px; flex: 1 1 280px; letter-spacing: -.01em; }
.title-input:hover { border-color: var(--border); }
.editor-actions { display: flex; align-items: center; gap: 12px; }

.step { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.step-head { display: flex; gap: 14px; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.step-icon { width: 38px; height: 38px; border-radius: 9px; flex: none; position: relative; background: var(--accent-soft); }
.step-icon::after { content: ""; position: absolute; inset: 0; background: no-repeat center / 20px; }
.step-icon-in::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e8590c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12h12M11 7l5 5-5 5M20 4v16'/%3E%3C/svg%3E"); }
.step-icon-out::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e8590c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 4v16M8 12h12M15 7l5 5-5 5'/%3E%3C/svg%3E"); }
.step-kind { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.step-num { color: var(--accent); }
.step-body { padding: 6px 20px 20px; }
.step-link { width: 2px; height: 28px; margin: 0 auto; background: var(--border-strong); position: relative; }
.step-link::after { content: ""; position: absolute; left: -4px; bottom: -2px; border: 5px solid transparent; border-top-color: var(--border-strong); border-bottom: 0; }

.field { margin-top: 18px; }
.field > label { margin-bottom: 6px; }
.field-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.field-row label { margin: 0; }
.hint { color: var(--muted); font-size: .83rem; margin: 6px 0 0; }
.field > .hint:first-of-type:not(:last-child) { margin: 0 0 8px; }
.copy-field, .url-row { display: flex; gap: 8px; }
.url-row select { width: 104px; flex: none; }
.url-row .tpl-wrap { flex: 1; }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; padding: 3px; gap: 2px; background: var(--surface-2); flex-wrap: wrap; }
.seg label { font-weight: 500; margin: 0; cursor: pointer; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: block; padding: 5px 14px; border-radius: 6px; font-size: .88rem; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.kv { display: grid; gap: 8px; }
.kv-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) auto; gap: 8px; align-items: start; }
.kv + .kv-add { margin-top: 8px; }

/* field picker */
.tpl-wrap { position: relative; }
.tpl-wrap input.tpl { padding-right: 40px; }
.tpl-btn {
  position: absolute; right: 5px; top: 5px; height: calc(100% - 10px); max-height: 28px; min-width: 30px;
  font-family: var(--mono); font-size: .78rem; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border: 0; border-radius: 6px; cursor: pointer; padding: 0 6px;
}
.tpl-area .tpl-btn { height: 28px; }
.tpl-btn:hover { filter: brightness(.95); }
.picker {
  position: absolute; z-index: 50; width: min(420px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15);
}
.picker-search { border: 0; border-bottom: 1px solid var(--border); border-radius: 10px 10px 0 0; }
.picker-search:focus { outline: none; border-color: var(--border); }
.picker-list { max-height: 300px; overflow: auto; padding: 4px; }
.picker-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 8px 10px 4px; }
.picker-item { display: grid; gap: 1px; width: 100%; text-align: left; background: none; border: 0; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--text); font: inherit; }
.picker-item:hover, .picker-item.is-active { background: var(--accent-soft); }
.picker-path { font-family: var(--mono); font-size: .82rem; font-weight: 600; word-break: break-all; }
.picker-val { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-empty { padding: 14px; color: var(--muted); font-size: .88rem; }

/* samples */
.samples { border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.samples:has(.samples-empty:not([hidden])) { border-style: dashed; }
.sample { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-top: 1px solid var(--border); font-weight: 400; cursor: pointer; }
.sample:first-child { border-top: 0; }
.sample:hover { background: var(--surface-2); }
.sample:has(input:checked) { background: var(--accent-soft); }
.sample input { width: auto; accent-color: var(--accent); margin: 0; }
.sample-main { flex: 1; display: flex; gap: 10px; flex-wrap: wrap; font-size: .88rem; }
.sample-when { font-size: .82rem; white-space: nowrap; }
.sample.is-new { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--ok-soft); } }
.samples-empty { margin: 0; padding: 14px; font-size: .88rem; }
.sample-data { margin-top: 10px; }
#listen-btn.is-listening { border-color: var(--ok); color: var(--ok); }
#listen-btn.is-listening::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

details > summary { cursor: pointer; color: var(--muted); font-size: .88rem; font-weight: 600; padding: 4px 0; user-select: none; }
details > summary:hover { color: var(--text); }
details[open] > summary { margin-bottom: 6px; }

pre.code {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; margin: 0; overflow: auto; max-height: 420px;
  font-size: .8rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.preview.is-error { color: var(--bad); background: var(--bad-soft); border-color: transparent; }

.test-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.test-result { margin-top: 12px; border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; }
.test-result.ok { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }
.test-result.bad { border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: var(--bad-soft); }
.test-result .test-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.test-result pre.code { background: var(--surface); max-height: 260px; }

.savebar {
  position: sticky; bottom: 0; margin-top: 20px; padding: 12px 0;
  display: flex; justify-content: flex-end; align-items: center; gap: 12px;
  background: linear-gradient(to bottom, transparent, var(--bg) 35%);
}

.danger-zone { max-width: 760px; margin-top: 36px; padding: 16px 20px; border: 1px solid var(--border); border-radius: 12px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.danger-actions { display: flex; gap: 8px; }
.danger-actions form { margin: 0; }

/* ---------- activity & request ---------- */
.filters { display: flex; gap: 8px; margin: 0; }
.filters select { width: auto; min-width: 150px; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table td { padding: 11px 16px; border-top: 1px solid var(--border); white-space: nowrap; }
.table tbody tr:first-child td { border-top: 0; }
.table tr[data-href] { cursor: pointer; }
.table tr[data-href]:hover td { background: var(--surface-2); }
.table .num { text-align: right; }
.pager { margin-top: 14px; text-align: right; }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.card-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sub { font-size: .88rem; margin-top: 4px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; font-size: .88rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-all; }
.kv-table { width: 100%; border-collapse: collapse; }
.kv-table th, .kv-table td { text-align: left; vertical-align: top; padding: 4px 8px 4px 0; border-top: 1px solid var(--border); word-break: break-all; }
.kv-table th { color: var(--muted); font-weight: 500; width: 38%; }
.delivery { border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; display: grid; gap: 6px; }
.delivery-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.out-line { word-break: break-all; }
.error-text { color: var(--bad); margin: 0; }

@media (max-width: 760px) {
  .cols { grid-template-columns: 1fr; }
  .hook-row { flex-wrap: wrap; gap: 10px 14px; }
  .hook-stats { width: 100%; padding-left: 54px; flex-wrap: wrap; }
  .create-form { flex: 1 1 100%; }
  .filters { flex-wrap: wrap; width: 100%; }
  .filters select { flex: 1; }
  .kv-row { grid-template-columns: 1fr auto; }
  .kv-row > input { grid-column: 1 / -1; }
  .kv-row > .tpl-wrap { grid-column: 1; }
  .step-body { padding: 4px 14px 16px; }
  .step-head { padding: 14px; }
  .editor-actions { width: 100%; justify-content: flex-end; }
  .topbar-inner { gap: 12px; }
}
