:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --border: #e3e6eb;
  --text: #171a1f; --muted: #646b78; --accent: #4f6bed; --accent-fg: #fff; --accent-soft: #eaeefe;
  --ok: #16834a; --ok-soft: #e4f5ea; --warn: #a15c00; --warn-soft: #fff1dc; --bad: #c4322b; --bad-soft: #fde8e6;
  --run: #2d6cdf; --run-soft: #e5eeff;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
  --radius: 12px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a20; --surface-2: #1e222a; --border: #2a2f38;
    --text: #e8eaee; --muted: #9aa2b1; --accent: #7b91ff; --accent-fg: #0f1115; --accent-soft: #232a45;
    --ok: #4cc584; --ok-soft: #15301f; --warn: #f0a640; --warn-soft: #33260f; --bad: #ff6b61; --bad-soft: #3a1714;
    --run: #6d9cff; --run-soft: #172440; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.2em; margin: 0; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 15px; margin: 0; }
a { color: var(--accent); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 4px; }
label .hint { font-weight: 400; color: var(--muted); }
.btn { font: inherit; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand.big { font-size: 24px; justify-content: center; }
.logo { width: 24px; height: 24px; border-radius: 7px; background: var(--accent); display: inline-block; position: relative; }
.logo::after { content: ""; position: absolute; inset: 7px 5px 5px; border-radius: 50% 50% 3px 3px; background: var(--accent-fg); opacity: .9; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface); padding: 28px; border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); display: grid; gap: 12px; text-align: center; }
.login-card p { margin: 0; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
nav { display: flex; gap: 4px; }
nav button { font: inherit; border: 0; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
nav button:hover { color: var(--text); background: var(--surface-2); }
nav button.active { color: var(--accent); background: var(--accent-soft); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--bad-soft); color: var(--bad); }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.view-head p { margin: 0; max-width: 640px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions input, .actions select { width: auto; min-width: 180px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.emp { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.emp.inactive { opacity: .6; }
.emp-top { display: flex; gap: 12px; align-items: center; }
.avatar { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; flex: none; }
.avatar.sm { width: 26px; height: 26px; border-radius: 7px; font-size: 11px; }
.emp-name { font-weight: 700; font-size: 15px; }
.emp-role { color: var(--muted); font-size: 13px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.resp { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; margin: 0; }
.status-line { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.status-line.working { background: var(--run-soft); color: var(--run); cursor: pointer; }
.status-line.working::before { content: "● "; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.stats { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); }
.stats b { color: var(--text); }
.emp-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); }
.empty h3 { color: var(--text); margin-bottom: 6px; }

.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.col-head { display: flex; justify-content: space-between; font-weight: 700; font-size: 13px; padding: 4px 6px 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tcard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; display: grid; gap: 8px; }
.tcard:hover { border-color: var(--accent); }
.tcard-title { font-weight: 600; }
.tcard-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.prio { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px; }
.prio.p1 { background: var(--bad-soft); color: var(--bad); }
.prio.p3 { background: var(--surface-2); color: var(--muted); }
.st { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.st.queued { background: var(--warn-soft); color: var(--warn); }
.st.running { background: var(--run-soft); color: var(--run); }
.st.done { background: var(--ok-soft); color: var(--ok); }
.st.failed, .st.cancelled { background: var(--bad-soft); color: var(--bad); }

.list { display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.row .grow { flex: 1; min-width: 0; }
.row .sub { font-size: 13px; color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; margin: 0; }
.switch input { width: auto; }

/* drawer */
.drawer { position: fixed; inset: 0; z-index: 20; }
.drawer-backdrop, .modal-backdrop { position: absolute; inset: 0; background: rgba(10,12,16,.45); }
.drawer-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(760px, 100%); background: var(--bg); display: flex; flex-direction: column; box-shadow: -8px 0 32px rgba(0,0,0,.2); }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin-bottom: 6px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; display: grid; gap: 16px; align-content: start; }
.drawer-foot { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface); display: grid; gap: 8px; }
.drawer-foot textarea { min-height: 56px; }
.foot-row { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.msg { display: grid; gap: 8px; }
.bubble { border-radius: 12px; padding: 12px 14px; }
.bubble.me { background: var(--accent-soft); justify-self: end; max-width: 90%; white-space: pre-wrap; }
.bubble.them { background: var(--surface); border: 1px solid var(--border); }
.bubble-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; flex-wrap: wrap; }
.bubble-head b { color: var(--text); }
details.activity { font-size: 12.5px; border-top: 1px solid var(--border); margin-top: 10px; padding-top: 8px; }
details.activity summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.ev { display: grid; grid-template-columns: 54px 1fr; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.ev:last-child { border-bottom: 0; }
.ev .k { font-weight: 700; font-size: 11px; text-transform: uppercase; color: var(--muted); padding-top: 1px; }
.ev.tool .t { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.ev.denied .k, .ev.error .k { color: var(--bad); }
.ev .t { white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }
.errbox { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; font-size: 13px; }
.typing { color: var(--run); font-weight: 600; font-size: 13px; }
.typing::before { content: "● "; animation: pulse 1.2s infinite; }

.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; font-size: 15px; }
.md h1 { font-size: 17px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md pre { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.md blockquote { margin: 6px 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }

/* modal */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal-card { position: relative; background: var(--surface); border-radius: 16px; width: min(620px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.form-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.form-foot .right { display: flex; gap: 8px; margin-left: auto; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two > div > label { margin-top: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { font: inherit; font-size: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.colors { display: flex; gap: 8px; }
.colors button { width: 26px; height: 26px; border-radius: 8px; border: 2px solid transparent; cursor: pointer; }
.colors button.sel { border-color: var(--text); }
.files { display: grid; gap: 2px; max-height: 50vh; overflow-y: auto; margin-top: 10px; }
.file { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; font-size: 13px; }
.file:hover { background: var(--surface-2); }
.file .name { flex: 1; font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.file.dir .name { font-weight: 700; }
.preview { background: var(--surface-2); border-radius: 8px; padding: 10px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; max-height: 45vh; overflow: auto; margin-top: 10px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50; max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .top { padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
  nav { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 16px; }
  .board { grid-template-columns: repeat(4, 82vw); scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .two { grid-template-columns: 1fr; }
  .actions input, .actions select { min-width: 0; flex: 1; }
  .drawer-body { padding: 14px; }
}
