:root {
  color-scheme: light;
  --bg: #eef1ef;
  --panel: #ffffff;
  --panel-muted: #f6f7f6;
  --text: #171a18;
  --muted: #68716c;
  --border: #dce2de;
  --accent: #147d50;
  --accent-strong: #0d633e;
  --accent-soft: #e8f5ee;
  --danger: #b42318;
  --shadow: 0 18px 60px rgba(20, 32, 25, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  background: var(--panel);
}

.side-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: #151917;
  color: #fff;
  padding: 24px 16px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 7px 22px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 7px;
  background: #fff;
}

.brand div {
  display: grid;
  min-width: 0;
}

.brand strong {
  font-size: 17px;
  line-height: 1.25;
}

.brand span {
  margin-top: 2px;
  color: #aab4ae;
  font-size: 11px;
}

.quick-nav {
  display: grid;
  gap: 5px;
}

.quick-nav button {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #d5dcd8;
  padding: 10px 11px;
  text-align: left;
  font-size: 13px;
  transition: background 150ms ease, color 150ms ease;
}

.quick-nav button:hover,
.quick-nav button:focus-visible {
  background: #252c28;
  color: #fff;
  outline: none;
}

.nav-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: #81c7a3;
  font-size: 15px;
}

.security-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: auto;
  border-top: 1px solid #303733;
  padding: 16px 7px 0;
}

.security-mark {
  display: grid;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  place-items: center;
  border-radius: 50%;
  background: #254b38;
  color: #8dd0aa;
  font-size: 11px;
}

.security-note div {
  display: grid;
  gap: 3px;
}

.security-note strong {
  font-size: 11px;
  font-weight: 600;
}

.security-note span:last-child {
  color: #929c96;
  font-size: 10px;
  line-height: 1.4;
}

.chat-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 64px minmax(0, 1fr) auto auto;
  background: var(--panel-muted);
}

.chat-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  padding: 0 24px;
}

.agent {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.agent-avatar {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
}

.agent-avatar img,
.message-avatar img,
.loading-logo img {
  width: 72%;
  height: 72%;
  object-fit: contain;
}

.online-dot {
  position: absolute;
  right: -1px;
  bottom: 1px;
  width: 9px;
  height: 9px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #24a367;
}

.agent h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.agent p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.identity-button {
  display: flex;
  min-height: 32px;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: #39413d;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
}

.identity-button:hover {
  border-color: #b8c5bd;
  background: #f8faf9;
}

.identity-button.verified {
  border-color: #b7ddc8;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.identity-icon {
  font-size: 15px;
}

.messages {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 28px clamp(18px, 5vw, 72px) 18px;
  scrollbar-color: #c5cdc8 transparent;
  scrollbar-width: thin;
}

.messages-inner {
  width: min(840px, 100%);
  margin: 0 auto;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  margin: 0 0 18px;
}

.message-row.user {
  justify-content: flex-end;
}

.message-avatar {
  display: grid;
  width: 27px;
  height: 27px;
  flex: 0 0 27px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
}

.message-content {
  display: grid;
  max-width: min(680px, calc(100% - 44px));
  gap: 6px;
}

.message-row.user .message-content {
  justify-items: end;
}

.message-bubble {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px 8px 8px 2px;
  background: #fff;
  padding: 10px 13px;
  color: #252a27;
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 8px rgba(25, 40, 31, 0.035);
}

.message-row.user .message-bubble {
  border-color: var(--accent);
  border-radius: 8px 8px 2px 8px;
  background: var(--accent);
  color: #fff;
}

.message-bubble a {
  color: var(--accent-strong);
  font-weight: 600;
}

.message-row.user .message-bubble a {
  color: #fff;
}

.message-time {
  color: #8a938e;
  font-size: 9px;
}

.action-card {
  display: grid;
  width: min(480px, 100%);
  gap: 8px;
  border: 1px solid #cddbd3;
  border-radius: 7px;
  background: #fff;
  padding: 11px 12px;
}

.action-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.action-card strong {
  font-size: 12px;
}

.action-card span,
.action-card p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
}

.action-card code {
  display: block;
  overflow-wrap: anywhere;
  border-radius: 5px;
  background: #f1f4f2;
  padding: 8px;
  color: #28302b;
  font-size: 10px;
}

.action-button {
  display: inline-flex;
  min-height: 31px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  padding: 0 11px;
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
}

.loading-state {
  display: grid;
  min-height: 100%;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.loading-logo {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}

.typing-row {
  width: min(840px, calc(100% - clamp(36px, 10vw, 144px)));
  margin: 0 auto;
  align-items: flex-end;
  gap: 9px;
  padding-bottom: 8px;
}

.typing-row:not([hidden]) {
  display: flex;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 31px;
  border: 1px solid var(--border);
  border-radius: 8px 8px 8px 2px;
  background: #fff;
  padding: 0 12px;
}

.typing-bubble span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #8f9993;
  animation: typing 1.1s infinite ease-in-out;
}

.typing-bubble span:nth-child(2) {
  animation-delay: 120ms;
}

.typing-bubble span:nth-child(3) {
  animation-delay: 240ms;
}

.composer-wrap {
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 12px clamp(18px, 5vw, 72px) calc(10px + env(safe-area-inset-bottom));
}

.composer {
  display: flex;
  width: min(840px, 100%);
  min-height: 46px;
  align-items: flex-end;
  gap: 8px;
  margin: 0 auto;
  border: 1px solid #cfd6d2;
  border-radius: 8px;
  background: #fff;
  padding: 6px 6px 6px 13px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.composer:focus-within {
  border-color: #86b69d;
  box-shadow: 0 0 0 3px rgba(20, 125, 80, 0.1);
}

.composer textarea {
  width: 100%;
  max-height: 128px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 7px 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.composer textarea::placeholder {
  color: #929a95;
}

.send-button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.send-button:hover {
  background: var(--accent-strong);
}

.send-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.composer-caption {
  width: min(840px, 100%);
  margin: 6px auto 0;
  color: #919994;
  text-align: center;
  font-size: 9px;
}

.modal {
  width: min(420px, calc(100% - 28px));
  max-height: calc(100dvh - 32px);
  overflow: visible;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  padding: 0;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(13, 17, 15, 0.58);
  backdrop-filter: blur(2px);
}

.modal-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

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

.modal-kicker {
  display: block;
  margin-bottom: 3px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
}

.close-button,
.icon-button {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 21px;
}

.close-button:hover,
.icon-button:hover {
  background: #f0f3f1;
  color: var(--text);
}

.modal-body {
  display: grid;
  gap: 9px;
  padding: 18px 20px 20px;
}

.modal-body label {
  color: #3e4742;
  font-size: 11px;
  font-weight: 600;
}

.modal-body label span {
  color: var(--muted);
  font-weight: 400;
}

.modal-body input:not([type="checkbox"]) {
  width: 100%;
  height: 40px;
  border: 1px solid #cfd6d2;
  border-radius: 6px;
  outline: none;
  padding: 0 11px;
  color: var(--text);
  font-size: 13px;
}

.modal-body input:focus {
  border-color: #7caf94;
  box-shadow: 0 0 0 3px rgba(20, 125, 80, 0.1);
}

.modal-body p {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.code-input {
  text-align: center;
  font-size: 20px !important;
  font-weight: 700;
  letter-spacing: 0.22em !important;
}

.primary-button {
  min-height: 39px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled {
  cursor: default;
  opacity: 0.5;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  padding: 5px;
  font-size: 10px;
  font-weight: 600;
}

.form-grid {
  gap: 7px;
}

.form-grid input + label {
  margin-top: 4px;
}

.consent-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 7px 0;
  line-height: 1.4;
}

.consent-row input {
  margin: 1px 0 0;
  accent-color: var(--accent);
}

.form-error {
  border: 1px solid #f1c1bc;
  border-radius: 5px;
  background: #fff2f0;
  color: var(--danger);
  padding: 8px 9px;
  font-size: 10px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 20px;
  bottom: 20px;
  max-width: min(340px, calc(100% - 40px));
  border: 1px solid #b9d8c7;
  border-radius: 6px;
  background: #153d2a;
  color: #fff;
  padding: 10px 13px;
  font-size: 11px;
  box-shadow: var(--shadow);
}

.mobile-only,
.mobile-quick-actions {
  display: none;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

@keyframes pulse {
  50% {
    transform: scale(0.96);
    opacity: 0.72;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .side-panel {
    display: none;
  }

  .chat-panel {
    position: relative;
    width: 100%;
    height: 100dvh;
    grid-template-rows: 58px minmax(0, 1fr) auto auto;
  }

  .chat-header {
    padding: 0 13px;
  }

  .desktop-only {
    display: none;
  }

  .mobile-only {
    display: grid;
  }

  .mobile-quick-actions:not([hidden]) {
    position: absolute;
    z-index: 8;
    top: 58px;
    right: 0;
    left: 0;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    background: #fff;
    padding: 7px 12px;
    scrollbar-width: none;
  }

  .mobile-quick-actions button {
    height: 29px;
    flex: 0 0 auto;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: #fff;
    color: #3e4742;
    padding: 0 10px;
    font-size: 10px;
  }

  .identity-button {
    width: 33px;
    padding: 0;
    justify-content: center;
  }

  .identity-button span:last-child {
    display: none;
  }

  .messages {
    padding: 18px 12px 10px;
  }

  .message-content {
    max-width: calc(100% - 36px);
  }

  .message-bubble {
    font-size: 12px;
  }

  .typing-row {
    width: calc(100% - 24px);
  }

  .composer-wrap {
    padding: 9px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .composer-caption {
    display: none;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1110;
    --panel: #141816;
    --panel-muted: #101311;
    --text: #eef2ef;
    --muted: #9ba49f;
    --border: #2d342f;
    --accent: #2e9b68;
    --accent-strong: #72c89b;
    --accent-soft: #183326;
    --shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
  }

  .side-panel {
    background: #090b0a;
  }

  .chat-header,
  .composer-wrap,
  .identity-button,
  .mobile-quick-actions,
  .mobile-quick-actions button,
  .agent-avatar,
  .message-avatar,
  .message-bubble,
  .typing-bubble,
  .composer,
  .modal-card,
  .action-card,
  .loading-logo {
    background: var(--panel);
  }

  .message-bubble {
    color: var(--text);
  }

  .message-row.user .message-bubble {
    background: var(--accent);
    color: #fff;
  }

  .action-card code,
  .close-button:hover,
  .icon-button:hover {
    background: #202622;
    color: var(--text);
  }

  .online-dot {
    border-color: var(--panel);
  }
}
