:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --ink: #11162a;
  --ink-2: #4a5170;
  --muted: #8b91a9;
  --line: #e7e9f1;
  --line-2: #eef0f6;
  --brand: #5b5bf0;
  --brand-2: #7c5cf5;
  --brand-soft: #eef0ff;
  --sidebar: #14152b;
  --sidebar-2: #1d1f3d;
  --sidebar-ink: #c7cbe6;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --warn: #d97706;
  --err: #dc2626;
  --err-soft: #fdecec;
  --shadow: 0 1px 2px rgba(17,22,42,.04), 0 8px 24px rgba(17,22,42,.06);
  --shadow-sm: 0 1px 2px rgba(17,22,42,.06);
  --radius: 16px;
  --radius-sm: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
}

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 11px; padding: 20px 20px 18px; }
.side-brand .brand-mark {
  width: 36px; height: 36px; border-radius: 10px; color: #fff; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 4px 12px rgba(91,91,240,.4);
}
.side-brand strong { display: block; font-size: 15px; color: #fff; letter-spacing: -.01em; }
.side-brand span { font-size: 11.5px; color: #7b80a6; }
.nav { display: flex; flex-direction: column; gap: 3px; padding: 6px 12px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px;
  color: var(--sidebar-ink); font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none;
  transition: background .14s, color .14s;
}
.nav-item svg { opacity: .8; }
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 4px 12px rgba(91,91,240,.35); }
.nav-item.active svg { opacity: 1; }
.side-foot { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.07); }
.side-foot p { margin: 9px 0 0; font-size: 11.5px; color: #6b7099; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  padding: 16px 30px; background: rgba(245,246,250,.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 19px; font-weight: 800; letter-spacing: -.02em; margin: 0; flex: 1; }
.menu-btn { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-2); }
.content { padding: 28px 30px 48px; max-width: 1080px; width: 100%; }

.page { display: none; animation: fade .22s ease; }
.page.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Panels / forms ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.panel-head h2 { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.panel-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.label em { color: var(--brand); font-style: normal; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12.5px; }
.hint { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-size: 12.5px; }

.control { width: 100%; padding: 11px 13px; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); outline: none; transition: border-color .15s, box-shadow .15s; font-family: inherit; }
.control::placeholder { color: #aeb3c4; }
.control:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
select.control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%238b91a9' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 13px center; padding-right: 34px; cursor: pointer; }
.url-list { display: flex; flex-direction: column; gap: 9px; }
.form-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line-2); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; justify-content: center; border: 1px solid transparent; cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600; padding: 10px 16px; border-radius: var(--radius-sm); background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 1px 2px rgba(91,91,240,.25); transition: transform .06s, filter .15s, box-shadow .15s; text-decoration: none; }
.btn:hover { filter: brightness(1.06); box-shadow: 0 4px 14px rgba(91,91,240,.32); }
.btn:active { transform: translateY(1px); }
.btn-lg { padding: 12px 22px; }
.btn-sm { padding: 7px 13px; font-size: 13px; }
.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); filter: none; box-shadow: none; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }

/* ---------- Chips / badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 7px; background: var(--surface-2); border: 1px solid var(--line); padding: 6px 11px; border-radius: 999px; font-size: 12.5px; color: var(--ink-2); }
.side-foot .chip { background: var(--sidebar-2); border-color: rgba(255,255,255,.08); color: var(--sidebar-ink); }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
.chip-dot.warn { background: var(--warn); }
.badge { font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); text-transform: capitalize; }
.badge.running { background: var(--brand-soft); color: var(--brand); border-color: #d7d9ff; }
.badge.succeeded { background: var(--ok-soft); color: var(--ok); border-color: #cdebd6; }
.badge.failed { background: var(--err-soft); color: var(--err); border-color: #f3cccc; }

/* ---------- Budget bar ---------- */
.budget { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow-sm); margin-bottom: 18px; }
.budget-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13.5px; color: var(--ink-2); margin-bottom: 10px; }
.budget-head b { color: var(--ink); }
.budget-bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.budget-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #16a34a, #22c55e); transition: width .5s ease; }
.budget-fill.warn { background: linear-gradient(90deg, #d97706, #f59e0b); }
.budget-fill.over { background: linear-gradient(90deg, #dc2626, #ef4444); }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-grid.sm { margin-bottom: 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow-sm); }
.stat-num { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat-lbl { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- Quick cards ---------- */
.quick { display: flex; flex-direction: column; gap: 10px; }
.quick-card { text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; cursor: pointer; transition: border-color .15s, background .15s; font-family: inherit; }
.quick-card:hover { border-color: var(--brand); background: #fff; }
.quick-card strong { display: block; font-size: 14.5px; margin-bottom: 4px; }
.quick-card span { font-size: 12.5px; color: var(--muted); }

/* ---------- Content types ---------- */
.ctype-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ctype { border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.ctype b { font-size: 14px; } .ctype .k { font-size: 11px; color: var(--brand-2); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.ctype p { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }

/* ---------- Settings table ---------- */
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 11px 4px; border-top: 1px solid var(--line-2); font-size: 13.5px; vertical-align: top; }
.kv tr:first-child td { border-top: none; }
.kv td:first-child { color: var(--muted); width: 230px; }
.kv b { font-weight: 600; }

/* ---------- Job / stepper ---------- */
.job-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.job-title { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .8s linear infinite; }
.spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.stepper { list-style: none; display: flex; gap: 6px; margin: 0 0 18px; padding: 0; }
.stepper li { flex: 1; display: flex; flex-direction: column; gap: 7px; font-size: 12px; color: var(--muted); }
.stepper li .dot-row { display: flex; align-items: center; gap: 6px; }
.stepper li .bar { height: 4px; border-radius: 999px; background: var(--line); transition: background .3s; }
.stepper li .num { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--line); color: var(--muted); transition: all .3s; flex-shrink: 0; }
.stepper li.active .num, .stepper li.active .bar { background: var(--brand); } .stepper li.active .num { color: #fff; } .stepper li.active { color: var(--brand); font-weight: 600; }
.stepper li.done .num, .stepper li.done .bar { background: var(--ok); } .stepper li.done .num { color: #fff; } .stepper li.done { color: var(--ok); }
.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 2%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .5s ease; }
.job-result { margin-top: 16px; }
.result-card { background: var(--ok-soft); border: 1px solid #cdebd6; border-radius: 12px; padding: 16px; }
.result-card.fail { background: var(--err-soft); border-color: #f3cccc; }
.result-title { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ok); }
.result-card.fail .result-title { color: var(--err); }
.result-meta { margin: 10px 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.result-actions { display: flex; gap: 8px; }
.tag { font-size: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; color: var(--ink-2); }
.tag b { color: var(--ink); }
.src-warn { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; border-radius: 10px; padding: 10px 12px; font-size: 12.5px; margin: 0 0 12px; }
.src-warn ul { margin: 6px 0 0; padding-left: 18px; } .src-warn li { margin: 2px 0; word-break: break-all; }

/* ---------- History ---------- */
.htable { width: 100%; }
.hrow { display: grid; grid-template-columns: 96px 1fr 110px 150px 64px 96px; gap: 12px; align-items: center; padding: 13px 4px; border-top: 1px solid var(--line-2); font-size: 13.5px; }
.hrow:first-child { border-top: none; }
.pill { font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 4px 9px; border-radius: 7px; text-align: center; }
.pill.writer { background: var(--brand-soft); color: var(--brand); }
.pill.refresher { background: #f3eefe; color: var(--brand-2); }
.hkw { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctype-tag { font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--brand-2); background: #f3eefe; padding: 2px 6px; border-radius: 5px; margin-left: 4px; }
.hmeta { color: var(--muted); font-size: 12.5px; }
.empty { text-align: center; padding: 26px; color: var(--muted); }
a { color: var(--brand); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }

/* ---------- Pipeline flow ---------- */
.flow { display: flex; flex-direction: column; gap: 0; margin-top: 6px; }
.node { display: flex; gap: 14px; align-items: flex-start; padding: 12px 0; position: relative; }
.node:not(:last-child)::before { content: ""; position: absolute; left: 15px; top: 38px; bottom: -12px; width: 2px; background: var(--line); }
.node-num { width: 32px; height: 32px; flex-shrink: 0; border-radius: 9px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 13px; z-index: 1; }
.node-body { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow-sm); }
.node-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.node-title { font-weight: 700; font-size: 14px; }
.node-detail { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); }
.node-tag { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); }
.node-tag.ai { background: #eef0ff; color: var(--brand); border-color: #d7d9ff; }
.node-tag.claude { background: #f3eefe; color: var(--brand-2); border-color: #e3d8fb; }
.node-tag.prompt { background: var(--ok-soft); color: var(--ok); border-color: #cdebd6; }
.view-prompt { margin-left: auto; cursor: pointer; border: 1px solid var(--brand); color: var(--brand); background: #fff; border-radius: 8px; padding: 5px 11px; font-size: 12px; font-weight: 600; font-family: inherit; }
.view-prompt:hover { background: var(--brand-soft); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(17,22,42,.55); display: grid; place-items: center; z-index: 200; padding: 24px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 16px; width: min(900px, 96vw); max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0,0,0,.3); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head strong { font-size: 14px; }
.modal-head > div { display: flex; gap: 8px; }
.modal-body { margin: 0; padding: 18px 20px; overflow: auto; font-family: "Consolas", "SF Mono", monospace; font-size: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; color: var(--ink); background: var(--surface-2); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 11px; font-size: 13.5px; box-shadow: var(--shadow); max-width: 340px; transition: opacity .3s; }
.toast.err { background: var(--err); } .toast.ok { background: var(--ok); }

@media (max-width: 900px) {
  .cols, .ctype-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .25s; z-index: 60; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .sidebar.open { transform: none; }
  .menu-btn { display: block; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 20px; }
  .hrow { grid-template-columns: 70px 1fr 80px; } .hrow .hmeta, .hrow .hlink:nth-child(6) { display: none; }
}

/* ---- Lead Gen / scrape ---- */
.segmented.wrap { flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted, #555); margin: 4px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border, #e5e7eb); border-radius: 8px; margin: 10px 0; max-height: 460px; }
.data-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border, #eee); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.data-table thead th { position: sticky; top: 0; background: var(--panel, #f8fafc); font-weight: 600; }
.data-table tbody tr:hover { background: rgba(0,0,0,0.03); }
