:root {
  --bg: #f4f5f8; --panel: #ffffff; --panel-2: #f8f9fb; --line: #e3e6ec; --text: #1c2030; --muted: #677089;
  --accent: #4f46e5; --accent-soft: #eef0ff; --accent-text: #ffffff;
  --green: #15803d; --green-soft: #e8f6ee; --amber: #b45309; --amber-soft: #fdf3e3; --red: #b91c1c; --red-soft: #fdeceb;
  --grey-soft: #eef0f4; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px; --rail: 76px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --panel: #171a23; --panel-2: #1c2030; --line: #2a2f3d; --text: #e6e8ef; --muted: #9aa3b8;
    --accent: #8b85ff; --accent-soft: #23234a; --accent-text: #0f1117;
    --green: #4ade80; --green-soft: #12301f; --amber: #fbbf24; --amber-soft: #33270d; --red: #f87171; --red-soft: #3a1515;
    --grey-soft: #23283a; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] { --bg: #0f1117; --panel: #171a23; --panel-2: #1c2030; --line: #2a2f3d; --text: #e6e8ef; --muted: #9aa3b8;
  --accent: #8b85ff; --accent-soft: #23234a; --accent-text: #0f1117; --green: #4ade80; --green-soft: #12301f; --amber: #fbbf24;
  --amber-soft: #33270d; --red: #f87171; --red-soft: #3a1515; --grey-soft: #23283a; --shadow: none; color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 15px; margin: 20px 0 10px; } h3 { font-size: 14px; margin: 0 0 10px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--red); border-color: var(--red); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; }
select { width: auto; }
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.logo { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 800; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
.brand { display: flex; gap: 12px; align-items: center; } .brand small { display: block; color: var(--muted); font-weight: 400; }

/* layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.rail { width: var(--rail); background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 12px 6px; gap: 4px; }
.rail .logo { margin-bottom: 10px; }
.rail-btn { width: 100%; border: 0; background: transparent; display: grid; justify-items: center; gap: 2px; padding: 8px 2px; font-size: 11px; color: var(--muted); position: relative; border-radius: 8px; }
.rail-btn .ico { font-size: 18px; line-height: 1; }
.rail-btn.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.rail-spacer { flex: 1; }
.badge { position: absolute; top: 2px; right: 10px; background: var(--red); color: #fff; border-radius: 999px; font-size: 10px; padding: 1px 6px; }
.main { flex: 1; min-width: 0; overflow: auto; }
.view { padding: 20px 24px 40px; max-width: 1280px; }
.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.view-head h1 { margin-right: auto; }

.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); cursor: default; }
.kpi b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi.link { cursor: pointer; } .kpi.warn b { color: var(--red); }
.biz-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; margin-bottom: 8px; }
.biz-head small { color: var(--muted); display: block; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 700; background: var(--grey-soft); color: var(--muted); white-space: nowrap; }
.pill.red { background: var(--red-soft); color: var(--red); } .pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.green { background: var(--green-soft); color: var(--green); } .pill.blue { background: var(--accent-soft); color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.unknown { color: var(--muted); font-style: italic; }
.item { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: baseline; }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.alert { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; border: 1px solid var(--amber); background: var(--amber-soft); color: var(--text); }
.feed .row { display: grid; grid-template-columns: 150px 120px 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.feed .row:last-child { border-bottom: 0; }
.feed .row .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.feed .row.block .x { color: var(--red); }

/* team chat */
.view.team { display: flex; padding: 0; max-width: none; height: 100%; }
.channels { width: 280px; border-right: 1px solid var(--line); background: var(--panel-2); overflow: auto; flex-shrink: 0; }
.channels-head { padding: 16px; font-weight: 700; }
.agent { display: flex; gap: 10px; align-items: center; padding: 9px 14px; cursor: pointer; border-left: 3px solid transparent; }
.agent:hover { background: var(--grey-soft); }
.agent.active { background: var(--accent-soft); border-left-color: var(--accent); }
.agent .meta { min-width: 0; flex: 1; } .agent .meta b { display: block; font-size: 13px; }
.agent .meta small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11.5px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; flex-shrink: 0; position: relative; }
.avatar.big { width: 40px; height: 40px; font-size: 13px; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--panel-2); background: #9aa3b8; }
.avatar .dot.busy { background: #f59e0b; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-title { flex: 1; min-width: 0; } .chat-title small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 900px; }
.msg.owner { flex-direction: row-reverse; margin-left: auto; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-width: 0; overflow-wrap: anywhere; }
.msg.owner .bubble { background: var(--accent-soft); border-color: transparent; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg.system { justify-content: center; color: var(--muted); font-size: 12px; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; font-size: 12.5px; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.bubble table { margin: 8px 0; display: block; overflow-x: auto; }
.tools { margin-top: 8px; font-size: 12px; color: var(--muted); }
.tools summary { cursor: pointer; }
.tools li { margin: 2px 0; overflow-wrap: anywhere; }
.err { color: var(--red); font-size: 12.5px; margin-top: 6px; }
.working { display: flex; align-items: center; gap: 10px; padding: 8px 18px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); background: var(--panel-2); }
#working-text { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dots i { display: inline-block; width: 6px; height: 6px; margin-right: 3px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.composer { display: flex; gap: 10px; padding: 12px 18px 4px; background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { resize: none; min-height: 44px; max-height: 200px; }
.hint { padding: 0 18px 10px; margin: 0; background: var(--panel); }

/* approvals / docs */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.split { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 14px; align-items: start; }
.list { display: grid; gap: 8px; }
.list .entry { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; }
.list .entry.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.list .entry b { display: block; font-size: 13px; }
.list .group { font-size: 12px; font-weight: 700; color: var(--muted); margin: 10px 0 2px; }
.detail { min-height: 200px; overflow-wrap: anywhere; }
.detail .actions { display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.md h1 { font-size: 18px; margin: 4px 0 12px; } .md h2 { font-size: 15px; } .md h3 { font-size: 14px; margin-top: 14px; }
.md table { display: block; overflow-x: auto; }
.md pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; font-size: 12.5px; }

/* kanban */
.kanban { display: grid; grid-template-columns: repeat(7, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; justify-content: space-between; }
.task { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 12.5px; }
.task .tid { color: var(--muted); font-size: 11px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); width: min(560px, calc(100% - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog menu { display: flex; justify-content: flex-end; gap: 10px; padding: 0; margin: 16px 0 0; }
dialog blockquote { margin: 8px 0; padding: 8px 12px; background: var(--panel-2); border-left: 3px solid var(--accent); max-height: 240px; overflow: auto; white-space: pre-wrap; font-size: 12.5px; }
dialog label.check { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; }
dialog label.check input { width: auto; margin-top: 3px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 10; max-width: calc(100% - 32px); }

@media (max-width: 1000px) {
  .grid.three, .grid.two { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .channels { width: 220px; }
}
@media (max-width: 700px) {
  :root { --rail: 0px; }
  .app { flex-direction: column-reverse; }
  .rail { width: 100%; height: 58px; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 4px; overflow-x: auto; }
  .rail .logo, .rail-spacer { display: none; }
  .rail-btn { min-width: 58px; }
  .view { padding: 16px; }
  .view.team { flex-direction: column; }
  .channels { width: 100%; max-height: 132px; border-right: 0; border-bottom: 1px solid var(--line); display: flex; overflow-x: auto; }
  .channels-head { display: none; }
  #agent-list { display: flex; }
  .agent { flex-direction: column; min-width: 86px; border-left: 0; border-bottom: 3px solid transparent; text-align: center; padding: 8px 6px; }
  .agent.active { border-bottom-color: var(--accent); }
  .agent .meta small { display: none; } .agent .meta b { font-size: 11px; }
  .feed .row { grid-template-columns: 1fr; gap: 2px; }
  .chat-head #chat-new { padding: 6px 8px; font-size: 12px; }
}

.mdlist { padding-left: 18px; } .mdlist li { margin: 3px 0; } .mdlist li.num { list-style: none; margin-left: -18px; }
.mdlist li.sub { margin-left: 18px; list-style: circle; } .mdlist li.code { list-style: none; }
