:root {
  color-scheme: light;
  --bg: #e9ece8;
  --panel: #f9faf8;
  --line: #d7ddd5;
  --text: #14211c;
  --muted: #637067;
  --accent: #0f8f61;
  --accent-dark: #08734d;
  --bubble-self: #95e66f;
  --bubble-peer: #ffffff;
  --danger: #b3261e;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100%;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 40px rgba(23, 35, 29, 0.12);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.login-panel h1 {
  margin: 16px 0 22px;
  font-size: 28px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.login-form input,
.login-form select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 0 12px;
}

.login-form button,
.composer button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: 0 18px;
  font-weight: 700;
}

.login-form button:active,
.composer button:active {
  background: var(--accent-dark);
}

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

.chat-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  background: var(--bg);
}

.conversation-pane {
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.pane-header,
.thread-header {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(249, 250, 248, 0.96);
}

.pane-header {
  justify-content: space-between;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pane-header div,
.thread-header div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.pane-header .header-actions {
  display: flex;
}

.pane-header strong,
.thread-header strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

.pane-header span,
.thread-header span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
}

.conversation-list {
  display: grid;
}

.conversation-item {
  width: 100%;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 68px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 10px 14px;
  color: inherit;
  text-align: left;
}

.conversation-item.active,
.conversation-item:hover {
  background: #edf4ef;
}

.avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #cad8d1;
  color: #24352d;
  font-weight: 800;
}

.avatar.bot {
  background: #c7ddff;
}

.conversation-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.conversation-subtitle {
  margin-top: 4px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.thread-pane {
  min-width: 0;
  display: grid;
  grid-template-rows: 58px 1fr auto;
  height: 100vh;
}

.back-button {
  display: none;
}

.message-list {
  min-height: 0;
  overflow-y: auto;
  padding: 18px 14px 20px;
}

.message-row {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

.message-row.self {
  justify-content: flex-end;
}

.message-row.peer {
  justify-content: flex-start;
}

.message-stack {
  max-width: min(72%, 620px);
  display: grid;
  gap: 4px;
}

.message-meta,
.message-footer {
  color: var(--muted);
  font-size: 11px;
}

.message-footer {
  line-height: 1.25;
}

.message-row.self .message-meta,
.message-row.self .message-footer {
  text-align: right;
}

.bubble {
  width: fit-content;
  max-width: 100%;
  border-radius: 8px;
  padding: 9px 11px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.self .bubble {
  margin-left: auto;
  background: var(--bubble-self);
}

.peer .bubble {
  background: var(--bubble-peer);
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.bot-badge {
  display: inline-block;
  margin-right: 6px;
  color: #285faa;
  font-weight: 800;
}

.composer {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.image-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--accent);
  font-size: 24px;
  font-weight: 700;
}

.image-button input {
  display: none;
}

.composer input {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
}

.image-message {
  display: block;
  max-width: min(260px, 100%);
  max-height: 320px;
  border-radius: 8px;
  object-fit: cover;
}

.image-dialog {
  width: min(94vw, 900px);
  max-width: 94vw;
  max-height: 92vh;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #101412;
}

.image-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.image-dialog img {
  display: block;
  max-width: 100%;
  max-height: 92vh;
  margin: auto;
}

.image-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
}

@media (max-width: 760px) {
  .chat-view {
    grid-template-columns: 1fr;
  }

  .conversation-pane {
    min-height: 100vh;
    border-right: 0;
  }

  .thread-pane {
    display: none;
  }

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

  .chat-view.thread-open .thread-pane {
    display: grid;
  }

  .back-button {
    display: block;
  }

  .message-stack {
    max-width: 82%;
  }
}
