
.back-to-list { display: none; }
.back-to-list svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chat-title-row { display: flex; align-items: center; gap: 8px; min-width: 0; margin-bottom: 0; }
.chat-title-row h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.connection-icon { display: inline-block; flex: 0 0 9px; width: 9px; height: 9px; border-radius: 50%; background: #eab308; }
.connection-icon[data-status="connecting"] { background: #eab308; animation: connection-blink 1s ease-in-out infinite; }
.connection-icon[data-status="connected"] { background: #16a34a; }
.connection-icon[data-status="reconnecting"] { background: #dc2626; }
.connection-icon:focus-visible { outline: 2px solid #64748b; outline-offset: 3px; }
@keyframes connection-blink { 0%, 100% { opacity: 1; } 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .connection-icon[data-status="connecting"] { animation: none; } }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
#older-messages, #new-messages { padding: 8px; border: 0; color: #2563eb; background: #eff6ff; cursor: pointer; }
[hidden] { display: none !important; }
.messages { overflow-anchor: none; grid-row: 3; }
.chat-header { grid-row: 1; }
#older-messages { grid-row: 2; }
#new-messages { grid-row: 4; }
.composer { grid-row: 6; }
#send-feedback { grid-row: 5; font-size: 13px; color: var(--muted); padding: 0 16px; }
#send-feedback:has(#send-status:empty) { display: none; }
#retry-message { margin: 6px; cursor: pointer; }
.message { flex-shrink: 0; }

:root {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-soft: #f7f8fa;
  --text: #1f2a37;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #176b87;
  --primary-dark: #10556c;
  --accent: #d97706;
  --danger: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea {
  font: inherit;
}

dialog {
  width: min(420px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}

dialog::backdrop { background: rgba(18, 29, 43, .5); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.dialog-actions button { min-width: 84px; }

button {
  border: 0;
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(18, 29, 43, .66), rgba(18, 29, 43, .44)),
    url("https://images.unsplash.com/photo-1556761175-b413da4baf72?auto=format&fit=crop&w=1600&q=80") center/cover;
}

.login-panel {
  width: min(420px, 100%);
  padding: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 24px 80px rgba(15, 23, 42, .28);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  font-size: 12px;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 8px;
  font-size: 32px;
}

.muted {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 14px;
  font-weight: 700;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: 0;
}

input {
  height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 46px;
  max-height: 160px;
  padding: 12px 14px;
  resize: vertical;
}

input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, .13);
}

.primary {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.primary:hover {
  background: var(--primary-dark);
}

.error {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
}

.chat-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.profile {
  height: 80px;
  min-height: 80px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  align-items: center;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

#profile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile strong, .profile-role {
  display: block;
}

.profile-role {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.avatar, .mini-avatar {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e0f2fe;
  color: #075985;
  font-weight: 900;
}

.avatar {
  width: 44px;
  height: 44px;
  font-size: 20px;
}

.mini-avatar {
  width: 28px;
  height: 28px;
  font-size: 13px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
}

.profile-edit {
  display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center;
  gap: 12px; min-width: 0; padding: 0; background: transparent; color: var(--text); text-align: left;
}
.profile-copy { min-width: 0; }
.profile-edit:hover #profile-name { color: var(--primary); }
.profile-edit:focus-visible, .tool-icon:focus-visible, .account-menu button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.account-menu { position: absolute; top: 66px; right: 18px; width: 164px; padding: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; z-index: 20;
  box-shadow: 0 10px 30px rgba(15,23,42,.15); }
.profile { position: relative; }
.account-menu button { display: block; width: 100%; padding: 11px 12px; background: transparent;
  color: var(--text); border-radius: 6px; text-align: left; font-size: 14px; }
.account-menu button:hover { background: var(--panel-soft); }
.account-menu .logout-item { color: var(--danger); }
.tool-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
  padding: 12px 18px; flex-shrink: 0; border-bottom: 1px solid var(--line); }
.tool-icon { position: relative; height: 42px; display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--muted); border-radius: 9px; }
.tool-icon:hover { background: var(--panel-soft); color: var(--primary); }
.tool-icon[aria-pressed="true"] { background: #e6f4f8; color: var(--primary); }
.tool-icon svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round; }
.tool-badge { position: absolute; top: 1px; right: 8px; border-radius: 12px; background: var(--danger);
  color: #fff; font-size: 10px; min-width: 17px; padding: 1px 4px; }
.sidebar-panel { min-height: 0; flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; min-height: 46px;
  padding: 6px 18px; flex-shrink: 0; }
.panel-heading h2 { margin: 0; font-size: 13px; color: var(--muted); }
.panel-heading h2 span { font-size: 12px; font-weight: 400; margin-left: 5px; }
.add-member { width: 30px; height: 30px; border-radius: 8px; color: var(--primary);
  background: #e6f4f8; font-size: 22px; }

.section-title {
  padding: 12px 18px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.conversation-list, .user-list {
  flex: 1;
  min-height: 0;
  align-content: start;
  display: grid;
  gap: 4px;
  padding: 0 10px 8px;
  overflow: auto;
  overscroll-behavior: contain;
}

.conversation, .user-item {
  width: 100%;
  display: grid;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conversation {
  grid-template-columns: 40px minmax(0, 1fr) auto;
  min-height: 62px;
  padding: 8px;
}

.conversation.active {
  background: #e6f4f8;
}

.conversation-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fef3c7;
  color: #92400e;
  font-weight: 900;
}

.conversation-copy {
  min-width: 0;
}

.conversation-copy strong, .conversation-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-copy small {
  margin-top: 3px;
  color: var(--muted);
}

.conversation b {
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
}

.user-item {
  grid-template-columns: 28px 1fr;
  min-height: 42px;
  padding: 7px 8px;
}

.user-item:hover, .conversation:hover {
  background: var(--panel-soft);
}

.main-chat {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  background: #f8fafc;
}

.chat-header {
  height: 80px;
  min-height: 80px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.chat-header { gap: 12px; }
.chat-header > div { min-width: 0; max-width: 100%; }
.chat-heading { flex: 1; }
.header-avatar { width: 44px; display: flex; align-items: center; }


.chat-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 20px;
}
.profile strong { line-height: 20px; }

.chat-header p {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: normal;
}

.messages {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  overflow: auto;
  overscroll-behavior: contain;
}

.user-avatar {
  width: 40px; height: 40px; flex: 0 0 40px; display: inline-flex;
  align-items: center; justify-content: center; border-radius: 50%;
  font-size: 27px; line-height: 1; user-select: none;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .04);
}
.user-avatar.small { width: 28px; height: 28px; flex-basis: 28px; font-size: 20px; border-radius: 50%; }
.avatar-preview .user-avatar { width: 64px; height: 64px; font-size: 44px; border-radius: 50%; }
.stack select { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px 12px; font: inherit; }
.message {
  display: flex; align-items: flex-start; gap: 10px;
  max-width: min(760px, 88%);
}
.message-content { min-width: 0; }
.message.mine { flex-direction: row-reverse; }
@media (max-width: 760px) {
  .messages { padding: 16px 12px; }
  .message { gap: 8px; }
  .message > .user-avatar { width: 34px; height: 34px; flex-basis: 34px; font-size: 24px; border-radius: 50%; }
}

.message.mine {
  align-self: flex-end;
}

.message-meta {
  margin: 0 0 5px 4px;
  color: var(--muted);
  font-size: 12px;
}

.message.mine .message-meta {
  text-align: right;
  margin-right: 4px;
}

.bubble {
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  line-height: 1.55;
  white-space: normal;
  overflow-wrap: anywhere;
}

.message.mine .bubble {
  background: #dff6ff;
  border-color: #b9e8f5;
}

.composer {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.composer textarea {
  min-width: 0;
  height: 46px;
  max-height: 120px;
  resize: none;
  overflow-y: auto;
}

.composer .primary {
  align-self: end;
}

.empty {
  color: var(--muted);
  padding: 8px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: 0 18px 60px rgba(15, 23, 42, .22);
}

@media (max-width: 760px) {
  .chat-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  .sidebar, .main-chat { grid-area: 1 / 1; }
  .chat-shell[data-mobile-view="list"] .main-chat { display: none; }
  .chat-shell[data-mobile-view="chat"] .sidebar { display: none; }
  .sidebar { border-right: 0; }
  .chat-header { grid-template-columns: auto 40px minmax(0, 1fr); gap: 10px; padding: 14px 16px; }
  .header-avatar { width: 40px; }
  .back-to-list { display: inline-flex; align-items: center; gap: 2px; min-height: 40px;
    padding: 6px 2px; background: transparent; color: var(--primary); font-size: 14px; white-space: nowrap; }
  .back-to-list:focus-visible { outline: 2px solid var(--primary); border-radius: 6px; }



  .messages {
    padding: 16px;
  }

  .message {
    max-width: 92%;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  }
}
