:root {
  --bg: #0a100e;
  --bg-elev: #121c18;
  --bg-soft: #182722;
  --bg-panel: rgba(16, 26, 22, 0.88);
  --line: rgba(160, 200, 175, 0.1);
  --line-strong: rgba(160, 200, 175, 0.18);
  --text: #eef5f0;
  --muted: #7f978b;
  --accent: #3ecf8e;
  --accent-dim: #248f5c;
  --accent-glow: rgba(62, 207, 142, 0.22);
  --in: #1e2f28;
  --out: #164a34;
  --danger: #e85d5d;
  --warn: #d4a017;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden],
.is-hidden {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse 70% 45% at 0% 0%, rgba(62, 207, 142, 0.12), transparent 50%),
    radial-gradient(ellipse 50% 40% at 100% 80%, rgba(30, 90, 70, 0.25), transparent 55%),
    linear-gradient(180deg, #0c1411 0%, var(--bg) 40%, #0b1210 100%);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

/* —— Login —— */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 44px 40px;
  background:
    linear-gradient(145deg, rgba(30, 48, 40, 0.9), rgba(14, 22, 18, 0.95)),
    var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  animation: rise 0.55s ease both;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-size: 0.95rem;
}

.login-panel h1 {
  margin-top: 12px;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.sub {
  margin: 10px 0 28px;
  color: var(--muted);
  font-size: 0.95rem;
}

.hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.8rem;
}

.hint code {
  font-family: var(--mono);
  color: var(--accent);
}

.login-panel label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.login-panel input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-panel input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-panel button[type="submit"] {
  margin-top: 16px;
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #4ae09c, var(--accent));
  color: #052016;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, filter 0.15s;
}

.login-panel button[type="submit"]:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 0.875rem;
}

/* —— App shell —— */
.app {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100%;
  width: 100%;
  max-width: none;
  margin: 0;
  border: none;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  animation: fade 0.4s ease both;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-elev), #101916);
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 10px;
  gap: 10px;
}

.sidebar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand-tag {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.ghost:hover {
  color: var(--text);
  border-color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

.search-wrap {
  padding: 12px 14px;
}

.search-wrap input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-wrap input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.conv-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0 10px 14px;
}

.conv-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 10px;
  padding: 12px;
  border-radius: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  margin-bottom: 4px;
}

.conv-item:hover {
  background: var(--bg-soft);
  transform: translateX(2px);
}

.conv-item.active {
  background: linear-gradient(90deg, rgba(62, 207, 142, 0.12), transparent 80%);
  border-color: var(--line-strong);
}

.conv-item .avatar {
  grid-row: 1 / 3;
  align-self: center;
}

.conv-item .name {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-item .preview {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-item .time {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
}

.conv-item .badge-slot {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  background: linear-gradient(145deg, #2a4a3c, #1a3028);
  color: var(--accent);
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #062016;
  font-size: 0.7rem;
  font-weight: 700;
}

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(ellipse 60% 30% at 50% 0%, rgba(62, 207, 142, 0.05), transparent),
    transparent;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 18, 16, 0.45);
}

.chat-head-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-head h2 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.meta {
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.back-btn {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
  flex-shrink: 0;
}

.back-btn:active {
  background: var(--bg-soft);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.empty-title {
  color: var(--text);
  font-weight: 600;
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: min(82%, 480px);
  animation: bubble-in 0.22s ease both;
}

.msg-row.in {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-row.out {
  align-self: flex-end;
  align-items: flex-end;
}

.bubble {
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  min-height: 36px;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
  border: none;
}

.bubble .body {
  display: inline;
}

.bubble.in {
  background: #2c2c2e;
  color: #f2f2f2;
  border-bottom-left-radius: 5px;
}

.bubble.in::after {
  content: "";
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-right-color: #2c2c2e;
  border-left: 0;
}

.bubble.out {
  background: #34d399;
  color: #0a1a12;
  border-bottom-right-radius: 5px;
  box-shadow: none;
}

.bubble.out::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: #34d399;
  border-right: 0;
}

.bubble.zh {
  background: #3a3a3c;
  color: #e8e8ea;
  font-size: 0.9rem;
  padding: 8px 12px;
  min-height: 32px;
  border-radius: 14px;
  margin-top: 0;
}

.bubble.zh::after {
  display: none;
}

.bubble .kind {
  display: block;
  font-size: 0.72rem;
  color: var(--accent);
  margin-bottom: 2px;
}

.translation.translating {
  color: #9a9a9e;
  font-style: italic;
  font-size: 0.85rem;
}

.translation.tr-error {
  color: var(--danger);
  font-style: normal;
}

.msg-row > .stamp {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--muted);
  line-height: 1;
  padding: 0 4px;
  opacity: 0.8;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px 18px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16, 24, 20, 0.5), var(--bg-elev));
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.composer textarea {
  resize: none;
  min-height: 48px;
  max-height: 140px;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  outline: none;
  field-sizing: content;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer textarea:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.composer #send-btn {
  align-self: end;
  padding: 0 22px;
  height: 48px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #4ae09c, var(--accent));
  color: #052016;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.15s;
}

.composer #send-btn:hover {
  filter: brightness(1.05);
}

.composer #send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

  .back-btn {
    display: grid;
    place-items: center;
  }

  .sidebar {
    display: none;
  }

  .app.show-list .sidebar {
    display: flex;
  }

  .app.show-list .chat {
    display: none;
  }

  .app:not(.show-list) .sidebar {
    display: none;
  }

  .messages {
    padding: 12px 12px 10px;
    gap: 8px;
  }

  .msg-row {
    max-width: 85%;
  }

  .bubble {
    padding: 9px 13px;
    font-size: 0.94rem;
    min-height: 34px;
    border-radius: 15px;
  }

  .bubble.zh {
    padding: 7px 11px;
    font-size: 0.88rem;
  }
}

@media (min-width: 861px) {
  .back-btn {
    display: none !important;
  }
}

@media (min-width: 1200px) {
  .app {
    grid-template-columns: 400px 1fr;
  }

  .messages {
    padding: 20px 28px;
  }

  .msg-row {
    max-width: min(48%, 480px);
  }
}

/* —— Settings modal —— */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: min(520px, 100%);
  max-height: min(90vh, 640px);
  overflow: auto;
  background: linear-gradient(165deg, #16241e, #101916);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px 22px 22px;
  animation: rise 0.3s ease both;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
}

.modal-head h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

.settings-form label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 8px;
}

.settings-form label + textarea {
  margin-bottom: 16px;
}

.settings-form textarea {
  width: 100%;
  padding: 12px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  outline: none;
  resize: vertical;
  min-height: 72px;
  line-height: 1.45;
}

.settings-form textarea:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.settings-form button[type="submit"] {
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #4ae09c, var(--accent));
  color: #052016;
  font-weight: 600;
  cursor: pointer;
}

.settings-status {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--accent);
}

.settings-status.error {
  color: var(--danger);
}
