:root {
  --bg: #f6f7f9; --panel: #fff; --panel2: #f1f3f6; --line: #e3e6eb; --text: #1d2330; --muted: #6b7385;
  --accent: #4f6bed; --accent-soft: #e8ecfd; --ok: #1f9d55; --warn: #c98a04; --bad: #d64545; --idle: #9aa1ae;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12151b; --panel: #1a1e26; --panel2: #222733; --line: #2c3240; --text: #e6e9ef; --muted: #8e96a8;
    --accent: #7b91ff; --accent-soft: #252c4a; --ok: #3fbf7f; --warn: #e0a72a; --bad: #ef6b6b; --idle: #6b7280; --shadow: none; }
}
* { box-sizing: border-box; }
body { margin: 0; }
.hidden { display: none !important; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
pre { background: var(--panel2); padding: 10px 12px; border-radius: 8px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 6px 0; }
a { color: var(--accent); cursor: pointer; }
h2 { font-size: 18px; margin: 0 0 14px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0; }
.error { color: var(--bad); min-height: 1em; }

/* layout */
.layout { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; padding: 18px 18px 14px; display: flex; gap: 8px; align-items: center; }
.logo { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle, var(--accent) 35%, transparent 36%), conic-gradient(var(--accent) 0 10%, transparent 0 33%, var(--accent) 0 43%, transparent 0 66%, var(--accent) 0 76%, transparent 0); }
nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 2px; }
nav a { padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; display: flex; justify-content: space-between; align-items: center; }
nav a:hover { background: var(--panel2); }
nav a.ext { color: var(--muted); margin-top: 6px; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; padding-top: 10px; }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-foot { margin-top: auto; padding: 14px 18px; display: flex; justify-content: space-between; font-size: 12px; }
.live { color: var(--warn); } .live.on { color: var(--ok); }
main { padding: 22px 28px 60px; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }

/* controls */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 13px; border-radius: 8px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 12.5px; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.link:hover { color: var(--accent); }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }

/* cards */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--muted); font-size: 12.5px; }
.agents { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.agent { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
.agent:hover { border-color: var(--accent); }
.agent .name { font-weight: 600; font-size: 15px; }
.agent .status { min-height: 2.6em; color: var(--text); line-height: 1.3; }
.agent .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--idle); vertical-align: middle; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.dot.late { background: var(--warn); } .dot.offline { background: var(--bad); } .dot.never, .dot.disabled { background: var(--idle); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.tag.working, .tag.in_progress, .tag.claimed { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.tag.blocked, .tag.error, .tag.failed { color: var(--bad); }
.tag.review { color: var(--warn); }
.tag.done { color: var(--ok); }
.tag.p1 { color: var(--bad); font-weight: 600; }
.badge { background: var(--warn); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; }
.badge:empty { display: none; }
.bar { height: 5px; border-radius: 3px; background: var(--panel2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s; }

/* kanban */
.board { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; align-items: start; overflow-x: auto; }
.col { background: var(--panel2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h4 { margin: 2px 4px 10px; font-size: 13px; display: flex; justify-content: space-between; color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.card:hover { border-color: var(--accent); }
.card .t { font-weight: 500; line-height: 1.35; }
.card .m { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.dispatch { display: flex; gap: 8px; margin-bottom: 8px; }
.dispatch input { font-size: 15px; padding: 10px 12px; }

/* feed */
.feed { display: flex; flex-direction: column; }
.ev { display: grid; grid-template-columns: 82px 100px 1fr; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); align-items: baseline; }
.ev:last-child { border-bottom: 0; }
.ev .time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.ev .who { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev .what { line-height: 1.4; word-break: break-word; }
.ev .what .type { font-size: 11px; color: var(--muted); margin-right: 6px; }
.ev.t-task_done .what, .ev.t-task_approved .what { color: var(--ok); }
.ev.t-task_failed .what, .ev.t-lease_expired .what, .ev.t-offline .what, .ev.t-task_rejected .what { color: var(--bad); }
.ev.t-online .what, .ev.t-status .what { color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.mem { padding: 12px 0; border-bottom: 1px solid var(--line); }
.mem .k { font-weight: 600; }
.mem .c { white-space: pre-wrap; margin: 6px 0; line-height: 1.5; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(10,14,22,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal-card { background: var(--panel); border-radius: 14px; width: min(760px, 100%); padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); position: relative; }
.modal-card .close { position: absolute; right: 14px; top: 12px; font-size: 20px; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; max-width: 360px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: in .2s ease; font-size: 13px; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(380px, 92vw); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 14px 0 10px; }
.tabs button { background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--muted); font: inherit; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.check-inline { flex-direction: row; align-items: center; gap: 4px; color: var(--text); font-size: 13px; }
.check-inline input { width: auto; }
.tag.public { color: var(--ok); } .tag.private { color: var(--bad); }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } .side { position: static; height: auto; } nav { flex-direction: row; overflow-x: auto; } .side-foot { display: none; } main { padding: 16px; } .ev { grid-template-columns: 70px 1fr; } .ev .what { grid-column: 1 / -1; } }
