:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --border: #e2e6ee;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #15803d;
  --primary-dark: #166534;
  --user-bubble: #dcfce7;
  --ai-bubble: #ffffff;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }

/* ---------- auth ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #14532d 0%, #166534 55%, #15803d 100%);
  padding: 20px;
}
.auth-card {
  background: var(--panel);
  border-radius: 18px;
  padding: 34px 38px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .28);
}
.auth-logo { font-size: 44px; text-align: center; }
.auth-card h1 { text-align: center; margin: 6px 0 4px; color: var(--primary-dark); }
.auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 20px; line-height: 1.45; }
.tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.tab {
  flex: 1; border: 0; background: transparent; padding: 9px 0; border-radius: 8px;
  font-weight: 600; color: var(--muted);
}
.tab.active { background: var(--panel); color: var(--primary-dark); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.auth-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px; outline: none;
}
.auth-card input:focus { border-color: var(--primary); }
.btn-primary {
  width: 100%; margin-top: 18px; padding: 12px; border: 0; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 15px; font-weight: 600;
}
.btn-primary:hover { background: var(--primary-dark); }
.error { background: #fee2e2; color: var(--danger); border-radius: 8px; padding: 9px 12px; margin-top: 12px; font-size: 13px; }

/* ---------- app layout ---------- */
.app-wrap { display: flex; height: 100vh; }
.sidebar {
  width: 290px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-head { padding: 16px; border-bottom: 1px solid var(--border); }
.sidebar-title { font-weight: 700; font-size: 17px; color: var(--primary-dark); margin-bottom: 12px; }
.btn-new {
  width: 100%; padding: 10px; border: 1px dashed var(--primary); border-radius: 10px;
  background: #f0fdf4; color: var(--primary-dark); font-weight: 600; font-size: 14px;
}
.btn-new:hover { background: #dcfce7; }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
  padding: 11px 12px; border-radius: 10px; margin-bottom: 4px; cursor: pointer;
  color: var(--text); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: #dcfce7; font-weight: 600; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.me-label { font-size: 13px; color: var(--muted); }
.btn-ghost { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 6px 10px; border-radius: 8px; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-xs { padding: 2px 7px; font-size: 12px; }

/* ---------- chat ---------- */
.main { flex: 1; display: flex; min-width: 0; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 420px; line-height: 1.6; }
.empty-icon { font-size: 52px; margin-bottom: 10px; }
.empty-hint { font-size: 13px; color: #9ca3af; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--panel); }
.chat-title-wrap { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 21px; line-height: 1.3; }
.file-chips { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.file-chip {
  display: flex; align-items: center; gap: 12px; font-size: 14.5px; font-weight: 500;
  padding: 12px 16px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); min-width: 260px; max-width: 100%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
.file-chip a { color: inherit; text-decoration: none; font-size: 14.5px; overflow-wrap: anywhere; }
.file-chip a:hover { text-decoration: underline; }
.file-chip .chip-size { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: auto; white-space: nowrap; }
.chip-del {
  border: 0; background: var(--bg); color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 2px 7px; border-radius: 50%; line-height: 1.4; flex-shrink: 0;
}
.chip-del:hover { color: var(--danger); background: #fee2e2; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- панель предпросмотра документа ---------- */
.preview-handle {
  width: 6px; flex-shrink: 0; cursor: col-resize; user-select: none;
  background: transparent; position: relative; transition: background .15s;
}
.preview-handle::after {
  content: ""; position: absolute; left: 2px; top: 20%; bottom: 20%;
  width: 2px; border-radius: 2px; background: var(--border);
}
.preview-handle:hover, .preview-handle:active { background: rgba(21, 128, 61, .18); }
.preview-handle:hover::after, .preview-handle:active::after { background: var(--primary); }
body.resizing { cursor: col-resize; user-select: none; }
.preview {
  width: 460px; max-width: 46vw; border-left: 1px solid var(--border);
  background: var(--panel); display: flex; flex-direction: column; min-width: 0; flex-shrink: 0;
}
.preview-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.preview-title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.preview-body { flex: 1; overflow: auto; padding: 16px; }
.preview-body.no-pad { padding: 0; display: flex; flex-direction: column; }
.preview-frame { width: 100%; height: 100%; border: 0; flex: 1; }
.preview-text {
  margin: 0; font-family: inherit; font-size: 14.5px; line-height: 1.6;
  white-space: pre-wrap; word-wrap: break-word;
}
.preview-img { max-width: 100%; height: auto; border-radius: 8px; }
.preview-loading, .preview-note { color: var(--muted); font-size: 14px; }
.preview-note a { color: var(--primary); }
.msg { max-width: 80%; padding: 13px 17px; border-radius: 14px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; font-size: 16px; }
.msg.user { align-self: flex-start; background: var(--user-bubble); border-bottom-left-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--ai-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: #fef3c7; font-size: 14px; }
.msg .role-tag { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.msg-stats {
  font-size: 11px; color: var(--muted); margin-top: 8px; padding-top: 6px;
  border-top: 1px dashed var(--border); user-select: text;
}
.typing { align-self: flex-start; background: var(--ai-bubble); border: 1px solid var(--border); border-radius: 14px; padding: 13px 17px; color: var(--muted); font-size: 15px; display: flex; align-items: center; gap: 10px; }
.dots { display: inline-flex; gap: 4px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); animation: pulse 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%,100% { opacity: .25; transform: scale(.85); } 50% { opacity: 1; transform: scale(1); } }

.input-bar { display: flex; align-items: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--panel); }
.attach-btn { font-size: 22px; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.attach-btn:hover { background: var(--bg); }
#msgInput {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 12px; padding: 12px 15px;
  font-family: inherit; font-size: 16px; outline: none; max-height: 150px; line-height: 1.5;
}
#msgInput::placeholder { font-size: 15px; }
#msgInput:focus { border-color: var(--primary); }
.btn-send {
  border: 0; background: var(--primary); color: #fff; width: 48px; height: 48px; border-radius: 12px; font-size: 18px;
}
.btn-send:hover { background: var(--primary-dark); }
.btn-send:disabled { background: #9ca3af; cursor: not-allowed; }
