:root {
  color-scheme: light;
  --bg: #eef4ff;
  --panel: rgba(255,255,255,.92);
  --text: #172033;
  --muted: #687386;
  --line: rgba(39,56,84,.12);
  --brand: #2563eb;
  --brand-2: #7c3aed;
  --left: #ffffff;
  --right: linear-gradient(135deg, #2563eb, #7c3aed);
  --shadow: 0 24px 80px rgba(31, 41, 55, .18);
  --radius: 24px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, "Noto Sans", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37,99,235,.18), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(124,58,237,.16), transparent 30rem),
    var(--bg);
}
button, textarea { font: inherit; }
.app-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.chat-card {
  width: min(980px, 100%);
  height: min(820px, calc(100dvh - 44px));
  min-height: 520px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.78);
}
.avatar {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 16px;
  color: white;
  font-weight: 800;
  letter-spacing: .03em;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
}
.agent { min-width: 0; flex: 1; }
.agent h1 { margin: 0; font-size: 18px; line-height: 1.25; }
.agent p { margin: 4px 0 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status {
  padding: 6px 10px;
  border-radius: 999px;
  color: #9a3412;
  background: #ffedd5;
  font-size: 12px;
  font-weight: 700;
}
.status.online { color: #166534; background: #dcfce7; }
.messages {
  overflow: auto;
  padding: 20px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.empty-state {
  width: fit-content;
  margin: 10vh auto 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.68);
  font-size: 14px;
}
.message {
  display: grid;
  gap: 6px;
  margin: 14px 0;
  max-width: 78%;
}
.message.left { justify-items: start; margin-right: auto; white-space: pre-wrap;}
.message.right { justify-items: end; margin-left: auto; white-space: pre-wrap;}
.bubble {
  padding: 11px 13px;
  border-radius: 18px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  box-shadow: 0 10px 24px rgba(31,41,55,.08);
}
.left .bubble { background: var(--left); border-top-left-radius: 6px; border: 1px solid var(--line); }
.right .bubble { color: white; background: var(--right); border-top-right-radius: 6px; }
.meta { color: var(--muted); font-size: 12px; padding: 0 4px; }
.right .meta { text-align: right; }
.media-img {
  display: block;
  max-width: min(280px, 70vw);
  max-height: 300px;
  margin-bottom: 8px;
  border-radius: 14px;
  cursor: zoom-in;
  object-fit: cover;
}
.file-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  color: inherit;
  background: rgba(255,255,255,.18);
  text-decoration: none;
  border: 1px solid rgba(255,255,255,.25);
}
.left .file-link { background: #f8fafc; border-color: var(--line); }
.composer {
  padding: 10px 14px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.86);
}
.tips { min-height: 20px; color: var(--muted); font-size: 12px; padding: 0 8px 4px; }
.compose-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: end;
}
textarea {
  width: 100%;
  max-height: 130px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  outline: none;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea:focus { border-color: rgba(37,99,235,.55); box-shadow: 0 0 0 4px rgba(37,99,235,.12); }
.icon-button, .send-button {
  border: 0;
  cursor: pointer;
  min-height: 46px;
  border-radius: 16px;
}
.icon-button {
  width: 48px;
  display: grid;
  place-items: center;
  color: var(--brand);
  background: #eaf1ff;
}
.icon-button svg { width: 23px; height: 23px; fill: currentColor; }
.send-button {
  padding: 0 18px;
  color: white;
  font-weight: 800;
  background: var(--right);
}
.send-button:disabled { opacity: .62; cursor: not-allowed; }
.loading, .toast, .preview {
  position: fixed;
  z-index: 50;
}
.loading {
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  color: white;
  background: rgba(15,23,42,.28);
}
.loading[hidden], .toast[hidden], .preview[hidden] { display: none; }
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255,255,255,.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: min(460px, 82vw);
  padding: 12px 16px;
  border-radius: 14px;
  color: white;
  background: rgba(15,23,42,.88);
  text-align: center;
  box-shadow: 0 18px 44px rgba(15,23,42,.24);
}
.preview {
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.76);
}
.preview img {
  max-width: 92vw;
  max-height: 88dvh;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,.42);
}
.preview-close {
  position: fixed;
  top: 14px;
  right: 18px;
  border: 0;
  color: white;
  background: rgba(255,255,255,.16);
  width: 44px;
  height: 44px;
  border-radius: 999px;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

.office-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 22px;
}
.office-modal[hidden] { display: none; }
.office-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(37,99,235,.24), transparent 28rem),
    radial-gradient(circle at bottom right, rgba(124,58,237,.22), transparent 26rem),
    rgba(15,23,42,.38);
  backdrop-filter: blur(10px);
  opacity: 0;
  animation: officeBackdropIn .28s ease forwards;
}
.office-dialog {
  position: relative;
  width: min(420px, 100%);
  padding: 30px 26px 24px;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 28px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 28px 90px rgba(31,41,55,.28);
  text-align: center;
  overflow: hidden;
  transform: translateY(18px) scale(.96);
  opacity: 0;
  animation: officeDialogIn .34s cubic-bezier(.16,1,.3,1) forwards;
}
.office-dialog::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--right);
}
.office-icon {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 22px;
  color: white;
  background: var(--right);
  box-shadow: 0 16px 36px rgba(37,99,235,.28);
}
.office-icon svg { width: 34px; height: 34px; fill: currentColor; }
.office-kicker {
  margin: 0 0 7px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.office-dialog h2 {
  margin: 0;
  color: var(--text);
  font-size: 22px;
  line-height: 1.22;
}
.office-dialog p:not(.office-kicker) {
  margin: 12px 0 22px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}
.office-primary {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 16px;
  color: white;
  background: var(--right);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 14px 30px rgba(37,99,235,.24);
  transition: transform .16s ease, box-shadow .16s ease;
}
.office-primary:hover { transform: translateY(-1px); box-shadow: 0 18px 38px rgba(37,99,235,.3); }
.office-primary:active { transform: translateY(0) scale(.99); }
.office-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(15,23,42,.06);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.office-close:hover { color: var(--text); background: rgba(15,23,42,.1); transform: rotate(90deg); }
.office-modal.is-closing .office-backdrop { animation: officeBackdropOut .22s ease forwards; }
.office-modal.is-closing .office-dialog { animation: officeDialogOut .22s ease forwards; }
@keyframes officeBackdropIn { to { opacity: 1; } }
@keyframes officeBackdropOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes officeDialogIn { to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes officeDialogOut { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(12px) scale(.97); } }

@media (max-width: 640px) {
  .app-shell { padding: 0; }
  .chat-card {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  .chat-header { padding: 14px 14px; }
  .avatar { width: 42px; height: 42px; border-radius: 14px; font-size: 13px; }
  .agent h1 { font-size: 16px; }
  .messages { padding: 14px; }
  .message { max-width: 88%; }
  .compose-row { grid-template-columns: 1fr auto auto; gap: 6px; }
  .send-button { padding: 0 14px; }
  .office-dialog { padding: 28px 20px 22px; border-radius: 24px; }
  .office-dialog h2 { font-size: 20px; }
}
