:root {
  --bg: #e8edf7;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --line: #d0d5dd;
  --brand: #0f4cda;
  --brand-strong: #0b3cae;
  --danger: #b42318;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Manrope', sans-serif;
  color: var(--ink);
  background: radial-gradient(1100px 500px at 0% 0%, #d5e3ff 0%, transparent 52%), var(--bg);
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 10px 40px rgba(16, 24, 40, 0.08);
}

.auth-card h1,
.side-panel h2 {
  margin: 0;
}

.auth-card p,
.side-panel p {
  color: var(--muted);
}

.tabs {
  margin: 16px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tab-btn,
.lang-btn,
.ghost-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  cursor: pointer;
}

.tab-btn.active,
.lang-btn.active {
  border-color: var(--brand);
  color: var(--brand);
  background: #edf4ff;
}

.lang-switch {
  display: flex;
  gap: 8px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

input,
textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font: inherit;
  background: #fff;
}

input:focus,
textarea:focus {
  outline: 2px solid #bfd3ff;
  border-color: var(--brand);
}

.primary-btn {
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.ghost-btn {
  width: 100%;
}

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

.chat-shell {
  width: 100%;
  max-width: 1220px;
  height: min(92dvh, 860px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  display: grid;
  grid-template-columns: 300px 1fr;
  box-shadow: 0 14px 44px rgba(16, 24, 40, 0.1);
}

.side-panel {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #f8fbff, #f2f5fa);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
}

.side-top {
  padding: 18px 16px 12px;
  border-bottom: 1px solid #e4e7ec;
}

.side-top p {
  margin-top: 8px;
  margin-bottom: 12px;
  font-size: 13px;
}

.side-new-btn {
  width: 100%;
}

.conversation-list {
  min-height: 0;
  overflow: auto;
  padding: 10px;
  display: grid;
  gap: 6px;
  align-content: start;
}

.conversation-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  cursor: pointer;
}

.conversation-item:hover {
  background: #eaf1ff;
}

.conversation-item.active {
  background: #dfeaff;
  border-color: #bfd3ff;
}

.conversation-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.conversation-date {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

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

.conversation-actions {
  opacity: 0;
  transition: opacity 120ms ease;
  display: flex;
  gap: 8px;
}

.conversation-item:hover .conversation-actions,
.conversation-item.active .conversation-actions {
  opacity: 1;
}

.conversation-action {
  font-size: 11px;
  color: #475467;
}

.conversation-action:hover {
  color: var(--brand);
  text-decoration: underline;
}

.empty-list {
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
}

.side-bottom {
  border-top: 1px solid #e4e7ec;
  padding: 12px 16px 16px;
}

.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 0;
}

.chat-header {
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.chat-header h3 {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header .lang-btn {
  padding: 8px 10px;
}

.messages {
  overflow: auto;
  padding: 18px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.empty-chat {
  margin: auto;
  color: var(--muted);
  text-align: center;
  max-width: 560px;
}

.msg {
  max-width: min(90%, 820px);
  border-radius: 12px;
  padding: 12px 14px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.msg.user {
  margin-left: auto;
  background: #edf4ff;
  border: 1px solid #bfd3ff;
}

.msg.assistant {
  margin-right: auto;
  background: #f8fafc;
  border: 1px solid #e4e7ec;
}

.refs {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.chat-input-wrap {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

textarea {
  resize: none;
  min-height: 48px;
  max-height: 170px;
}

#chatError {
  margin: 0;
  padding: 0 12px 10px;
}

@media (max-width: 960px) {
  .app-shell {
    padding: 0;
  }

  .chat-shell {
    grid-template-columns: 1fr;
    height: 100dvh;
    border-radius: 0;
    max-width: none;
  }

  .side-panel {
    grid-template-rows: auto;
    border-right: none;
    border-bottom: 1px solid #e4e7ec;
    padding: 10px;
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .side-top {
    border: none;
    padding: 0;
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .side-top p,
  .conversation-list,
  .side-bottom {
    display: none;
  }

  .side-top h2 {
    font-size: 18px;
  }

  .chat-header h3 {
    font-size: 16px;
  }
}
