:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e232c; --text: #e6e8ec;
  --muted: #8b93a1; --accent: #4c8bf5; --accent2: #2c5fb0; --user: #2a3340; --ok: #46b26a;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg); color: var(--text); height: 100vh; }
.hidden { display: none !important; }

.login { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: var(--panel); padding: 32px; border-radius: 16px; width: 320px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.login-card h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }
input, select { background: var(--panel2); border: 1px solid #2a2f3a; color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-size: 15px; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
button { background: var(--accent); color: white; border: none; padding: 12px 16px;
  border-radius: 10px; font-size: 15px; cursor: pointer; font-weight: 600; }
button:hover { background: var(--accent2); }
button.ghost { background: transparent; color: var(--muted); }
.error { color: #e0625e; font-size: 13px; min-height: 16px; margin: 0; }

.app { display: flex; flex-direction: column; height: 100vh; max-width: 860px; margin: 0 auto; }
header { display: flex; align-items: center; gap: 16px; padding: 14px 18px; border-bottom: 1px solid #232833; }
header h1 { font-size: 18px; margin: 0; }
.tabs { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.tabs button { background: transparent; color: var(--muted); padding: 8px 12px; font-weight: 500; }
.tabs button.active { color: var(--text); background: var(--panel2); }

main { flex: 1; overflow: hidden; display: flex; }
.tab { display: none; flex-direction: column; width: 100%; }
.tab.active { display: flex; }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.bubble { max-width: 78%; padding: 11px 14px; border-radius: 14px; line-height: 1.45; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--user); }
.bubble.assistant { align-self: flex-start; background: var(--panel2); }

.pending-bar { padding: 10px 18px; background: #2a2410; border-bottom: 1px solid #3a3316;
  color: #e8d48a; font-size: 13px; }

.status { padding: 4px 20px 8px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.status em { font-size: 13px; }
.spinner { width: 14px; height: 14px; border: 2px solid #333; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.composer { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid #232833; }
.composer input { flex: 1; }

.list { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel2); border: 1px solid #262c37; border-radius: 12px; padding: 12px 14px; }
.card .t { font-weight: 600; }
.card .m { color: var(--muted); font-size: 13px; margin-top: 4px; white-space: pre-wrap; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--accent); }
.card .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.card .actions button { padding: 6px 10px; font-size: 13px; font-weight: 500; }
.card .actions .danger { background: #7a2f2c; }
.card .actions .danger:hover { background: #943a36; }
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 6px;
  background: #24405e; color: #a9cdf6; margin-left: 6px; }

.activity-head { padding: 14px 18px 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.activity-head button, .activity-head input, .activity-head select { font-size: 14px; }
.activity-head .chk { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.ext-status { color: var(--muted); font-size: 13px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 16px; width: 560px; max-width: 100%;
  max-height: 86vh; display: flex; flex-direction: column; padding: 22px; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-card h2 { margin: 0 0 12px; font-size: 18px; padding-right: 28px; }
.modal-close { position: absolute; top: 14px; right: 16px; background: transparent;
  color: var(--muted); font-size: 24px; line-height: 1; padding: 0; }
.modal-body { color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: 12px; }
.modal-body .row { margin: 6px 0; }
.modal-body .row b { color: var(--text); font-weight: 600; }
.modal-chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 10px; min-height: 40px; }
.modal-chat .bubble { max-width: 90%; font-size: 14px; }

.chat-toolbar { padding: 10px 18px 0; }
.chat-toolbar button { font-size: 13px; padding: 6px 12px; }