:root {
  --bg-a: #eefde2;
  --bg-b: #f9fff2;
  --panel: rgba(255, 255, 255, 0.86);
  --line: #d5e9b5;
  --line-strong: #b8d97f;
  --text: #16230f;
  --muted: #5f7153;
  --accent: #8de01b;
  --accent-2: #6db30d;
  --danger: #d64536;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(circle at 8% 8%, #dbffb3 0%, rgba(219, 255, 179, 0) 30%),
    radial-gradient(circle at 92% 0%, #d6f7a1 0%, rgba(214, 247, 161, 0) 33%),
    linear-gradient(180deg, var(--bg-a), var(--bg-b));
}

.app-shell {
  min-height: 100vh;
  padding: 14px;
}

.hidden {
  display: none !important;
}

.auth-card {
  width: 100%;
  max-width: 460px;
  margin: 70px auto;
  padding: 22px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(6px);
  box-shadow: 0 18px 35px rgba(84, 120, 22, 0.14);
}

input,
textarea,
select,
button {
  width: 100%;
  border-radius: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  font-size: 14px;
}

input,
textarea,
select {
  background: #ffffff;
  color: var(--text);
}

textarea {
  min-height: 76px;
  resize: vertical;
}

#messageInput {
  font-size: 16px;
  line-height: 1.45;
}

button {
  border: none;
  cursor: pointer;
  font-weight: 700;
  color: #1a2a0b;
  background: linear-gradient(180deg, #a8f03d, var(--accent));
}

button.secondary {
  color: #f3ffe0;
  background: linear-gradient(180deg, #88c91a, var(--accent-2));
}

button.danger {
  color: #661e18;
  background: #f5d7d4;
}

button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.status {
  margin-top: 8px;
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: 285px 1fr 355px;
  gap: 12px;
  min-height: calc(100vh - 28px);
}

.sidebar,
.chat-main,
.docs-panel {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(4px);
  box-shadow: 0 10px 24px rgba(91, 122, 26, 0.09);
}

.sidebar-header,
.chat-main-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.sidebar-header h2,
.chat-main-header h2,
.docs-panel h3 {
  margin: 0;
}

.chat-main-header h2 {
  margin-bottom: 2px;
}

.controls-stack {
  display: grid;
  gap: 6px;
  min-width: 330px;
}

.control-row label {
  width: auto;
  min-width: 56px;
  color: var(--muted);
  font-size: 12px;
}

.new-chat-block,
.docs-upload {
  display: grid;
  gap: 6px;
}

.chat-list,
.doc-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  max-height: 330px;
  overflow: auto;
}

.chat-item,
.doc-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #ffffff;
}

.chat-item {
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.12s ease;
}

.chat-item:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.chat-item.active {
  border-color: #9ece46;
  background: #f8ffe9;
}

.chat-title,
.doc-title {
  font-weight: 600;
  word-break: break-word;
}

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

.doc-toggle {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.doc-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.doc-item.attached {
  border-color: #98c951;
  background: #f7ffe8;
}

.doc-actions button {
  font-size: 12px;
  padding: 6px 7px;
}

.messages {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px;
  height: calc(100vh - 338px);
  overflow: auto;
  background: linear-gradient(180deg, #fdfff7, #f7fdec);
  line-height: 1.38;
}

.msg {
  margin-bottom: 6px;
  padding: 6px 8px;
  border-radius: 7px;
}

.msg-content {
  font-size: 18px;
  line-height: 1.42;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  background: #ecfccb;
  border: 1px solid #d7f6a0;
}

.msg.assistant {
  background: #f4f9eb;
  border: 1px solid #dfeccc;
}

.msg.pending {
  opacity: 0.94;
}

.msg-role {
  margin-bottom: 3px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.typing-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #d9f5aa;
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.msg-latency {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.input-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 130px;
  gap: 6px;
}

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

  .controls-stack {
    min-width: 0;
    width: 100%;
  }

  .chat-list,
  .doc-list,
  .messages {
    max-height: 340px;
    height: auto;
  }
}





.cloud-consent {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fbffef;
}

.cloud-consent input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}
