:root {
  --bg: #090d14;
  --bg-soft: #0d131e;
  --panel: #111a29;
  --panel-strong: #162235;
  --border: #1e2b40;
  --border-soft: #182437;
  --text: #e8edf7;
  --muted: #8a98ad;
  --faint: #55647b;
  --accent: #d7a54f;
  --accent-strong: #f1c873;
  --accent-soft: rgba(215, 165, 79, .13);
  --blue: #71a8f7;
  --green: #70d9a0;
  --purple: #b697f2;
  --warn: #f3ad4f;
  --danger: #f38b92;
  --user-bubble: linear-gradient(135deg, #1d3b60, #17304d);
  --agent-bubble: #121b2b;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1100px 600px at 74% -10%, #17264266, transparent), var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
body[data-domain="aga"] {
  --accent: #ad91e8;
  --accent-strong: #d2baff;
  --accent-soft: rgba(173, 145, 232, .14);
}
button, textarea, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#app { display: flex; height: 100vh; height: 100dvh; min-height: 500px; }

/* ── sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: 268px; flex: 0 0 268px; display: flex; flex-direction: column;
  padding: 18px 14px 14px; background: rgba(12, 18, 29, .91);
  border-right: 1px solid var(--border); overflow-y: auto;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 5px 20px; }
.brand { display: flex; align-items: center; gap: 11px; }
.logo {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px;
  color: var(--accent-strong); background: var(--accent-soft); border: 1px solid #d7a54f55;
  font-size: 22px; box-shadow: 0 8px 22px #0003;
}
.brand-text { display: flex; flex-direction: column; gap: 2px; line-height: 1.2; }
.brand-name { font-size: 14px; font-weight: 750; letter-spacing: .25px; }
.brand-name em { color: var(--accent-strong); font-style: normal; }
.brand-sub { color: var(--faint); font-size: 10px; letter-spacing: .7px; text-transform: uppercase; }
.icon-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center; padding: 0;
  border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: 9px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--panel); border-color: var(--border); }
.sidebar-close, .menu-btn { display: none; }
.primary-action {
  border: 1px solid #d7a54f66; background: linear-gradient(135deg, #d7a54f, #b77e2c);
  color: #1c1409; font-weight: 750; border-radius: 10px; padding: 10px 13px; cursor: pointer;
  box-shadow: 0 8px 22px #d7a54f1a; transition: transform .18s, filter .18s;
}
.primary-action:hover { filter: brightness(1.08); transform: translateY(-1px); }
.new-chat { width: 100%; display: flex; gap: 8px; align-items: center; justify-content: center; }
.new-chat span { font-size: 18px; line-height: .8; }
.main-nav { display: flex; flex-direction: column; gap: 3px; margin: 24px 0 22px; }
.workspace-section { margin-top: 18px; }
.workspace-section + .main-nav { margin-top: 9px; }
.nav-item, .quick-link {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 39px; padding: 8px 10px;
  border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: 9px;
  cursor: pointer; text-align: left; transition: color .18s, background .18s, border-color .18s;
}
.nav-item:hover, .quick-link:hover { color: var(--text); background: #17233899; border-color: var(--border-soft); }
.nav-item.active { color: var(--accent-strong); background: var(--accent-soft); border-color: #d7a54f2b; }
.nav-icon { width: 17px; text-align: center; color: var(--faint); font-size: 15px; }
.nav-item.active .nav-icon { color: var(--accent-strong); }
.nav-item kbd { margin-left: auto; opacity: .65; }
.nav-count { min-width: 22px; margin-left: auto; padding: 2px 6px; border-radius: 999px; color: var(--faint); background: #0b1320; text-align: center; font: 9px ui-monospace, SFMono-Regular, Menlo, monospace; }
.domain-nav.active .nav-count { color: var(--accent-strong); background: var(--accent-soft); }
kbd {
  padding: 2px 5px; border: 1px solid var(--border); border-bottom-color: #2b3b53; border-radius: 5px;
  color: var(--faint); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.sidebar-section { border-top: 1px solid var(--border-soft); padding-top: 17px; }
.section-label { color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: 1.3px; margin: 0 10px 8px; text-transform: uppercase; }
.quick-link { font-size: 13px; min-height: 35px; }
.quick-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 7px currentColor; }
.mail-dot { color: var(--blue); background: var(--blue); }
.calendar-dot { color: var(--green); background: var(--green); }
.task-dot { color: var(--accent); background: var(--accent); }
.rag-dot { color: var(--purple); background: var(--purple); }
.sidebar-spacer { flex: 1; min-height: 24px; }
.health-card { padding: 11px 12px; border: 1px solid var(--border); background: #101827cc; border-radius: 10px; margin-bottom: 10px; }
.health-top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.health-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.health-card.healthy .health-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.health-card.unhealthy .health-dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.health-card.healthy .health-top { color: var(--green); }
.health-card.unhealthy .health-top { color: var(--danger); }
.refresh-btn { width: 22px; height: 22px; margin-left: auto; font-size: 16px; }
.health-detail { color: var(--faint); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-card { display: flex; align-items: center; gap: 9px; padding: 10px; border-top: 1px solid var(--border-soft); }
.profile-avatar { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 8px; background: #28436a; color: #cfe4ff; font-size: 12px; font-weight: 700; }
.profile-card strong, .profile-card small { display: block; }
.profile-card strong { font-size: 12px; }
.profile-card small { color: var(--faint); font-size: 10px; margin-top: 2px; }
.lock { margin-left: auto; color: var(--faint); font-size: 16px; }

/* ── workspace/topbar ───────────────────────────────────────────── */
.workspace { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.topbar { height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 10px 27px; border-bottom: 1px solid var(--border-soft); background: #0d1420b8; backdrop-filter: blur(14px); }
.topbar-left, .top-actions { display: flex; align-items: center; gap: 12px; }
.page-title { display: flex; flex-direction: column; gap: 2px; }
.eyebrow { color: var(--faint); font-size: 10px; font-weight: 750; letter-spacing: 1.4px; margin: 0; }
.page-title h1 { font-size: 17px; line-height: 1.2; margin: 0; font-weight: 700; }
.status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 8px var(--warn); transition: .3s; }
.status.online .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status.busy .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ── dashboard ───────────────────────────────────────────────────── */
.dashboard-view { min-height: 0; flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.dashboard-inner { width: min(1160px, 100%); margin: 0 auto; padding: 34px 32px 45px; }
.dashboard-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.dashboard-heading h2 { margin: 8px 0 9px; font-size: clamp(25px, 3vw, 35px); line-height: 1.15; letter-spacing: -.7px; }
.dashboard-copy { max-width: 690px; margin: 0; color: var(--muted); line-height: 1.65; }
.dashboard-actions { display: flex; align-items: center; gap: 11px; flex: 0 0 auto; }
.domain-switch { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: -5px 0 14px; }
.domain-tab { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 11px; color: var(--muted); background: #0e1725aa; cursor: pointer; text-align: left; }
.domain-tab:hover { color: var(--text); border-color: #50627d; background: var(--panel-strong); }
.domain-tab.active { color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: linear-gradient(135deg, var(--accent-soft), #111a29); }
.domain-tab span { font-size: 13px; font-weight: 750; }
.domain-tab small { overflow: hidden; color: var(--faint); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.data-status { color: var(--faint); font-size: 11px; white-space: nowrap; }
.data-status.ready { color: var(--green); }
.data-status.error { color: var(--danger); }
.next-action-strip { display: flex; align-items: center; gap: 12px; min-width: 0; margin: 0 0 12px; padding: 12px 14px; border: 1px solid #d7a54f45; border-radius: 12px; background: linear-gradient(110deg, #191b25, #111a29); }
.next-action-mark { flex: 0 0 auto; padding: 5px 7px; border-radius: 6px; color: var(--accent-strong); background: var(--accent-soft); font-size: 10px; font-weight: 750; }
.next-action-main { min-width: 0; flex: 1; }
.next-action-main strong { display: block; overflow: hidden; color: var(--text); font-size: 12px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.next-action-main p { overflow: hidden; margin: 3px 0 0; color: var(--muted); font-size: 10px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.next-action-strip .inline-btn { flex: 0 0 auto; padding: 7px 9px; }
.secondary-btn, .text-btn, .inline-btn { border: 1px solid var(--border); color: var(--muted); background: #101827aa; cursor: pointer; border-radius: 8px; }
.secondary-btn { padding: 8px 11px; font-size: 12px; }
.secondary-btn:hover, .text-btn:hover, .inline-btn:hover { color: var(--text); border-color: #5b6d87; background: var(--panel-strong); }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat-card { position: relative; min-height: 103px; padding: 15px 16px; border: 1px solid var(--border); border-radius: 12px; background: linear-gradient(135deg, #121d2e, #0f1725); }
.clickable-stat {
  width: 100%; appearance: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
  transition: transform .18s, border-color .18s, background .18s, box-shadow .18s;
}
.clickable-stat:hover, .clickable-stat:focus-visible {
  transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 58%, var(--border));
  background: linear-gradient(135deg, #17263b, #111d2f); box-shadow: 0 10px 22px #0003;
}
.clickable-stat:active { transform: translateY(0); }
.stat-card-link { position: absolute; top: 14px; right: 15px; color: var(--faint); font-size: 10px; transition: color .18s; }
.clickable-stat:hover .stat-card-link, .clickable-stat:focus-visible .stat-card-link { color: var(--accent-strong); }
.stat-label, .stat-card small { display: block; color: var(--muted); font-size: 11px; }
.stat-card strong { display: block; margin: 8px 0 5px; color: var(--text); font-size: 26px; letter-spacing: -.4px; }
.stat-card small { color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.confirmation-panel { margin-bottom: 12px; padding: 15px 17px; border: 1px solid #d7a54f36; border-radius: 13px; background: linear-gradient(135deg, #171b25, #111827cc); }
.review-note { color: var(--faint); font-size: 10px; }
.confirmation-list { display: flex; flex-wrap: wrap; gap: 8px; }
.confirmation-item { display: flex; align-items: flex-start; gap: 8px; flex: 1 1 330px; min-width: 0; padding: 9px; border: 1px solid var(--border-soft); border-radius: 9px; background: #0c1421aa; }
.confirmation-icon { flex: 0 0 auto; padding: 3px 5px; border-radius: 4px; color: var(--accent-strong); background: var(--accent-soft); font-size: 9px; font-weight: 700; }
.confirmation-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.confirmation-item p { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; margin: 4px 0 0; color: var(--muted); font-size: 10px; line-height: 1.45; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 12px; }
.dash-panel { min-width: 0; padding: 17px; border: 1px solid var(--border); border-radius: 13px; background: #101827cc; scroll-margin-top: 16px; transition: border-color .2s, box-shadow .2s; }
.dash-panel:focus { outline: none; }
.dash-panel.focused-panel { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); animation: panel-focus 1.4s ease-out; }
@keyframes panel-focus { 0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); } 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 7%, transparent); } }
.detail-drawer { position: fixed; inset: 0; z-index: 25; }
.detail-drawer[hidden] { display: none; }
.detail-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: #02050bcc; cursor: pointer; }
.detail-sheet {
  position: absolute; inset: 0 0 0 auto; display: flex; flex-direction: column; width: min(620px, 100%);
  padding: 24px 25px max(20px, env(safe-area-inset-bottom)); border-left: 1px solid var(--border);
  background: linear-gradient(180deg, #111b2b, #0b111c); box-shadow: -18px 0 50px #0008; overflow-y: auto;
  animation: detail-in .2s ease-out;
}
@keyframes detail-in { from { transform: translateX(24px); opacity: .7; } to { transform: translateX(0); opacity: 1; } }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; padding-bottom: 17px; border-bottom: 1px solid var(--border-soft); }
.detail-head h2 { margin: 7px 0 0; font-size: 23px; line-height: 1.2; }
.detail-content { flex: 1; padding: 19px 0 24px; }
.detail-summary { margin: 0 0 16px; color: var(--muted); line-height: 1.65; }
.detail-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
.detail-meta > div { min-width: 0; padding: 10px 11px; border: 1px solid var(--border-soft); border-radius: 9px; background: #0c1421aa; }
.detail-meta small, .detail-section-label { display: block; color: var(--faint); font-size: 10px; }
.detail-meta strong { display: block; margin-top: 4px; overflow-wrap: anywhere; color: var(--text); font-size: 12px; line-height: 1.4; }
.detail-section { margin: 19px 0 0; }
.detail-section h3 { margin: 0 0 8px; color: var(--text); font-size: 13px; }
.detail-section p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-list { display: flex; flex-direction: column; gap: 8px; }
.detail-list-item { padding: 10px 11px; border: 1px solid var(--border-soft); border-radius: 9px; background: #0c1421aa; }
.detail-list-item strong { display: block; color: var(--text); font-size: 12px; line-height: 1.45; }
.detail-list-item small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.detail-collection { display: flex; flex-direction: column; gap: 9px; }
.detail-collection-item { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 12px; border: 1px solid var(--border-soft); border-radius: 10px; color: var(--text); background: #0c1421aa; cursor: pointer; text-align: left; transition: border-color .18s, background .18s, transform .18s; }
.detail-collection-item:hover, .detail-collection-item:focus-visible { border-color: #566b87; background: #15243a; transform: translateY(-1px); }
.detail-collection-item .item-main { min-width: 0; flex: 1; }
.detail-collection-item .item-title { display: flex; align-items: flex-start; gap: 7px; }
.detail-collection-item .item-title strong { overflow: hidden; color: var(--text); font-size: 12px; line-height: 1.45; text-overflow: ellipsis; }
.detail-collection-item p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.detail-collection-item small { display: block; margin-top: 6px; color: var(--faint); font-size: 10px; }
.detail-arrow { flex: 0 0 auto; color: var(--accent-strong); font-size: 17px; }
.detail-body { margin: 0; padding: 13px; border: 1px solid var(--border-soft); border-radius: 10px; color: var(--muted); background: #080e18; font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-loading { color: var(--muted); }
.detail-warning { padding: 10px 11px; border: 1px solid #d7a54f44; border-radius: 9px; color: var(--accent-strong); background: var(--accent-soft); font-size: 11px; line-height: 1.5; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 15px; border-top: 1px solid var(--border-soft); }
.detail-actions:empty { display: none; }
.detail-action-btn { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); background: #101827; cursor: pointer; font-size: 12px; }
.detail-action-btn.primary { border-color: #d7a54f66; color: #1c1409; background: var(--accent); font-weight: 700; }
.detail-action-btn:hover, .detail-action-btn:focus-visible { color: var(--text); border-color: #647794; background: var(--panel-strong); }
.detail-action-btn.primary:hover, .detail-action-btn.primary:focus-visible { color: #1c1409; background: var(--accent-strong); }
.detail-empty { padding: 26px 8px; color: var(--muted); text-align: center; line-height: 1.6; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-head h3 { margin: 6px 0 0; font-size: 16px; }
.panel-head-actions { display: flex; align-items: center; gap: 2px; }
.text-btn { padding: 5px 7px; border-color: transparent; background: transparent; font-size: 11px; }
.compact-list { display: flex; flex-direction: column; gap: 8px; }
.compact-item { display: flex; align-items: flex-start; gap: 9px; min-width: 0; padding: 10px; border: 1px solid var(--border-soft); border-radius: 9px; background: #0c1421aa; }
.item-main { min-width: 0; flex: 1; }
.item-title { display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.item-title strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.compact-item p { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; margin: 5px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.compact-item small { display: block; color: var(--faint); font-size: 10px; line-height: 1.4; }
.priority, .mail-state { flex: 0 0 auto; padding: 2px 5px; border-radius: 4px; color: var(--accent-strong); background: var(--accent-soft); font-size: 9px; font-weight: 700; }
.mail-state { color: var(--blue); background: #71a8f71b; }
.inline-btn { flex: 0 0 auto; padding: 5px 7px; font-size: 10px; }
.empty-state { padding: 16px 4px; color: var(--faint); font-size: 12px; line-height: 1.5; }
.compact-empty { padding: 6px 0; }
.agenda-block + .agenda-block { margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.agenda-label { display: block; margin-bottom: 6px; color: var(--accent-strong); font-size: 11px; font-weight: 700; }
.agenda-item { display: flex; align-items: flex-start; gap: 10px; padding: 6px 0; }
.agenda-time { flex: 0 0 53px; color: var(--green); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.agenda-item strong, .agenda-item small { display: block; }
.agenda-item strong { font-size: 12px; line-height: 1.35; }
.agenda-item small { margin-top: 2px; color: var(--faint); font-size: 10px; }
.training-note { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border-soft); color: var(--muted); font-size: 11px; line-height: 1.5; }
.knowledge-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.knowledge-metrics span, .knowledge-metrics button { display: block; width: 100%; padding: 9px 6px; border: 1px solid transparent; border-radius: 8px; background: #0b1320; text-align: center; }
.knowledge-metrics button { color: inherit; font: inherit; cursor: pointer; transition: border-color .18s, background .18s; }
.knowledge-metrics button:hover, .knowledge-metrics button:focus-visible { border-color: var(--border); background: #132139; outline: none; }
.knowledge-metrics strong, .knowledge-metrics small { display: block; }
.knowledge-metrics strong { color: var(--purple); font-size: 17px; }
.knowledge-metrics small { margin-top: 3px; color: var(--faint); font-size: 9px; }
.topic-preview { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.topic-preview span, .topic-preview .topic-chip { max-width: 100%; overflow: hidden; padding: 4px 7px; border: 1px solid var(--border-soft); border-radius: 999px; color: var(--muted); background: #0b1320; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.topic-preview .topic-chip { cursor: pointer; font-family: inherit; transition: border-color .18s, color .18s; }
.topic-preview .topic-chip:hover, .topic-preview .topic-chip:focus-visible { border-color: var(--accent-strong); color: var(--text); outline: none; }
.detail-collection-item.static { cursor: default; }
.detail-collection-item.static:hover { border-color: var(--border-soft); background: #0c1421aa; transform: none; }
.panel-note { margin: 11px 0 14px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.case-list { display: flex; flex-direction: column; gap: 6px; }
.case-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 9px; width: 100%; padding: 8px 9px; border: 1px solid var(--border-soft); border-radius: 8px; color: var(--muted); background: #0c1421aa; text-align: left; cursor: pointer; font-size: 11px; }
.case-row:hover { color: var(--text); border-color: #5b6d87; background: var(--panel-strong); }
.case-pid { color: var(--purple); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; }
.case-row > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-arrow { color: var(--faint); font-size: 15px; }
.upload-row { display: flex; align-items: center; gap: 7px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border-soft); }
.upload-row select { max-width: 105px; padding: 5px 4px; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); background: #0b1320; font-size: 10px; }
.upload-row span { overflow: hidden; color: var(--faint); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.upload-row span.error { color: var(--danger); }
.upload-row span.ready { color: var(--green); }

/* Mobile sidebar scrim: it also gives keyboard and touch users a clear exit. */
.sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 9; border: 0; background: #03060b99; }
.sidebar-backdrop.visible { display: block; }

/* ── welcome/chat ────────────────────────────────────────────────── */
#chat { min-height: 0; flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.chat-inner { width: min(920px, 100%); min-height: 100%; margin: 0 auto; padding: 38px 28px 26px; display: flex; flex-direction: column; gap: 16px; }
.welcome { max-width: 760px; margin: auto; padding: 13px 0 35px; }
.welcome.hidden { display: none; }
.welcome-mark { width: 49px; height: 49px; display: grid; place-items: center; border-radius: 16px; color: var(--accent-strong); background: var(--accent-soft); border: 1px solid #d7a54f45; font-size: 28px; margin-bottom: 20px; box-shadow: 0 12px 30px #0003; }
.welcome-mark.small { width: 42px; height: 42px; font-size: 22px; margin: 0 0 14px; }
.welcome h2 { font-size: clamp(26px, 4vw, 37px); line-height: 1.15; margin: 9px 0 13px; letter-spacing: -.8px; }
.welcome-copy { max-width: 650px; color: var(--muted); font-size: 14px; line-height: 1.75; margin: 0; }
.capability-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 24px; }
.capability-row span, .context-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); background: #10182799; font-size: 11px; }
.welcome-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.welcome-card { min-height: 78px; display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 11px; padding: 13px 14px; text-align: left; border: 1px solid var(--border); border-radius: 12px; background: linear-gradient(135deg, #111a29, #0e1623); cursor: pointer; transition: transform .18s, border-color .18s, background .18s; }
.welcome-card:hover { transform: translateY(-2px); border-color: #647694; background: var(--panel-strong); }
.welcome-card strong, .welcome-card small { display: block; }
.welcome-card strong { font-size: 13px; }
.welcome-card small { color: var(--muted); font-size: 11px; margin-top: 4px; }
.welcome-card b { color: var(--faint); font-size: 18px; font-weight: 400; }
.card-icon { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; font-size: 15px; }
.card-icon.gold { color: var(--accent-strong); background: var(--accent-soft); }
.card-icon.blue { color: var(--blue); background: #71a8f71b; }
.card-icon.purple { color: var(--purple); background: #b697f21b; }
.card-icon.green { color: var(--green); background: #70d9a01b; }
.msg { display: flex; gap: 11px; max-width: 88%; animation: rise .2s ease-out; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.avatar { width: 31px; height: 31px; flex: 0 0 31px; display: grid; place-items: center; border-radius: 9px; margin-top: 2px; background: var(--panel); border: 1px solid var(--border); color: var(--accent-strong); font-size: 15px; }
.msg.user .avatar { background: var(--user-bubble); border-color: #274a74; color: #d6e7ff; font-size: 12px; font-weight: 700; }
.msg-body { min-width: 0; }
.bubble { padding: 11px 15px; border-radius: 14px; border-top-left-radius: 5px; background: var(--agent-bubble); border: 1px solid var(--border); line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.msg.user .bubble { border-radius: 14px; border-top-right-radius: 5px; background: var(--user-bubble); border-color: #27466f; }
.bubble a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }
.bubble h3, .bubble h4 { margin: 9px 0 4px; line-height: 1.3; }
.bubble h3:first-child, .bubble h4:first-child { margin-top: 0; }
.bubble strong { color: #fff0cb; }
.bubble code { padding: 1px 6px; border-radius: 5px; background: #0a101d; color: #ffd58b; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.bubble pre { overflow-x: auto; padding: 11px; margin: 8px 0; border: 1px solid var(--border); border-radius: 8px; background: #0a101d; }
.bubble pre code { padding: 0; background: transparent; }
.md-bullet { color: var(--accent); font-weight: 700; }
.meta { color: var(--faint); font-size: 10px; margin-top: 5px; }
.message-actions { display: flex; gap: 4px; min-height: 22px; opacity: 0; transition: opacity .15s; }
.msg:hover .message-actions, .message-actions:focus-within { opacity: 1; }
.message-action { border: 0; padding: 2px 5px; background: transparent; color: var(--faint); font-size: 10px; cursor: pointer; }
.message-action:hover { color: var(--accent-strong); }
.cursor { display: inline-block; width: 7px; height: 16px; vertical-align: text-bottom; border-radius: 2px; background: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ── activity/tool trace ─────────────────────────────────────────── */
.activity { align-self: flex-start; width: min(100%, 760px); padding: 8px 12px; border: 1px solid var(--border-soft); border-radius: 10px; background: #0d1522cc; color: var(--muted); font-size: 11px; animation: rise .2s ease-out; }
.activity-head { display: flex; align-items: center; gap: 8px; }
.activity-spinner { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1s infinite; }
.activity-spinner.stopped { animation: none; background: var(--green); box-shadow: 0 0 8px var(--green); }
.activity.failed .activity-spinner { animation: none; background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.activity-title { color: var(--muted); }
.activity.done .activity-title { color: var(--green); }
.activity.failed .activity-title { color: var(--danger); }
.activity-toggle { margin-left: auto; padding: 2px 5px; border: 0; background: transparent; color: var(--faint); cursor: pointer; font-size: 10px; }
.activity-toggle:hover { color: var(--text); }
.activity-body { padding: 8px 0 2px 17px; }
.activity-note { color: var(--faint); margin-bottom: 7px; }
.tool-list { display: flex; flex-wrap: wrap; gap: 5px; }
.tool-chip { display: inline-flex; align-items: center; max-width: 100%; padding: 3px 8px; border: 1px solid #d7a54f33; border-radius: 999px; color: var(--accent); background: var(--accent-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-chip.done { color: var(--green); border-color: #70d9a033; background: #70d9a00e; }
.tool-chip.done::after { content: " ✓"; }
.tool-chip.failed { color: var(--danger); border-color: #f38b9233; background: #f38b920e; }
.err { align-self: flex-start; display: flex; align-items: center; gap: 10px; max-width: 760px; padding: 9px 12px; color: #f9b7bc; border: 1px dashed #7f313e; border-radius: 9px; background: #1b1118; font-size: 12px; }
.error-retry { border: 0; border-radius: 5px; padding: 3px 7px; color: #ffd4d7; background: #652631; cursor: pointer; font-size: 11px; }

/* ── composer ────────────────────────────────────────────────────── */
.composer-wrap { padding: 8px 28px max(13px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 26%); }
.composer-inner { width: min(920px, 100%); margin: 0 auto; padding: 8px 11px 10px; border: 1px solid var(--border); border-radius: 15px; background: #111a29ee; box-shadow: 0 15px 35px #0002; }
.composer-inner:focus-within { border-color: #d7a54f66; box-shadow: 0 0 0 3px #d7a54f0d, 0 15px 35px #0002; }
.composer-tools { display: flex; gap: 6px; margin-bottom: 7px; }
.context-pill { padding: 3px 7px; font-size: 10px; }
.context-pill i { width: 5px; height: 5px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); }
.domain-context { color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background: var(--accent-soft); }
.composer-row { display: flex; align-items: flex-end; gap: 9px; }
textarea { flex: 1; min-width: 0; max-height: 180px; resize: none; outline: none; border: 0; background: transparent; color: var(--text); line-height: 1.55; }
textarea::placeholder { color: #5d6d83; }
#send, #stop { width: 37px; height: 37px; flex: 0 0 37px; border-radius: 10px; border: 0; cursor: pointer; }
#send { color: #1a1208; background: var(--accent); font-size: 15px; }
#send:disabled { opacity: .35; cursor: default; }
#stop { color: #ffc1c8; background: #3a1d25; border: 1px solid #7f313e; }
.footnote { color: var(--faint); font-size: 10px; text-align: center; margin: 7px 0 0; }
body[data-view="dashboard"] .composer-wrap { padding-top: 5px; padding-bottom: max(7px, env(safe-area-inset-bottom)); }
body[data-view="dashboard"] .composer-tools, body[data-view="dashboard"] .footnote { display: none; }
body[data-view="dashboard"] .composer-inner { padding: 6px 9px; border-radius: 12px; }
body[data-view="dashboard"] textarea { max-height: 42px; }
body.detail-open { overflow: hidden; }

/* ── modals/toast ────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: #03060bcc; backdrop-filter: blur(8px); }
.modal-backdrop[hidden] { display: none; }
.auth-card, .help-card { width: min(410px, 100%); position: relative; padding: 27px; border: 1px solid var(--border); border-radius: 17px; background: #111a29; box-shadow: 0 22px 70px #0008; }
.auth-card h2, .help-card h2 { margin: 0 0 10px; font-size: 21px; }
.auth-card p, .help-note { color: var(--muted); line-height: 1.65; font-size: 13px; }
.auth-card label { display: block; color: var(--muted); font-size: 12px; margin: 18px 0 6px; }
.auth-card input { width: 100%; padding: 10px 11px; color: var(--text); border: 1px solid var(--border); border-radius: 8px; outline: none; background: #0a101b; }
.auth-card .primary-action { width: 100%; margin-top: 15px; }
.form-error { color: var(--danger) !important; font-size: 12px !important; margin: 8px 0 0; }
.modal-close { position: absolute; top: 12px; right: 12px; }
.shortcut-list { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
.shortcut-list div { display: flex; align-items: center; justify-content: space-between; color: var(--muted); }
.shortcut-list kbd { color: var(--text); }
.help-note { border-top: 1px solid var(--border-soft); padding-top: 13px; margin-bottom: 0; }
.toast { position: fixed; left: 50%; bottom: 92px; z-index: 30; max-width: calc(100% - 30px); padding: 9px 13px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: #1a2638; box-shadow: 0 12px 25px #0005; opacity: 0; pointer-events: none; transform: translate(-50%, 8px); transition: opacity .18s, transform .18s; font-size: 12px; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; width: min(290px, 88vw); transform: translateX(-101%); transition: transform .2s ease; box-shadow: 15px 0 35px #0008; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close, .menu-btn { display: inline-grid; }
  .sidebar-backdrop { display: none; }
  .sidebar-backdrop.visible { display: block; }
  .menu-btn { margin-left: -7px; }
  .topbar { padding: 9px 16px; }
  .top-actions { gap: 4px; }
  .top-actions .status { margin-right: 2px; }
  .chat-inner { padding: 26px 16px 20px; }
  .chat-inner { padding-bottom: 72px; }
  .composer-wrap { padding-left: 16px; padding-right: 16px; }
  .detail-sheet { padding: 18px 16px max(16px, env(safe-area-inset-bottom)); }
  .detail-head h2 { font-size: 20px; }
  .detail-meta { grid-template-columns: 1fr 1fr; }
  .dashboard-inner { padding: 25px 16px 72px; }
  .dashboard-heading { display: block; }
  .next-action-strip { align-items: flex-start; }
  .next-action-main strong { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; white-space: normal; }
  .next-action-main p { white-space: normal; }
  .next-action-strip .inline-btn { align-self: center; }
  .dashboard-actions { justify-content: space-between; margin-top: 15px; }
  .domain-switch { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .welcome { padding-top: 16px; }
  .welcome-actions { grid-template-columns: 1fr; }
  .msg { max-width: 96%; }
  .message-actions { opacity: 1; }
}
@media (max-width: 430px) {
  .eyebrow { letter-spacing: 1px; }
  .page-title h1 { font-size: 15px; }
  #export-chat { display: none; }
  .composer-tools .context-pill:nth-child(3) { display: none; }
  .welcome h2 { font-size: 27px; }
  .dashboard-heading h2 { font-size: 27px; }
  .dashboard-copy { font-size: 13px; }
  .data-status { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
}
