:root {
  --chat-brand: #0B2559;
  --chat-brand-strong: #071A40;
  --chat-accent: #B56B45;
  --chat-bg: #F4F6F8;
  --chat-panel: #FFFFFF;
  --chat-soft: #F8FAFC;
  --chat-line: #DDE3EA;
  --chat-ink: #1F2937;
  --chat-muted: #667085;
  --chat-danger: #B42318;
  --chat-safe-bottom: env(safe-area-inset-bottom, 0px);
}
[data-theme="dark"] {
  --chat-bg: #101828;
  --chat-panel: #182230;
  --chat-soft: #202C3B;
  --chat-line: #344054;
  --chat-ink: #F2F4F7;
  --chat-muted: #98A2B3;
}
* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; }
body.chat-page {
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--chat-ink);
  background: var(--chat-bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.chat-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 58px;
  padding: 8px 18px;
  color: var(--chat-ink);
  background: var(--chat-panel);
  border-bottom: 1px solid var(--chat-line);
}
.chat-back, .chat-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--chat-brand);
  background: transparent;
  border: 1px solid var(--chat-line);
  border-radius: 10px;
  text-decoration: none;
}
.chat-back:hover, .chat-back:focus-visible, .chat-icon-btn:hover, .chat-icon-btn:focus-visible { background: var(--chat-soft); border-color: var(--chat-brand); outline: none; }
.chat-brand { color: var(--chat-brand); font-size: 16px; font-weight: 850; letter-spacing: -.04em; text-decoration: none; }
.chat-heading { min-width: 0; flex: 1; }
.chat-heading strong { display: block; font-size: 14px; font-weight: 850; }
.chat-heading span { display: block; overflow: hidden; margin-top: 2px; color: var(--chat-muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.chat-top-actions { display: flex; gap: 6px; }

#chat-app { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: calc(100dvh - 58px); min-height: 520px; overflow: hidden; }
#chat-sidebar { display: flex; min-width: 0; flex-direction: column; gap: 14px; padding: 18px; overflow: auto; background: var(--chat-panel); border-right: 1px solid var(--chat-line); }
.chat-sidebar-title { margin-bottom: 2px; font-size: 20px; font-weight: 850; letter-spacing: -.04em; }
.chat-sidebar-copy { margin: 0; color: var(--chat-muted); font-size: 12px; line-height: 1.5; }
.chat-card { padding: 14px; background: var(--chat-soft); border: 1px solid var(--chat-line); border-radius: 14px; }
.chat-card h2 { margin: 0 0 5px; font-size: 14px; }
.chat-card p { margin: 0 0 12px; color: var(--chat-muted); font-size: 11px; line-height: 1.5; }
.chat-field { display: grid; gap: 5px; margin-top: 10px; }
.chat-field label { color: var(--chat-muted); font-size: 10px; font-weight: 800; }
.chat-input, .chat-select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  color: var(--chat-ink);
  background: var(--chat-panel);
  border: 1px solid var(--chat-line);
  border-radius: 9px;
  outline: none;
}
.chat-input:focus, .chat-select:focus, .chat-composer-input:focus { border-color: var(--chat-brand); box-shadow: 0 0 0 3px rgba(11,37,89,.12); }
.chat-actions { display: flex; gap: 7px; margin-top: 12px; }
.chat-primary, .chat-secondary, .chat-danger {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 800;
}
.chat-primary { color: #fff; background: var(--chat-brand); border: 1px solid var(--chat-brand); }
.chat-primary:hover, .chat-primary:focus-visible { background: var(--chat-brand-strong); }
.chat-secondary { color: var(--chat-brand); background: var(--chat-panel); border: 1px solid var(--chat-line); }
.chat-danger { color: var(--chat-danger); background: var(--chat-panel); border: 1px solid #FECACA; }
.chat-status { min-height: 20px; color: var(--chat-muted); font-size: 11px; line-height: 1.4; }
.chat-status.is-error { color: var(--chat-danger); }
.chat-status.is-success { color: #027A48; }
.chat-note { margin-top: auto; padding-top: 10px; color: var(--chat-muted); border-top: 1px solid var(--chat-line); font-size: 10px; line-height: 1.5; }

#chat-main { min-width: 0; background: var(--chat-soft); }
#chat-empty, #chat-room-view { width: 100%; height: 100%; }
#chat-empty { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 9px; padding: 30px; color: var(--chat-muted); text-align: center; }
#chat-empty[hidden], #chat-room-view[hidden], #chat-create-modal[hidden] { display: none; }
#chat-empty svg { color: var(--chat-brand); }
#chat-empty h1 { margin: 0; color: var(--chat-ink); font-size: 24px; letter-spacing: -.04em; }
#chat-empty p { max-width: 360px; margin: 0; font-size: 13px; line-height: 1.5; }
#chat-room-view { display: flex; flex-direction: column; background: var(--chat-panel); }
.chat-room-header { display: flex; align-items: center; gap: 11px; min-height: 70px; padding: 12px 18px; border-bottom: 1px solid var(--chat-line); }
.chat-room-title { min-width: 0; flex: 1; }
.chat-room-name { overflow: hidden; font-size: 15px; font-weight: 850; text-overflow: ellipsis; white-space: nowrap; }
.chat-room-meta { margin-top: 3px; color: var(--chat-muted); font-size: 11px; }
.chat-messages { min-height: 0; flex: 1; overflow: auto; padding: 22px clamp(16px, 4vw, 56px); background: var(--chat-soft); }
.chat-empty-messages { display: grid; place-items: center; min-height: 100%; color: var(--chat-muted); font-size: 13px; text-align: center; }
.chat-message { max-width: min(700px, 88%); margin: 8px 0; padding: 10px 13px; color: var(--chat-ink); background: var(--chat-panel); border: 1px solid var(--chat-line); border-radius: 13px 13px 13px 4px; }
.chat-message.is-mine { margin-left: auto; color: #fff; background: var(--chat-brand); border-color: var(--chat-brand); border-radius: 13px 13px 4px 13px; }
.chat-message-author { margin-bottom: 4px; color: var(--chat-accent); font-size: 10px; font-weight: 800; }
.chat-message.is-mine .chat-message-author { color: #D0D5DD; }
.chat-message-content { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; }
.chat-message-time { margin-top: 4px; color: var(--chat-muted); font-size: 9px; }
.chat-message.is-mine .chat-message-time { color: #D0D5DD; }
.chat-composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 18px calc(12px + var(--chat-safe-bottom)); border-top: 1px solid var(--chat-line); background: var(--chat-panel); }
.chat-composer-input { min-height: 40px; max-height: 140px; flex: 1; overflow: auto; padding: 10px 12px; color: var(--chat-ink); background: var(--chat-soft); border: 1px solid var(--chat-line); border-radius: 10px; outline: none; white-space: pre-wrap; }
.chat-composer-input:empty::before { color: var(--chat-muted); content: attr(data-placeholder); pointer-events: none; }

#chat-create-modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.42); }
.chat-modal { width: min(460px, 100%); max-height: 90dvh; overflow: auto; padding: 18px; background: var(--chat-panel); border: 1px solid var(--chat-line); border-radius: 16px; box-shadow: 0 24px 70px rgba(15,23,42,.22); }
.chat-modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.chat-modal-title { flex: 1; font-size: 17px; font-weight: 850; }
.chat-modal-close { width: 34px; height: 34px; color: var(--chat-muted); background: transparent; border: 1px solid var(--chat-line); border-radius: 9px; }
.chat-modal-actions { justify-content: flex-end; }

@media (max-width: 760px) {
  body.chat-page { overflow: hidden; }
  .chat-topbar { padding-inline: 12px; }
  .chat-heading span { display: none; }
  #chat-app { display: block; height: calc(100dvh - 58px); min-height: 0; }
  #chat-sidebar, #chat-main { width: 100%; height: 100%; }
  #chat-sidebar { border-right: 0; }
  #chat-main { display: none; }
  body.room-open #chat-sidebar { display: none; }
  body.room-open #chat-main { display: block; }
  .chat-room-header { min-height: 62px; padding: 10px 12px; }
  .chat-messages { padding: 16px 12px; }
  .chat-message { max-width: 92%; }
  .chat-composer { padding-inline: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
