:root {
  color-scheme: light;
  --rail: #2d2f32;
  --rail-active: #404348;
  --list: #f6f6f6;
  --list-active: #dedede;
  --chat: #ededed;
  --surface: #ffffff;
  --surface-soft: #f8f8f8;
  --line: #d8d8d8;
  --ink: #171717;
  --muted: #777d80;
  --green: #07c160;
  --green-dark: #05984b;
  --bubble-green: #95ec69;
  --danger: #c33b3b;
  --warning: #a66500;
  --blue: #2672ad;
  --rail-width: 68px;
  --conversation-width: 304px;
  --header-height: 66px;
  --composer-height: 190px;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--chat);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.hidden {
  display: none !important;
}

.login-view {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #e9ece9;
}

.login-panel {
  width: min(100%, 360px);
  padding: 34px;
  border: 1px solid #cfd5d0;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(24, 32, 27, 0.12);
}

.login-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
}

.login-mark svg {
  width: 30px;
  height: 30px;
}

.login-panel h1 {
  margin: 0 0 26px;
  font-size: 24px;
}

.login-panel label {
  display: grid;
  gap: 7px;
  margin-top: 16px;
  color: #4f5752;
  font-size: 13px;
}

.login-panel input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #cdd3ce;
  border-radius: 5px;
  outline: none;
  color: var(--ink);
}

.login-panel input:focus {
  border-color: var(--green-dark);
  box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.12);
}

.form-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.primary-button,
.secondary-button,
.send-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 5px;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--green-dark);
  background: var(--green);
  color: #fff;
}

.primary-button:hover,
.send-button:hover {
  background: var(--green-dark);
}

.primary-button svg,
.secondary-button svg {
  width: 17px;
  height: 17px;
}

.app {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-width) var(--conversation-width) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.rail {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 0 14px;
  background: var(--rail);
  color: #b8bbbf;
}

.me-avatar,
.contact-avatar {
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #bde6f0;
  color: #17323a;
  font-weight: 700;
}

.profile-id {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.me-avatar {
  width: 42px;
  height: 42px;
  margin-bottom: 10px;
}

.rail-button,
.tool-button,
.header-button,
.mobile-back {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.rail-button {
  width: 42px;
  height: 42px;
  border-radius: 5px;
  color: inherit;
}

.rail-button:hover,
.rail-button.active {
  background: var(--rail-active);
  color: var(--green);
}

.rail-button svg {
  width: 22px;
  height: 22px;
}

.rail-spacer,
.composer-spacer {
  flex: 1;
}

.conversation-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: var(--header-height) minmax(0, 1fr);
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--list);
}

.search-row {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid #e2e2e2;
}

.search-box {
  width: 100%;
  height: 35px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid #d1d1d1;
  border-radius: 5px;
  background: #e9e9e9;
  color: var(--muted);
}

.search-box svg {
  width: 16px;
  height: 16px;
}

.search-box input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
}

.conversation-list {
  overflow: auto;
}

.conversation-item {
  width: 100%;
  height: 74px;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid #ebebeb;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--list-active);
}

.contact-avatar {
  width: 46px;
  height: 46px;
  background: #c6ecf5;
}

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

.conversation-name {
  display: block;
  overflow: hidden;
  font-size: 15px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-preview {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-time {
  align-self: start;
  margin-top: 4px;
  color: #999;
  font-size: 11px;
}

.chat-pane {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: var(--header-height) auto minmax(0, 1fr) var(--composer-height);
  overflow: hidden;
  background: var(--chat);
}

.chat-header {
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}

.chat-heading {
  min-width: 0;
  flex: 1;
}

.chat-heading h2 {
  margin: 0;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-state,
.status-line {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.agent-state {
  margin-top: 4px;
}

.state-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #9a9fa1;
}

.state-dot.online {
  background: var(--green);
}

.state-dot.offline {
  background: #9a9fa1;
}

.header-button,
.mobile-back {
  width: 38px;
  height: 38px;
  border-radius: 5px;
}

.header-button:hover,
.mobile-back:hover,
.tool-button:hover {
  background: rgba(0, 0, 0, 0.06);
}

.header-button svg,
.mobile-back svg {
  width: 21px;
  height: 21px;
}

.mobile-back {
  display: none;
  margin-right: 5px;
}

.connection-banner {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-bottom: 1px solid #ecd9b7;
  background: #fff4dc;
  color: #79500a;
  font-size: 12px;
}

.connection-banner svg {
  width: 15px;
  height: 15px;
}

.message-list {
  min-height: 0;
  overflow-y: auto;
  padding: 24px max(24px, 4vw);
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.day-divider {
  margin: 4px 0 18px;
  color: #8b8f91;
  font-size: 12px;
  text-align: center;
}

.message-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 14px 0;
}

.message-row.outbound {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: #c6ecf5;
  font-weight: 700;
}

.message-row.outbound .message-avatar {
  background: #c9e5d1;
}

.message-stack {
  max-width: min(68%, 680px);
}

.message-bubble {
  position: relative;
  padding: 10px 12px;
  border: 1px solid #d7d7d7;
  border-radius: 5px;
  background: var(--surface);
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-row.outbound .message-bubble {
  border-color: #86d65d;
  background: var(--bubble-green);
}

.image-bubble {
  padding: 4px;
  background: var(--surface);
}

.image-bubble img {
  display: block;
  max-width: min(360px, 100%);
  max-height: 360px;
  border-radius: 3px;
  object-fit: contain;
}

.message-meta {
  margin-top: 5px;
  color: #888d90;
  font-size: 11px;
}

.message-row.outbound .message-meta {
  text-align: right;
}

.message-meta.failed,
.message-meta.unknown {
  color: var(--danger);
}

.composer {
  min-height: 0;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr) 42px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 14px 0;
}

.tool-button {
  width: 34px;
  height: 34px;
  border-radius: 5px;
}

.tool-button svg {
  width: 21px;
  height: 21px;
}

.upload-status {
  color: var(--muted);
  font-size: 12px;
}

.composer textarea {
  width: 100%;
  min-height: 0;
  resize: none;
  padding: 6px 18px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  line-height: 1.55;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 0 16px 8px;
}

.character-count {
  color: var(--muted);
  font-size: 11px;
}

.send-button {
  min-width: 78px;
  min-height: 34px;
  border: 1px solid #bfc6c1;
  background: var(--surface);
  color: var(--green-dark);
}

.send-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.detail-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 30;
  width: min(88vw, 350px);
  transform: translateX(105%);
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -12px 0 36px rgba(24, 28, 25, 0.12);
  transition: transform 180ms ease;
}

.detail-drawer.open {
  transform: translateX(0);
}

.detail-drawer > header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.detail-section {
  padding: 20px;
  border-bottom: 1px solid #ededed;
}

.detail-label {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12px;
}

.contact-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.contact-profile .contact-avatar {
  width: 42px;
  height: 42px;
}

.status-line {
  margin-bottom: 16px;
  font-size: 14px;
}

.secondary-button {
  padding: 0 14px;
  border: 1px solid #cbd1cd;
  background: var(--surface);
}

.secondary-button:hover {
  border-color: var(--green-dark);
  color: var(--green-dark);
}

.pairing-code {
  width: 100%;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #cbd1cd;
  border-radius: 5px;
  background: #f1f4f1;
  font-family: Consolas, monospace;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(23, 28, 25, 0.35);
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: grid;
  gap: 8px;
}

.toast {
  max-width: min(88vw, 360px);
  padding: 11px 14px;
  border: 1px solid #cfd4d0;
  border-radius: 5px;
  background: #222825;
  color: #fff;
  box-shadow: 0 8px 26px rgba(20, 25, 22, 0.2);
}

.toast.error {
  background: #8f2f2f;
}

@media (max-width: 760px) {
  :root {
    --header-height: 60px;
    --composer-height: 170px;
  }

  .app {
    display: block;
  }

  .rail {
    display: none;
  }

  .conversation-pane,
  .chat-pane {
    width: 100%;
    height: 100%;
  }

  .chat-pane {
    display: none;
  }

  .app.chat-open .conversation-pane {
    display: none;
  }

  .app.chat-open .chat-pane {
    display: grid;
  }

  .mobile-back {
    display: grid;
  }

  .message-list {
    padding: 18px 12px;
  }

  .message-stack {
    max-width: calc(100% - 58px);
  }

  .image-bubble img {
    max-width: min(68vw, 320px);
  }

  .login-panel {
    padding: 28px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
