:root {
  color-scheme: dark;
  --bg: #030607;
  --panel: #080d11;
  --panel-2: #0d151b;
  --card: #101a22;
  --border: #263741;
  --border-bright: rgba(34, 211, 238, 0.5);
  --text: #d8e6ed;
  --strong: #f8fbfc;
  --muted: #8fa6b3;
  --accent: #22d3ee;
  --teal: #2dd4bf;
  --danger: #fb7185;
  --shadow: rgba(0, 0, 0, 0.42);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef6f8;
  --panel: #ffffff;
  --panel-2: #f5fafb;
  --card: #ffffff;
  --border: #cbdde3;
  --border-bright: rgba(8, 145, 178, 0.48);
  --text: #263a45;
  --strong: #071d27;
  --muted: #647b86;
  --accent: #0284a8;
  --teal: #0f8f80;
  --danger: #be123c;
  --shadow: rgba(15, 45, 58, 0.14);
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  max-height: 100%;
}
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.expert-shell {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  overflow: hidden;
}
.expert-shell.has-side-chat {
  grid-template-columns: 340px minmax(0, 1fr) minmax(280px, 360px);
}
.chat-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.expert-side-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-left: 1px solid var(--border);
  background: var(--panel);
}
.expert-side-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.expert-side-title { color: var(--strong); font-size: 15px; font-weight: 800; }
.expert-side-subtitle { margin-top: 4px; color: var(--muted); font-size: 11px; }
.expert-side-window {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 10px;
}
.expert-side-bubble {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.5;
}
.expert-side-bubble.user {
  border-color: rgba(34, 211, 238, .28);
  background: linear-gradient(135deg, rgba(8, 145, 178, .16), rgba(15, 118, 110, .1)), var(--panel-2);
}
.expert-side-bubble .side-role {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.expert-side-composer {
  flex: 0 0 auto;
  padding: 12px 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
}
.expert-side-composer textarea {
  width: 100%;
  resize: vertical;
  max-height: 160px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  outline: none;
}
.expert-side-composer textarea:focus { border-color: var(--accent); }
#expertSideStatus { min-height: 18px; color: var(--muted); font-size: 12px; }
.session-doc-card { width: min(820px, 100%); }
.session-doc-content {
  margin: 0;
  max-height: min(55vh, 520px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}
.expert-sidebar {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--panel);
}
.sidebar-header {
  flex: 0 0 auto;
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(150deg, rgba(8, 145, 178, .12), transparent 58%);
}
.brand { display: inline-flex; margin-bottom: 22px; }
.brand img { width: 124px; height: auto; display: block; }
.page-heading, .modal-head, .chat-header, .section-title, .composer-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; color: var(--strong); font-size: 24px; line-height: 1.12; }
h2 { margin-bottom: 0; color: var(--strong); }
.eyebrow { margin-bottom: 6px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.header-actions { display: flex; gap: 8px; }
.icon-button { min-width: 38px; height: 38px; display: inline-grid; place-items: center; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); color: var(--strong); text-decoration: none; cursor: pointer; }
.icon-button:hover { border-color: var(--accent); }
.intro { margin: 14px 0 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.primary-actions { display: grid; gap: 9px; }
.primary-button, .secondary-button, .text-button { border-radius: 11px; padding: 11px 15px; font-weight: 750; cursor: pointer; }
.primary-button { border: 1px solid #22d3ee; background: linear-gradient(135deg, #0786a8, #0f766e); color: #fff; }
.primary-button:hover { box-shadow: 0 10px 25px rgba(34, 211, 238, .17); }
.secondary-button { border: 1px solid var(--border); background: var(--panel-2); color: var(--strong); }
.secondary-button:hover { border-color: var(--accent); }
.text-button { padding: 0; border: 0; background: transparent; color: var(--accent); text-align: left; }
button:disabled { opacity: .55; cursor: not-allowed; box-shadow: none !important; }

.account-card {
  flex: 0 0 auto;
  margin: 16px 20px 8px;
  padding: 15px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-2);
}
.account-card strong { color: var(--strong); }
.type-pill { align-self: center; padding: 4px 8px; border-radius: 99px; background: rgba(45, 212, 191, .12); color: var(--teal); font-size: 11px; font-weight: 800; }
.phone-status, .account-card .text-button { grid-column: 1 / -1; }
.phone-status { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.conversation-section {
  min-height: 0;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  padding: 12px 14px 18px;
  overflow: hidden;
}
.section-title { flex: 0 0 auto; padding: 0 8px 9px; }
.section-title h2 { font-size: 14px; }
.section-title button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; }
.conversation-list {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  align-content: start;
  gap: 7px;
}
.conversation-card { width: 100%; padding: 13px; display: block; text-align: left; border: 1px solid transparent; border-radius: 12px; background: transparent; color: var(--text); cursor: pointer; }
.conversation-card:hover, .conversation-card.active { border-color: var(--border-bright); background: var(--panel-2); }
.conversation-card h3 { margin: 0 0 6px; color: var(--strong); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-card p { margin: 0; display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; }
.invite-badge { color: #fbbf24; font-weight: 800; }
.list-state { padding: 20px 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.waiting-section {
  flex: 0 1 auto;
  max-height: min(220px, 28vh);
  border-bottom: 1px solid var(--border);
}
.waiting-card { border-color: rgba(251, 191, 36, .28); background: rgba(251, 191, 36, .06); }
.phone-status.online { color: var(--teal); }

.chat-main {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(circle at 80% 0, rgba(14, 165, 233, .08), transparent 33%), var(--bg);
}
.welcome-state {
  max-width: 680px;
  margin: auto;
  padding: 40px;
  text-align: center;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.welcome-mark { width: 70px; height: 70px; margin: 0 auto 22px; display: grid; place-items: center; border: 1px solid var(--border-bright); border-radius: 22px; background: rgba(34, 211, 238, .08); color: var(--accent); font-size: 30px; }
.welcome-state h2 { font-size: clamp(27px, 4vw, 44px); }
.welcome-state > p { max-width: 600px; margin: 16px auto 24px; color: var(--muted); line-height: 1.65; }
.welcome-points { display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; }
.welcome-points span { padding: 7px 11px; border: 1px solid var(--border); border-radius: 99px; color: var(--muted); font-size: 12px; }

.chat-state {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-header {
  flex: 0 0 auto;
  min-height: 92px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}
.chat-header h2 { font-size: 20px; }
.chat-header p:last-child { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.call-banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 28px;
  border-bottom: 1px solid var(--border-bright);
  background: rgba(34, 211, 238, .08);
  color: var(--strong);
  font-size: 13px;
  font-weight: 650;
}
.chat-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.call-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.call-overlay-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  color: var(--strong);
  font-size: 13px;
  font-weight: 700;
}
.daily-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
}
.daily-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
}
.message-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px clamp(18px, 6vw, 80px);
}
.message { max-width: 740px; margin-bottom: 18px; }
.message.mine { margin-left: auto; }
.message-label { margin: 0 4px 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.message.mine .message-label { text-align: right; }
.message-bubble { padding: 13px 16px; border: 1px solid var(--border); border-radius: 15px 15px 15px 4px; background: var(--card); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.message.mine .message-bubble { border-color: rgba(34, 211, 238, .32); border-radius: 15px 15px 4px 15px; background: linear-gradient(135deg, rgba(8, 145, 178, .2), rgba(15, 118, 110, .16)), var(--card); }
.message.briefing { max-width: 820px; margin-right: auto; margin-left: 0; }
.message.briefing .message-label { color: var(--accent); }
.message.briefing .message-bubble {
  border-color: rgba(251, 191, 36, .35);
  border-radius: 15px 15px 15px 4px;
  background: linear-gradient(135deg, rgba(251, 191, 36, .1), rgba(8, 145, 178, .08)), var(--card);
}
.message-time { margin: 5px 4px 0; color: var(--muted); font-size: 10px; }
.message.mine .message-time { text-align: right; }
.composer {
  flex: 0 0 auto;
  padding: 14px clamp(18px, 6vw, 80px) 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.composer textarea { width: 100%; max-height: 190px; resize: vertical; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel-2); color: var(--text); outline: none; }
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, .1); }
.composer-policy { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.composer-row { margin-top: 9px; }
#chatStatus, .form-status { min-height: 18px; color: var(--muted); font-size: 12px; }
.error { color: var(--danger) !important; }

.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 22px; background: rgba(0, 0, 0, .7); backdrop-filter: blur(6px); }
.modal-card { width: min(620px, 100%); max-height: calc(100dvh - 44px); overflow-y: auto; padding: 24px; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); box-shadow: 0 24px 80px var(--shadow); }
.compact-card { width: min(470px, 100%); }
.modal-head { margin-bottom: 18px; }
.modal-head h2 { font-size: 23px; }
.modal-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 28px; }
.modal-card label { display: grid; gap: 7px; margin-bottom: 15px; color: var(--muted); font-size: 12px; font-weight: 750; }
.modal-card input, .modal-card select, .modal-card textarea { width: 100%; padding: 12px 13px; border: 1px solid var(--border); border-radius: 11px; background: var(--panel-2); color: var(--text); outline: none; }
.modal-card input:focus, .modal-card select:focus, .modal-card textarea:focus { border-color: var(--accent); }
.modal-card textarea { resize: vertical; }
.modal-copy { color: var(--muted); font-size: 13px; line-height: 1.5; }
.modal-actions { margin-top: 18px; display: flex; justify-content: flex-end; gap: 10px; }
.full-button { width: 100%; margin-bottom: 15px; }

@media (max-width: 820px) {
  .expert-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 36vh) minmax(0, 1fr);
  }
  .expert-shell.has-side-chat {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 28vh) minmax(0, 1fr) minmax(0, 34vh);
  }
  .expert-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .expert-side-panel {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  .conversation-section { flex: 1 1 auto; min-height: 120px; }
  .waiting-section { max-height: 140px; }
  .chat-main { min-height: 0; }
  .chat-header { align-items: flex-start; padding: 16px 18px; }
  .call-banner { padding: 10px 18px; }
  .message-list, .composer { padding-left: 16px; padding-right: 16px; }
}
