:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f7f9;
  color: #17202a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: #1967d2;
  color: #fff;
  cursor: pointer;
  min-height: 40px;
  padding: 0 14px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(360px, 1fr) minmax(280px, 320px);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid #d9dee7;
  background: #fff;
  min-width: 0;
  min-height: 0;
}

label {
  display: grid;
  gap: 6px;
  color: #526070;
  font-size: 13px;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cfd6e1;
  border-radius: 6px;
  background: #fff;
  color: #17202a;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.login-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(23, 32, 42, 0.24);
}

.login-dialog::backdrop {
  background: rgba(23, 32, 42, 0.42);
}

.login-form {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.login-form h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.login-form p {
  margin: 0;
  color: #526070;
  font-size: 14px;
}

.login-error {
  margin: -4px 0 0;
  color: #b3261e;
  font-size: 13px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 72px;
  padding: 16px;
  border-bottom: 1px solid #e5e8ee;
}

.chat-header > div {
  min-width: 0;
}

.close-chat,
.metadata-toggle,
.logout-button {
  display: none;
  flex: 0 0 auto;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid #cfd6e1;
  border-radius: 999px;
  background: #fff;
  color: #17202a;
  font-weight: 700;
}

.close-chat {
  font-size: 28px;
  line-height: 1;
}

.logout-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-height: 34px;
  border-radius: 6px;
  color: #526070;
  font-weight: 600;
}

.logout-button svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.conversation-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid #e5e8ee;
}

.conversation-tab {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid #cfd6e1;
  background: #fff;
  color: #526070;
  font-size: 13px;
  text-align: center;
}

.conversation-tab.active {
  border-color: #1967d2;
  background: #eef5ff;
  color: #17202a;
}

.conversation-tab.has-unread {
  font-weight: 700;
}

.conversation-list {
  min-height: 0;
  flex: 1;
  overflow: auto;
}

.conversation-status {
  margin: 0;
  padding: 10px 16px 12px;
  border-top: 1px solid #e5e8ee;
  color: #667587;
  font-size: 12px;
  text-align: center;
}

.conversation {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid #eef1f5;
  border-radius: 0;
  background: #fff;
  color: #17202a;
  text-align: left;
}

.conversation:hover,
.conversation.active {
  background: #eef5ff;
}

.conversation-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.conversation-user {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #d93025;
  color: #fff;
  font-size: 12px;
}

.conversation-preview,
.conversation-date,
.active-meta {
  margin: 0;
  color: #667587;
  font-size: 13px;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.details-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid #d9dee7;
  background: #fff;
}

.details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 72px;
  padding: 16px;
  border-bottom: 1px solid #e5e8ee;
}

.details-header > div {
  min-width: 0;
}

.conversation-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  width: 100%;
}

.archive-button,
.delete-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #cfd6e1;
  background: #fff;
  font-size: 12px;
}

.archive-button {
  color: #526070;
}

.archive-button:hover {
  border-color: #1967d2;
  color: #17202a;
}

.delete-button {
  color: #b3261e;
}

.delete-button:hover {
  border-color: #1967d2;
  color: #b3261e;
}

.close-details {
  display: none;
  flex: 0 0 auto;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid #cfd6e1;
  border-radius: 999px;
  background: #fff;
  color: #17202a;
  font-size: 24px;
  line-height: 1;
}

.details-header h2 {
  margin: 0;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.details-email,
.details-id {
  margin: 4px 0 0;
  color: #667587;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.details-id {
  font-size: 12px;
}

.user-context {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.empty-details {
  margin: 0;
  color: #667587;
  font-size: 13px;
}

.metadata-updated {
  margin: 0;
  color: #667587;
  font-size: 12px;
}

.context-section {
  display: grid;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid #eef1f5;
}

.context-section h3 {
  margin: 0;
  color: #17202a;
  font-size: 13px;
  text-transform: uppercase;
}

.context-row {
  display: grid;
  gap: 2px;
}

.context-key {
  color: #667587;
  font-size: 12px;
}

.context-value {
  color: #17202a;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.active-user {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.empty-state {
  margin: auto;
  color: #667587;
}

.message {
  max-width: min(680px, 76%);
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(18, 32, 52, 0.08);
}

.message.operator {
  align-self: flex-end;
  background: #d7ebff;
}

.message.user {
  align-self: flex-start;
}

.message p {
  margin: 0;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message img {
  display: block;
  max-width: 260px;
  max-height: 260px;
  margin-top: 8px;
  border-radius: 6px;
  cursor: zoom-in;
  object-fit: contain;
}

.message-time {
  display: block;
  margin-top: 6px;
  color: #667587;
  font-size: 11px;
}

.message.operator .message-time {
  text-align: right;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: stretch;
  padding: 16px;
  border-top: 1px solid #d9dee7;
  background: #fff;
}

.composer textarea {
  min-height: 148px;
  max-height: 220px;
  font-size: 13px;
}

.attachment-area {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.attach-button {
  display: grid;
  place-items: center;
  width: 40px;
  min-height: 40px;
  border: 1px solid #cfd6e1;
  border-radius: 6px;
  color: #17202a;
  cursor: pointer;
  font-size: 18px;
}

.image-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.attachment-preview {
  position: relative;
  width: 72px;
  height: 72px;
}

.attachment-preview img {
  width: 72px;
  height: 72px;
  border: 1px solid #d9dee7;
  border-radius: 6px;
  object-fit: cover;
}

.remove-attachment {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 999px;
  background: #17202a;
  color: #fff;
  line-height: 1;
}

.send-button {
  align-self: end;
  width: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 18px;
}

.image-dialog {
  width: min(94vw, 1100px);
  height: min(92vh, 900px);
  padding: 0;
  border: 0;
  background: transparent;
}

.image-dialog::backdrop {
  background: rgba(15, 23, 42, 0.82);
}

.image-dialog img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  object-fit: contain;
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  font-size: 24px;
  line-height: 1;
}

@media (max-width: 980px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    position: relative;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100vh;
    height: 100dvh;
  }

  .sidebar {
    min-height: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .chat-panel {
    display: none;
    min-height: 0;
  }

  .chat-open .sidebar {
    display: none;
  }

  .chat-open .chat-panel {
    display: grid;
  }

  .chat-header {
    min-height: 64px;
    padding: 12px;
  }

  .metadata-toggle {
    display: block;
  }

  .close-chat {
    display: block;
  }

  .details-panel {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 10;
    width: min(88vw, 360px);
    height: 100vh;
    height: 100dvh;
    transform: translateX(100%);
    border-left: 1px solid #d9dee7;
    box-shadow: -12px 0 28px rgba(18, 32, 52, 0.18);
    transition: transform 160ms ease;
  }

  .details-open .details-panel {
    transform: translateX(0);
  }

  .close-details {
    display: block;
  }

  .composer {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px;
  }

  .composer textarea {
    min-height: 104px;
    max-height: 150px;
  }

  .attachment-area {
    flex-direction: column;
  }

  .attachment-preview,
  .attachment-preview img {
    width: 52px;
    height: 52px;
  }

  .message {
    max-width: 92%;
  }

  .message img {
    max-width: 220px;
    max-height: 220px;
  }
}
