:root {
  --bg: #f6f6f7;
  --panel: #ffffff;
  --panel-2: #f1f1f3;
  --text: #17171a;
  --muted: #6b6b76;
  --border: #e3e3e8;
  --accent: #e5252f;
  --accent-ink: #ffffff;
  --accent-soft: #fde8e9;
  --ok: #138a4b;
  --ok-soft: #e3f5ea;
  --warn: #b25e00;
  --warn-soft: #fff1dc;
  --danger: #c4161f;
  --danger-soft: #fde4e5;
  --info-soft: #e8f0fe;
  --link: #1a5fd6;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 24px rgba(0,0,0,.06);
  --radius: 14px;
  --sidebar: 288px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f11;
    --panel: #18181c;
    --panel-2: #212126;
    --text: #ececf1;
    --muted: #9a9aa6;
    --border: #2c2c33;
    --accent: #f0434c;
    --accent-ink: #ffffff;
    --accent-soft: #3a1518;
    --ok: #4cc884;
    --ok-soft: #12301f;
    --warn: #f2a33c;
    --warn-soft: #36260f;
    --danger: #ff5a62;
    --danger-soft: #3a1416;
    --info-soft: #172336;
    --link: #7fb0ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--link); }
code { font: .88em ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--panel-2); padding: .1em .35em; border-radius: 6px; }
pre { background: var(--panel-2); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
pre code { background: none; padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100dvh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px; padding: 14px 12px; min-height: 0;
}
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.icon-btn.only-mobile { display: none; }
.scrim { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 30;
    transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .app.drawer .sidebar { transform: none; }
  .app.drawer .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
  .icon-btn.only-mobile { display: inline-grid; }
  .switch-label { display: none; }
}

/* ----------------------------------------------------------------- brand */
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 4px 6px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; }
.brand-text .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo {
  width: 34px; height: 24px; border-radius: 8px; background: var(--accent); flex: none;
  display: grid; place-items: center;
}
.logo::after { content: ""; border-left: 9px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent; margin-left: 3px; }

/* --------------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 10px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  border: 0; background: transparent; color: var(--text); width: 36px; height: 36px;
  border-radius: 10px; cursor: pointer; font-size: 17px; display: inline-grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--panel-2); }

/* ---------------------------------------------------------- conversations */
.convos { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 4px -4px; padding: 0 4px; min-height: 80px; }
.convo { display: flex; align-items: center; border-radius: 10px; }
.convo:hover { background: var(--panel-2); }
.convo .open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 8px 4px 8px 10px;
  cursor: pointer; color: var(--text); border: 0; background: none; text-align: left; font: inherit;
}
.convo.active { background: var(--accent-soft); }
.convo .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.convo .when { font-size: 11.5px; color: var(--muted); flex: none; }
.convo .del { visibility: hidden; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 8px; margin-right: 4px; border-radius: 6px; font: inherit; }
.convo:hover .del, .convo .del:focus-visible { visibility: visible; }
.convo .del:hover { color: var(--danger); background: var(--danger-soft); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.side-links { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 8px; }
.side-link { border: 0; background: none; color: var(--text); font: inherit; text-align: left; padding: 7px 10px; border-radius: 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.side-link:hover { background: var(--panel-2); }
a.side-link { text-decoration: none; }
.approval .warnings { margin: 0 0 8px; padding-left: 1.2em; color: var(--warn); font-size: 13px; }
.side-link .count { margin-left: auto; color: var(--muted); font-size: 12px; }

/* ----------------------------------------------------------- channel card */
.channel-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--panel-2); display: flex; flex-direction: column; gap: 8px; }
.channel-card .row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.channel-card img { width: 34px; height: 34px; border-radius: 50%; flex: none; }
.channel-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-card .stats { font-size: 12px; color: var(--muted); }
.status-pill { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.status-pill.ok { background: var(--ok-soft); color: var(--ok); }
.status-pill.warn { background: var(--warn-soft); color: var(--warn); }

/* ----------------------------------------------------------------- topbar */
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); min-height: 56px; }
.title { font-size: 16px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--muted); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 36px; height: 20px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; flex: none; }
.switch .track::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,.3); }
.switch input:checked + .track { background: var(--warn); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--link); outline-offset: 2px; }

/* -------------------------------------------------------------------- log */
.log { flex: 1; overflow-y: auto; padding: 20px 16px 8px; scroll-behavior: smooth; }
.thread { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.turn.user { align-self: flex-end; max-width: 84%; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.turn.assistant { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.bubble { background: var(--panel); border: 1px solid var(--border); border-radius: 4px 16px 16px 16px; padding: 12px 16px; overflow-wrap: anywhere; box-shadow: var(--shadow); }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 1.05em; margin: 1em 0 .4em; }
.bubble table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; font-size: 14px; margin: .6em 0; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; vertical-align: top; }
.bubble th { background: var(--panel-2); }
.bubble ul, .bubble ol { padding-left: 1.4em; }
.bubble blockquote { margin: .6em 0; padding: 2px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.bubble.error { border-color: var(--danger); background: var(--danger-soft); }
.meta { font-size: 12px; color: var(--muted); padding-left: 4px; }
.note { font-size: 13.5px; color: var(--muted); font-style: italic; padding: 0 4px; }

/* ----------------------------------------------------------- video cards */
.vcards { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.vcard { flex: 0 0 200px; text-decoration: none; color: var(--text); border-radius: 12px; overflow: hidden; background: var(--panel); border: 1px solid var(--border); }
.vcard img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--panel-2); }
.vcard span { display: block; padding: 6px 8px; font-size: 12.5px; line-height: 1.35; max-height: 3.2em; overflow: hidden; }

/* -------------------------------------------------------------- activity */
.activity { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); font-size: 13.5px; }
.activity > summary { list-style: none; cursor: pointer; padding: 8px 12px; display: flex; align-items: center; gap: 8px; color: var(--muted); user-select: none; }
.activity > summary::-webkit-details-marker { display: none; }
.activity > summary::before { content: "▸"; transition: transform .15s; }
.activity[open] > summary::before { transform: rotate(90deg); }
.steps { list-style: none; margin: 0; padding: 0 12px 10px; display: flex; flex-direction: column; gap: 6px; }
.step { display: grid; grid-template-columns: 20px 1fr auto; gap: 8px; align-items: start; }
.step .ico { text-align: center; }
.step .name { font-weight: 600; }
.step .args { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.step .preview { color: var(--muted); font-size: 12px; white-space: pre-wrap; max-height: 4.2em; overflow: hidden; margin-top: 2px; }
.step .st { font-size: 12px; white-space: nowrap; }
.st.ok { color: var(--ok); } .st.error { color: var(--danger); } .st.rejected { color: var(--warn); }
.bar { height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.thinking { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; padding: 2px 4px; }
.thinking .stop-inline { padding: 2px 10px; font-size: 12.5px; }

/* ------------------------------------------------------------------ cards */
.card { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); padding: 12px 14px; box-shadow: var(--shadow); }
.card h4 { margin: 0 0 6px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.plan ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.plan li { display: flex; gap: 8px; align-items: baseline; font-size: 14px; }
.plan li.done { color: var(--muted); text-decoration: line-through; }
.plan li.in_progress { font-weight: 600; }
.approval { border-color: var(--warn); background: var(--warn-soft); }
.approval.destroy { border-color: var(--danger); background: var(--danger-soft); }
.approval .summary { font-weight: 600; margin-bottom: 8px; }
.approval .kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; margin-bottom: 10px; }
.approval .kv dt { color: var(--muted); }
.approval .kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 14em; overflow-y: auto; }
.approval textarea { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 13px; background: var(--panel); color: var(--text); resize: vertical; min-height: 34px; }
.approval .actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.approval .verdict { font-weight: 600; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.badge.change { background: var(--warn); color: #fff; }
.badge.destroy { background: var(--danger); color: #fff; }
.job .links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.job .stage { font-size: 13px; color: var(--muted); }
.job.failed { border-color: var(--danger); }

/* ------------------------------------------------------------ empty state */
.empty { text-align: center; padding: 6vh 8px 2vh; }
.empty h2 { margin: 10px 0 4px; font-size: 22px; }
.caps { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 22px 0 14px; text-align: left; }
.cap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.cap h3 { margin: 0 0 6px; font-size: 14px; }
.cap p { margin: 0; font-size: 13px; color: var(--muted); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.example { border: 1px solid var(--border); background: var(--panel); color: var(--text); border-radius: 999px; padding: 7px 13px; font: inherit; font-size: 13.5px; cursor: pointer; }
.example:hover { border-color: var(--accent); }

/* --------------------------------------------------------------- composer */
.composer { padding: 10px 16px 14px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer-row { max-width: 860px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 6px; box-shadow: var(--shadow); }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; background: transparent; color: var(--text); font: inherit; padding: 8px 6px; max-height: 200px; min-height: 24px; }
.hint { max-width: 860px; margin: 6px auto 0; text-align: center; }
.attachments { max-width: 860px; margin: 0 auto 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12.5px; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; display: inline-flex; align-items: center; gap: 6px; }
.chip .bar { width: 70px; margin: 0; }

/* ------------------------------------------------------------------ modals */
.modal { border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px; background: var(--panel); color: var(--text); width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); box-shadow: var(--shadow); }
.modal.wide { width: min(760px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(0,0,0,.4); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal h3 { font-size: 14px; margin: 16px 0 6px; }
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.item { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow-wrap: anywhere; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 13.5px; }
.field input { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font: inherit; background: var(--panel); color: var(--text); }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }
.status-box { white-space: pre-wrap; background: var(--panel-2); border-radius: 10px; padding: 10px 12px; font-family: ui-monospace, Consolas, monospace; }
.steps-guide { counter-reset: s; list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 10px; }
.steps-guide li { counter-increment: s; padding-left: 34px; position: relative; font-size: 14px; }
.steps-guide li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: 13px; }
.callout { background: var(--info-soft); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin: 10px 0; }
.dropzone { display: block; border: 2px dashed var(--border); border-radius: 12px; padding: 18px; text-align: center; cursor: pointer; margin: 10px 0; color: var(--muted); }
.dropzone.over, body.dragging .dropzone { border-color: var(--accent); background: var(--accent-soft); }

/* ------------------------------------------------------------ video studio */
.modal.studio { width: min(920px, calc(100vw - 32px)); }
.item.top { align-items: flex-start; }
.item video.thumb { width: 168px; aspect-ratio: 16/9; background: #000; border-radius: 8px; flex: none; object-fit: contain; }
.player { display: block; width: 100%; max-height: 440px; background: #000; border-radius: 10px; margin-top: 8px; }
img.player { object-fit: contain; }
.actions.left { justify-content: flex-start; margin-top: 8px; align-items: center; }
select.mini { border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; font: inherit; font-size: 13px; background: var(--panel); color: var(--text); }
.notes { color: var(--warn); font-size: 12.5px; margin: 4px 0 0; padding-left: 1.2em; }
.meta-out { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.meta-out pre { white-space: pre-wrap; margin: 0; font-family: inherit; }
.status-pill.run { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 640px) { .item.top { flex-wrap: wrap; } .item video.thumb { width: 100%; } }

/* ------------------------------------------------------------------ toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
