* { box-sizing: border-box; }

:root {
  --ergo-red: #e30613;
  --ergo-red-dark: #b80510;
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --end-btn: #374151;
  --end-btn-hover: #1f2937;
  --user-bubble: #2563eb;
  --model-bubble: #f3f4f6;
  --sidebar-width: 360px;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Roboto", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

/* ===== Transcript sidebar ===== */
.transcript-sidebar {
  width: 0;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid transparent;
  overflow: hidden;
  transition: width 0.3s ease, border-color 0.3s ease;
  display: flex;
  flex-direction: column;
}

.transcript-sidebar.open {
  width: var(--sidebar-width);
  border-right-color: var(--border);
}

.transcript-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  min-width: var(--sidebar-width);
}

.transcript-header .material-icons {
  color: var(--user-bubble);
}

.transcript-header h2 {
  flex: 1;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.icon-btn {
  background: transparent;
  border: none;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--text-muted);
}

.icon-btn:hover { background: var(--bg); color: var(--text); }

.transcript-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  min-width: var(--sidebar-width);
  position: relative;
}

.transcript-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}

.transcript-empty .material-icons {
  font-size: 40px;
  opacity: 0.5;
}

.transcript-empty p {
  margin: 0;
  font-size: 14px;
}

.transcript-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.msg-bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-bubble.assistant {
  align-self: flex-start;
  background: var(--model-bubble);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-bubble.live { opacity: 0.75; }

/* ===== Main stage ===== */
.main-stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 72px 24px 52px;
  gap: 16px;
  min-width: 0;
}

.top-bar-left {
  position: absolute;
  top: 20px;
  left: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10;
}

.ergo-logo {
  height: 44px;
  width: auto;
  object-fit: contain;
}

.toggle-pill {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: background-color 0.15s ease;
}

.toggle-pill:hover { background: #fff; }
.toggle-pill.active {
  background: #dbeafe;
  color: var(--user-bubble);
  border-color: #bfdbfe;
}
.toggle-pill.ptt-pill {
  padding: 8px 14px 8px 10px;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}
.ptt-label {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.toggle-pill.ptt-on {
  background: var(--ergo-red);
  color: #fff;
  border-color: var(--ergo-red);
  box-shadow: 0 2px 8px rgba(227, 6, 19, 0.35);
}
.toggle-pill.ptt-on:hover {
  background: var(--ergo-red-dark);
}
.ptt-hint {
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
  backdrop-filter: blur(6px);
}
.ptt-hint kbd {
  font-family: inherit;
  font-weight: 700;
  background: rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 1px 5px;
}

.top-bar-right {
  position: absolute;
  top: 20px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10;
}

/* Pulsing ring on mic button while PTT is actively transmitting */
@keyframes ptt-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(227, 6, 19, 0.5); }
  70%  { box-shadow: 0 0 0 8px rgba(227, 6, 19, 0); }
  100% { box-shadow: 0 0 0 0 rgba(227, 6, 19, 0); }
}
.device-btn.ptt-transmitting {
  background: #fee2e2;
  color: var(--ergo-red);
  border-color: #fecaca;
  animation: ptt-pulse 1s ease-out infinite;
}

/* ===== Avatar card ===== */
.avatar-card {
  position: relative;
  aspect-ratio: 9 / 16;
  max-height: calc(100vh - 200px);
  max-width: min(92vw, 560px);
  background: #0a0a0a;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  transition: box-shadow 0.4s ease;
}

.avatar-card.connected {
  box-shadow: 0 0 40px rgba(34, 197, 94, 0.25), 0 10px 30px rgba(0, 0, 0, 0.08);
}

#video_player {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.status-pill {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  max-width: calc(100% - 40px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
}

.status-pill[data-state="connecting"] .dot { background: #fbbf24; animation: pulse 1s infinite; }
.status-pill[data-state="connected"]  .dot { background: #22c55e; }
.status-pill[data-state="speaking"]   .dot { background: #22c55e; animation: pulse 0.9s infinite; }
.status-pill[data-state="error"]      .dot { background: #ef4444; }
.status-pill[data-state="error"]      .status-text { color: #fca5a5; }

/* ===== Control bar ===== */
.control-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.primary-btn {
  background: var(--ergo-red);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 14px rgba(227, 6, 19, 0.25);
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.2s ease;
}

.primary-btn:hover { background: var(--ergo-red-dark); }
.primary-btn:active { transform: translateY(1px); }

.primary-btn.active {
  background: var(--end-btn);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.primary-btn.active:hover { background: var(--end-btn-hover); }

.primary-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.device-controls {
  display: flex;
  gap: 8px;
}

.device-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: background-color 0.15s ease;
}

.device-btn:hover { background: var(--bg); }
.device-btn.device-btn-off { color: var(--text-muted); }
.device-btn.muted {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
}

/* ===== Footer ===== */
.ergo-footer {
  position: absolute;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.ergo-footer img {
  height: 16px;
  width: auto;
  object-fit: contain;
}

/* ===== Animations ===== */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ===== Dialog ===== */
md-dialog { --md-dialog-container-color: #fff; }

/* ===== Login dialog ===== */
.login-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 300px;
  padding-top: 4px;
}

.login-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.login-content md-outlined-text-field {
  width: 100%;
}

.login-error {
  color: var(--ergo-red);
  font-size: 0.8125rem;
  min-height: 1.2em;
}

/* ===== Disclaimer dialog ===== */
.disclaimer-content {
  max-width: 520px;
  max-height: 55vh;
  overflow-y: auto;
  line-height: 1.65;
  font-size: 0.9rem;
  padding-right: 4px;
}

.disclaimer-content p { margin: 0 0 10px; }
.disclaimer-content ul { margin: 0 0 10px; padding-left: 20px; }
.disclaimer-content li { margin-bottom: 6px; }

.disclaimer-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ERGO red for the action buttons in login + disclaimer dialogs */
#loginSubmitBtn,
#disclaimerAckBtn {
  --md-filled-button-container-color: var(--ergo-red);
  --md-filled-button-hover-state-layer-color: #fff;
}

/* Disabled device buttons should look clearly locked */
.device-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.primary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Dashboard overlay ===== */
.dashboard-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  /* Grid layout: header row is fixed height, body row gets the rest.
     A grid-allocated 1fr height is a genuine CSS computed height that
     overflow-y on .dashboard-body can use as its scroll boundary.
     flex-based layouts do not reliably create this boundary. */
  display: grid;
  grid-template-rows: 64px 1fr;
  transform: translateX(0);
  transition: transform 0.3s ease;
}

.dashboard-overlay.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

.dashboard-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: 64px;
  background: var(--ergo-red);
  color: #fff;
}

.dashboard-header .material-icons { font-size: 22px; }
.dashboard-header h2 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; }

.dashboard-close-btn { color: rgba(255,255,255,0.85); }
.dashboard-close-btn:hover { color: #fff; background: rgba(255,255,255,0.15); }

.dashboard-body {
  overflow-y: auto; /* works because the grid parent gives this row a hard 1fr height */
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== KPI strip ===== */
.kpi-strip {
  display: flex;
  gap: 16px;
}

.kpi-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--ergo-red);
  line-height: 1.1;
}

.kpi-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ===== Chart grid ===== */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.chart-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  height: 260px;
}

.chart-card--wide {
  grid-column: 1 / -1;
  height: 340px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .transcript-sidebar.open {
    position: absolute;
    inset: 0;
    width: 100%;
    z-index: 100;
  }
  .avatar-card { max-height: calc(100vh - 200px); max-width: 100%; }
  .main-stage { padding-top: 64px; }

  .kpi-strip { flex-direction: column; }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-card--wide { grid-column: 1; height: 320px; }
}

/* ===== Broker Dashboard ===== */

.broker-count-badge {
  font-size: 13px;
  font-weight: 500;
  background: rgba(255,255,255,0.2);
  border-radius: 999px;
  padding: 2px 10px;
  margin-left: 4px;
}

/* Filter bar */
.broker-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  flex-shrink: 0;
}

.broker-filter-icon { color: var(--text-muted); font-size: 20px; }

.broker-filter-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  background: transparent;
  color: var(--text);
}

.broker-filter-input::placeholder { color: var(--text-muted); }

/* Table */
.broker-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
  max-height: 40vh; /* cap so the table never fills the whole viewport; detail panel stays reachable */
}

.broker-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.broker-table thead tr {
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
}

.broker-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.broker-table td {
  padding: 11px 16px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.broker-row { cursor: pointer; transition: background 0.1s ease; }
.broker-row:hover { background: #f9fafb; }
.broker-row--selected { background: #eff6ff !important; }
.broker-row:last-child td { border-bottom: none; }

.broker-cell-muted { color: var(--text-muted); font-size: 13px; }
.broker-cell-mono  { font-family: "Roboto Mono", ui-monospace, monospace; font-size: 12.5px; }

.broker-loading { padding: 24px; text-align: center; color: var(--text-muted); }
.broker-error   { color: #b91c1c; }
.broker-empty   { padding: 20px 24px; color: var(--text-muted); font-size: 14px; }

/* Status & age badges */
.broker-status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.lead-age-dot {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 6px;
  vertical-align: middle;
}

/* Detail panel */
.broker-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  /* flex-shrink:0 prevents the flex parent (.dashboard-body) from
     compressing this panel; combined with overflow-y:auto on .dashboard-body
     the whole body scrolls to reveal the full detail content */
  flex-shrink: 0;
}

.broker-detail-inner { padding: 24px; display: flex; flex-direction: column; gap: 20px; }

.broker-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  align-self: flex-start;
  transition: background 0.15s, border-color 0.15s;
}
.broker-back-btn:hover { background: #e5e7eb; border-color: #d1d5db; }
.broker-back-btn .material-icons { font-size: 16px; }

.broker-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.broker-detail-name { font-size: 20px; font-weight: 700; color: var(--text); }
.broker-detail-meta { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.broker-detail-status-wrap { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; flex-shrink: 0; }
.broker-status-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }

.broker-status-select {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.broker-status-select:focus { outline: 2px solid var(--ergo-red); outline-offset: 2px; }

/* Sections */
.broker-section { display: flex; flex-direction: column; gap: 8px; }
.broker-section-title {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.broker-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.broker-info-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.broker-info-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.broker-info-value { font-size: 13.5px; color: var(--text); display: flex; align-items: center; gap: 6px; }

.broker-copy-btn {
  background: transparent;
  border: none;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
}

.broker-copy-btn:hover { color: var(--ergo-red); background: #fee2e2; }

.broker-text-block {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}

/* Transcript */
.broker-transcript-details {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.broker-transcript-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  background: #f9fafb;
  user-select: none;
}

.broker-transcript-summary::-webkit-details-marker { display: none; }
.broker-transcript-summary:hover { background: #f3f4f6; }
.broker-transcript-summary .material-icons { font-size: 18px; color: var(--text-muted); }

.broker-transcript-block {
  /* kept for any existing references — chat wrap is used instead */
  display: none;
}

/* ── Full-width info cell (email, phone) ─────────────────────────── */
.broker-info-cell--full {
  grid-column: 1 / -1;
}

.broker-info-cell--full .broker-info-value {
  word-break: break-all;
  overflow-wrap: anywhere;
  white-space: normal;
}

/* ── Promoted summary block ──────────────────────────────────────── */
.broker-summary-block {
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #3b82f6;
  border-radius: 8px;
  padding: 14px 18px;
}

/* ── Insurance / interest tag pills ─────────────────────────────── */
.broker-tag-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.broker-tag-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.broker-tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.broker-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #e5e7eb;
}

.broker-tag--highlight {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

/* ── Transcript chat bubbles ─────────────────────────────────────── */
.broker-chat-wrap {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff;
  border-top: 1px solid var(--border);
  max-height: 500px;
  overflow-y: auto;
}

.broker-chat-line {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.broker-chat-line--user  { align-self: flex-start; }
.broker-chat-line--agent { align-self: flex-end; }

.broker-chat-role {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.broker-chat-line--agent .broker-chat-role { text-align: right; }

.broker-chat-bubble {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}

.broker-chat-line--user  .broker-chat-bubble {
  background: #f3f4f6;
  border-bottom-left-radius: 3px;
}

.broker-chat-line--agent .broker-chat-bubble {
  background: #fee2e2;
  border-bottom-right-radius: 3px;
}

@media (max-width: 768px) {
  /* With 4 columns, hide Anliegen (col 2) on narrow screens */
  .broker-table th:nth-child(2),
  .broker-table td:nth-child(2) { display: none; }
  .broker-info-grid { grid-template-columns: 1fr 1fr; }
  .broker-detail-header { flex-direction: column; }
}
