:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --border: #d9e2ec;
  --text: #14212f;
  --muted: #697586;
  --accent: #087443;
  --accent-deep: #055a35;
  --accent-soft: #def7e8;
  --accent-ring: rgba(8, 116, 67, 0.16);
  --incoming: #ffffff;
  --outgoing: #dff7e8;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  background:
    radial-gradient(circle at top right, rgba(8, 116, 67, 0.08), transparent 28%),
    linear-gradient(180deg, #fbfcfd 0%, #f3f6f8 100%);
}

.thread-panel,
.chat-panel {
  min-height: 100vh;
  background: var(--panel);
}

.thread-panel {
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.panel-header,
.chat-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.panel-header {
  justify-content: space-between;
  padding: 18px 18px 16px;
}

.panel-heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.panel-header p {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-header h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.panel-caption {
  color: var(--muted);
  font-size: 12px;
}

.panel-header button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  transition: 140ms ease;
}

.panel-header button:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.thread-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 10px 14px;
  gap: 6px;
}

.thread-button {
  min-height: 72px;
  border: 1px solid transparent;
  padding: 12px 14px;
  text-align: left;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: 140ms ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thread-button.active {
  background: var(--accent-soft);
  border-color: rgba(8, 116, 67, 0.16);
}

.thread-button:hover {
  background: var(--panel-soft);
}

.thread-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.thread-labels {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thread-name-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.thread-name {
  display: block;
  min-width: 0;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-mode-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.thread-mode-bot {
  background: #e7f8ee;
  color: #0f7a48;
}

.thread-mode-human {
  background: #fff1f3;
  color: #be123c;
}

.thread-meta,
.thread-time {
  color: var(--muted);
  font-size: 12px;
}

.thread-time {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.thread-preview,
.chat-header span {
  color: var(--muted);
  font-size: 13px;
}

.thread-preview {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.chat-panel {
  display: grid;
  grid-template-rows: 76px 1fr auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.76), rgba(255, 255, 255, 0.76)),
    radial-gradient(circle at top left, rgba(8, 116, 67, 0.08), transparent 24%);
}

.chat-header {
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(16px);
}

.chat-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header > div:last-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-header strong {
  font-size: 17px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.mode-bot {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.mode-human {
  background: #fff1f3;
  color: #be123c;
}

.chat-actions button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #12a065);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(8, 116, 67, 0.22);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px;
  overflow-y: auto;
}

.message {
  max-width: min(70ch, 80%);
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: pre-wrap;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.message p {
  margin: 0;
}

.message.inbound {
  align-self: flex-start;
  background: var(--incoming);
  border-top-left-radius: 3px;
}

.message.outbound {
  align-self: flex-end;
  background: var(--outgoing);
  border-color: rgba(8, 116, 67, 0.16);
  border-top-right-radius: 3px;
}

.message time {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.message-attachment {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.message-attachment-image {
  width: min(260px, 100%);
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--panel-soft);
}

.message-attachment-label {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.message-attachment-name {
  font-size: 14px;
}

.message-attachment-caption,
.message-text {
  color: var(--text);
}

.reply-form {
  display: grid;
  grid-template-columns: 1fr 104px;
  gap: 12px;
  padding: 18px 20px 20px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
}

.reply-main {
  display: grid;
  gap: 10px;
}

.reply-tools {
  display: flex;
  gap: 8px;
}

.reply-tools button,
.attachment-chip button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}

.attachment-preview.hidden {
  display: none;
}

.attachment-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.attachment-copy {
  display: grid;
  gap: 2px;
}

.attachment-kind {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.reply-form textarea {
  resize: vertical;
  min-height: 54px;
  max-height: 160px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  font: inherit;
  outline: none;
  transition: 140ms ease;
}

.reply-form textarea:focus {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.reply-form button {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: 140ms ease;
}

.reply-form button:hover:not(:disabled) {
  background: var(--accent-deep);
}

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

.empty-state {
  margin: auto;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

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

  .thread-panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .thread-list {
    max-height: 280px;
  }

  .chat-panel {
    min-height: calc(100vh - 220px);
  }

  .panel-header,
  .chat-header {
    min-height: 72px;
  }

  .message-list {
    padding: 18px;
  }

  .message {
    max-width: 92%;
  }

  .reply-form {
    grid-template-columns: 1fr;
  }

  .reply-form button {
    min-height: 48px;
  }
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.panel-header .logout-button {
  width: auto;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
}

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

.login-shell {
  width: 100%;
  max-width: 380px;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.login-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.login-heading p {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.login-heading h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

.login-field input {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  font-weight: 400;
  font-size: 15px;
}

.login-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.login-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fdecec;
  color: #b42318;
  font-size: 13px;
}

.login-error[hidden] {
  display: none;
}

.login-card button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: 140ms ease;
}

.login-card button:hover:not(:disabled) {
  background: var(--accent-deep);
}

.login-card button:disabled {
  opacity: 0.7;
  cursor: progress;
}
