/* ============================================================================
   OMEGA AI v2 — Mockup styles (M3 design gate)
   Implements the full app shell: sidebar / chat / status rail / composer.
   Consumes tokens.css only. Same markup rendered under both themes.
   Sidebar is INVERTED per theme (dark on light app, light on dark app).
   Fully responsive — mobile uses the same markup (off-canvas sidebar).
   ========================================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  background: var(--bg-app);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr var(--rail-w); height: 100vh; height: 100dvh; }
.chat, .rail, .sidebar { min-height: 0; }

/* ─── Sidebar (inverted) ──────────────────────────────────────────────── */
.sidebar {
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex; flex-direction: column;
  padding: var(--sp-4) var(--sp-3);
  gap: var(--sp-3);
  overflow-y: auto;
  transition: transform var(--t-med);
}
.brand { display: flex; align-items: center; gap: var(--sp-3); padding: 4px var(--sp-2); }
.brand img { height: 26px; display: none; }
[data-theme="aurora"] .brand img.logo-dark { display: block; }   /* white wordmark on dark sidebar */
[data-theme="onyx"]   .brand img.logo-light { display: block; }  /* blue wordmark on light sidebar */

.state-switch {
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--sb-border);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
  background: var(--sb-panel);
  cursor: pointer;
}
.state-switch:hover { border-color: var(--sb-text-3); }
.state-switch .st-current { display: flex; align-items: center; gap: var(--sp-2); font-weight: 600; font-size: var(--fs-sm); color: var(--sb-text-1); }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.state-switch .st-label { font-size: var(--fs-xs); color: var(--sb-text-3); }

.new-chat {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  background: var(--accent-grad); color: #fff;
  border: none; border-radius: var(--r-md);
  padding: 11px; font-weight: 600; font-size: var(--fs-md);
  cursor: pointer; box-shadow: var(--shadow-md);
}
.new-chat:hover { filter: brightness(1.06); }

.side-search {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--sb-panel); border: 1px solid var(--sb-border);
  border-radius: var(--r-md); padding: 9px var(--sp-3);
  color: var(--sb-text-3); font-size: var(--fs-sm);
}
.side-search input { border: none; outline: none; background: none; color: var(--sb-text-1); font-size: var(--fs-sm); width: 100%; font-family: inherit; }

.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin: 0 calc(-1 * var(--sp-1)); padding: 4px 2px; }
.conv-group { font-size: var(--fs-xs); color: var(--sb-text-3); text-transform: uppercase; letter-spacing: .09em; padding: var(--sp-5) var(--sp-3) var(--sp-2); }
.conv {
  padding: 17px var(--sp-3); border-radius: var(--r-md);
  font-size: var(--fs-sm); color: var(--sb-text-2);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: var(--sp-2);
  line-height: 1.45;
  border: 1px solid transparent;
}
.conv .c-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.conv:hover { background: var(--sb-hover); }
.conv.active { background: var(--sb-active); color: var(--sb-text-1); font-weight: 600; }
.conv .badge { margin-left: auto; font-size: 10px; background: var(--accent); color: #fff; border-radius: var(--r-full); padding: 1px 7px; font-weight: 700; }

.set-user-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.set-user-actions .set-btn { margin-right: 0 !important; }
@media (max-width: 700px) {
  .set-table th, .set-table td { padding: 7px 6px; }
  .set-user-actions .set-btn { padding: 4px 8px; font-size: 11.5px; }
  /* Names identify users well enough on small screens — free the width for actions */
  #set-users-table th:nth-child(2), #set-users-table td:nth-child(2) { display: none; }
}

/* Impersonation banner */
.impersonation-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 95;
  background: var(--accent-grad); color: #fff;
  font-size: var(--fs-sm); font-weight: 600;
  padding: 7px var(--sp-4);
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  box-shadow: var(--shadow-md);
}
.impersonation-banner[hidden] { display: none; }
.impersonation-banner button {
  border: 1px solid rgba(255,255,255,.6); background: rgba(255,255,255,.15);
  color: #fff; font-family: inherit; font-size: var(--fs-xs); font-weight: 700;
  padding: 3px 12px; border-radius: var(--r-full); cursor: pointer;
}
.impersonation-banner button:hover { background: rgba(255,255,255,.3); }

/* Add-user form */
.set-add-user { margin-bottom: var(--sp-3); }
.set-add-user summary {
  cursor: pointer; font-size: var(--fs-sm); font-weight: 650; color: var(--accent);
  padding: 6px 0; list-style: none;
}
.set-add-form { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); max-width: 640px; }
.set-add-form input, .set-add-form select {
  flex: 1 1 180px; padding: 8px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--bg-input);
  color: var(--text-1); font-family: inherit; font-size: var(--fs-sm);
}
.set-role-select {
  padding: 4px 8px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--bg-input);
  color: var(--text-1); font-family: inherit; font-size: var(--fs-xs);
}

/* ═══ Settings dialog (ChatGPT-style) ═══ */
.user-chip { cursor: pointer; }
.settings-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(4, 10, 18, .55);
  display: grid; place-items: center; padding: var(--sp-4);
}
.settings-overlay[hidden] { display: none; }
.settings-dialog {
  width: min(880px, 100%); height: min(640px, 92dvh);
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  display: grid; grid-template-columns: 200px 1fr; overflow: hidden;
}
.settings-nav {
  background: var(--bg-app); border-right: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-2); display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
.settings-nav-title { font-size: var(--fs-lg); font-weight: 700; padding: 0 var(--sp-3) var(--sp-3); }
.settings-nav-item {
  border: none; background: none; cursor: pointer; text-align: left;
  font-family: inherit; font-size: var(--fs-md); color: var(--text-2);
  padding: 9px var(--sp-3); border-radius: var(--r-sm);
}
.settings-nav-item:hover { background: var(--bg-hover); }
.settings-nav-item.active { background: var(--bg-active); color: var(--text-1); font-weight: 650; }
.settings-body { position: relative; padding: var(--sp-6); overflow: auto; min-width: 0; }
.settings-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--bg-panel); color: var(--text-2);
  cursor: pointer; font-size: 14px;
}
.settings-close:hover { background: var(--bg-hover); color: var(--text-1); }
.settings-pane h3 { font-size: var(--fs-xl); font-weight: 700; margin-bottom: var(--sp-4); }
.set-hint { font-size: var(--fs-sm); color: var(--text-3); margin: 0 0 var(--sp-4); }
.set-field { display: block; max-width: 420px; margin-bottom: var(--sp-4); }
.set-field > span { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.set-field input, .set-field select, .set-actions input {
  width: 100%; padding: 9px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--bg-input);
  color: var(--text-1); font-family: inherit; font-size: var(--fs-md);
}
.set-field input:focus, .set-field select:focus, .set-actions input:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow-accent); }
.set-field input[disabled] { opacity: .6; }
.set-static { font-size: var(--fs-md); color: var(--text-1); text-transform: capitalize; }
.set-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; max-width: 420px; margin-top: var(--sp-2); }
.set-btn {
  border: 1px solid var(--border-strong); background: var(--bg-input);
  color: var(--text-1); font-family: inherit; font-size: var(--fs-sm); font-weight: 650;
  padding: 8px 16px; border-radius: var(--r-full); cursor: pointer;
}
.set-btn:hover { background: var(--bg-hover); }
.set-btn.primary { background: var(--accent-grad); border: none; color: #fff; }
.set-btn.primary:hover { filter: brightness(1.06); }
.set-btn.danger { color: var(--err); }
.set-seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-full); overflow: hidden; }
.set-seg button {
  border: none; background: none; cursor: pointer; font-family: inherit;
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-2);
  padding: 8px 18px;
}
.set-seg button.active { background: var(--accent); color: #fff; }
.set-token-result {
  margin: var(--sp-3) 0; padding: var(--sp-3); max-width: 560px;
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: var(--r-md);
}
.set-token-result code {
  display: block; font-family: var(--font-mono); font-size: var(--fs-sm);
  word-break: break-all; color: var(--text-1); margin-top: 4px; cursor: copy;
}
.set-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); margin-top: var(--sp-3); }
.set-table th, .set-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.set-table th { color: var(--text-3); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; }
@media (max-width: 700px) {
  .settings-dialog { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: 94dvh; }
  .settings-nav { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .settings-nav-title { display: none; }
  .settings-nav-item { white-space: nowrap; }
}

/* Tiny toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  z-index: 120; background: var(--bg-elevated); color: var(--text-1);
  border: 1px solid var(--border-strong); border-radius: var(--r-full);
  box-shadow: var(--shadow-lg); padding: 9px 18px;
  font-size: var(--fs-sm); font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity var(--t-fast), transform var(--t-fast);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Trailing delete ✕ — always visible, subtle; full opacity on hover/focus */
.conv .conv-del {
  flex: none; margin-left: auto; padding: 0 4px;
  font-size: 13px; color: var(--sb-text-3); opacity: .55;
  cursor: pointer; border-radius: 5px;
}
.conv .conv-del:hover { opacity: 1; color: var(--err); }
.conv:has(.badge) .conv-del { margin-left: 0; }

/* Right-click context menu */
.ctx-menu {
  position: fixed; z-index: 100; min-width: 150px;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: 5px; display: flex; flex-direction: column; gap: 1px;
}
.ctx-menu button {
  display: flex; align-items: center; gap: 8px;
  border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: var(--fs-sm); color: var(--text-1);
  text-align: left; padding: 8px 10px; border-radius: var(--r-sm);
}
.ctx-menu button:hover { background: var(--bg-hover); }
.ctx-menu button.danger { color: var(--err); }

.conv-count { font-size: var(--fs-xs); color: var(--sb-text-3); padding: 2px var(--sp-3) 0; }

/* Skeleton shimmer while conversations load */
.conv-skeleton {
  height: 40px; border-radius: var(--r-md);
  margin: 0 var(--sp-1);
  background: linear-gradient(90deg, var(--sb-hover) 25%, var(--sb-active) 50%, var(--sb-hover) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
.conv-skeleton.short { width: 62%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.apps { border-top: 1px solid var(--sb-border); padding-top: var(--sp-3); display: flex; flex-direction: column; gap: 2px; }
.apps summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--sb-text-3);
  padding: 6px var(--sp-3); border-radius: var(--r-sm);
}
.apps summary::-webkit-details-marker { display: none; }
.apps summary:hover { background: var(--sb-hover); }
.apps summary::before { content: '▸'; transition: transform var(--t-fast); font-size: 10px; }
.apps[open] summary::before { transform: rotate(90deg); }
.apps summary .apps-count { margin-left: auto; font-weight: 600; text-transform: none; letter-spacing: 0; }
.apps[open] summary { margin-bottom: 2px; }
.app-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px var(--sp-3); border-radius: var(--r-sm);
  font-size: var(--fs-sm); color: var(--sb-text-2); cursor: pointer;
}
.app-item:hover { background: var(--sb-hover); }
.app-item.active { background: var(--sb-active); color: var(--sb-text-1); font-weight: 600; }
.app-item .icon { width: 18px; text-align: center; opacity: .8; }
.app-item .soon { margin-left: auto; font-size: 10px; color: var(--sb-text-3); border: 1px solid var(--sb-border); border-radius: var(--r-full); padding: 1px 7px; }
.user-chip { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2); border-top: 1px solid var(--sb-border); margin-top: var(--sp-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-grad); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.user-chip .u-name { font-size: var(--fs-sm); font-weight: 600; color: var(--sb-text-1); }
.user-chip .u-role { font-size: var(--fs-xs); color: var(--sb-text-3); }

/* ─── Sub-agent pills (v1 agent orbs, token-styled) ─────────────────────
   Row of orb cards above an assistant message; each orb = one pipeline
   agent. States: working (spinning ring) / done (green full ring) / error. */
.agent-status-panel { display: flex; gap: 2px; margin: -6px 0 8px; }
.agent-status-panel:empty { display: none; }
.agent-card {
  width: 32px; height: 32px; border: none; background: transparent;
  cursor: pointer; position: relative; border-radius: 50%;
  transition: transform var(--t-fast);
}
.agent-card:hover { transform: scale(1.15); }
.agent-card.agent-enter { animation: agentPopIn 260ms cubic-bezier(.2,.8,.3,1.4); }
@keyframes agentPopIn { from { transform: scale(.4); opacity: 0; } }
.agent-orb { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }
.agent-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.agent-ring .ring-track { stroke: var(--border); }
.agent-ring .ring-progress { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 56.55; stroke-dashoffset: 42.41; }
.agent-card.working .ring-progress { animation: ringSpin 1.1s linear infinite; transform-origin: center; }
@keyframes ringSpin { to { transform: rotate(360deg); } }
.agent-card.done .ring-progress { stroke: var(--ok); stroke-dashoffset: 0; opacity: .8; }
.agent-card.error .ring-progress { stroke: var(--err); stroke-dashoffset: 0; }
.agent-icon { font-size: 14px; line-height: 1; z-index: 1; }

/* Provider badge — which model generated THIS message (v1 msg-provider-badge) */
.msg-author { display: flex; align-items: center; gap: 6px; }
.msg-provider-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-3);
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px;
}

/* ─── Chat column ─────────────────────────────────────────────────────── */
.chat { display: flex; flex-direction: column; background: var(--bg-chat); min-width: 0; }
.chat-header {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
.chat-title { font-weight: 650; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); color: var(--text-2);
  border: 1px solid var(--border); border-radius: var(--r-full);
  padding: 4px 10px; white-space: nowrap;
}
.model-badge .m-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.header-actions { margin-left: auto; display: flex; gap: var(--sp-2); }
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--bg-panel);
  color: var(--text-2); cursor: pointer; font-size: 15px;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-1); }
.only-mobile { display: none !important; }
#rail-btn.pulse { animation: railPulse 900ms cubic-bezier(.2,.8,.3,1.4); }
@keyframes railPulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.35); box-shadow: 0 0 0 6px var(--glow-accent); border-color: var(--accent); }
  55% { transform: scale(1.12); }
  75% { transform: scale(1.28); }
  100% { transform: scale(1); box-shadow: none; }
}

.messages { flex: 1; overflow-y: auto; padding: var(--sp-6) var(--sp-8) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-6); }

.msg { display: flex; gap: var(--sp-4); max-width: none; width: 100%; flex-wrap: wrap; }
.msg .avatar { flex: none; margin-top: 2px; }
.msg-body { min-width: 0; flex: 1; max-width: 860px; }
.msg-author { font-size: var(--fs-xs); color: var(--text-3); margin-bottom: 6px; font-weight: 600; }
.msg-text { line-height: 1.65; font-size: var(--fs-md); color: var(--text-1); }
.msg-text p + p { margin-top: var(--sp-3); }
.msg-text strong { font-weight: 650; }
.msg-text ul { margin: var(--sp-2) 0 var(--sp-2) var(--sp-5); }
.msg-text li { margin: 3px 0; }
.msg-text table { border-collapse: collapse; margin: var(--sp-3) 0; font-size: var(--fs-sm); width: 100%; }
.msg-text th, .msg-text td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.msg-text th { background: var(--bg-hover); font-weight: 650; }
.cite {
  display: inline-grid; place-items: center;
  min-width: 17px; height: 17px; padding: 0 4px;
  font-size: 10px; font-weight: 700;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 5px; vertical-align: 2px; margin: 0 1px;
  cursor: pointer;
}

.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-user .avatar { display: none; }
.msg-user .bubble {
  background: var(--bg-user-msg); color: #fff;
  border-radius: var(--r-lg); border-bottom-right-radius: var(--r-sm);
  padding: 11px var(--sp-4); max-width: 560px;
  font-size: var(--fs-md); line-height: 1.55;
  box-shadow: var(--shadow-sm);
}
.msg-user { flex-wrap: wrap; justify-content: flex-start; }

/* v1-style checkpoint divider — full-column hairline with centered flag button */
.checkpoint-row {
  flex-basis: 100%;
  display: flex; justify-content: center;
  border-top: none;
  margin-top: 14px; padding-top: 0;
  position: relative;
}
.checkpoint-row::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  border-top: 1px solid var(--border);
}
.checkpoint-row .act {
  transform: translateY(-50%);
  background: var(--bg-panel);
  border-color: var(--border-strong);
  padding: 6px 16px;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.checkpoint-row .act:hover { border-color: var(--accent); color: var(--accent); }

.msg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; opacity: .8; transition: opacity var(--t-fast); }
.msg:focus-within .msg-actions, .msg:hover .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 28px; height: 28px; border: none; background: none; font-size: 13px; }
/* VS Code-style labeled actions — icon + text, readable at a glance */
.act {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--bg-panel);
  color: var(--text-2); font-family: inherit;
  font-size: 12.5px; font-weight: 600;
  padding: 6px 12px; border-radius: var(--r-sm);
  cursor: pointer; line-height: 1.2;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.act:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.act:active { transform: translateY(1px); }

/* Widget cards (document/map/chart/image renderers) */
.widget {
  margin-top: var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--bg-panel); box-shadow: var(--shadow-sm);
  overflow: hidden; max-width: 520px;
}
.widget-head { display: flex; align-items: center; gap: var(--sp-2); padding: 10px var(--sp-4); border-bottom: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.widget-head .w-icon { color: var(--accent); }
.widget-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.doc-card { display: flex; gap: var(--sp-3); align-items: center; }
.doc-thumb {
  width: 42px; height: 52px; flex: none; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 10px; font-weight: 800;
  border: 1px solid var(--border);
}
.doc-name { font-weight: 600; font-size: var(--fs-sm); color: var(--text-1); }
.doc-meta { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.doc-peek { font-size: var(--fs-xs); color: var(--text-2); background: var(--bg-hover); border-left: 3px solid var(--accent); padding: 8px 10px; border-radius: 0 var(--r-sm) var(--r-sm) 0; line-height: 1.5; }

/* Chart widget */
.w-chart-svg { width: 100%; height: auto; display: block; }
.w-chart-tick, .w-chart-lbl { font-size: 10.5px; fill: var(--text-3); font-family: var(--font-sans); }
.w-chart-inlbl { font-size: 12px; font-weight: 700; font-family: var(--font-sans); }
.w-chart-grid { stroke: var(--border); stroke-width: 1; }
.w-chart-axis { stroke: var(--border-strong); stroke-width: 1.5; }
.w-chart-legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); font-size: var(--fs-xs); color: var(--text-2); }
.w-chart-legend .w-key { display: inline-flex; align-items: center; gap: 6px; }
.w-chart-legend .w-key i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.w-chart-empty { color: var(--text-3); font-size: var(--fs-sm); margin: 0; }

/* Map widget */
.w-map, [data-widget-mount]:empty {
  min-height: 220px; border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--border); background: var(--bg-hover);
}
[data-widget-mount]:empty::after {
  content: "Loading map…"; display: grid; place-items: center; min-height: 220px;
  color: var(--text-3); font-size: var(--fs-xs);
}
.w-map { min-height: 280px; padding: 0; z-index: 0; }
.w-map-loading { padding: var(--sp-4); color: var(--text-3); font-size: var(--fs-sm); }
.w-map-caption { font-size: var(--fs-xs); color: var(--text-3); }
.leaflet-container { font-family: var(--font-sans); }

/* Image widget */
.w-image { margin: 0; }
.w-image img { max-width: 100%; max-height: 420px; border-radius: var(--r-md); cursor: zoom-in; display: block; border: 1px solid var(--border); }
.w-image figcaption { font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--sp-2); }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 1000; background: rgba(4, 8, 14, .88);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-3);
  cursor: zoom-out; padding: var(--sp-6);
}
.lightbox img { max-width: 96%; max-height: 90vh; border-radius: var(--r-md); box-shadow: var(--shadow-lg); }
.lightbox-cap { color: #cdd7e4; font-size: var(--fs-sm); }

/* API tokens — endpoints card */
.set-endpoints { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }
.ep-row { display: flex; gap: var(--sp-3); align-items: baseline; font-size: var(--fs-xs); }
.ep-row span { flex: none; width: 84px; color: var(--text-3); font-weight: 600; }
.ep-row code { font-family: var(--font-mono); font-size: var(--fs-xs); color: #0b1a2b; word-break: break-all; background: rgba(11,26,43,.07); padding: 2px 6px; border-radius: 4px; }
.ep-snippets summary { cursor: pointer; font-size: var(--fs-xs); color: var(--accent); font-weight: 600; }
.ep-snippets pre { margin: var(--sp-2) 0 0; padding: var(--sp-3); background: #eef2f7; border-radius: var(--r-sm); font-family: var(--font-mono); font-size: 11.5px; line-height: 1.5; overflow-x: auto; color: #0b1a2b; white-space: pre; }

/* Login overlay — always a light card regardless of app theme */
.login-overlay[hidden] { display: none !important; } /* `display:grid` below would otherwise beat the UA's [hidden] rule (equal specificity, author > UA) */
.login-overlay {
  position: fixed; inset: 0; z-index: 900;
  display: grid; place-items: center; padding: var(--sp-6);
  background: color-mix(in srgb, var(--bg-app) 82%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.login-card {
  width: 100%; max-width: 380px;
  background: #fff; color: #0b1a2b;
  border: 1px solid var(--border); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-8) var(--sp-6) var(--sp-6);
  display: flex; flex-direction: column; gap: var(--sp-4);
}
.login-logo { height: 44px; object-fit: contain; align-self: center; }
.login-sub { text-align: center; font-size: var(--fs-sm); color: #64748b; margin-top: -6px; }
.login-field { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-xs); color: #64748b; font-weight: 600; }
.login-field input {
  padding: 10px 12px; border: 1px solid #d7dee8; border-radius: var(--r-sm);
  font-size: var(--fs-md); background: #fff; color: #0b1a2b; outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.login-field input:focus { border-color: #0071BC; box-shadow: 0 0 0 3px rgba(0,113,188,.15); }
.login-error { font-size: var(--fs-xs); color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; border-radius: var(--r-sm); padding: 8px 10px; }
.login-btn {
  margin-top: var(--sp-1); padding: 11px; border: none; border-radius: var(--r-md);
  background: linear-gradient(135deg, #0071BC 0%, #0091d8 100%); color: #fff;
  font-size: var(--fs-md); font-weight: 700; cursor: pointer;
  transition: filter var(--t-fast), transform var(--t-fast);
}
.login-btn:hover:not(:disabled) { filter: brightness(1.07); }
.login-btn:active:not(:disabled) { transform: translateY(1px); }
.login-btn:disabled { opacity: .6; cursor: default; }
.login-hint { font-size: var(--fs-xs); color: #8494ab; text-align: center; }
.login-hint a { color: #0071BC; }

/* Composer */
.composer-wrap { flex: none; padding: var(--sp-3) var(--sp-8) var(--sp-5); }

/* Provider bar (v1 chat-provider-bar) — model picker above the composer */
.provider-bar {
  max-width: var(--composer-max); margin: 0 auto var(--sp-2);
  display: flex; align-items: center; gap: var(--sp-3);
  font-size: var(--fs-xs); color: var(--text-3);
}
.provider-bar .pb-label { font-weight: 600; }
.provider-select {
  appearance: none; -webkit-appearance: none;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--r-full); color: var(--text-1);
  font-family: inherit; font-size: var(--fs-xs); font-weight: 650;
  padding: 5px 26px 5px 12px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 14px) 55%, calc(100% - 10px) 55%;
  background-size: 4px 4px; background-repeat: no-repeat;
}
.provider-select:hover, .provider-select:focus { border-color: var(--accent); outline: none; }
.reasoning-toggle {
  margin-left: auto; display: flex; align-items: center; gap: 6px;
  cursor: pointer; font-size: var(--fs-xs); color: var(--text-3);
  user-select: none;
}
.reasoning-toggle input { accent-color: var(--accent); cursor: pointer; }
.composer {
  max-width: var(--composer-max); margin: 0 auto;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
}
.composer:focus-within { border-color: var(--accent); box-shadow: var(--shadow-md), var(--glow-accent); }
.attach-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); padding: 0 var(--sp-1) var(--sp-2); }
.attach-chip {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--accent-soft); color: var(--text-1);
  border: 1px solid var(--border);
  font-size: var(--fs-xs); font-weight: 600;
  padding: 6px 10px; border-radius: var(--r-full);
}
/* Chip upload progress bar */
.attach-chip { position: relative; overflow: hidden; }
.attach-chip .a-pct { font-size: 10.5px; color: var(--text-3); font-weight: 700; min-width: 30px; }
.attach-chip .a-prog {
  position: absolute; left: 0; bottom: 0; height: 3px; width: 0;
  background: var(--accent-grad);
  transition: width var(--t-fast);
}
.attach-chip .a-x { color: var(--text-3); cursor: pointer; font-weight: 700; }
.attach-chip .a-x:hover { color: var(--err); }
.composer-row { display: flex; align-items: flex-end; gap: var(--sp-2); }
.composer textarea {
  flex: 1; border: none; outline: none; resize: none; background: none;
  font-family: inherit; font-size: 16px; color: var(--text-1);
  padding: 9px var(--sp-2); max-height: 200px; line-height: 1.5;
}
.composer-tools { display: flex; align-items: center; gap: var(--sp-1); padding-top: 6px; border-top: 1px solid var(--border); margin-top: var(--sp-1); }
.tool-btn {
  display: flex; align-items: center; gap: 6px;
  border: none; background: none; color: var(--text-2);
  font-size: var(--fs-sm); font-weight: 550;
  padding: 7px 10px; border-radius: var(--r-sm); cursor: pointer;
  font-family: inherit;
}
.tool-btn:hover { background: var(--bg-hover); color: var(--text-1); }
.send-btn {
  margin-left: auto;
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: var(--accent-grad); color: #fff;
  font-size: 15px; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.send-btn:hover { filter: brightness(1.08); }
.composer-hint { text-align: center; font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--sp-2); }

/* ─── Status rail ─────────────────────────────────────────────────────── */
.rail {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.rail-head { padding: var(--sp-4) var(--sp-4) var(--sp-2); display: flex; align-items: center; justify-content: space-between; }
.rail-title { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.rail-section { padding: var(--sp-2) var(--sp-4) var(--sp-3); border-bottom: 1px solid var(--border); }
.job {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-2); border-radius: var(--r-md);
}
.job:hover { background: var(--bg-hover); }
.job { position: relative; }
.job-cancel {
  position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-panel);
  color: var(--text-3); font-size: 11px; cursor: pointer;
  display: grid; place-items: center;
}
.job-cancel:hover { color: var(--err); border-color: var(--err); }
.job-icon { width: 32px; height: 32px; flex: none; border-radius: var(--r-sm); display: grid; place-items: center; font-size: 14px; background: var(--accent-soft); }
.job-icon.ok { background: rgba(5,150,105,.12); }
.job-icon.warn { background: rgba(217,119,6,.12); }
.job-body { flex: 1; min-width: 0; }
.job-name { font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-sub { font-size: var(--fs-xs); color: var(--text-3); margin-top: 1px; }
.progress { height: 5px; border-radius: var(--r-full); background: var(--bg-hover); margin-top: 7px; overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: var(--r-full); background: var(--accent-grad); transition: width var(--t-med); }
.progress > i.ok { background: var(--ok); }
.job-status { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-top: 5px; display: flex; align-items: center; gap: 5px; }
.job-status .spin { width: 10px; height: 10px; border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.job-status.ok { color: var(--ok); }
.job-status.warn { color: var(--warn); }

.meter { padding: var(--sp-3) var(--sp-4); }
.meter-label { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--text-3); margin-bottom: 6px; }
.meter-bar { height: 6px; border-radius: var(--r-full); background: var(--bg-hover); overflow: hidden; display: flex; }
.meter-bar > i.ctx { background: var(--accent); }
.meter-bar > i.rag { background: var(--accent-2); opacity: .55; }
.meter-legend { display: flex; gap: var(--sp-3); margin-top: 7px; font-size: 10.5px; color: var(--text-3); }
.meter-legend b { font-weight: 600; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; }
.dot.ctx { background: var(--accent); }
.dot.rag { background: var(--accent-2); opacity: .55; }

.rail-empty { padding: var(--sp-6) var(--sp-4); text-align: center; color: var(--text-3); font-size: var(--fs-xs); line-height: 1.6; }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
::-webkit-scrollbar-track { background: transparent; }


.citations { margin-top: 16px; font-size: var(--fs-xs); }
.citations summary {
  list-style: none; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; color: var(--text-3); letter-spacing: .03em;
  padding: 4px 8px; border-radius: var(--r-sm);
}
.citations summary::-webkit-details-marker { display: none; }
.citations summary:hover { background: var(--bg-hover); color: var(--text-1); }
.citations summary::after { content: '▸'; font-size: 10px; transition: transform var(--t-fast); }
.citations[open] summary::after { transform: rotate(90deg); }
.citations .cit-count { font-weight: 600; }
.citation-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 2px 2px; }
.citation-chip {
  font-size: 11px; color: var(--text-2); background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 8px; cursor: pointer; max-width: 260px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-decoration: none; transition: border-color var(--t-fast), color var(--t-fast);
}
a.citation-chip:hover { border-color: var(--accent); color: var(--accent); }
.msg-text code { background:var(--bg-hover); border-radius:4px; padding:1px 5px; font-family:var(--font-mono); font-size:12px; }
.msg-text pre { background:var(--bg-code); color:#e6edf3; border-radius:var(--r-md); padding:12px 14px; overflow-x:auto; margin:8px 0; font-size:12.5px; }
.msg-text h1,.msg-text h2,.msg-text h3 { margin:12px 0 6px; line-height:1.3; }
.rail-sub { font-size: var(--fs-xs); color: var(--text-3); }

/* Code block toolbar (v1 parity: preview/print/copy-rich/copy) */
.code-block { margin: 10px 0; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.code-block-head { display: flex; align-items: center; gap: var(--sp-2); background: var(--bg-hover); border-bottom: 1px solid var(--border); padding: 5px 10px; font-size: var(--fs-xs); color: var(--text-3); }
.code-block-head .cb-lang { font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.code-block-head .cb-actions { margin-left: auto; display: flex; gap: 2px; }
.cb-btn { border: none; background: none; color: var(--text-3); font-family: inherit; font-size: var(--fs-xs); font-weight: 600; padding: 3px 8px; border-radius: 5px; cursor: pointer; }
.cb-btn:hover { background: var(--bg-active); color: var(--text-1); }
.code-block pre { margin: 0; border-radius: 0; }
.code-preview { background: var(--bg-panel); }
.code-preview iframe { display: block; }
.doc-creating {
  display: flex; align-items: center; gap: 8px;
  padding: 18px var(--sp-4); margin: 10px 0;
  background: var(--bg-panel); border: 1px dashed var(--border-strong);
  border-radius: var(--r-md); color: var(--text-2);
  font-size: var(--fs-sm); font-weight: 600;
}

/* Produced-document anchor cards (rail) */
.rail-docs-section { padding-top: var(--sp-2); }
.rail-section-title { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); padding: var(--sp-2) var(--sp-2) var(--sp-1); }
.doc-anchor {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 9px 10px; border-radius: var(--r-md);
  cursor: pointer; border: 1px solid transparent;
}
.doc-anchor:hover { background: var(--bg-hover); border-color: var(--border); }
.doc-anchor .da-icon { font-size: 15px; }
.doc-anchor .da-title {
  flex: 1; min-width: 0; font-size: var(--fs-sm); font-weight: 600; color: var(--text-1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-anchor .da-jump { color: var(--accent); font-size: 14px; font-weight: 700; }
.code-block.flash { animation: docFlash 1.6s ease-out; }
@keyframes docFlash {
  0%, 60% { box-shadow: 0 0 0 3px var(--accent); border-color: var(--accent); }
  100% { box-shadow: none; }
}

/* State switcher dropdown */
.state-menu { position: relative; }
.state-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  min-width: 250px;
  background: var(--sb-panel); border: 1px solid var(--sb-border);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: 5px; display: none; flex-direction: column; gap: 1px;
}
.state-dropdown.open { display: flex; }
.state-item {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 9px 10px; border-radius: var(--r-sm);
  font-size: var(--fs-sm); color: var(--sb-text-2); cursor: pointer;
}
.state-item:hover { background: var(--sb-hover); }
.state-item.current { background: var(--sb-active); color: var(--sb-text-1); font-weight: 650; }
.state-item .si-check { width: 16px; text-align: center; color: var(--accent); }
.state-item .si-name { flex: 1; }
.state-item .si-main { flex: 1; display: grid; grid-template-columns: 1fr auto; column-gap: var(--sp-2); }
.state-item .si-name { grid-row: 1; grid-column: 1; }
.state-item .si-top { grid-row: 1; grid-column: 2; justify-self: end; font-size: var(--fs-xs); color: var(--sb-text-3); white-space: nowrap; }
.state-item .si-convos { grid-row: 2; grid-column: 1; font-size: var(--fs-xs); color: var(--sb-text-3); white-space: nowrap; }

/* Loading shimmer rows — the panel opens at full size instantly, then fills in */
.state-skeleton { cursor: default; pointer-events: none; }
.state-skeleton .sk-dot {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  background: linear-gradient(90deg, var(--sb-hover) 25%, var(--sb-active) 50%, var(--sb-hover) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
.state-skeleton .sk-line {
  height: 13px; border-radius: 6px; width: 55%;
  background: linear-gradient(90deg, var(--sb-hover) 25%, var(--sb-active) 50%, var(--sb-hover) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
.state-skeleton .sk-num {
  margin-left: auto; height: 11px; border-radius: 6px; width: 34%;
  background: linear-gradient(90deg, var(--sb-hover) 25%, var(--sb-active) 50%, var(--sb-hover) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}

/* Theme icon button (right of user chip) */
.user-chip { position: relative; }
.theme-btn {
  margin-left: auto; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--sb-border); background: var(--sb-panel);
  color: var(--sb-text-2); cursor: pointer; font-size: 15px;
  display: grid; place-items: center; flex: none;
}
.theme-btn:hover { color: var(--sb-text-1); border-color: var(--sb-text-3); }

/* ═══ Responsive — same markup, adaptive layout ═══ */
.sb-backdrop { display: none; }

@media (max-width: 1240px) {
  .app { grid-template-columns: var(--sidebar-w) 1fr; }
  .rail {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--rail-w), 86vw);
    z-index: 46; box-shadow: var(--shadow-lg);
    transform: translateX(100%); transition: transform var(--t-med);
  }
  .rail.open { transform: translateX(0); }
  .only-tablet { display: grid !important; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(var(--sidebar-w), 84vw);
    z-index: 46; box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sb-backdrop {
    display: block; position: fixed; inset: 0; z-index: 39;
    background: rgba(4, 10, 18, .55);
    opacity: 0; pointer-events: none; transition: opacity var(--t-med);
  }
  /* Backdrop must sit ABOVE both drawers (z-40) so tapping outside always dismisses */
  .sb-backdrop.show { opacity: 1; pointer-events: auto; z-index: 45; }
  .only-mobile { display: grid !important; }
  .chat-header { padding: 0 var(--sp-3); }
  .header-actions .hide-mobile { display: none; }
  .messages { padding: var(--sp-4) var(--sp-4) var(--sp-2); }
  .composer-wrap { padding: var(--sp-2) var(--sp-3) calc(var(--sp-3) + env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .msg { max-width: 100%; }
}
