:root {
  --bg: #f5f5f7; --panel: #fff; --sidebar: #fbfbfd; --text: #1d1d1f; --muted: #6e6e73;
  --border: rgba(0,0,0,.09); --accent: #0a84ff; --accent-text: #fff; --code: #f0f0f3;
  --error: #d70015; --error-soft: rgba(215,0,21,.08);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111214; --panel: #1b1c1f; --sidebar: #16171a; --text: #ececf1; --muted: #9a9aa2;
    --border: rgba(255,255,255,.1); --code: #26272b; --error: #ff6961; --error-soft: rgba(255,69,58,.14); }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", system-ui, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.danger { color: var(--error); border-color: var(--error); }
input, textarea, select { border: 1px solid var(--border); border-radius: 8px; background: var(--panel); padding: 7px 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.subtle { color: var(--muted); font-size: 13px; }
.error-text { color: var(--error); font-size: 14px; }
[hidden] { display: none !important; }

.layout { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.sidebar { background: var(--sidebar); border-right: 1px solid var(--border); padding: 16px; display: flex;
  flex-direction: column; gap: 12px; overflow-y: auto; }
.brand { font-weight: 700; font-size: 17px; }
.rooms { display: flex; flex-direction: column; gap: 4px; }
.room-link { text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; }
.room-link:hover { background: var(--border); }
.room-link.active { background: var(--accent); color: var(--accent-text); }
.room-link small { display: block; font-size: 12px; opacity: .75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pane { height: 100vh; min-width: 0; }
.empty { display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 24px; }

.setup { overflow-y: auto; }
.setup-inner { max-width: 880px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.setup h1 { font-size: 20px; margin: 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.field > span { color: var(--muted); font-size: 13px; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field.inline input { width: 180px; }
.field.inline input[type=number] { width: 80px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.role-editor { display: flex; flex-direction: column; gap: 10px; }
.role-card { background: var(--panel); border: 1px solid var(--border); border-left: 5px solid var(--role, var(--accent));
  border-radius: 12px; padding: 12px; display: grid; gap: 8px;
  grid-template-columns: 1.1fr .8fr .8fr 1.4fr .8fr auto; align-items: center; }
.role-card > * { min-width: 0; }
.role-card select, .role-card input { width: 100%; text-overflow: ellipsis; }
.role-card textarea, .role-card .wide { grid-column: 1 / -1; }
.role-card textarea { resize: vertical; min-height: 54px; }

.room { display: flex; flex-direction: column; }
.room-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.room-header h1 { font-size: 17px; margin: 0; }
.room-meta { display: flex; gap: 10px; align-items: center; }
.badge { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--border); font-weight: 600; }
.badge.running, .badge.closing { background: #34c759; color: #fff; }
.badge.paused { background: #ff9f0a; color: #fff; }
.badge.finished { background: #8e8e93; color: #fff; }
.roster { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--border); }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.chip .dot, .who .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--role); display: inline-block; }
.chip.speaking { outline: 2px solid var(--role); }
.tag { font-size: 11px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); }
.role-settings { padding: 12px 20px; background: var(--bg); border-bottom: 1px solid var(--border); max-height: 50vh; overflow-y: auto; }
.role-settings .role-card { grid-template-columns: 1.1fr .8fr 1.3fr .7fr auto auto; }
@media (max-width: 760px) { .role-settings .role-card { grid-template-columns: 1fr 1fr; } }
.controls { display: flex; gap: 8px; padding: 8px 20px; flex-wrap: wrap; background: var(--panel); border-bottom: 1px solid var(--border); }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 820px; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.msg .who b { color: var(--text); }
.bubble { padding: 10px 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--border);
  border-left: 4px solid var(--role, var(--border)); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; }
.msg.user .who { justify-content: flex-end; }
.msg.user .bubble { background: var(--accent); color: var(--accent-text); border: 0; white-space: pre-wrap; }
.bubble.error { background: var(--error-soft); color: var(--error); border-color: var(--error); }
.work { font-size: 13px; color: var(--muted); margin-bottom: 6px; padding: 4px 10px; border-radius: 10px; background: var(--code); }
.work ol { margin: 4px 0; padding-left: 20px; }
.work li { word-break: break-all; }
.usage { font-size: 12px; color: var(--muted); margin-top: 4px; }
.spinner { display: inline-block; width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.system { align-self: center; font-size: 13px; color: var(--muted); text-align: center; max-width: 640px; }
.bubble pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.bubble :not(pre) > code { background: var(--code); padding: 1px 5px; border-radius: 4px; }
.bubble h4 { margin: 10px 0 4px; font-size: 15px; }
.bubble p { margin: 4px 0; } .bubble ul, .bubble ol { margin: 4px 0; padding-left: 22px; }
.bubble a { color: var(--accent); }
.mention { font-weight: 600; color: var(--role, inherit); }
.msg.user .mention { color: inherit; text-decoration: underline; }

.status-bar { padding: 6px 20px; font-size: 14px; background: var(--panel); border-top: 1px solid var(--border); }
.composer { display: flex; gap: 10px; padding: 10px 20px 16px; background: var(--panel); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: vertical; min-height: 48px; max-height: 220px; background: var(--bg); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .pane { height: auto; min-height: 70vh; }
  .role-card { grid-template-columns: 1fr 1fr; }
}

/* 附件 */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dropzone { display: flex; align-items: center; justify-content: center; min-height: 64px; border: 2px dashed var(--border);
  border-radius: 12px; background: var(--panel); color: var(--muted); cursor: pointer; padding: 10px; text-align: center; }
.dropzone.dragover, .room.dragover .messages { outline: 2px dashed var(--accent); outline-offset: -6px; }
.dropzone input, .attach-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone:focus-within, .attach-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-list:empty { display: none; }
.room-attachments { padding: 8px 20px; background: var(--panel); border-bottom: 1px solid var(--border); }
.attachment { display: inline-flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--panel); font-size: 13px; max-width: 320px; }
.attachment a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.attachment a:hover .name { text-decoration: underline; }
.attachment .thumb { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; background: var(--code);
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px; flex: none; }
.attachment .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.attachment button { padding: 0 6px; border: 0; background: transparent; color: var(--muted); font-size: 16px; }
.attachment.pending { opacity: .6; }
.attachment.failed { border-color: var(--error); color: var(--error); }
.attach-button { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 20px; background: var(--bg); }

/* 登录 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 20px; }
.logout { margin-top: auto; }

/* 发言失败的处理卡片 */
.badge.blocked { background: #ff3b30; color: #fff; }
.tag.absent { color: var(--error); border-color: var(--error); }
.failure-card { align-self: stretch; max-width: 820px; border: 1px solid #ff9f0a; background: rgba(255,159,10,.08);
  border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.failure-card.resolved { border-color: var(--border); background: transparent; opacity: .7; }
.failure-title { font-weight: 600; }
.failure-hint { margin: 0; font-size: 14px; color: var(--muted); }
.failure-hint:empty { display: none; }
.failure-controls { display: flex; flex-direction: column; gap: 8px; }
.failure-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.failure-row select { min-width: 0; max-width: 100%; }
.failure-done { margin: 0; font-size: 13px; color: var(--muted); }
.toggle-inline { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; white-space: nowrap; }
