:root {
  --ink: #172235;
  --muted: #718096;
  --line: #e8edf3;
  --panel: #ffffff;
  --canvas: #f5f7fb;
  --navy: #08005a;
  --navy-soft: #1b1b4b;
  --violet: #08005a;
  --violet-soft: #efefff;
  --green: #00a875;
  --green-soft: #e8f8f1;
  --red: #d8505b;
  --amber: #e89241;
  --brand-mint: #2ae6a1;
  --shadow: 0 16px 42px rgba(33, 44, 79, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { color: var(--violet); font-size: 11px; font-weight: 800; letter-spacing: .14em; margin: 0 0 8px; }

.login-screen {
  align-items: center;
  background:
    radial-gradient(circle at 15% 15%, rgba(116, 91, 231, .25), transparent 30%),
    radial-gradient(circle at 90% 80%, rgba(45, 204, 148, .14), transparent 28%),
    var(--navy);
  display: flex;
  inset: 0;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  position: fixed;
  z-index: 20;
}

.login-card {
  background: white;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(2, 6, 23, .38);
  max-width: 430px;
  padding: 42px;
  width: 100%;
}

.login-card h1 { font-size: 30px; margin: 4px 0 10px; letter-spacing: -.04em; }
.login-card > .muted { line-height: 1.6; margin: 0 0 28px; }
.login-card form { display: grid; gap: 9px; }
.login-card label { color: #3e4a5f; font-size: 12px; font-weight: 700; margin-top: 7px; }
.login-card input {
  border: 1px solid #dce2ea;
  border-radius: 11px;
  outline: none;
  padding: 13px 14px;
  transition: border-color .2s, box-shadow .2s;
}
.login-card input:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(111,91,231,.12); }
.form-error { color: var(--red); font-size: 12px; min-height: 18px; margin: 2px 0 0; }

.brand-mark {
  align-items: center;
  background: linear-gradient(145deg, #7e6df0, #5a46d0);
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(111, 91, 231, .25);
  color: white;
  display: flex;
  font-family: Georgia, serif;
  font-size: 26px;
  font-style: italic;
  font-weight: 700;
  height: 48px;
  justify-content: center;
  margin-bottom: 24px;
  width: 48px;
}
.brand-mark.small { border-radius: 10px; box-shadow: none; font-size: 21px; height: 38px; margin: 0; width: 38px; }
.official-logo { display: block; height: auto; object-fit: contain; }
.login-logo { margin-bottom: 25px; max-width: 185px; width: 55%; }
.sidebar-logo { filter: brightness(0) invert(1); max-width: 115px; width: 100%; }

.button {
  border: 0;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 750;
  padding: 13px 18px;
}
.button.primary { background: var(--violet); color: white; box-shadow: 0 9px 20px rgba(111,91,231,.2); }
.button.primary:hover { background: #604cda; }
.button.full { margin-top: 5px; width: 100%; }
.button.compact { box-shadow: none; padding: 10px 15px; }
.button.secondary { background: white; border: 1px solid #dce2ea; padding: 9px 14px; }
.button.subtle { background: transparent; color: var(--muted); padding: 9px 12px; }
.button:disabled { cursor: not-allowed; opacity: .55; }

.app-shell { display: grid; grid-template-columns: 235px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--navy);
  color: white;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  padding: 26px 16px 18px;
  position: sticky;
  top: 0;
}
.brand { align-items: flex-start; display: flex; flex-direction: column; gap: 7px; margin: 2px 13px 38px; }
.brand strong { display: block; font-size: 18px; letter-spacing: .02em; }
.brand span { color: #b9b9db; display: block; font-size: 11px; margin-top: 2px; }
.sidebar nav { flex: 1; }
.nav-item {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 11px;
  color: #adb4d2;
  cursor: pointer;
  display: flex;
  font-size: 13px;
  font-weight: 650;
  gap: 11px;
  padding: 12px 13px;
  text-align: left;
  width: 100%;
}
.nav-item svg { height: 19px; width: 19px; }
.nav-item.active { background: rgba(42, 230, 161, .15); color: white; box-shadow: inset 3px 0 var(--brand-mint); }
.nav-item.logout { margin-top: 7px; }
.nav-item.logout:hover { background: rgba(255,255,255,.07); color: white; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.08); padding-top: 16px; }
.connection-pill { align-items: center; display: flex; gap: 10px; padding: 4px 12px 13px; }
.connection-pill strong, .connection-pill span { display: block; }
.connection-pill strong { font-size: 12px; }
.connection-pill div span { color: #a9afd0; font-size: 10px; margin-top: 2px; }
.live-dot { background: var(--brand-mint); border-radius: 50%; box-shadow: 0 0 0 5px rgba(42,230,161,.1); height: 8px; width: 8px; }

main { min-width: 0; padding: 30px clamp(20px, 3vw, 46px) 45px; }
.topbar { align-items: center; display: flex; justify-content: space-between; margin-bottom: 24px; }
.topbar h1 { font-size: clamp(24px, 2.2vw, 31px); letter-spacing: -.04em; margin: 0 0 6px; }
.topbar .muted { margin: 0; }
.topbar-actions { align-items: center; display: flex; gap: 12px; }
.sync-label { color: var(--muted); font-size: 11px; }
.icon-button {
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  height: 42px;
  justify-content: center;
  width: 42px;
}
.icon-button:hover { border-color: #c8cfda; }
.icon-button svg { height: 19px; width: 19px; }
.icon-button.loading svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-banner {
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: inline-flex;
  gap: 8px;
  min-height: 40px;
  padding: 6px 9px;
}
.status-banner.warning { background: #fffdf9; border-color: #eadfc9; }
.status-dot {
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(42, 230, 161, .14);
  flex: 0 0 auto;
  height: 7px;
  width: 7px;
}
.warning .status-dot { background: var(--amber); box-shadow: 0 0 0 3px rgba(232, 146, 65, .13); }
.status-copy { line-height: 1; white-space: nowrap; }
.status-copy strong { font-size: 11px; font-weight: 700; }
.status-copy span { display: none; }

.master-toggle, .contact-toggle { align-items: center; cursor: pointer; display: flex; gap: 12px; }
.status-banner .master-toggle { border-left: 1px solid var(--line); gap: 8px; margin-left: 2px; padding-left: 10px; }
.master-toggle > span:first-child { text-align: right; }
.master-toggle strong, .master-toggle small { display: block; }
.master-toggle strong { font-size: 12px; }
.master-toggle small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.master-toggle input, .contact-toggle input { opacity: 0; pointer-events: none; position: absolute; }
.toggle-ui { background: #cbd3dd; border-radius: 20px; height: 24px; position: relative; transition: .2s; width: 43px; }
.toggle-ui::after { background: white; border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,.18); content: ""; height: 18px; left: 3px; position: absolute; top: 3px; transition: .2s; width: 18px; }
input:checked + .toggle-ui { background: var(--green); }
input:checked + .toggle-ui::after { transform: translateX(19px); }
.master-toggle input:disabled + .toggle-ui,
.contact-toggle input:disabled + .toggle-ui { cursor: not-allowed; opacity: .52; }
.toggle-ui.small { height: 21px; width: 38px; }
.toggle-ui.small::after { height: 15px; width: 15px; }
input:checked + .toggle-ui.small::after { transform: translateX(17px); }

.stats-grid { background: white; border: 1px solid var(--line); border-radius: 12px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; overflow: hidden; }
.stat-card { border-right: 1px solid var(--line); min-width: 0; padding: 13px 18px; }
.stat-card:last-child { border-right: 0; }
.stat-card div { min-width: 0; }
.stat-card span { color: var(--muted); display: block; font-size: 10px; white-space: nowrap; }
.stat-card strong { display: block; font-size: 20px; letter-spacing: -.035em; margin-top: 2px; }

.workspace-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(310px, 38%) minmax(0, 1fr);
  height: clamp(740px, 78vh, 900px);
  min-height: 740px;
  overflow: hidden;
}
.conversation-list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pane-header { padding: 21px 20px 13px; }
.pane-header > div:first-child { align-items: baseline; display: flex; justify-content: space-between; margin-bottom: 16px; }
.pane-header h2 { font-size: 17px; margin: 0; }
.pane-header > div:first-child span { color: var(--muted); font-size: 10px; }
.search-box { align-items: center; background: var(--canvas); border: 1px solid transparent; border-radius: 10px; display: flex; gap: 9px; padding: 0 12px; }
.search-box:focus-within { background: white; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(111,91,231,.08); }
.search-box svg { color: #8b96a7; height: 17px; width: 17px; }
.search-box input { background: transparent; border: 0; color: var(--ink); min-width: 0; outline: none; padding: 11px 0; width: 100%; }
.search-box input::placeholder { color: #9ca5b3; }
.filter-row { display: flex; gap: 7px; padding: 0 20px 14px; }
.filter-chip { background: white; border: 1px solid var(--line); border-radius: 20px; color: var(--muted); cursor: pointer; font-size: 10px; font-weight: 700; padding: 7px 11px; }
.filter-chip.active { background: var(--violet-soft); border-color: transparent; color: var(--violet); }
.score-legend { align-items: center; border-top: 1px solid #f2f3f6; color: var(--muted); display: flex; flex-wrap: wrap; font-size: 9px; gap: 10px; padding: 10px 20px; }
.score-legend > span { align-items: center; display: inline-flex; gap: 5px; }
.score-legend > span:first-child { color: var(--ink); font-weight: 750; }
.score-legend .score-dot { display: inline-block; margin: 0; }
.contact-list { border-top: 1px solid var(--line); flex: 1; min-height: 0; overflow-y: auto; }
.contact-row { align-items: center; background: white; border: 0; border-bottom: 1px solid #f0f2f5; cursor: pointer; display: grid; gap: 11px; grid-template-columns: auto minmax(0, 1fr) auto; padding: 15px 18px; text-align: left; width: 100%; }
.contact-row:hover { background: #fafbfe; }
.contact-row.active { background: #f4f1ff; box-shadow: inset 3px 0 var(--violet); }
.avatar { align-items: center; background: #eae7fb; border-radius: 50%; color: #5e4cc7; display: flex; flex: 0 0 auto; font-size: 11px; font-weight: 800; height: 38px; justify-content: center; width: 38px; }
.avatar.large { font-size: 14px; height: 44px; width: 44px; }
.contact-copy { min-width: 0; }
.contact-copy strong, .contact-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-copy strong { font-size: 12px; }
.contact-copy span { color: var(--muted); font-size: 10px; margin-top: 4px; }
.contact-meta { align-self: stretch; display: flex; flex-direction: column; justify-content: space-between; text-align: right; }
.contact-time { color: #9aa4b1; font-size: 9px; white-space: nowrap; }
.score-dot { background: #cad2dc; border-radius: 50%; height: 7px; margin-left: auto; width: 7px; }
.score-dot.hot { background: #e35860; }
.score-dot.warm { background: #e9a22f; }
.score-dot.cold { background: #cad2dc; }
.loading-list { display: grid; gap: 1px; }
.loading-list span { animation: pulse 1.3s infinite; background: linear-gradient(90deg,#f3f5f8,#fafbfc,#f3f5f8); height: 69px; }
@keyframes pulse { 50% { opacity: .55; } }
.no-results { color: var(--muted); padding: 45px 20px; text-align: center; }

.conversation-pane { min-height: 0; min-width: 0; overflow: hidden; position: relative; }
.empty-state { align-items: center; display: flex; flex-direction: column; height: 100%; justify-content: center; padding: 40px; text-align: center; }
.empty-illustration { align-items: center; background: var(--violet-soft); border-radius: 50%; color: var(--violet); display: flex; height: 92px; justify-content: center; margin-bottom: 19px; width: 92px; }
.empty-illustration svg { height: 50px; width: 50px; }
.empty-state h3 { font-size: 16px; margin: 0 0 8px; }
.empty-state p { color: var(--muted); font-size: 12px; margin: 0; }
.conversation-content { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; }
.conversation-header { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; padding: 19px 22px; }
.contact-identity { align-items: center; display: flex; gap: 12px; min-width: 0; }
.contact-identity h2 { font-size: 15px; margin: 0 0 4px; }
.contact-identity span { color: var(--muted); font-size: 10px; }
.contact-toggle { color: var(--muted); font-size: 10px; font-weight: 700; }
.contact-overview { border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1.2fr 1fr 1fr; padding: 15px 22px; }
.contact-overview > div { border-right: 1px solid var(--line); min-width: 0; padding: 0 15px; }
.contact-overview > div:first-child { padding-left: 0; }
.contact-overview > div:last-child { border: 0; padding-right: 0; }
.contact-overview span, .contact-overview strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-overview span { color: var(--muted); font-size: 9px; margin-bottom: 5px; text-transform: uppercase; }
.contact-overview strong { font-size: 11px; }
.detail-tabs { align-items: center; border-bottom: 1px solid var(--line); display: flex; gap: 7px; padding: 11px 22px 0; }
.detail-tab { align-items: center; background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; display: flex; font-size: 11px; font-weight: 750; gap: 7px; padding: 9px 12px 11px; }
.detail-tab svg { height: 16px; width: 16px; }
.detail-tab:hover { color: var(--ink); }
.detail-tab.active { border-bottom-color: var(--violet); color: var(--violet); }
.detail-panel { flex: 1; min-height: 0; }
.summary-panel { overflow-y: auto; padding-bottom: 22px; }
.summary-box { background: #faf9fe; border: 1px solid #ebe7fb; border-radius: 11px; margin: 18px 22px 5px; padding: 18px; }
.section-title { align-items: center; display: flex; font-size: 11px; font-weight: 800; justify-content: space-between; }
.section-title small { color: var(--muted); font-size: 9px; font-weight: 600; }
.score-badge { background: var(--violet-soft); border-radius: 20px; color: var(--violet); font-size: 9px; padding: 5px 8px; }
.summary-box p { color: #5f6879; font-size: 11px; line-height: 1.6; margin: 9px 0 0; white-space: pre-wrap; }
.message-section { display: flex; flex-direction: column; overflow: hidden; padding: 16px 22px 22px; }
.messages { display: flex; flex: 1 1 0; flex-direction: column; gap: 11px; margin-top: 14px; min-height: 0; overscroll-behavior: contain; overflow-y: auto; padding: 4px 8px 5px 0; scrollbar-gutter: stable; }
.message { display: flex; flex-direction: column; max-width: 76%; }
.message.user { align-self: flex-start; }
.message.bot { align-self: flex-end; }
.bubble { background: #f0f2f5; border-radius: 4px 13px 13px 13px; color: #374151; font-size: 11px; line-height: 1.55; padding: 10px 12px; white-space: pre-wrap; }
.message.bot .bubble { background: var(--violet); border-radius: 13px 4px 13px 13px; color: white; }
.message.agent { align-self: flex-end; }
.message.agent .bubble { background: #1b1b4b; border: 2px solid var(--brand-mint); border-radius: 13px 4px 13px 13px; color: white; }
.message time { color: #99a2ae; font-size: 8px; margin-top: 4px; }
.message.bot time, .message.agent time { text-align: right; }
.message-author { color: var(--navy); font-size: 8px; font-weight: 800; margin: 0 5px 3px; text-align: right; text-transform: uppercase; }
.empty-messages { color: var(--muted); font-size: 11px; margin: auto; }

.manual-handoff { border-top: 1px solid var(--line); flex: 0 0 auto; margin-top: 8px; padding-top: 8px; }
.handoff-state { align-items: center; color: var(--muted); display: flex; font-size: 9px; gap: 7px; margin-bottom: 6px; }
.handoff-dot { background: var(--amber); border-radius: 50%; height: 7px; width: 7px; }
.manual-handoff.ready .handoff-dot { background: var(--green); }
.manual-handoff.blocked .handoff-dot { background: var(--red); }
.manual-reply-form { align-items: flex-end; background: #f7f8fb; border: 1px solid #e4e8ef; border-radius: 10px; display: flex; gap: 8px; padding: 6px 8px; }
.manual-reply-form:focus-within { background: white; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(8,0,90,.07); }
.manual-reply-form textarea { background: transparent; border: 0; color: var(--ink); flex: 1; line-height: 1.4; max-height: 72px; min-height: 34px; outline: none; resize: vertical; }
.manual-reply-form textarea:disabled { cursor: not-allowed; opacity: .6; }
.manual-reply-actions { align-items: flex-end; display: flex; flex-direction: column; gap: 7px; }
.manual-reply-actions small { color: var(--muted); font-size: 8px; }
.send-button { align-items: center; background: var(--navy); border: 0; border-radius: 8px; color: white; cursor: pointer; display: flex; font-size: 10px; font-weight: 750; gap: 6px; padding: 9px 11px; }
.send-button:hover:not(:disabled) { background: var(--navy-soft); }
.send-button:disabled { cursor: not-allowed; opacity: .42; }
.send-button svg { height: 13px; width: 13px; }

.toast { background: #20273a; border-radius: 10px; bottom: 22px; color: white; font-size: 12px; opacity: 0; padding: 12px 16px; pointer-events: none; position: fixed; right: 22px; transform: translateY(12px); transition: .25s; z-index: 30; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #a93643; }

.modal-backdrop { align-items: center; background: rgba(9, 15, 32, .55); display: flex; inset: 0; justify-content: center; padding: 24px; position: fixed; z-index: 50; }
.settings-dialog { background: white; border-radius: 16px; box-shadow: 0 28px 80px rgba(8, 15, 35, .25); display: flex; flex-direction: column; max-height: calc(100vh - 48px); max-width: 880px; padding: 25px; width: 100%; }
.settings-header { align-items: flex-start; display: flex; justify-content: space-between; }
.settings-header h2 { font-size: 22px; letter-spacing: -.025em; margin: 0; }
.dialog-close { align-items: center; background: #f4f6f9; border: 0; border-radius: 9px; cursor: pointer; display: flex; font-size: 22px; height: 34px; justify-content: center; line-height: 1; width: 34px; }
.settings-intro { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 12px 0 15px; }
.prompt-meta { align-items: center; color: var(--muted); display: flex; font-size: 10px; justify-content: space-between; margin-bottom: 8px; }
.prompt-state { background: #f0f2f6; border-radius: 20px; color: #455167; font-weight: 700; padding: 5px 9px; }
.prompt-state.custom { background: var(--green-soft); color: #087b59; }
.prompt-label { color: #344055; font-size: 11px; font-weight: 750; margin-bottom: 7px; }
#assistantPromptInput { border: 1px solid #dce2ea; border-radius: 11px; color: var(--ink); flex: 1; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; line-height: 1.55; min-height: 390px; outline: none; padding: 15px; resize: vertical; }
#assistantPromptInput:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(8,0,90,.07); }
.settings-footer { align-items: center; color: var(--muted); display: flex; font-size: 10px; justify-content: space-between; padding-top: 14px; }
.settings-footer > div { display: flex; gap: 7px; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card:nth-child(2) { border-right: 0; }
  .stat-card:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .workspace-card { grid-template-columns: minmax(285px, 42%) minmax(0, 1fr); }
  .contact-overview { grid-template-columns: 1fr; gap: 10px; }
  .contact-overview > div { border: 0; padding: 0; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { align-items: center; flex-direction: row; height: auto; min-height: auto; padding: 12px 16px; position: static; }
  .brand { flex: 1; margin: 0; }
  .sidebar-logo { max-width: 88px; }
  .sidebar nav, .connection-pill { display: none; }
  .sidebar-footer { border: 0; padding: 0; }
  .nav-item.logout { margin: 0; width: auto; }
  .nav-item.logout svg { margin: 0; }
  .nav-item.logout { font-size: 0; }
  main { padding: 22px 15px 30px; }
  .topbar { align-items: flex-start; }
  .topbar-actions { gap: 7px; }
  .topbar .muted, .sync-label { display: none; }
  .status-banner .master-toggle > span:first-child { display: none; }
  .status-banner .master-toggle { padding-left: 8px; }
  .stat-card { padding: 13px; }
  .stat-card span { font-size: 9px; }
  .workspace-card { display: block; height: auto; min-height: 620px; }
  .conversation-list-pane { border: 0; }
  .contact-list { max-height: 430px; }
  .conversation-pane { background: white; inset: 0; min-height: 100vh; position: fixed; transform: translateX(100%); transition: transform .25s; z-index: 10; }
  .conversation-pane.open { transform: translateX(0); }
  .conversation-header::before { color: var(--violet); content: "←"; cursor: pointer; font-size: 22px; margin-right: 8px; }
  .conversation-content { min-height: 100vh; }
  .detail-tabs { padding-left: 16px; }
  .messages { max-height: none; }
  .login-card { padding: 32px 25px; }
  .modal-backdrop { padding: 12px; }
  .settings-dialog { max-height: calc(100vh - 24px); padding: 18px; }
  #assistantPromptInput { min-height: 320px; }
  .settings-footer { align-items: stretch; flex-direction: column; gap: 10px; }
  .settings-footer > div { justify-content: flex-end; }
}
