:root {
  --primary: #0050a0;
  --primary-deep: #123f75;
  --primary-soft: #eaf2ff;
  --screen-bg: #f4f7fc;
  --text: #1f2024;
  --text-twin: #1f3554;
  --muted: #8f9098;
  --placeholder: #8f9098;
  --copy: #7a8ca6;
  --border: rgba(0, 80, 160, 0.14);
  --border-light: rgba(0, 80, 160, 0.3);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --col-max: 760px;
  --desktop-bp: 960px;
  font-family: "Montserrat", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--screen-bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.screen {
  height: 100dvh;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--screen-bg);
  overflow: hidden;
}

@media (min-width: 960px) {
  .screen {
    background: #fff;
  }
}

.web-content-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

@media (min-width: 960px) {
  .web-content-wrap {
    max-width: var(--col-max);
    margin: 0 auto;
    align-self: center;
  }
}

.header {
  flex-shrink: 0;
  padding: calc(16px + var(--safe-top)) 16px 12px;
}

.header-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.header-leading {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  width: 44px;
}

.header-icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 22px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.shared-header-identity {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.shared-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 21px;
  border: 1px solid var(--border-light);
  object-fit: cover;
  background: var(--primary-soft);
  flex-shrink: 0;
}

.shared-header-name-wrap {
  min-width: 0;
  max-width: 190px;
}

.shared-header-name {
  display: block;
  font-weight: 600;
  font-size: 16px;
  line-height: 19px;
  color: var(--primary);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-login-btn {
  flex-shrink: 0;
  min-width: 44px;
  padding: 7px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  font-family: inherit;
  text-align: center;
}

.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.messages-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  padding-bottom: 8px;
  display: flex;
  flex-direction: column;
}

@media (max-width: 959px) {
  .messages-scroll {
    padding: 12px;
    padding-top: 12px;
  }
}

.bubble-row-left {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 12px;
  max-width: 100%;
  align-self: stretch;
}

.bubble-row-left .msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 16px;
  border: 2px solid #fff;
  object-fit: cover;
  flex-shrink: 0;
}

@media (min-width: 960px) {
  .bubble-row-left .msg-avatar {
    display: none;
  }
}

.bubble-twin {
  flex: 1;
  flex-shrink: 1;
  min-width: 0;
  max-width: 100%;
  background: #fff;
  border: none;
  border-radius: 8px 18px 18px 18px;
  padding: 12px 14px;
}

@media (min-width: 960px) {
  .bubble-twin {
    background: transparent;
    border-radius: 0;
    padding: 4px 0;
  }
}

.bubble-twin-text {
  margin: 0;
  font-weight: 400;
  font-size: 13px;
  line-height: 20px;
  letter-spacing: 0;
  color: var(--text-twin);
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble-row-right {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.user-bubble-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 85%;
  gap: 2px;
}

@media (min-width: 960px) {
  .user-bubble-col {
    max-width: 78%;
  }
}

.bubble-user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-radius: 18px 8px 18px 18px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 20px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 10px 24px rgba(0, 80, 160, 0.22);
}

@media (min-width: 960px) {
  .bubble-user {
    border-radius: 18px 18px 6px 18px;
    box-shadow: none;
  }
}

.copy-msg-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 2px 0;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  color: var(--copy);
}

.copy-msg-btn.user {
  align-self: flex-end;
  margin-top: 4px;
}

.thinking-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
  flex: 1;
  min-width: 0;
}

.thinking-row .msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 16px;
  flex-shrink: 0;
  visibility: hidden;
}

@media (min-width: 960px) {
  .thinking-row .msg-avatar {
    display: none;
  }
}

.thinking-inner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.thinking-spinner {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border: 2px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

.thinking-text {
  font-weight: 400;
  font-size: 15px;
  line-height: 22px;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}

.error-inline {
  font-size: 12px;
  color: #b91c1c;
  margin: 4px 16px 0;
  flex-shrink: 0;
}

.recording-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 14px 4px;
  padding: 8px 14px;
  background: rgba(229, 57, 53, 0.1);
  border: 1px solid rgba(229, 57, 53, 0.35);
  border-radius: 10px;
  flex-shrink: 0;
}

.recording-pulse {
  width: 10px;
  height: 10px;
  border-radius: 5px;
  background: #e53935;
}

.recording-banner-text {
  font-size: 14px;
  font-weight: 600;
  color: #c62828;
}

.composer-wrap {
  flex-shrink: 0;
  position: relative;
  z-index: 200;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 12px 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 18px 42px rgba(18, 63, 117, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

@media (min-width: 960px) {
  .input-row {
    margin: 0 0 18px;
    padding: 10px;
    background: #f4f4f5;
    border: none;
    box-shadow: none;
    border-radius: 22px;
  }
}

.input-row textarea {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  max-height: 200px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 16px;
  font-family: "Montserrat", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 18px;
  background: #f7faff;
  color: var(--text);
  outline: none;
}

.input-row textarea::placeholder {
  color: var(--placeholder);
}

@media (min-width: 960px) {
  .input-row textarea {
    background: transparent;
    border: none;
    border-radius: 0;
  }
}

.composer-btn {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  padding: 0;
  background: transparent;
}

.composer-btn.mic {
  background: var(--primary-soft);
}

@media (min-width: 960px) {
  .composer-btn {
    border-radius: 12px;
  }
  .composer-btn.mic {
    background: transparent;
  }
}

.composer-btn.send {
  background: transparent;
  box-shadow: none;
}

.composer-btn.record-active {
  min-width: 46px;
  width: auto;
  padding: 0 12px;
  border-radius: 23px;
  background: #e53935;
  border: 1px solid #c62828;
}

@media (min-width: 960px) {
  .composer-btn.record-active {
    border: none;
    border-radius: 12px;
  }
}

.record-active-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.composer-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.cta-block {
  flex-shrink: 0;
  margin: 0 16px calc(16px + var(--safe-bottom));
  padding: 18px 24px;
  max-width: 560px;
  width: calc(100% - 32px);
  align-self: center;
  text-align: center;
  background: rgba(0, 80, 160, 0.05);
  border: 1px solid var(--border-light);
  border-radius: 12px;
}

@media (max-width: 959px) {
  .cta-block {
    margin-top: 0;
    padding: 14px 18px;
  }
  .cta-block.below-chat {
    margin: 8px 12px calc(12px + var(--safe-bottom));
    width: calc(100% - 24px);
    border: none;
    background: transparent;
    padding: 0 0 8px;
  }
}

.cta-title {
  margin: 0 0 4px;
  font-weight: 500;
  font-size: 18px;
  color: var(--primary);
  text-align: center;
}

.cta-desc {
  margin: 0 0 8px;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  text-align: center;
}

.cta-subtitle {
  margin: 0 0 10px;
  font-weight: 500;
  font-size: 13px;
  color: var(--primary);
  text-align: center;
}

.cta-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 560px;
  min-height: 55px;
  margin: 0 auto;
  padding: 16px 24px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-weight: 500;
  font-size: 24px;
  text-transform: uppercase;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

@media (max-width: 399px) {
  .cta-title {
    font-size: 16px;
  }
  .cta-button {
    font-size: 16px;
    padding: 14px 20px;
    min-height: 48px;
  }
}

.cta-block.compact .cta-title,
.cta-block.compact .cta-desc,
.cta-block.compact .cta-subtitle {
  display: none;
}

.cta-block.compact .cta-button {
  font-size: 14px;
  padding: 10px 18px;
  min-height: 44px;
}

.cta-block.compact.below-chat .cta-button {
  width: 100%;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--screen-bg);
  z-index: 100;
  gap: 12px;
}

.loading-overlay .spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 14px;
  color: var(--primary);
  margin: 12px 0 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.bubble-twin-text strong {
  font-weight: 700;
}

.bubble-twin-text a {
  color: var(--primary);
  text-decoration: underline;
}

.bubble-twin-text .md-line {
  margin: 0;
}

.bubble-twin-text .md-h {
  font-family: "Montserrat", system-ui, -apple-system, sans-serif;
  font-weight: 700;
  margin: 10px 0 6px;
}

.bubble-twin-text .md-h1 {
  font-size: 16px;
}

.bubble-twin-text .md-h2 {
  font-size: 15px;
}

.bubble-twin-text .md-h3 {
  font-size: 14px;
  font-weight: 600;
}

.bubble-twin-text .md-h4 {
  font-size: 13px;
  font-weight: 600;
}

.bubble-twin-text .md-h5 {
  font-size: 12px;
  font-weight: 600;
}

.bubble-twin-text .md-bullet {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 2px;
}

.bubble-twin-text .md-bullet-mark {
  flex-shrink: 0;
}

.bubble-twin-text .md-hr {
  border: 0;
  border-top: 1px solid #d0d7de;
  margin: 10px 0;
}

/* Shared thread (/c/{code}) read-only transcript. */
.shared-header-sub {
  display: block;
  font-size: 12px;
  line-height: 15px;
  color: #7a8ca6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 14px;
  color: #7a8ca6;
}
