:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f5;
  --sidebar: #f3f3f0;
  --surface: #ffffff;
  --border: #e4e4df;
  --border-strong: #cfcfc8;
  --text: #1d1d1b;
  --text-soft: #5e5e58;
  --text-faint: #8d8d86;
  --accent: #003399;          /* EU blue */
  --accent-soft: #e8eefb;
  --star: #ffcc00;            /* EU gold */
  --user-bubble: #efefeb;
  --code-bg: #f4f4f1;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --ok: #14662f;
  --ok-soft: #e5f4ea;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .12), 0 2px 6px rgba(0, 0, 0, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a;
    --bg-soft: #232322;
    --sidebar: #141413;
    --surface: #262625;
    --border: #353533;
    --border-strong: #4a4a47;
    --text: #ecece8;
    --text-soft: #b2b2ab;
    --text-faint: #85857f;
    --accent: #7ea2ff;
    --accent-soft: #24304d;
    --user-bubble: #2d2d2b;
    --code-bg: #141413;
    --warn: #ffc56b;
    --warn-soft: #3a2c13;
    --ok: #7fd69a;
    --ok-soft: #173322;
    --danger: #ff8a80;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
textarea, input { font: inherit; color: inherit; }

.app { display: flex; height: 100dvh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: 272px; flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px 10px;
  gap: 10px;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: #003399;
  background-image: radial-gradient(circle, var(--star) 1.4px, transparent 1.6px);
  background-size: 7px 7px; background-position: center;
  box-shadow: inset 0 0 0 4px #003399;
}

.new-chat {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  font-weight: 550;
}
.new-chat:hover { border-color: var(--border-strong); }

.eu-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; user-select: none;
}
.eu-toggle-text { display: flex; align-items: center; gap: 10px; line-height: 1.25; }
.eu-toggle-text small { display: block; color: var(--text-faint); font-size: 12px; }
.eu-flag { font-size: 20px; }
.eu-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative; width: 36px; height: 20px; flex-shrink: 0;
  border-radius: 999px; background: var(--border-strong); transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.eu-toggle input:checked + .switch { background: #003399; }
.eu-toggle input:checked + .switch::after { transform: translateX(16px); }
.eu-toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; margin: 4px -4px 0; padding: 0 4px; }
.chat-list h3 { font-size: 12px; font-weight: 600; color: var(--text-faint); margin: 12px 8px 4px; }
.chat-item {
  display: flex; align-items: center; gap: 6px;
  border-radius: 8px; padding: 0 4px 0 10px;
}
.chat-item:hover, .chat-item.active { background: var(--border); }
.chat-item button.open {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 7px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px;
}
.chat-item .eu-dot { font-size: 11px; flex-shrink: 0; opacity: .85; }
.chat-item button.del {
  visibility: hidden; background: none; border: 0; padding: 4px; border-radius: 6px; color: var(--text-faint);
}
.chat-item:hover button.del, .chat-item.active button.del { visibility: visible; }
.chat-item button.del:hover { color: var(--danger); }
.empty-list { color: var(--text-faint); font-size: 13px; padding: 8px 10px; }

.sidebar-bottom { border-top: 1px solid var(--border); padding-top: 8px; }
.ghost-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: 0; border-radius: 8px; padding: 8px 10px; color: var(--text-soft);
}
.ghost-btn:hover { background: var(--border); color: var(--text); }

.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--text-soft); display: inline-flex; }
.icon-btn:hover { background: var(--border); color: var(--text); }
.only-mobile { display: none; }
.scrim { display: none; }

/* ── Main ────────────────────────────────────────────── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; min-height: 56px;
  border-bottom: 1px solid transparent;
}

.picker { position: relative; min-width: 0; }
.picker-btn {
  display: flex; align-items: center; gap: 6px; max-width: 100%;
  background: none; border: 0; border-radius: 10px; padding: 7px 10px;
  font-weight: 600; font-size: 16px;
}
.picker-btn:hover, .picker-btn[aria-expanded="true"] { background: var(--bg-soft); }
.picker-label { display: flex; align-items: baseline; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-label .prov { color: var(--text-faint); font-weight: 500; font-size: 14px; }

.picker-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  width: min(420px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.picker-search { padding: 10px; border-bottom: 1px solid var(--border); }
.picker-search input {
  width: 100%; border: 1px solid var(--border); background: var(--bg-soft);
  border-radius: 8px; padding: 7px 10px; outline: none;
}
.picker-search input:focus { border-color: var(--accent); }
.picker-list { overflow-y: auto; padding: 6px; }
.region-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint); padding: 10px 10px 4px;
}
.prov-group { margin-bottom: 4px; }
.prov-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 10px 2px; font-size: 13px; font-weight: 600;
}
.prov-head > span:first-child { white-space: nowrap; flex-shrink: 0; }
.prov-head .where { font-weight: 400; color: var(--text-faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prov-missing { padding: 2px 10px 8px; font-size: 12.5px; color: var(--text-faint); }
.prov-missing code { font-family: var(--mono); font-size: 11.5px; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.model-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  background: none; border: 0; border-radius: 8px; padding: 7px 10px 7px 18px; text-align: left;
  font-family: var(--mono); font-size: 13px;
}
.model-opt:hover, .model-opt.kb { background: var(--bg-soft); }
.model-opt[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.model-opt .check { visibility: hidden; }
.model-opt[aria-selected="true"] .check { visibility: visible; }
.picker-empty { padding: 18px; text-align: center; color: var(--text-faint); font-size: 14px; }

.residency {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 550; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.residency.eu { background: var(--ok-soft); color: var(--ok); }
.residency.non-eu { background: var(--warn-soft); color: var(--warn); }
.residency:empty { display: none; }

/* ── Thread ──────────────────────────────────────────── */
.thread { flex: 1; overflow-y: auto; padding: 8px 16px 24px; scroll-behavior: smooth; }
.thread-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

.welcome { max-width: 640px; margin: 14vh auto 0; text-align: center; }
.welcome h1 { font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 8px; }
.welcome p { color: var(--text-soft); margin: 0 0 24px; }
.welcome .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; text-align: left; }
.welcome .card {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface);
  font-size: 14px; color: var(--text-soft); text-align: left;
}
.welcome .card:hover { border-color: var(--border-strong); color: var(--text); }
.welcome .card strong { display: block; color: var(--text); font-weight: 600; margin-bottom: 2px; }

.msg { display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble); border-radius: 18px; padding: 9px 16px;
  max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant .meta {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
  font-size: 12.5px; color: var(--text-faint);
}
.msg.assistant .meta .model { font-family: var(--mono); color: var(--text-soft); }
.msg.assistant .content { overflow-wrap: anywhere; }
.msg .actions { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .actions, .msg:last-child .actions { opacity: 1; }
.msg .actions button { background: none; border: 0; padding: 4px 8px; border-radius: 6px; font-size: 12.5px; color: var(--text-faint); }
.msg .actions button:hover { background: var(--bg-soft); color: var(--text); }

.thinking { margin: 2px 0 8px; border-left: 2px solid var(--border-strong); padding-left: 12px; }
.thinking summary { cursor: pointer; color: var(--text-faint); font-size: 13px; list-style: none; user-select: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::before { content: "▸ "; }
.thinking[open] summary::before { content: "▾ "; }
.thinking .thinking-body { color: var(--text-soft); font-size: 14px; white-space: pre-wrap; margin-top: 6px; max-height: 320px; overflow-y: auto; }

.notice { font-size: 13px; color: var(--warn); background: var(--warn-soft); padding: 6px 10px; border-radius: 8px; margin-top: 8px; }
.error { font-size: 14px; color: var(--danger); border: 1px solid currentColor; padding: 8px 12px; border-radius: 10px; margin-top: 6px; }

.cursor::after {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 4px;
  border-radius: 50%; background: var(--text); vertical-align: middle;
  animation: pulse 1s infinite ease-in-out;
}
@keyframes pulse { 50% { opacity: .2; transform: scale(.7); } }

/* Markdown */
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p, .content ul, .content ol, .content blockquote, .content pre, .content table { margin: 0 0 12px; }
.content h1, .content h2, .content h3, .content h4 { line-height: 1.3; margin: 20px 0 8px; letter-spacing: -.01em; }
.content h1 { font-size: 1.45em; } .content h2 { font-size: 1.25em; } .content h3 { font-size: 1.1em; } .content h4 { font-size: 1em; }
.content ul, .content ol { padding-left: 24px; }
.content li { margin: 3px 0; }
.content a { color: var(--accent); }
.content blockquote { border-left: 3px solid var(--border-strong); padding-left: 12px; color: var(--text-soft); }
.content hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.content code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.content table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.content th, .content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.content th { background: var(--bg-soft); }
.codeblock { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin: 0 0 12px; background: var(--code-bg); }
.codeblock .code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 6px 4px 12px; font-size: 12px; color: var(--text-faint); border-bottom: 1px solid var(--border);
}
.codeblock .code-head button { background: none; border: 0; font-size: 12px; color: var(--text-faint); padding: 3px 8px; border-radius: 6px; }
.codeblock .code-head button:hover { background: var(--border); color: var(--text); }
.codeblock pre { margin: 0; padding: 12px; overflow-x: auto; }
.codeblock code { background: none; padding: 0; font-size: 13px; line-height: 1.55; }

/* ── Composer ────────────────────────────────────────── */
.composer-wrap { padding: 0 16px 14px; }
.composer {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 22px;
  padding: 8px 8px 8px 18px; box-shadow: 0 2px 10px rgba(0,0,0,.04);
}
.composer:focus-within { border-color: var(--text-faint); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none; background: transparent;
  max-height: 240px; padding: 6px 0; line-height: 1.5;
}
.send-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 0; flex-shrink: 0;
  background: var(--text); color: var(--bg); display: grid; place-items: center;
}
.send-btn:disabled { opacity: .3; cursor: default; }
.send-btn .i-stop { display: none; }
.app.streaming .send-btn .i-send { display: none; }
.app.streaming .send-btn .i-stop { display: block; }
.composer-note { max-width: 760px; margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--text-faint); }

/* ── Dialog ──────────────────────────────────────────── */
.dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 0;
  width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.dialog h2 { margin: 0; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 14px; }
.field textarea { border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: var(--bg-soft); font-weight: 400; resize: vertical; outline: none; }
.field textarea:focus { border-color: var(--accent); }
.field small { color: var(--text-faint); font-weight: 400; }
.provider-status { font-size: 13.5px; }
.provider-status h3 { font-size: 14px; margin: 0 0 6px; }
.provider-status ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.provider-status li { display: flex; justify-content: space-between; gap: 8px; }
.provider-status .ok { color: var(--ok); }
.provider-status .missing { color: var(--text-faint); }
.dialog-actions { display: flex; justify-content: space-between; gap: 8px; }
.primary-btn { background: var(--text); color: var(--bg); border: 0; border-radius: 10px; padding: 8px 18px; font-weight: 600; }
.danger-btn { background: none; border: 1px solid var(--border); color: var(--danger); border-radius: 10px; padding: 8px 14px; }
.danger-btn.armed { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ── Mobile ──────────────────────────────────────────── */
@media (max-width: 820px) {
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .topbar { padding: 8px 10px; gap: 4px; }
  .picker-btn { font-size: 15px; }
  .picker-label .prov { display: none; }
  .residency .long { display: none; }
  .welcome { margin-top: 8vh; }
  .welcome h1 { font-size: 24px; }
  .composer-wrap { padding: 0 10px 10px; }
  .thread { padding: 8px 12px 20px; }
}

/* ── Login ───────────────────────────────────────────── */
.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 16px; background: var(--bg-soft); }
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); text-align: center;
}
.login-brand { justify-content: center; margin-bottom: 22px; }
.login-card h1 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 6px; }
.login-sub { color: var(--text-soft); margin: 0 0 22px; }
.login-buttons { display: grid; gap: 10px; }
.login-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 11px 16px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); text-decoration: none; font-weight: 550;
}
.login-btn:hover { background: var(--bg-soft); }
.login-error { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 16px; text-align: left; }
.login-foot { color: var(--text-faint); font-size: 12.5px; margin: 20px 0 0; }

/* user chip in sidebar */
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.user-chip img, .user-chip .avatar-fallback {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; object-fit: cover;
  background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 600;
}
.user-chip .who { flex: 1; min-width: 0; line-height: 1.25; }
.user-chip .who strong, .user-chip .who small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .who strong { font-size: 13.5px; font-weight: 600; }
.user-chip .who small { font-size: 12px; color: var(--text-faint); }
.user-chip form { margin: 0; }
.user-chip button { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--text-faint); display: inline-flex; }
.user-chip button:hover { background: var(--border); color: var(--text); }

/* ── Bring-your-own-key ──────────────────────────────── */
.dialog { width: min(620px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.keys h3 { font-size: 14px; margin: 0 0 4px; }
.keys .hint { font-size: 13px; color: var(--text-faint); margin: 0 0 10px; }
.keys-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.key-row { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin: 0; }
.key-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; margin-bottom: 6px; }
.key-head small { color: var(--text-faint); font-size: 11.5px; font-weight: 600; margin-left: 2px; }
.key-head a { font-size: 12.5px; color: var(--accent); white-space: nowrap; }
.key-input { display: flex; gap: 6px; }
.key-input input {
  flex: 1; min-width: 0; border: 1px solid var(--border); background: var(--bg-soft);
  border-radius: 8px; padding: 6px 10px; font-family: var(--mono); font-size: 13px; outline: none;
}
.key-input input:focus { border-color: var(--accent); }
.key-input button { border-radius: 8px; padding: 6px 12px; font-size: 13px; border: 1px solid var(--border); background: var(--surface); }
.key-input .key-save { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.key-input .key-save:disabled { opacity: .5; }
.key-input .key-remove { color: var(--danger); }
.key-status { font-size: 12.5px; margin-top: 5px; color: var(--text-faint); }
.key-status:empty { display: none; }
.key-status.ok { color: var(--ok); }
.key-status.bad { color: var(--danger); }

.prov-add {
  display: block; margin: 2px 10px 8px 18px; padding: 5px 10px; font-size: 13px;
  border: 1px dashed var(--border-strong); background: none; border-radius: 8px; color: var(--accent);
}
.prov-add:hover { background: var(--accent-soft); border-style: solid; }

.onboard { display: grid; gap: 8px; text-align: left; max-width: 520px; margin: 0 auto; }
.onboard-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); text-align: left;
}
.onboard-item:hover { border-color: var(--border-strong); }
.onboard-item > span:first-child { font-size: 20px; }
.onboard-item strong { display: block; font-weight: 600; }
.onboard-item small { display: block; color: var(--text-faint); font-size: 12.5px; }
.onboard-item > span:nth-child(2) { flex: 1; min-width: 0; }
.onboard-item .go { color: var(--accent); font-size: 13px; white-space: nowrap; }
@media (max-width: 820px) { .welcome:has(.onboard) { margin-top: 4vh; } }
.dialog-body > * { min-width: 0; }
@media (max-width: 520px) {
  .dialog-body { padding: 16px; }
  .key-input button { padding: 6px 9px; }
}

/* privacy / terms */
.doc-card { width: min(680px, 100%); text-align: left; }
.doc-card h2 { font-size: 16px; margin: 20px 0 6px; }
.doc-card p { margin: 0 0 10px; line-height: 1.55; }
.login-foot a { color: inherit; }

/* ── AI Team panel ───────────────────────────────────── */
.team-btn {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 6px 12px; font-weight: 600; font-size: 14px;
}
.team-btn:hover { border-color: var(--border-strong); }
.team-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.team-panel {
  display: none; flex-direction: column; min-height: 0; flex-shrink: 0;
  width: 520px; background: var(--bg); border-left: 1px solid var(--border);
}
.app.team-open .team-panel { display: flex; }
@media (max-width: 1180px) {
  .team-panel { position: fixed; inset: 0 0 0 auto; width: min(560px, 100vw); z-index: 45; box-shadow: var(--shadow); }
}

.tm-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); min-height: 56px; }
.tm-title { display: flex; align-items: center; gap: 8px; margin-right: auto; min-width: 0; }
.tm-title div { display: flex; flex-direction: column; line-height: 1.2; }
.tm-title small { color: var(--text-faint); font-size: 12px; }
.tm-logo { font-size: 20px; }
.tm-tabs { display: flex; background: var(--bg-soft); border-radius: 9px; padding: 3px; }
.tm-tabs button { border: 0; background: none; border-radius: 7px; padding: 4px 12px; font-size: 13.5px; font-weight: 550; color: var(--text-soft); }
.tm-tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.tm-body { flex: 1; overflow-y: auto; padding: 12px 14px 18px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.tm-body > * { min-width: 0; }
.tm-toolbar { display: flex; gap: 8px; align-items: center; }
.tm-mission-select { flex: 1; min-width: 0; }
.tm-body select, .tm-body input, .tm-body textarea, .tm-composer select {
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg-soft); padding: 6px 8px;
  font-size: 14px; outline: none; max-width: 100%;
}
.tm-body textarea { width: 100%; resize: vertical; line-height: 1.45; }
.tm-body select:focus, .tm-body input:focus, .tm-body textarea:focus { border-color: var(--accent); }
.tm-stats { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-faint); }
.tm-controls { display: flex; gap: 6px; }

.tm-btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 4px 10px; font-size: 13px; font-weight: 550; white-space: nowrap;
}
.tm-btn:hover { border-color: var(--border-strong); }
.tm-btn.subtle { border-color: transparent; background: none; color: var(--text-soft); }
.tm-btn.subtle:hover { background: var(--bg-soft); }
.tm-btn.danger { color: var(--danger); }
.tm-link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }
.tm-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tm-actions .primary-btn { padding: 5px 14px; font-size: 13.5px; }
.tm-spacer { flex: 1; }
.tm-muted { color: var(--text-faint); font-size: 13px; }
.tm-error { color: var(--danger); font-size: 13.5px; }
.tm-model { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); margin-left: auto; }
.tm-working::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: var(--accent); animation: tm-pulse 1s infinite ease-in-out; vertical-align: middle; }
@keyframes tm-pulse { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .tm-working::after { animation: none; } }

.tm-empty { text-align: left; padding: 6px 2px; }
.tm-empty h3 { margin: 4px 0 6px; font-size: 17px; letter-spacing: -.01em; }
.tm-empty p { color: var(--text-soft); font-size: 14px; margin: 0 0 12px; }
.tm-examples { display: grid; gap: 8px; margin-bottom: 12px; }
.tm-examples button {
  text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 9px 12px; font-size: 13.5px; color: var(--text-soft);
}
.tm-examples button:hover { border-color: var(--border-strong); color: var(--text); }

.tm-ceo { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; margin-top: 6px; }
.tm-who { font-size: 12px; color: var(--text-faint); }
.tm-bubble { background: var(--user-bubble); border-radius: 14px; padding: 8px 12px; max-width: 92%; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }

.tm-card { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 14px; }
.tm-card-head, .tm-card > summary { display: flex; align-items: center; gap: 8px; padding: 9px 12px; }
.tm-card > summary { cursor: pointer; list-style: none; }
.tm-card > summary::-webkit-details-marker { display: none; }
.tm-card-body { padding: 0 12px 12px; overflow-wrap: anywhere; }
.tm-card-body > p { margin: 0 0 8px; }
.tm-card .content { font-size: 14px; line-height: 1.55; }
.tm-card .content h1, .tm-card .content h2, .tm-card .content h3 { font-size: 15px; margin: 12px 0 6px; }
.tm-sum { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.tm-sum span { color: var(--text-soft); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.tm-task:not([open]) .tm-sum span { white-space: nowrap; }
.tm-avatar { width: 30px; height: 30px; border-radius: 9px; background: var(--bg-soft); display: grid; place-items: center; font-size: 16px; flex-shrink: 0; }
.tm-brief { border-color: var(--accent); }
.tm-brief .tm-avatar { background: var(--accent-soft); }

.tm-pill { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; background: var(--bg-soft); color: var(--text-soft); flex-shrink: 0; }
.tm-pill.p-working, .tm-pill.p-running, .tm-pill.p-planning, .tm-pill.p-synthesizing { background: var(--accent-soft); color: var(--accent); }
.tm-pill.p-done { background: var(--ok-soft); color: var(--ok); }
.tm-pill.p-review, .tm-pill.p-paused, .tm-pill.p-pausing, .tm-pill.p-stopped { background: var(--warn-soft); color: var(--warn); }
.tm-pill.p-failed, .tm-pill.p-error { background: var(--warn-soft); color: var(--danger); }

.tm-plan-list { margin: 4px 0 0; padding-left: 20px; }
.tm-plan-list li { margin: 2px 0; }
.tm-plan-row { border: 1px solid var(--border); border-radius: 10px; padding: 8px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.tm-plan-top { display: flex; align-items: center; gap: 6px; }
.tm-plan-top select { flex: 1; min-width: 0; }
.tm-plan-row input { width: 100%; font-weight: 600; }
.tm-tid { font-family: var(--mono); font-size: 12px; color: var(--text-faint); }

.tm-consult { border-left: 2px solid var(--border-strong); padding: 2px 0 2px 10px; margin: 0 0 10px; font-size: 13.5px; }
.tm-consult .content { margin-top: 4px; color: var(--text-soft); }
.tm-feedback { margin-top: 8px; }

.tm-section { display: flex; flex-direction: column; gap: 8px; padding-bottom: 6px; }
.tm-section h3 { margin: 4px 0 0; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.tm-section p { margin: 0; }
.tm-check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.tm-agent { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; background: var(--surface); }
.tm-agent.off { opacity: .55; }
.tm-agent-info { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.tm-agent-info small { color: var(--text-soft); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-agent-info .tm-model { margin: 0; }
.tm-agent.editing { flex-direction: column; align-items: stretch; gap: 8px; }
.tm-agent.editing label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.tm-agent.editing input, .tm-agent.editing select { width: 100%; font-weight: 400; color: var(--text); }
.tm-grid { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 8px; }
.tm-badge { font-size: 11.5px; font-weight: 650; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; }
.tm-switch { position: relative; width: 34px; height: 20px; flex-shrink: 0; }
.tm-switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.tm-switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .15s; pointer-events: none; }
.tm-switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.tm-switch input:checked + span { background: var(--accent); }
.tm-switch input:checked + span::after { transform: translateX(14px); }
.tm-switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.tm-composer { border-top: 1px solid var(--border); padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.tm-to { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); min-width: 0; }
.tm-to select { max-width: 45%; }
.tm-hint { color: var(--text-faint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tm-hint.warn { color: var(--warn); white-space: normal; }
.tm-input { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--border-strong); border-radius: 14px; padding: 6px 6px 6px 12px; background: var(--surface); }
.tm-input:focus-within { border-color: var(--accent); }
.tm-input textarea { flex: 1; border: 0; outline: none; resize: none; background: none; max-height: 160px; padding: 4px 0; font-size: 14.5px; }

@media (max-width: 520px) {
  .team-btn span { display: none; }
  .team-btn { padding: 6px 8px; }
  .tm-head { padding: 8px 10px; gap: 6px; }
  .tm-title small { display: none; }
  .tm-body { padding: 10px 12px 16px; }
}
