/* Cokwest Hub: shared tokens, workspace, conversation, dialogs, responsive rules. */
:root {
  color-scheme: light;
  --ink: #20314b;
  --muted: #5c6c82;
  --line: #dfe6ef;
  --paper: #fff;
  --canvas: #f4f7fb;
  --blue: #255ad6;
  --blue-soft: #edf3ff;
  --green: #087c59;
  --amber: #8b5b10;
  --red: #b52f4b;
  --danger-soft: #fff1f3;
  --success-soft: #eaf7f1;
  --warning-soft: #fff8e8;
  --field-border: #cbd6e5;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --shadow: 0 12px 36px rgb(25 45 78 / 12%);
  --shadow-sm: 0 2px 8px rgb(25 45 78 / 6%);
  --focus: 0 0 0 3px rgb(37 90 214 / 14%);
  --font-mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }
body {
  background: var(--canvas);
  color: var(--ink);
  font: var(--text-base)/1.55 "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100%; }
[v-cloak] { display: none; }
::selection { background: #dce8ff; color: #173f97; }
button, input, select, textarea { font: inherit; }
button {
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--blue);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}
button:hover:not(:disabled) { background: #1e4dbb; }
button:disabled { cursor: not-allowed; opacity: .5; }
:is(button, [role="button"], input, select, textarea):focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}
input, select, textarea { min-width: 0; color: var(--ink); }
input::placeholder, textarea::placeholder { color: #748197; }
input[type="checkbox"] { accent-color: var(--blue); }
textarea { line-height: 1.65; }
.ghost { color: #425571; background: var(--paper); border-color: var(--field-border); }
.ghost:hover:not(:disabled) { color: var(--blue); background: var(--blue-soft); border-color: #a9bfeb; }
.danger { color: var(--red); background: var(--danger-soft); border-color: #f0c9d2; }
.danger:hover:not(:disabled) { color: #9c2440; background: #ffe4e9; border-color: #e3a7b4; }
.tiny { min-height: 32px; padding: 6px 10px; font-size: var(--text-xs); }
.muted { color: var(--muted); font-size: var(--text-xs); }
.meta { margin-top: 3px; color: var(--muted); font-size: var(--text-xs); }

/* Application frame and shared navigation. */
.shell { display: flex; flex-direction: column; height: 100%; height: 100dvh; overflow: hidden; }
.bar {
  position: relative;
  z-index: 10;
  display: flex;
  flex: 0 0 56px;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  background: #162640;
  color: #fff;
}
.brand { flex-shrink: 0; font-weight: 700; font-size: 16px; letter-spacing: -.2px; white-space: nowrap; }
.brand b {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-right: 9px;
  border-radius: 8px;
  background: #3b72ee;
  font-size: 14px;
}
.bar-note, .sse-status { color: #c5d2e6; font-size: var(--text-xs); }
.bar-right { display: flex; min-width: 0; align-items: center; gap: var(--space-4); margin-left: auto; }
.logout-button { display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; gap: 6px; }
.logout-button svg { flex-shrink: 0; }
.sse-status { display: flex; flex-shrink: 0; align-items: center; gap: 7px; white-space: nowrap; }
.sse-dot { width: 7px; height: 7px; border-radius: 50%; background: #ff8597; }
.sse-dot.ok { background: #54d5a7; }
.sse-dot.connecting { background: #f2bd58; animation: pulse 1.4s infinite; }
.online-count { color: #b4c9ee; font-size: var(--text-xs); font-variant-numeric: tabular-nums; white-space: nowrap; }
.model-select { position: relative; min-width: 0; }
.model-trigger { display: inline-flex; max-width: 250px; align-items: center; gap: 7px; }
.model-trigger > span:nth-child(2) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-icon { display: inline-flex; flex-shrink: 0; align-items: center; line-height: 0; }
.model-backdrop { position: fixed; inset: 0; z-index: 25; }
.model-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 30;
  width: max-content;
  min-width: 240px;
  max-width: min(360px, calc(100vw - 24px));
  max-height: min(440px, 70dvh);
  margin-top: 10px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  color: var(--ink);
}
.model-group { padding: 4px; border-bottom: 1px solid var(--line); }
.model-group:last-child { border-bottom: 0; }
.model-group-head { display: flex; align-items: center; gap: 7px; padding: 8px; color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
.model-item { padding: 9px 12px 9px 30px; border-radius: var(--radius-sm); cursor: pointer; font-size: var(--text-sm); overflow-wrap: anywhere; }
.model-item:hover { background: var(--canvas); }
.model-item.active { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.model-settings { position: sticky; bottom: 0; width: 100%; min-height: 42px; border-top: 1px solid var(--line); border-radius: 0; background: var(--paper); color: var(--blue); text-align: left; }
.model-settings:hover:not(:disabled) { background: var(--blue-soft); }

.main {
  display: grid;
  flex: 1;
  grid-template-columns: 240px 310px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}
.accounts, .convos {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--paper);
}
.accounts-head { display: flex; align-items: center; gap: var(--space-2); padding: 16px 12px 12px; }
.accounts-head input, .convo-search input, .ranking-toolbar input[type="search"] {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  background: #fbfcfe;
  font-size: var(--text-sm);
}
.accounts-head input { flex: 1; min-width: 0; }
.accounts-head button { flex-shrink: 0; width: 36px; height: 36px; padding: 0; font-size: 20px; }
.account-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 0 12px 14px; border-bottom: 1px solid var(--line); }
.account-summary button { min-width: 0; padding: 6px 4px; border-color: transparent; background: var(--canvas); color: #425571; font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.account-summary button:hover { background: #e9eff9; }
.account-summary button.on { border-color: #bed0f5; background: var(--blue-soft); color: var(--blue); }
.accounts-list, .convos-list { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 8px; }
.acct { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; padding: 12px 10px; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer; }
.acct:hover, .convo:hover { background: #f5f8fc; }
.acct.active { border-color: #c9d9f7; background: var(--blue-soft); }
.acct:focus-visible, .convo:focus-visible, .model-item:focus-visible { outline-offset: -2px; }
.acct-dot { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; background: #a7b3c4; }
.acct-dot.online { background: var(--green); }
.acct-dot.starting, .acct-dot.connecting, .acct-dot.reconnecting { background: var(--amber); animation: pulse 1.4s infinite; }
.acct-dot.stopping { background: #8091a9; }
.acct-dot.offline { background: #a7b3c4; }
.acct-dot.error { background: var(--red); }
.acct-info, .convo-info { flex: 1; min-width: 0; }
.acct-name { overflow: hidden; font-size: 13px; font-weight: 600; line-height: 1.6; text-overflow: ellipsis; white-space: nowrap; }
.acct-meta { margin-top: 2px; overflow: hidden; color: var(--muted); font-size: var(--text-xs); text-overflow: ellipsis; white-space: nowrap; }
.acct-coordinates { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.acct-meta.error { color: var(--red); }
.acct-operation-warning { color: var(--amber); }
.acct-batch-progress { display: block; width: 100%; min-height: 0; margin-top: 7px; padding: 3px 0; border: 0; background: transparent; color: var(--muted); text-align: left; }
.acct-batch-progress:hover:not(:disabled) { background: transparent; color: var(--blue); }
.acct-batch-line { display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); line-height: 1.5; }
.acct-batch-line span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-batch-line b { flex-shrink: 0; margin-left: auto; font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.acct-batch-track { display: block; height: 4px; margin-top: 5px; overflow: hidden; border-radius: 4px; background: #dce5f3; }
.acct-batch-fill { display: block; height: 100%; border-radius: 4px; background: var(--blue); transition: width .3s; }
.acct-batch-progress.complete { color: var(--green); }
.acct-batch-progress.complete .acct-batch-fill { background: var(--green); }
.acct-batch-progress.attention { color: var(--red); }
.acct-batch-progress.attention .acct-batch-fill { background: var(--red); }
.acct-badge { flex-shrink: 0; padding: 2px 6px; border: 1px solid #ecd5a5; border-radius: 6px; background: var(--warning-soft); color: var(--amber); font-size: var(--text-xs); font-weight: 600; white-space: nowrap; }
.acct-actions { display: flex; gap: var(--space-2); padding: var(--space-3); border-top: 1px solid var(--line); }
.acct-actions button { flex: 1; min-height: 36px; }

.convos-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 16px 14px 12px; }
.convos-head .title { flex: 1; min-width: 0; overflow: hidden; font-size: 14px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.convos-head .actions { display: flex; flex: 1 0 100%; gap: 8px; }
.convos-head .actions button { flex: 1; min-width: 0; min-height: 36px; }
.convos-head button.on { border-color: #bed0f5; background: var(--blue-soft); color: var(--blue); }
.convo-search { padding: 0 14px 14px; border-bottom: 1px solid var(--line); }
.convo { display: flex; align-items: center; gap: 9px; margin-bottom: 4px; padding: 12px 10px; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer; }
.convo.active { border-color: #bfd2f5; background: var(--blue-soft); }
.convo-dot { flex-shrink: 0; width: 7px; height: 7px; border-radius: 50%; background: transparent; }
.convo-dot.unread { background: var(--amber); }
.convo-name { overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.convo-preview { margin-top: 4px; overflow: hidden; color: var(--muted); font-size: var(--text-sm); text-overflow: ellipsis; white-space: nowrap; }
.convo-time { flex-shrink: 0; align-self: flex-start; margin-top: 3px; color: var(--muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.convo.needs-reply .convo-name { color: #795012; }
.convo.unseen { background: #fffaf0; }
.convo.unseen .convo-name { font-weight: 700; }
.convo.unseen .convo-preview { color: #57677d; }
.convo.active.unseen { border-color: #bfd2f5; background: var(--blue-soft); }
.reply-tag { flex-shrink: 0; padding: 2px 6px; border: 1px solid #ecd5a5; border-radius: 6px; background: var(--warning-soft); color: var(--amber); font-size: var(--text-xs); font-weight: 600; }
.convo-empty { padding: 40px 18px; color: var(--muted); text-align: center; font-size: var(--text-sm); line-height: 1.9; }
.convo-empty.error { color: var(--red); }
.inline-error, .sales-error { margin: 8px; padding: 9px 12px; border: 1px solid #f0c9d2; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--red); font-size: var(--text-xs); overflow-wrap: anywhere; }
.retry-link { margin-top: 10px; }

/* Named areas keep the message viewport and composer independent of panel height. */
.thread-pane {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "heading" "assistant" "messages" "composer";
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--canvas);
}
.thread-head { grid-area: heading; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--paper); }
.thread-head .name { min-width: 0; max-width: 240px; overflow: hidden; font-size: 16px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.thread-head .uid { color: var(--muted); font: 12px/1.5 var(--font-mono); overflow-wrap: anywhere; }
.thread-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-left: auto; }
.thread-actions .auto-translate-toggle.active { border-color: #a9c2ef; background: var(--blue-soft); color: var(--blue); }
.thread-head .close { margin-left: auto; }
.thread-body { grid-area: messages; min-width: 0; min-height: 0; padding: 20px 24px; overflow: auto; overscroll-behavior: contain; }
.thread-empty { display: flex; align-items: center; justify-content: center; height: 100%; min-height: 60px; padding: 20px; color: var(--muted); font-size: 14px; text-align: center; }
.load-older { margin: 0 0 20px; text-align: center; }
.load-older button { min-width: 120px; border-radius: 20px; }
.message { display: flex; gap: 10px; margin: 0 0 20px; }
.message.mine { flex-direction: row-reverse; justify-content: flex-start; }
.message .sec { display: flex; flex-direction: column; min-width: 0; max-width: min(80%, 640px); }
.message.mine .sec { align-items: flex-end; }
.avatar { display: grid; flex-shrink: 0; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: #dcefe8; color: #116648; font-size: 13px; font-weight: 650; }
.message.mine .avatar { background: #dfe9fc; color: #2552a6; }
.message.unknown .avatar { background: #e4e9f0; color: #566880; }
.bubble { max-width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px 12px 12px 4px; background: var(--paper); font-size: 14px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.mine .bubble { border-color: #d4e1fa; border-radius: 12px 12px 4px 12px; background: #eaf1ff; }
.message.unknown .bubble { border-style: dashed; background: #f0f3f8; }
.message-translation { display: flex; gap: 8px; max-width: 100%; margin-top: 6px; padding: 8px 11px; border-left: 3px solid #d4a84d; border-radius: 3px 8px 8px 3px; background: #fffbf1; color: #544426; font-size: 13px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-translation-label { flex-shrink: 0; color: #956b17; font-size: var(--text-xs); font-weight: 650; }
.stamp { margin: 5px 2px 0; color: var(--muted); font-size: var(--text-xs); line-height: 1.6; overflow-wrap: anywhere; }
.intent { display: inline-block; margin: 4px 0 0; padding: 2px 7px; border-radius: 5px; background: #edf1f6; color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
.intent.high { background: var(--danger-soft); color: var(--red); }
.intent.medium { background: var(--warning-soft); color: var(--amber); }
.intent.low { background: #edf1f6; color: var(--muted); }
.day-sep { display: flex; align-items: center; gap: 14px; margin: 12px 0 24px; color: var(--muted); font-size: var(--text-xs); white-space: nowrap; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.scroll-bottom { position: relative; z-index: 5; grid-area: messages; align-self: end; justify-self: end; display: grid; place-items: center; width: 40px; height: 40px; min-height: 40px; margin: 0 20px 16px 0; padding: 0; border: 1px solid var(--field-border); border-radius: 50%; background: var(--paper); color: var(--blue); box-shadow: var(--shadow-sm); font-size: 18px; }
.scroll-bottom:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-soft); }
.scroll-bottom .new-badge { position: absolute; top: -5px; right: -5px; min-width: 20px; padding: 1px 5px; border-radius: 10px; background: var(--red); color: #fff; font-size: var(--text-xs); font-weight: 600; }

/* AI assistance remains secondary to the conversation. */
.thread-assistance { grid-area: assistant; min-width: 0; min-height: 0; max-height: min(290px, 32dvh); margin: 12px 20px 0; overflow: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.sales-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.sales-head { position: sticky; top: 0; z-index: 2; display: flex; flex-shrink: 0; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f8fafd; font-size: var(--text-sm); }
.sales-head > b { flex-shrink: 0; }
.sales-summary { min-width: 0; overflow: hidden; color: var(--muted); font-size: var(--text-xs); text-overflow: ellipsis; white-space: nowrap; }
.sales-close { flex-shrink: 0; min-width: 28px; min-height: 28px; padding: 2px 6px; border: 0; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; }
.sales-close:hover:not(:disabled) { background: #e9eef6; color: var(--ink); }
.sales-body { flex: 1; min-height: 0; padding: 12px; font-size: var(--text-sm); line-height: 1.65; }
.sales-body .label { display: block; margin-bottom: 5px; color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
.sales-core { display: grid; gap: 10px; }
.sales-core-item { padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfd; }
.sales-core-item.next { border-color: #d1dff9; background: #f3f7ff; }
.sales-core-note { margin-top: 5px; color: var(--muted); font-size: var(--text-xs); }
.sales-reply { padding: 10px 12px; border: 1px solid #d1dff9; border-radius: 7px; background: var(--blue-soft); font-size: 13px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.sales-reply.zh { border-color: #ecdfbd; background: #fffbf1; }
.sales-warning { margin: 8px 0; padding: 9px 12px; border: 1px solid #ecd5a5; border-radius: 7px; background: var(--warning-soft); color: var(--amber); font-size: var(--text-xs); line-height: 1.65; overflow-wrap: anywhere; }
.sales-error { margin: 8px 0; }
.sales-actions { position: sticky; bottom: 0; display: flex; flex-shrink: 0; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--paper); }
.sales-actions .hint { flex: 1 1 200px; color: var(--muted); font-size: var(--text-xs); }

.composer { grid-area: composer; min-width: 0; max-height: 46dvh; padding: 16px 20px; overflow: auto; border-top: 1px solid var(--line); background: var(--paper); }
.composer textarea, .modal textarea { display: block; width: 100%; min-height: 84px; padding: 11px 12px; border: 1px solid var(--field-border); border-radius: 8px; background: #fbfcfe; resize: vertical; }
.composer > textarea { height: 88px; max-height: 180px; }
.composer textarea:focus, .modal textarea:focus, .modal input:focus, .accounts-head input:focus, .convo-search input:focus, .ranking-toolbar input[type="search"]:focus { border-color: #8baae7; background: var(--paper); box-shadow: var(--focus); }
.composer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 12px; }
.composer-row .hint { flex: 1 1 220px; color: var(--muted); font-size: var(--text-xs); }
.composer-row .hint.pending { color: var(--amber); }
.composer-row .right { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-left: auto; }
.composer-row .right button { min-height: 36px; }
.rewrite-preview { margin: 12px 0; overflow: hidden; border: 1px solid #c8d9f7; border-radius: var(--radius); background: #f5f8ff; }
.rewrite-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #d5e1f6; background: #edf3ff; font-size: var(--text-sm); }
.rewrite-body { padding: 12px; font-size: var(--text-sm); line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.rewrite-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid #d5e1f6; }
.rewrite-actions .hint { flex: 1 1 160px; color: var(--muted); font-size: var(--text-xs); }
.batch-ai { margin-top: 12px; }
.batch-ai-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.batch-ai-hint, .icebreaker-label { color: var(--muted); font-size: var(--text-xs); }
.icebreaker-zh { border-top: 1px solid #d5e1f6; background: #fffbf1; }
.icebreaker-label { display: block; margin-bottom: 5px; font-weight: 600; }

/* Dialogs, tables and long-running task feedback. */
.notice { position: fixed; z-index: 100; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 32px)); padding: 12px 16px; border-radius: var(--radius); background: #1d304e; color: #fff; box-shadow: var(--shadow); font-size: var(--text-sm); overflow-wrap: anywhere; }
.notice.error { background: #a02d46; }
.modal-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: max(24px, 5dvh) 16px; overflow: auto; background: rgb(17 32 56 / 42%); }
.modal { width: min(600px, 100%); min-width: 0; max-height: 90dvh; padding: 24px; overflow: auto; overscroll-behavior: contain; border: 1px solid rgb(255 255 255 / 50%); border-radius: var(--radius-lg); background: var(--paper); box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 6px; color: var(--ink); font-size: 18px; font-weight: 650; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: var(--text-sm); line-height: 1.7; overflow-wrap: anywhere; }
.modal input[type="text"], .modal input[type="datetime-local"], .modal input:not([type]), .modal select { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--field-border); border-radius: var(--radius-sm); background: var(--paper); color: var(--ink); }
.modal input[type="number"] { min-height: 34px; border: 1px solid var(--field-border); border-radius: 5px; }
.dialog-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.modal.ai-config-modal { display: flex; flex-direction: column; width: min(840px, 100%); padding: 0; overflow: hidden; }
.ai-config-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px 16px; border-bottom: 1px solid var(--line); }
.ai-config-head h2 { margin-bottom: 3px; }
.ai-config-head p { margin: 0; font-size: var(--text-xs); }
.ai-config-head > button { min-width: 34px; font-size: 20px; }
.ai-config-form { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.ai-config-body { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 18px 22px; }
.ai-config-body fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.ai-config-field { margin-bottom: 16px; }
.ai-config-field label { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: var(--text-sm); font-weight: 600; }
.ai-config-modal input, .ai-config-modal select { width: 100%; min-width: 0; min-height: 40px; padding: 8px 10px; border: 1px solid var(--field-border); border-radius: var(--radius-sm); background: var(--paper); color: var(--ink); }
.ai-config-modal input:disabled, .ai-config-modal select:disabled { color: var(--muted); background: var(--canvas); }
.ai-config-field small { display: block; margin-top: 5px; color: var(--muted); font-size: var(--text-xs); line-height: 1.5; }
.ai-config-row { display: flex; gap: 8px; }
.ai-config-row > input, .ai-config-row > select { flex: 1; }
.ai-config-row > button { flex-shrink: 0; white-space: nowrap; padding: 8px 12px; }
.ai-key-saved { color: var(--green); font-size: var(--text-xs); font-weight: 400; }
.ai-model-picker { margin: 2px 0 16px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fafbfd; }
.ai-model-picker-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.ai-model-picker-head > div:first-child { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.ai-model-picker-head b { font-size: var(--text-sm); }
.ai-model-picker-head span { color: var(--muted); font-size: var(--text-xs); }
.ai-model-picker-actions { display: flex; flex-shrink: 0; gap: 6px; }
.ai-config-modal .ai-model-search { min-height: 36px; margin-bottom: 10px; }
.ai-model-checklist { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; max-height: min(300px, 34dvh); padding: 2px; overflow: auto; overscroll-behavior: contain; }
.ai-model-option { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; min-width: 0; padding: 7px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); }
.ai-model-option.selected { border-color: #bfd2f5; background: var(--blue-soft); }
.ai-model-option > label:first-child { display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer; }
.ai-model-option > label:first-child span { min-width: 0; overflow: hidden; font: 12px/1.5 var(--font-mono); text-overflow: ellipsis; white-space: nowrap; }
.ai-config-modal .ai-model-option input[type="checkbox"], .ai-config-modal .ai-model-option input[type="radio"] { flex-shrink: 0; width: 17px; min-width: 17px; height: 17px; min-height: 17px; margin: 0; padding: 0; accent-color: var(--blue); }
.ai-model-current { display: flex; align-items: center; gap: 4px; padding-left: 7px; border-left: 1px solid var(--line); color: var(--muted); cursor: pointer; font-size: var(--text-xs); white-space: nowrap; }
.ai-model-current.active { color: var(--blue); font-weight: 650; }
.ai-model-current.disabled { cursor: not-allowed; opacity: .5; }
.ai-model-empty { padding: 22px 12px; color: var(--muted); font-size: var(--text-sm); text-align: center; }
.ai-model-picker > small { display: block; margin-top: 9px; color: var(--muted); font-size: var(--text-xs); line-height: 1.5; }
.ai-config-advanced summary { width: fit-content; color: var(--muted); cursor: pointer; font-size: var(--text-sm); }
.ai-config-advanced input { margin-top: 10px; }
.ai-proxy-label { display: block; margin-top: 10px; color: var(--muted); font-size: var(--text-xs); }
.ai-config-feedback { margin-top: 14px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--canvas); font-size: var(--text-sm); line-height: 1.6; overflow-wrap: anywhere; }
.ai-config-feedback.success { color: var(--green); }
.ai-config-footer { display: flex; flex-shrink: 0; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); }
.ai-config-footer > div { display: flex; gap: 8px; }
.ai-config-footer button { padding: 8px 12px; white-space: nowrap; }
.batch-list { max-height: min(360px, 42dvh); margin-bottom: 14px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.batch-list table, .ranking-table { width: 100%; border-collapse: collapse; }
th { position: sticky; top: 0; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f4f7fb; color: var(--muted); font-size: var(--text-xs); font-weight: 600; text-align: left; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid #e9eef5; font-size: var(--text-sm); }
.batch-list tr[role="button"] { cursor: pointer; }
.batch-list tr[role="button"]:hover td { background: var(--blue-soft); }
.check { width: 18px; height: 18px; accent-color: var(--blue); cursor: pointer; }
.uid-cell { color: #50617c; font: 12px/1.6 var(--font-mono); }
.recipient-review { max-height: 200px; margin-bottom: 14px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.recipient-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #e9eef5; }
.recipient-row:last-child { border-bottom: 0; }
.recipient-row .name { font-weight: 600; overflow-wrap: anywhere; }
.recipient-row .uid { color: var(--muted); font: 12px/1.6 var(--font-mono); overflow-wrap: anywhere; }
.flow-steps { display: flex; gap: 8px; margin: 12px 0 16px; }
.flow-step { flex: 1; min-width: 0; padding: 9px 8px; border: 1px solid var(--line); border-radius: 7px; background: #f5f7fa; color: var(--muted); font-size: var(--text-xs); font-weight: 600; text-align: center; }
.flow-step.active { border-color: #bfd2f5; background: var(--blue-soft); color: var(--blue); }
.flow-step.done { border-color: #c8e8d9; background: var(--success-soft); color: var(--green); }
.progress-bar { height: 8px; overflow: hidden; border-radius: 5px; background: #e7edf6; }
.progress-fill { width: 0; height: 100%; border-radius: 5px; background: var(--blue); transition: width .3s; }
.fail-item { display: flex; align-items: center; gap: 8px; padding: 7px 0; font-size: var(--text-sm); cursor: pointer; overflow-wrap: anywhere; }
.confirm-panel { margin: 14px 0; padding: 14px; border: 1px solid #ecd5a5; border-radius: var(--radius); background: var(--warning-soft); }
.confirm-panel b { display: block; margin-bottom: 8px; }
.confirm-content { max-height: 160px; margin-top: 10px; padding: 11px 12px; overflow: auto; border: 1px solid #ecdfbd; border-radius: 7px; background: var(--paper); line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.state-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.state-grid label { display: flex; flex-direction: column; gap: 6px; min-width: 0; color: var(--muted); font-size: var(--text-sm); }
.state-grid label.check-row { flex-direction: row; align-items: center; min-height: 40px; padding: 5px 0; color: var(--ink); }
.state-grid input[type="checkbox"] { flex-shrink: 0; width: 18px; height: 18px; }
.state-section { grid-column: 1 / -1; padding-top: 12px; border-top: 1px solid var(--line); font-size: var(--text-sm); font-weight: 650; }
.state-error { margin-top: 12px; color: var(--red); font-size: var(--text-sm); overflow-wrap: anywhere; }

.ranking-modal { display: flex; flex-direction: column; width: min(1120px, 100%); height: min(840px, 90dvh); max-height: 90dvh; padding: 0; overflow: hidden; }
.ranking-head { display: flex; flex-shrink: 0; flex-wrap: wrap; align-items: center; gap: 12px; padding: 20px 24px 16px; border-bottom: 1px solid var(--line); }
.ranking-head h2 { margin: 0; }
.ranking-head p { margin: 5px 0 0; }
.ranking-head-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.ranking-summary { display: grid; flex-shrink: 0; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; padding: 16px 24px; border-bottom: 1px solid var(--line); background: #f7f9fd; }
.ranking-stat { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.ranking-stat b { display: block; margin-bottom: 4px; color: var(--ink); font-size: 22px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
.ranking-stat span { color: var(--muted); font-size: var(--text-xs); }
.ranking-toolbar { display: flex; flex-shrink: 0; flex-wrap: wrap; align-items: center; gap: 8px; padding: 14px 24px; border-bottom: 1px solid var(--line); }
.ranking-toolbar input[type="search"] { flex: 1 1 200px; min-width: 120px; }
.ranking-toolbar select { min-height: 36px; padding: 7px 10px; border: 1px solid var(--field-border); border-radius: var(--radius-sm); background: var(--paper); }
.ranking-note { flex-shrink: 0; padding: 10px 24px; border-bottom: 1px solid #ecdfbd; background: var(--warning-soft); color: var(--amber); font-size: var(--text-xs); line-height: 1.65; }
.ranking-table-wrap { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.ranking-table { min-width: 820px; }
.ranking-table th { z-index: 1; }
.ranking-table tr.selected { background: var(--blue-soft); }
.ranking-table tr.excluded { color: var(--muted); background: #f7f8fb; }
.ranking-table tr:hover td { background: #f0f5ff; }
.ranking-rank { color: var(--muted); font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.ranking-player { font-weight: 600; }
.ranking-empty { display: grid; place-items: center; height: 100%; min-height: 160px; padding: 24px; color: var(--muted); text-align: center; }
.ranking-spinner { width: 28px; height: 28px; margin: 0 auto 12px; border: 3px solid #dce6fb; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
.ranking-footer { display: flex; flex-shrink: 0; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--line); background: var(--paper); }
.ranking-footer .selection { color: var(--muted); font-size: var(--text-sm); }
.ranking-footer .selection b { color: var(--blue); font-size: 18px; font-variant-numeric: tabular-nums; }
.status-pill { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 6px; font-size: var(--text-xs); font-weight: 600; white-space: nowrap; }
.status-pill.new { background: #edf1f6; color: #56677f; }
.status-pill.waiting { background: var(--warning-soft); color: var(--amber); }
.status-pill.reply { background: var(--success-soft); color: var(--green); }
.status-pill.handled { background: var(--blue-soft); color: #2856ae; }
.status-pill.failed, .status-pill.excluded { background: var(--danger-soft); color: var(--red); }
.mobile-only { display: none; }
.desktop-only { display: inline-flex; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* A real side panel only when there is room for both it and a useful transcript. */
@media (min-width: 1600px) {
  .thread-pane:has(.thread-assistance) {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "heading heading" "messages assistant" "composer assistant";
  }
  .thread-assistance {
    align-self: stretch;
    max-height: none;
    margin: 0;
    border: 0;
    border-left: 1px solid var(--line);
    border-radius: 0;
  }
  .thread-assistance .sales-panel { min-height: 100%; }
  .sales-head { min-height: 52px; }
  .sales-head .sales-summary { display: none; }
  .sales-body { padding: 16px; }
  .sales-actions { padding: 12px 16px; }
  .sales-actions .hint { flex-basis: 100%; }
}

@media (min-width: 901px) and (max-width: 1199px) {
  .main { grid-template-columns: 204px 270px minmax(0, 1fr); }
  .bar-note { display: none; }
  .acct { padding: 10px 8px; gap: 8px; }
  .acct-badge { padding: 2px 4px; }
  .convo { flex-wrap: wrap; gap: 5px 8px; }
  .convo-info { flex-basis: calc(100% - 64px); }
  .convo .reply-tag { margin-left: 15px; }
  .convo-time { margin-left: auto; }
  .thread-head, .composer { padding: 12px 16px; }
  .thread-actions { flex-basis: 100%; margin-left: 0; }
  .thread-body { padding: 16px; }
  .thread-assistance { margin-right: 16px; margin-left: 16px; }
}

@media (max-width: 900px) {
  .bar { gap: 10px; padding: 0 14px; }
  .bar-note, .online-count { display: none; }
  .bar-right { gap: 12px; }
  .main { display: block; }
  .accounts, .convos, .thread-pane { width: 100%; height: 100%; border-right: 0; }
  .main:not(.has-account) .convos, .main:not(.has-account) .thread-pane,
  .main.has-account .accounts, .main.has-account:not(.has-person) .thread-pane,
  .main.has-person .convos { display: none; }
  .mobile-only { display: inline-flex; }
  .desktop-only, .thread-head .uid { display: none; }
  .account-summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .convos-head { padding: 14px; }
  .convos-head .mobile-only { align-items: center; justify-content: center; }
  .convos-head .actions { flex-basis: auto; }
  .thread-head { gap: 8px; padding: 10px 14px; }
  .thread-head .name { max-width: 220px; }
  .thread-actions { gap: 6px; }
  .thread-body { padding: 16px; }
  .message .sec { max-width: 85%; }
  .thread-assistance { max-height: min(270px, 32dvh); margin: 10px 14px 0; }
  .sales-actions .hint { flex-basis: 160px; }
  .composer { padding: 12px 14px max(12px, env(safe-area-inset-bottom)); }
  .modal-overlay { padding: 12px; }
  .modal { max-height: calc(100dvh - 24px); padding: 20px; }
  .ranking-modal { padding: 0; }
  .ranking-head { padding: 16px; }
  .ranking-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 12px 16px; }
  .ranking-toolbar, .ranking-note, .ranking-footer { padding: 12px 16px; }
}

@media (max-width: 600px) {
  .logout-label { display: none; }
  .logout-button { width: 34px; padding: 6px; }
  .brand { font-size: 14px; }
  .brand b { width: 24px; height: 24px; margin-right: 6px; font-size: 12px; }
  .bar-right { gap: 8px; }
  .model-trigger { max-width: 126px; padding: 6px 8px; }
  .sse-status { gap: 5px; font-size: var(--text-xs); }
  .convos-head .actions { flex-basis: 100%; }
  .thread-head .name { flex: 1; max-width: none; font-size: 15px; }
  .thread-actions { flex: 1 0 100%; gap: 6px; margin-left: 0; }
  .thread-actions button { flex: 1 1 auto; min-height: 36px; padding: 6px 8px; white-space: nowrap; }
  .thread-actions .desktop-only { display: none; }
  .sales-head { padding: 8px 10px; }
  .sales-summary { display: none; }
  .sales-body { padding: 10px; }
  .sales-actions { gap: 6px; padding: 8px 10px; }
  .sales-actions .hint { flex-basis: 100%; }
  .thread-assistance { max-height: 28dvh; }
  .thread-pane:has(.composer .rewrite-preview) .thread-assistance { max-height: 20dvh; }
  .thread-body { padding: 14px 12px; }
  .message { gap: 8px; margin-bottom: 16px; }
  .avatar { width: 28px; height: 28px; border-radius: 8px; }
  .bubble { padding: 9px 11px; }
  .stamp { font-size: var(--text-xs); }
  .composer { max-height: 36dvh; padding-right: 12px; padding-left: 12px; }
  .composer > textarea { height: 76px; min-height: 76px; max-height: 140px; }
  .composer-row { gap: 8px; margin-top: 10px; }
  .composer-row .hint { flex-basis: 100%; }
  .composer-row .right { width: 100%; gap: 6px; }
  .composer-row .right button { flex: 1; min-height: 40px; padding: 7px 8px; }
  .notice { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal { padding: 18px 16px; border-radius: 12px; }
  .modal h2 { font-size: 17px; }
  .modal.ai-config-modal { padding: 0; }
  .ai-config-head { padding: 16px 14px 12px; }
  .ai-config-body { padding: 14px; }
  .ai-config-row { flex-wrap: wrap; }
  .ai-config-row > button { flex: 1 0 100%; }
  .ai-model-picker-head { align-items: flex-start; flex-direction: column; }
  .ai-model-picker-actions { width: 100%; }
  .ai-model-picker-actions button { flex: 1; }
  .ai-model-checklist { grid-template-columns: minmax(0, 1fr); max-height: 32dvh; }
  .ai-config-footer { align-items: stretch; flex-direction: column; padding: 12px 14px; }
  .ai-config-footer > button, .ai-config-footer > div { width: 100%; }
  .ai-config-footer > div button { flex: 1; }
  .state-grid { grid-template-columns: minmax(0, 1fr); }
  .dialog-actions { gap: 8px; }
  .dialog-actions > span { flex-basis: 100%; }
  .dialog-actions button { min-height: 40px; }
  .ranking-modal { display: block; height: auto; padding: 0; overflow: auto; }
  .ranking-head { gap: 10px; padding: 14px; }
  .ranking-head-actions { width: 100%; margin-left: 0; }
  .ranking-head-actions button { flex: 1; min-height: 36px; padding: 6px 8px; }
  .ranking-head p { margin-bottom: 0; font-size: var(--text-xs); }
  .ranking-summary { gap: 6px; padding: 10px 12px; }
  .ranking-stat { padding: 9px 8px; }
  .ranking-stat b { font-size: 19px; }
  .ranking-stat span { font-size: var(--text-xs); }
  .ranking-toolbar { gap: 8px; padding: 12px; }
  .ranking-toolbar input[type="search"] { flex-basis: 100%; }
  .ranking-toolbar select { flex: 1 0 100%; }
  .ranking-toolbar button { flex: 1; min-height: 36px; }
  .ranking-note { padding: 10px 12px; }
  .ranking-table-wrap { min-height: 180px; max-height: 42dvh; }
  .ranking-footer { position: sticky; bottom: 0; z-index: 2; gap: 8px; padding: 12px; box-shadow: 0 -4px 12px rgb(25 45 78 / 6%); }
  .ranking-footer .selection { flex-basis: 100%; }
  .ranking-footer button { flex: 1 1 auto; min-height: 40px; }
  .flow-steps { gap: 6px; }
  .flow-step { padding: 8px 5px; }
}

@media (max-width: 380px) {
  .bar { padding: 0 10px; }
  .bar-right { gap: 6px; }
  .model-trigger { max-width: 94px; }
  .sse-status span { display: none; }
  .thread-actions button { flex-basis: calc(50% - 6px); }
  .thread-assistance { max-height: 25dvh; }
  .thread-pane:has(.composer .rewrite-preview) .thread-assistance { max-height: 18dvh; }
  .ranking-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (pointer: coarse) {
  button, .tiny, .thread-head button, .composer-row .right button, .dialog-actions button,
  .ranking-head-actions button, .ranking-toolbar button, .ranking-footer button { min-height: 44px; }
  .acct, .convo, .model-item { min-height: 44px; }
  .acct-batch-progress { min-height: 36px; }
  .sales-close { min-width: 36px; min-height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Operator sign-in shares the workspace palette without loading business data. */
.login-page { background: var(--canvas); }
.login-shell { display: flex; min-height: 100vh; min-height: 100dvh; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: min(360px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); box-shadow: var(--shadow-sm); }
.login-card h1 { margin: 0 0 24px; font-size: 20px; font-weight: 700; line-height: 1.4; }
.login-card form { display: flex; flex-direction: column; }
.login-card label { margin-bottom: 8px; font-size: var(--text-sm); font-weight: 600; }
.login-card input { width: 100%; height: 44px; margin-bottom: 16px; padding: 10px 12px; border: 1px solid var(--field-border); border-radius: 7px; background: #fbfcfe; }
.login-card input:disabled { background: var(--canvas); color: var(--muted); }
.login-card input:focus { border-color: #8baae7; background: var(--paper); box-shadow: var(--focus); }
.login-card button { min-height: 44px; margin-top: 4px; font-size: 14px; }
.login-error { margin: 0 0 12px; color: var(--red); font-size: var(--text-sm); overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .login-card { padding: 24px; }
}
