:root {
  --bg: #f5f6f8; --panel: #fff; --panel2: #f9fafb; --line: #e3e6ea; --line2: #eef0f3;
  --text: #1b1f24; --muted: #69717c; --accent: #1f6feb; --accent-2: #e8f0fe; --accent-text: #fff;
  --good: #1a7f37; --good-bg: #e6f4ea; --warn: #9a6700; --warn-bg: #fff4d6; --bad: #c62828; --bad-bg: #fdecea;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --panel2: #1c2128; --line: #2a3038; --line2: #222830;
    --text: #e6e9ed; --muted: #9aa3ad; --accent: #4c8dff; --accent-2: #1a2a45; --accent-text: #fff;
    --good: #4ac26b; --good-bg: #13291b; --warn: #e3b341; --warn-bg: #2d2412; --bad: #ff6b6b; --bad-bg: #331618;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .in { max-width: 1320px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 18px; height: 54px; }
.brand { font-weight: 700; color: var(--text); }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.nav a.on, .nav a:hover { background: var(--accent-2); color: var(--accent); text-decoration: none; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 20px 16px 80px; }
.pagehead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.pagehead h1 { margin: 0; flex: 1; min-width: 200px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card.flat { box-shadow: none; }
.card h2 { display: flex; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 900px) { .grid3, .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .grid2, .grid3, .grid4 { grid-template-columns: minmax(0, 1fr); } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* forms */
label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
label > input, label > select, label > textarea, label > .field { margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=datetime-local], input[type=time], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text);
  font: inherit; font-weight: 400;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; color: var(--text); font-size: 13px; cursor: pointer; }
.check input { margin: 0; }
.checks-inline { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 7px 12px; cursor: pointer; color: var(--muted); font: inherit; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-text); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; font: inherit; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.big { padding: 12px 22px; font-size: 15px; }

.note { padding: 10px 12px; border-radius: 8px; margin: 8px 0; }
.note.ok { background: var(--good-bg); color: var(--good); }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.err { background: var(--bad-bg); color: var(--bad); }
.note.info { background: var(--accent-2); color: var(--accent); }
.note ul { margin: 4px 0 0; padding-left: 18px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--line2); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.acc { background: var(--accent-2); color: var(--accent); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 99px; background: var(--accent-2); color: var(--accent); font-size: 12px; margin: 2px; }
.chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 4px; }
.chip.ex { background: var(--bad-bg); color: var(--bad); }

/* tables */
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
table.t tr:hover td { background: var(--panel2); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tablewrap { overflow-x: auto; }
.tree .lvl1 td:first-child { padding-left: 34px; }
.tree .lvl2 td:first-child { padding-left: 58px; }
.tree .toggle { width: 22px; height: 22px; border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 12px; }
.thumb-sm { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; background: var(--line2); vertical-align: middle; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--accent); border-color: var(--accent); text-decoration: none; }

/* media grid */
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.mitem { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); cursor: pointer; position: relative; display: flex; flex-direction: column; }
.mitem:hover { border-color: var(--accent); }
.mitem.sel { outline: 3px solid var(--accent); outline-offset: -1px; }
.mitem .ph { aspect-ratio: 1; background: var(--line2) center/cover no-repeat; position: relative; }
.mitem .ph .kind { position: absolute; left: 6px; top: 6px; }
.mitem .meta { padding: 8px; font-size: 12px; }
.mitem .meta .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mitem .meta .tx { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 720px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 1100px; }
.modal .mh { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .mh h2 { margin: 0; flex: 1; }
.modal .mb { padding: 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.x { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* toast */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast { background: #1b1f24; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: 13px; }
.toast.err { background: #b3261e; }
.toast.ok { background: #1a7f37; }

/* auth */
body.auth { display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.auth-card.wide { max-width: 640px; }
.auth-card .form > * + * { margin-top: 12px; }
table.checks td { padding: 3px 12px 3px 0; }
td.good { color: var(--good); font-weight: 700; } td.bad { color: var(--bad); font-weight: 700; }

/* editor */
.ed-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.ed-sec { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.ed-sec > .hd { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ed-sec > .hd h2 { margin: 0; flex: 1; font-size: 15px; }
.ed-sec > .bd { padding: 16px; }
.adset { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 14px; background: var(--panel2); }
.adset > .hd { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.adset > .hd .nm { flex: 1; min-width: 180px; font-weight: 600; }
.adset > .bd { padding: 12px; }
.adset.collapsed > .bd { display: none; }
.ad { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 12px; margin-top: 10px; display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 12px; }
@media (max-width: 700px) { .ad { grid-template-columns: minmax(0, 1fr); } }
.ad .pick { aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 10px; display: flex; align-items: center; justify-content: center; text-align: center;
  color: var(--muted); cursor: pointer; background: var(--panel2) center/cover no-repeat; font-size: 12px; padding: 6px; position: relative; }
.ad .pick.has { border-style: solid; }
.ad .pick .kind { position: absolute; left: 6px; top: 6px; }
.subsec { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 12px; }
.results { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; background: var(--panel); }
.results .it { display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px; border-bottom: 1px solid var(--line2); cursor: pointer; }
.results .it:hover { background: var(--panel2); }
.results .it .p { font-size: 11px; color: var(--muted); }
.stickybar { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 8px; align-items: center; justify-content: flex-end;
  margin: 0 -16px; z-index: 20; flex-wrap: wrap; }
.sum-ad { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-top: 1px solid var(--line2); }
.sum-ad img, .sum-ad .noimg { width: 70px; height: 70px; object-fit: cover; border-radius: 8px; background: var(--line2); }
.pre { white-space: pre-wrap; }
.kv { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 4px 12px; font-size: 13px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.log { font-family: var(--mono); font-size: 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 360px; overflow-y: auto; }
.log .ok { color: var(--good); } .log .error { color: var(--bad); } .log .warn { color: var(--warn); }
.wm-preview { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; max-width: 320px; }
.wm-preview .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin-bottom: 8px; white-space: pre-wrap; }
.wm-preview .q { border: 1px solid var(--accent); color: var(--accent); border-radius: 99px; padding: 4px 10px; margin: 4px 0; font-size: 12px; text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }

/* 🤖 agent */
.agent-badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px 1px 4px; border-radius: 99px; font-size: 11px; font-weight: 700;
  color: #fff; background: linear-gradient(90deg, #7c3aed, #06b6d4); vertical-align: middle; box-shadow: 0 0 0 1px rgba(124,58,237,.25), 0 2px 8px rgba(6,182,212,.25); }
.agent-badge .agent-ico rect, .agent-badge .agent-ico circle[fill^="url"] { fill: #fff; }
.agent-badge .agent-ico circle[fill="#fff"] { fill: #7c3aed; }
.agent-ico { vertical-align: middle; }
table.t tr.agent-row td { background: rgba(124,58,237,.07); }
table.t tr.agent-row td:first-child { box-shadow: inset 3px 0 0 #7c3aed; }
.agent-hero { border-radius: var(--radius); padding: 16px; background: linear-gradient(120deg, rgba(124,58,237,.10), rgba(6,182,212,.08)); border: 1px solid rgba(124,58,237,.25); }
.agent-hero.on { box-shadow: 0 0 0 1px rgba(6,182,212,.35), 0 6px 24px rgba(124,58,237,.12); }
.agent-avatar { width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); }
.agent-stat { min-width: 130px; padding: 8px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.agent-stat b { font-size: 18px; }
.agent-run { margin-top: 10px; }
.agent-run ul { margin: 4px 0 6px 18px; padding: 0; }
.agent-cr.off { opacity: .55; }
.thumb-md { width: 110px; height: 140px; flex: 0 0 110px; border-radius: 10px; background: var(--line2) center/cover no-repeat; position: relative; }
.thumb-md .badge { position: absolute; left: 6px; top: 6px; }
.ag-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0 8px; }
.ag-kpi { padding: 10px 12px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); }
.ag-kpi b { display: block; font-size: 19px; margin: 2px 0; }
.good-t { color: var(--good); }
.bad-t { color: var(--bad); }
.ag-list { margin: 4px 0 8px 18px; padding: 0; }
.ag-list li { margin: 2px 0; }
.modal .mb > p { white-space: pre-line; }
.ag-prop { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.ag-prop:first-of-type { border-top: 0; }
.card.ag-pending { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.ag-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; background: var(--panel2); display: block; }
.ag-dim td { opacity: .55; }
.ag-cap { max-width: 420px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ag-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 4px 18px; }
.ag-bar:hover path { opacity: .75; }

