:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-subtle: #f7f9fc;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-hover: #f2f6fb;
  --sidebar: #03264c;
  --sidebar-deep: #021d3a;
  --sidebar-active: #0b477f;
  --sidebar-text: #dce7f3;
  --text: #111827;
  --text-secondary: #526071;
  --text-muted: #7f8a99;
  --border: #dfe5ec;
  --border-strong: #c9d2dc;
  --accent: #0b5ed7;
  --accent-hover: #084fb8;
  --accent-soft: #edf5ff;
  --success: #23845b;
  --warning: #b7791f;
  --danger: #bb3e46;
  --neutral: #8a96a6;
  --shadow: 0 8px 24px rgba(26, 43, 66, 0.08);
  --sidebar-width: 244px;
  --topbar-height: 64px;
  --radius-sm: 6px;
  --radius: 9px;
  --radius-lg: 12px;
  --transition: 160ms ease;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e141c;
  --bg-subtle: #111a24;
  --surface: #121b26;
  --surface-raised: #18222e;
  --surface-hover: #1a2633;
  --sidebar: #031f3f;
  --sidebar-deep: #021831;
  --sidebar-active: #0d4276;
  --sidebar-text: #dce7f3;
  --text: #f3f6fa;
  --text-secondary: #adb8c7;
  --text-muted: #7f8c9e;
  --border: #293544;
  --border-strong: #3b4858;
  --accent: #4d93ff;
  --accent-hover: #72a9ff;
  --accent-soft: #132b49;
  --success: #48b889;
  --warning: #d4a44d;
  --danger: #e46d74;
  --neutral: #6f7d90;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, a, input, select, textarea { outline: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent); border-color: var(--accent) !important; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 32px; background: var(--bg-subtle); position: relative; }
.auth-brand { position: absolute; left: 36px; top: 28px; display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 750; letter-spacing: .08em; color: var(--text); }
.brand-rule { display: inline-block; width: 3px; height: 22px; background: var(--accent); border-radius: 2px; }
.auth-theme { position: absolute; right: 28px; top: 22px; }
.login-panel { width: min(100%, 420px); padding: 38px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.login-heading { margin-bottom: 30px; }
.login-heading h1 { margin: 0 0 8px; font-size: 28px; line-height: 1.2; letter-spacing: -.025em; }
.login-heading p { margin: 0; color: var(--text-secondary); }
.login-panel form { display: grid; gap: 10px; }
.login-panel label { margin-top: 8px; font-size: 13px; font-weight: 650; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); padding: 9px 12px; transition: border var(--transition), background var(--transition); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
.form-error { min-height: 20px; margin: 3px 0 0; color: var(--danger); font-size: 13px; }
.login-footnote { margin: 22px 0 0; text-align: center; color: var(--text-muted); font-size: 12px; }

.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); padding: 8px 14px; font-size: 13px; font-weight: 650; transition: background var(--transition), border var(--transition), color var(--transition); }
.button:hover { background: var(--surface-hover); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.danger { color: var(--danger); }
.button.full { width: 100%; margin-top: 8px; }
.button svg { width: 17px; height: 17px; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.icon-button { width: 40px; height: 40px; display: inline-grid; place-items: center; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; }
.icon-button:hover { background: var(--surface-hover); border-color: var(--border); }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--sidebar-width); display: flex; flex-direction: column; background: var(--sidebar); color: var(--sidebar-text); border-right: 1px solid rgba(255,255,255,.08); }
.brand { height: var(--topbar-height); display: flex; align-items: center; gap: 11px; padding: 0 24px; font-size: 16px; font-weight: 780; letter-spacing: .055em; color: #fff; border-bottom: 1px solid rgba(255,255,255,.09); white-space: nowrap; }
.brand .brand-rule { background: #65a8ff; }
.main-nav { display: grid; gap: 5px; padding: 28px 12px; }
.nav-item { width: 100%; height: 45px; display: flex; align-items: center; gap: 13px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--sidebar-text); padding: 0 13px; font-size: 14px; font-weight: 540; text-align: left; }
.nav-item svg { width: 21px; height: 21px; flex: 0 0 auto; }
.nav-item:hover { background: rgba(255,255,255,.065); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; border-color: rgba(255,255,255,.08); }
.nav-count { margin-left: auto; min-width: 21px; height: 21px; display: inline-grid; place-items: center; background: #fff; color: var(--sidebar); border-radius: 11px; font-size: 11px; font-weight: 750; }
.sidebar-footer { margin-top: auto; min-height: 68px; display: flex; align-items: center; padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-status { display: flex; align-items: center; gap: 9px; color: #afc0d3; font-size: 11.5px; }
.status-dot { display: inline-block; width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--neutral); }
.status-dot.success { background: var(--success); }
.status-dot.warning { background: var(--warning); }
.status-dot.danger { background: var(--danger); }
.status-dot.neutral { background: var(--neutral); }

.workspace { min-height: 100vh; margin-left: var(--sidebar-width); background: var(--bg); }
.topbar { height: var(--topbar-height); position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: flex-end; gap: 18px; padding: 0 28px; background: color-mix(in srgb, var(--bg) 96%, transparent); border-bottom: 1px solid var(--border); backdrop-filter: blur(10px); }
.global-search { width: min(360px, 40vw); position: relative; margin-right: auto; }
.global-search svg { position: absolute; left: 12px; top: 11px; width: 18px; height: 18px; color: var(--text-muted); pointer-events: none; }
.global-search input { height: 40px; padding-left: 40px; background: var(--bg-subtle); border-color: var(--border); }
.topbar-actions { display: flex; align-items: center; gap: 4px; position: relative; }
.topbar-divider { width: 1px; height: 28px; background: var(--border); margin: 0 10px; }
.user-menu-button { height: 40px; display: flex; align-items: center; gap: 9px; padding: 0 4px; border: 0; background: transparent; font-size: 13px; font-weight: 620; }
.user-menu-button > svg:first-child { width: 19px; height: 19px; }
.user-chevron { width: 14px; height: 14px; transform: rotate(90deg); color: var(--text-muted); }
.user-menu { position: absolute; right: 0; top: 48px; width: 170px; padding: 6px; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.user-menu button { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 9px 10px; border-radius: var(--radius-sm); text-align: left; font-size: 13px; }
.user-menu button:hover { background: var(--surface-hover); }
.user-menu svg { width: 17px; height: 17px; }
.mobile-menu { display: none; }
.page-content { min-height: calc(100vh - var(--topbar-height)); }

.page-shell { padding: 34px 34px 42px; max-width: 1600px; margin: 0 auto; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 25px; border-bottom: 1px solid var(--border); }
.page-heading h1 { margin: 0; font-size: 29px; line-height: 1.2; letter-spacing: -.025em; }
.page-heading p { margin: 7px 0 0; color: var(--text-secondary); }
.heading-actions { display: flex; align-items: center; gap: 8px; }
.metric-rail { min-height: 126px; display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--border); }
.metric { display: grid; grid-template-columns: 40px 1fr; align-content: center; column-gap: 14px; padding: 25px 30px; border-right: 1px solid var(--border); }
.metric:first-child { padding-left: 16px; }
.metric:last-child { border-right: 0; }
.metric svg { grid-row: 1 / span 2; align-self: center; width: 31px; height: 31px; color: var(--text-secondary); }
.metric-label { color: var(--text-secondary); font-size: 12.5px; }
.metric-value { margin-top: 4px; font-size: 35px; line-height: 1; font-weight: 620; letter-spacing: -.03em; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 350px; min-height: 520px; }
.dashboard-main { padding: 28px 26px 0 0; border-right: 1px solid var(--border); }
.dashboard-side { padding: 28px 0 0 26px; }
.section-header { min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-header h2 { margin: 0; font-size: 18px; letter-spacing: -.012em; }
.section-header .button { min-height: 34px; }
.table-frame { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th { height: 48px; padding: 0 14px; background: var(--bg-subtle); border-bottom: 1px solid var(--border); color: var(--text-secondary); font-size: 11.5px; font-weight: 700; letter-spacing: .02em; text-align: left; }
.data-table td { height: 58px; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--surface-hover); }
.primary-cell { font-weight: 650; }
.secondary-cell { color: var(--text-secondary); }
.empty-state { min-height: 340px; display: grid; place-items: center; text-align: center; padding: 40px; }
.empty-state-inner { display: grid; justify-items: center; }
.empty-icon { width: 54px; height: 54px; display: grid; place-items: center; border: 1px solid var(--border-strong); border-radius: 50%; color: var(--text-secondary); }
.empty-icon svg { width: 25px; height: 25px; }
.empty-state h3 { margin: 15px 0 4px; font-size: 15px; }
.empty-state p { margin: 0; color: var(--text-muted); font-size: 12.5px; }
.table-footer { height: 50px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 12px; }
.status-list { border-top: 1px solid var(--border); }
.status-row { min-height: 56px; display: grid; grid-template-columns: 1fr auto; align-items: center; border-bottom: 1px solid var(--border); font-size: 13px; }
.status-value { display: flex; align-items: center; gap: 9px; color: var(--text-secondary); }
.text-link { display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; border: 0; background: transparent; color: var(--accent); padding: 0; font-size: 13px; font-weight: 620; }
.text-link svg { width: 15px; height: 15px; }
.pipeline { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--border); }
.pipeline h2 { margin: 0 0 24px; font-size: 18px; }
.pipeline-steps { display: grid; grid-template-columns: repeat(4, 1fr); }
.pipeline-step { position: relative; text-align: center; }
.pipeline-step:not(:last-child)::after { content: ""; position: absolute; top: 16px; left: calc(50% + 17px); right: calc(-50% + 17px); height: 1px; background: var(--border-strong); }
.step-number { width: 33px; height: 33px; position: relative; z-index: 1; display: grid; place-items: center; margin: 0 auto 10px; border: 1px solid var(--border-strong); border-radius: 50%; background: var(--surface); font-size: 12px; }
.pipeline-step:first-child .step-number { border-color: var(--accent); color: var(--accent); }
.step-label { min-height: 35px; color: var(--text-secondary); font-size: 11.5px; line-height: 1.25; }
.step-count { margin-top: 8px; font-size: 24px; font-weight: 540; }

.status-chip { display: inline-flex; align-items: center; gap: 7px; color: var(--text-secondary); font-size: 12px; }
.status-chip .status-dot { width: 7px; height: 7px; }
.filters { display: flex; gap: 6px; }
.filter-button { min-height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); padding: 6px 10px; color: var(--text-secondary); font-size: 12px; }
.filter-button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ========================================================
   CONVERSATION WORKSPACE (REDESIGNED)
   ======================================================== */
.conversation-layout {
  height: calc(100dvh - var(--topbar-height));
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  overflow: hidden;
  background: var(--bg);
}
.conversation-layout.has-selection {
  grid-template-columns: 260px minmax(0, 1fr) 280px;
}
.conversation-layout.has-selection.inspector-collapsed {
  grid-template-columns: 260px minmax(0, 1fr);
}
.conversation-layout.inspector-collapsed .inspector {
  display: none !important;
}

/* 1. Left Sidebar: Conversation List */
.conversation-list-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.conversation-list-head {
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.conv-head-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.conv-head-top h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.conv-total-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
}
.conversation-search {
  position: relative;
  margin-bottom: 10px;
}
.conversation-search svg {
  position: absolute;
  left: 11px;
  top: 11px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}
.conversation-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 13px;
  color: var(--text);
  box-sizing: border-box;
  transition: border-color var(--transition), background var(--transition);
}
.conversation-search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.conversation-filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.conv-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.conv-filter-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.conv-filter-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.conv-filter-badge {
  padding: 1px 5px;
  border-radius: 10px;
  font-size: 10px;
  background: rgba(0,0,0,0.06);
}
.conv-filter-btn.active .conv-filter-badge {
  background: var(--accent);
  color: #fff;
}
.conversation-items {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 8px 16px;
}

/* Individual Conversation Row */
.conversation-row {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 5px;
  padding: 12px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  text-align: left;
  position: relative;
  transition: all var(--transition);
}
.conversation-row:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}
.conversation-row.active {
  background: var(--surface-raised);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  box-shadow: 0 4px 12px rgba(11, 94, 215, 0.08);
}
.conversation-row.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3.5px;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
}
.conv-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.conv-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 750;
  font-size: 13px;
  color: #ffffff;
  box-shadow: 0 2px 5px rgba(0,0,0,0.12);
}
.conv-beacon {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--surface);
}
.conv-beacon.success { background: #10b981; }
.conv-beacon.warning {
  background: #f59e0b;
  animation: pulse-beacon 1.6s ease-in-out infinite;
}
.conv-beacon.neutral { background: #6366f1; }
@keyframes pulse-beacon {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); }
  70% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

.conv-row-body {
  flex: 1;
  min-width: 0;
}
.conv-meta-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}
.conv-row-name {
  font-size: 13px;
  font-weight: 680;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-row-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-weight: 500;
}
.conv-tags-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 4px;
}
.status-pill.success {
  background: rgba(35, 132, 91, 0.1);
  color: var(--success);
}
.status-pill.warning {
  background: rgba(183, 121, 31, 0.12);
  color: #d97706;
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.status-pill.neutral {
  background: rgba(99, 102, 241, 0.1);
  color: #6366f1;
}
.lead-chip {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
}
.conv-preview-text {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}
.check-tick {
  color: var(--accent);
  font-weight: 700;
  margin-right: 3px;
}
.list-empty {
  padding: 40px 18px;
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
}

/* 2. Center: Chat Panel */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  background: var(--bg-subtle);
  position: relative;
}
.chat-head {
  height: 68px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
  z-index: 10;
  flex-shrink: 0;
}
.chat-back {
  display: none;
}
.chat-back svg {
  transform: rotate(180deg);
}
.chat-head-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 750;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 5px rgba(0,0,0,0.12);
}
.chat-head-info {
  min-width: 0;
  flex: 1;
}
.chat-head-name-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-head-name {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #22c55e;
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  flex-shrink: 0;
}
.chat-head-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 1px;
}
.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* AI Summary Card */
.ai-summary-card {
  margin: 12px 18px 0;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  box-shadow: 0 6px 20px rgba(11, 94, 215, 0.08);
  font-size: 13px;
  line-height: 1.55;
  animation: summarySlideDown 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}
@keyframes summarySlideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.ai-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 700;
  color: var(--accent);
  font-size: 13.5px;
}
.ai-summary-close {
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
}
.ai-summary-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.ai-summary-body {
  white-space: pre-wrap;
  color: var(--text);
}

/* Messages Area */
.chat-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: var(--bg-subtle);
  background-image: radial-gradient(var(--border) 0.85px, transparent 0.85px);
  background-size: 18px 18px;
}
.chat-date-pill {
  align-self: center;
  margin: 8px 0;
  padding: 4px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.message-bubble-row {
  display: flex;
  flex-direction: column;
  max-width: min(74%, 640px);
  animation: bubbleFadeIn 0.15s ease-out;
}
@keyframes bubbleFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.message-bubble-row.user {
  align-self: flex-start;
}
.message-bubble-row.assistant,
.message-bubble-row.agent {
  align-self: flex-end;
}

.chat-bubble {
  padding: 10px 14px 8px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-bubble-row.user .chat-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  color: var(--text);
}
.message-bubble-row.assistant .chat-bubble {
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 7%, var(--surface)), color-mix(in srgb, var(--accent) 14%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--border));
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 1px 3px rgba(11, 94, 215, 0.04);
  color: var(--text);
}
.message-bubble-row.agent .chat-bubble {
  background: linear-gradient(135deg, #0b5ed7, #084fb8);
  border: 1px solid #084fb8;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 3px 10px rgba(11, 94, 215, 0.22);
  color: #ffffff;
}

.bubble-author {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 4px;
}
.message-bubble-row.user .bubble-author { color: #0284c7; }
.message-bubble-row.assistant .bubble-author { color: var(--accent); }
.message-bubble-row.agent .bubble-author { color: rgba(255,255,255,0.9); }

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 10px;
}
.message-bubble-row.user .bubble-meta,
.message-bubble-row.assistant .bubble-meta { color: var(--text-muted); }
.message-bubble-row.agent .bubble-meta { color: rgba(255,255,255,0.7); }
.double-tick {
  color: var(--accent);
  font-weight: 700;
  font-size: 11px;
}
.message-bubble-row.agent .double-tick {
  color: rgba(255,255,255,0.85);
}
.chat-link {
  color: var(--accent);
  text-decoration: underline;
  word-break: break-all;
}
.message-bubble-row.agent .chat-link {
  color: #ffffff;
  text-decoration: underline;
}

/* Canned responses bar */
.canned-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.canned-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.canned-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.canned-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  transform: translateY(-1px);
}

/* Composer */
.composer-area {
  padding: 8px 18px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.composer-takeover-tip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  background: rgba(11, 94, 215, 0.06);
  border: 1px solid rgba(11, 94, 215, 0.18);
  font-size: 11.5px;
  color: var(--text-secondary);
}
.composer-takeover-tip button {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: 20px;
  background: var(--bg-subtle);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.composer-box:focus-within {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(11, 94, 215, 0.12);
}
.composer-box textarea {
  flex: 1;
  min-height: 24px;
  max-height: 120px;
  border: 0;
  padding: 3px 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  resize: none;
  outline: none;
  box-shadow: none !important;
}
.composer-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}
.composer-send-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}
.composer-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.composer-send-btn svg {
  width: 16px;
  height: 16px;
}

/* 3. Right Sidebar: Inspector */
.inspector {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--surface);
}
.inspector-hero {
  padding: 24px 20px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-subtle) 0%, var(--surface) 100%);
}
.inspector-hero-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 750;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.14);
}
.inspector-hero-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.inspector-hero-phone {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.inspector-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.inspector-section h2 {
  margin: 0 0 12px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.spec-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.spec-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.spec-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.spec-val {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}
.inspector-stage-select {
  width: 100%;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  padding: 0 10px;
  margin-top: 6px;
}
.inspector-actions-box {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Empty Conversation Workspace */
.chat-empty-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  background: var(--bg-subtle);
}
.chat-empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  margin-bottom: 16px;
}
.chat-empty-icon svg {
  width: 32px;
  height: 32px;
}
.chat-empty-workspace h3 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.chat-empty-workspace p {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 360px;
  line-height: 1.5;
}

.content-section { margin-top: 24px; }
.list-toolbar { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.list-toolbar input { max-width: 320px; }
.subtle-count { color: var(--text-muted); font-size: 12px; align-self: center; }
.product-list { border-top: 1px solid var(--border); }
.product-row { display: grid; grid-template-columns: 130px 1.2fr 1fr 1.4fr auto; gap: 18px; align-items: center; padding: 17px 4px; border-bottom: 1px solid var(--border); }
.product-model { font-weight: 750; }
.product-name { font-weight: 620; }
.product-category, .product-specs { color: var(--text-secondary); font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 390px); gap: 30px; margin-top: 28px; }
.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); gap: 32px; margin-top: 24px; }
.settings-section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.full-width { grid-column: 1 / -1; }
.form-field label { font-size: 13px; font-weight: 600; color: var(--text-primary, currentColor); }
.form-field input { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text-primary, currentColor); font-size: 13px; box-sizing: border-box; }
.form-field input:focus { outline: none; border-color: var(--accent); }
.field-hint { font-size: 11.5px; color: var(--text-secondary); line-height: 1.4; }
.input-with-action { position: relative; display: flex; align-items: center; width: 100%; }
.input-with-action input { padding-right: 42px; }
.input-with-action .toggle-pwd { position: absolute; right: 6px; height: 28px; width: 28px; border: 0; background: transparent; cursor: pointer; color: var(--text-secondary); display: flex; align-items: center; justify-content: center; padding: 0; }
.test-result-box { margin-bottom: 16px; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; line-height: 1.5; }
.test-result-box.success { background: rgba(34, 197, 94, 0.12); border: 1px solid rgba(34, 197, 94, 0.35); color: #16a34a; }
.test-result-box.error { background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239, 68, 68, 0.35); color: #dc2626; }
.form-actions-bar { display: flex; align-items: center; gap: 16px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.settings-section { padding: 22px 0; border-top: 1px solid var(--border); }
.settings-section:first-child { border-top: 0; padding-top: 0; }
.settings-section h2 { margin: 0 0 7px; font-size: 16px; }
.settings-section > p { margin: 0 0 18px; color: var(--text-secondary); font-size: 12.5px; }
.setting-row { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border); }
.setting-row strong { display: block; font-size: 13px; }
.setting-row span { color: var(--text-secondary); font-size: 11.5px; }
.connection-panel { padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-subtle); }
.connection-panel h2 { margin: 0 0 12px; font-size: 16px; }
.report-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-top: 28px; background: var(--border); border: 1px solid var(--border); }
.report-stat { min-height: 118px; background: var(--surface); padding: 22px; }
.report-stat span { color: var(--text-secondary); font-size: 12px; }
.report-stat strong { display: block; margin-top: 9px; font-size: 30px; }
.report-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 30px; }
.bar-list { border-top: 1px solid var(--border); }
.bar-row { padding: 13px 0; border-bottom: 1px solid var(--border); }
.bar-meta { display: flex; justify-content: space-between; margin-bottom: 7px; font-size: 12px; }
.bar-track { height: 5px; background: var(--bg-subtle); }
.bar-fill { height: 100%; background: var(--accent); }
.user-card { max-width: 620px; display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: center; padding: 18px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.user-card .avatar { width: 46px; height: 46px; }
.user-card strong { display: block; }
.user-card span { color: var(--text-secondary); font-size: 12px; }
.role-label { color: var(--text-secondary); font-size: 12px; }
.skeleton { background: var(--surface-hover); animation: skeleton-pulse 1.4s ease-in-out infinite alternate; border-radius: 4px; }
@keyframes skeleton-pulse { to { opacity: .48; } }
.toast-region { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: grid; gap: 8px; width: min(380px, calc(100vw - 40px)); }
.toast { padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-raised); box-shadow: var(--shadow); font-size: 13px; animation: toast-in 180ms ease both; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1180px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-main { padding-right: 0; border-right: 0; }
  .dashboard-side { padding-left: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
  .pipeline { margin-top: 0; padding-top: 0; border-top: 0; }
  .conversation-layout, .conversation-layout.has-selection, .conversation-layout.has-selection.inspector-collapsed { grid-template-columns: 260px minmax(0, 1fr); }
  .inspector { position: fixed; right: 0; top: var(--topbar-height); bottom: 0; z-index: 25; width: 320px; box-shadow: var(--shadow); transform: translateX(100%); transition: transform var(--transition); }
  .inspector.open { transform: translateX(0); }
}

@media (max-width: 820px) {
  :root { --sidebar-width: 244px; }
  .sidebar { transform: translateX(-100%); transition: transform var(--transition); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: block; position: fixed; inset: 0; z-index: 29; border: 0; background: rgba(4,12,22,.48); }
  .workspace { margin-left: 0; }
  .mobile-menu { display: inline-grid; }
  .topbar { justify-content: flex-start; padding: 0 14px; }
  .global-search { flex: 1; width: auto; }
  .topbar-actions { margin-left: auto; }
  #refresh-button { display: none; }
  .page-shell { padding: 24px 18px 36px; }
  .metric-rail { grid-template-columns: 1fr 1fr; }
  .metric { border-bottom: 1px solid var(--border); }
  .metric:nth-child(2) { border-right: 0; }
  .dashboard-side { grid-template-columns: 1fr; }
  .conversation-layout, .conversation-layout.has-selection, .conversation-layout.has-selection.inspector-collapsed { grid-template-columns: minmax(0, 1fr); }
  .conversation-list-panel { border-right: 0; }
  .conversation-layout.has-selection .conversation-list-panel { display: none; }
  .conversation-layout:not(.has-selection) .chat-panel { display: none; }
  .chat-back { display: inline-grid; }
  .chat-messages { padding: 18px; }
  .message { max-width: 88%; }
  .settings-grid, .settings-layout, .report-columns { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-section-head, .form-actions-bar { flex-wrap: wrap; }
  .form-field input, .composer-box textarea { font-size: 16px; }
  .settings-layout { gap: 20px; }
  .input-with-action .toggle-pwd { height: 40px; width: 40px; right: 0; }
  .form-field input { min-height: 44px; }
  .product-row { grid-template-columns: 100px 1fr auto; }
  .product-category, .product-specs { display: none; }
}

@media (max-width: 560px) {
  .auth-screen { padding: 20px; align-items: center; }
  .auth-brand { left: 20px; top: 20px; }
  .login-panel { padding: 26px 22px; }
  .topbar { gap: 8px; }
  .global-search { display: none; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .topbar-divider { margin: 0 5px; }
  .user-menu-button span { display: none; }
  .page-heading { display: block; }
  .heading-actions { margin-top: 16px; }
  .metric { grid-template-columns: 30px 1fr; padding: 20px 12px; }
  .metric:first-child { padding-left: 12px; }
  .metric svg { width: 24px; height: 24px; }
  .metric-value { font-size: 28px; }
  .data-table th:nth-child(2), .data-table td:nth-child(2), .data-table th:nth-child(3), .data-table td:nth-child(3), .data-table th:nth-child(5), .data-table td:nth-child(5) { display: none; }
  .report-grid { grid-template-columns: 1fr; }
  .conversation-filters { padding-bottom: 3px; }
  .chat-head { padding: 0 10px; }
  .chat-head .avatar { display: none; }
  .chat-head-status { display: none; }
  .chat-head-actions .button span { display: none; }
  .composer-area { padding: 6px 10px 10px; }
}

/* Compact content, with full-size touch controls. */
.chat-bubble { white-space: normal; padding: 8px 12px; overflow-wrap: anywhere; }
.bubble-text { white-space: pre-wrap; }
.bubble-author svg { width: 13px; height: 13px; }
.chat-messages { gap: 10px; background-image: none; padding: 14px; }
.chat-head { height: auto; min-height: 64px; padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
.chat-head-info { flex: 1 1 110px; }
.chat-head-sub { overflow-wrap: anywhere; }
.chat-head-actions { flex-wrap: wrap; gap: 4px; }
.chat-head-actions .button { min-width: 40px; min-height: 40px; padding: 8px; }
.chat-head-actions .button span { display: none; }
.chat-head-avatar { width: 32px; height: 32px; }
.canned-bar { flex-wrap: nowrap; overflow-x: auto; padding: 8px 12px; }
.canned-chip { flex-shrink: 0; min-height: 36px; }
.composer-takeover-tip { padding: 6px 0; font-size: 11px; }
.composer-area { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.settings-layout > *, .form-grid > * { min-width: 0; }
#btn-test-deepseek { min-height: 44px; }
#deepseek-side-status .status-row { flex-wrap: wrap; }
#deepseek-side-status .status-value { white-space: normal; }
.conversation-row { padding-top: 12px; padding-bottom: 12px; }
.conversation-filters { gap: 4px; }
.conv-filter-btn { padding-inline: 7px; font-size: 11px; flex-shrink: 0; }
.inspector { overflow-y: auto; overscroll-behavior: contain; }
.inspector-close { display: none; }
.message-bubble-row { max-width: 100%; animation: none; }
.message-bubble-row .chat-bubble { max-width: 90%; }
@media (max-width: 1180px) {
  .inspector { width: min(340px, 100vw); }
  .inspector-close { display: inline-flex; min-height: 44px; align-items: center; }
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .chat-head-avatar { display: none; }
  .chat-head-info { flex-basis: calc(100% - 52px); }
  .chat-head-actions { width: 100%; justify-content: flex-end; }
  .chat-head-actions .button span { display: inline; font-size: 11px; }
  .chat-head-actions .button, .chat-back, .conv-filter-btn, .canned-chip { min-height: 44px; }
  .chat-head-actions .button svg { width: 16px; height: 16px; }
  .page-shell { padding: 18px 14px 28px; }
  .chat-messages { padding: 12px; }
  .composer-takeover-tip span { max-width: 85%; }
  .heading-actions { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
