:root {
  --bg: #0e1116; --bg2: #151a22; --bg3: #1c2330; --border: #2a3344;
  --fg: #e8edf5; --muted: #8b96ab; --accent: #4c9aff; --accent2: #7c5cff;
  --ok: #35d07f; --warn: #f5b942; --err: #ff6b6b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--fg); font-size: 14px; overflow: hidden;
}
#app { display: flex; height: 100vh; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2c3648; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- sidebar ---------- */
.sidebar { width: 220px; background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 6px 8px 18px; }
.brand-logo { font-size: 30px; }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 11px; }
nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn { display: flex; align-items: center; gap: 8px; background: transparent; border: 1px solid transparent; color: var(--fg); padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; text-align: left; }
.nav-btn:hover { background: var(--bg3); }
.nav-btn.active { background: #22314a; border-color: #2d4a75; }
.nav-ico { font-size: 16px; }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; }
.sidebar-foot { margin-top: auto; color: var(--muted); font-size: 11px; padding: 10px 8px; line-height: 1.6; }

/* ---------- main views ---------- */
.view { flex: 1; overflow: auto; padding: 22px 26px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; }
.muted { color: var(--muted); }
.head-actions { display: flex; gap: 10px; align-items: center; }

/* ---------- buttons ---------- */
.btn { background: var(--bg3); border: 1px solid var(--border); color: var(--fg); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: #1f4b8f; border-color: #2f66b8; }
.btn.primary:hover { background: #2459a8; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 3px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- stat cards ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stat-card .num { font-size: 24px; font-weight: 700; }
.stat-card .lbl { color: var(--muted); font-size: 12px; }

/* ---------- filters ---------- */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filter-group { display: flex; gap: 4px; flex-wrap: wrap; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.chip { background: transparent; color: var(--muted); border: 1px solid transparent; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.chip:hover { color: var(--fg); background: var(--bg3); }
.chip.active { background: #27436b; color: #fff; }
.search { background: var(--bg2); border: 1px solid var(--border); color: var(--fg); border-radius: 8px; padding: 7px 12px; min-width: 220px; }
.search:focus { outline: none; border-color: var(--accent); }

/* ---------- model table ---------- */
.table-wrap { border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-height: calc(100vh - 320px); }
.model-table { width: 100%; border-collapse: collapse; }
.model-table th { text-align: left; background: var(--bg2); color: var(--muted); font-size: 12px; padding: 10px 12px; position: sticky; top: 0; }
.model-table td { padding: 8px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.model-table tr:hover td { background: var(--bg3); }
.m-name { font-weight: 600; }
.m-id { color: var(--muted); font-size: 11px; font-family: Consolas, monospace; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; color: #fff; white-space: nowrap; }
.badge.t-language { background: #27436b; }
.badge.t-image { background: #7a4dbf; }
.badge.t-video { background: #216e5a; }
.badge.t-voice { background: #8a5a2b; }
.badge.t-other { background: #4a5568; }
.badge.a-ok { background: #1d5c39; color: #7fdcaa; }
.badge.a-not-activated { background: #5c4a1d; color: #ffd97f; }
.badge.a-unknown { background: #444; color: #aaa; }
.badge.a-shutdown, .badge.a-not-available { background: #5c2c2c; color: #ff9f9f; }
.badge.a-ok-media { background: #2a4a5c; color: #9fd0ff; }
.price { font-family: Consolas, monospace; font-size: 12px; white-space: pre-wrap; }
.price-note { color: var(--muted); font-size: 11px; }
.link { color: var(--accent); text-decoration: none; cursor: pointer; }

/* ---------- group layout ---------- */
.group-layout { display: flex; gap: 14px; height: calc(100vh - 150px); }
.member-panel { width: 300px; display: flex; flex-direction: column; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.member-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 600; }
.member-list { list-style: none; overflow-y: auto; flex: 1; }
.member-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; border: 1px solid transparent; margin-bottom: 6px; background: var(--bg3); }
.member-item.busy { border-color: var(--accent); }
.m-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 15px; color: #fff; flex-shrink: 0; }
.m-info { flex: 1; min-width: 0; }
.m-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-meta { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-actions { display: flex; gap: 4px; }
.m-status { font-size: 11px; }
.m-remove { background: transparent; border: none; color: var(--err); cursor: pointer; font-size: 14px; }
.phase-box { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.phase-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.phase-steps { list-style: none; font-size: 12px; color: var(--muted); }
.phase-steps li { padding: 4px 0 4px 18px; position: relative; }
.phase-steps li.done { color: var(--ok); }
.phase-steps li.active { color: var(--accent); font-weight: 600; }
.phase-steps li::before { content: "○"; position: absolute; left: 0; color: var(--muted); }
.phase-steps li.done::before { content: "●"; color: var(--ok); }
.phase-steps li.active::before { content: "●"; color: var(--accent); }

/* ---------- chat ---------- */
.chat-panel { flex: 1; display: flex; flex-direction: column; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 76%; border-radius: 12px; padding: 10px 12px; position: relative; }
.msg.owner { align-self: flex-end; background: #24406b; border: 1px solid #32578f; }
.msg.member { align-self: flex-start; background: var(--bg3); border: 1px solid var(--border); }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; text-align: center; border: none; padding: 2px 8px; }
.msg .msg-head { display: flex; gap: 8px; align-items: center; margin-bottom: 5px; font-size: 12px; }
.msg .msg-name { font-weight: 700; }
.msg .msg-model { color: var(--muted); font-size: 11px; font-family: Consolas, monospace; }
.msg .msg-body { white-space: pre-wrap; font-size: 13.5px; line-height: 1.65; }
.msg .msg-kicker { display: inline-block; font-size: 11px; color: var(--muted); background: #10151d; border-radius: 4px; padding: 1px 6px; margin: 4px 4px 0 0; }
.msg .msg-reasoning { border-left: 3px solid var(--accent2); padding: 6px 10px; margin-top: 6px; color: var(--muted); font-size: 12px; max-height: 180px; overflow: auto; background: #131926; border-radius: 0 6px 6px 0; }
.msg .msg-media { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.msg .msg-media img, .msg .msg-media video { max-width: 280px; max-height: 280px; border-radius: 8px; border: 1px solid var(--border); }
.msg .msg-media audio { width: 280px; }
.msg .cursor { display: inline-block; width: 7px; height: 15px; background: var(--accent); animation: blink 1s infinite; vertical-align: -2px; }
@keyframes blink { 50% { opacity: 0; } }

.workflow-bar { border-top: 1px solid var(--border); padding: 8px 12px; background: var(--bg3); }
.flow-steps { display: flex; gap: 8px; flex-wrap: wrap; }
.fstep { background: var(--bg2); border: 1px solid var(--border); color: var(--muted); padding: 6px 12px; border-radius: 20px; font-size: 12px; cursor: pointer; }
.fstep:hover { border-color: var(--accent); color: var(--fg); }
.fstep:disabled, .fstep.disabled { opacity: .45; cursor: not-allowed; }
.fstep.stop { color: var(--err); border-color: #5c2c2c; }
.fstep.busy { border-color: var(--accent); color: var(--accent); }
.chat-input { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--border); }
.chat-input textarea { flex: 1; background: #0d1117; color: var(--fg); border: 1px solid var(--border); border-radius: 10px; padding: 10px; font-size: 14px; resize: none; font-family: inherit; }
.chat-input textarea:focus { outline: none; border-color: var(--accent); }
.input-actions { display: flex; flex-direction: column; gap: 8px; justify-content: center; }

/* ---------- settings ---------- */
.config-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 14px; }
.config-item { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.config-item h3 { display: flex; align-items: center; gap: 8px; font-size: 15px; margin-bottom: 8px; }
.config-item label { display: block; color: var(--muted); font-size: 12px; margin: 8px 0 3px; }
.config-item input { width: 100%; background: #0d1117; color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.config-item .save { margin-top: 10px; }

/* ---------- modal ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { width: min(860px, 92vw); max-height: 82vh; display: flex; flex-direction: column; background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-filters { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.modal-list { overflow-y: auto; }
.modal-item { display: flex; gap: 10px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--bg3); align-items: center; }
.modal-item .add { margin-left: auto; }
.modal-item.in-group { opacity: .45; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #22314a; border: 1px solid #2d4a75; padding: 10px 20px; border-radius: 10px; z-index: 99; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.bal-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--bg3); }
.bal-amount { font-size: 22px; font-weight: 700; font-family: Consolas, monospace; }
.bal-info { flex: 1; }
.bal-detail { color: var(--muted); font-size: 12px; }
.bal-note { font-size: 12px; color: var(--muted); max-width: 340px; }
.cfg-balance { margin-top: 8px; font-size: 13px; }
.login-mask { position: fixed; inset: 0; background: var(--bg); z-index: 200; display: flex; align-items: center; justify-content: center; }
.login-box { width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; padding: 34px 30px; background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; }
.login-logo { font-size: 44px; }
.login-box h2 { font-size: 20px; }
.login-box input { background: #0d1117; color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-err { min-height: 18px; font-size: 12px; color: var(--err); }
.login-btn { padding: 11px; font-size: 15px; }
#whoami { color: var(--muted); font-size: 12px; }
body.running .fstep.busy-default { border-color: var(--warn); }
