* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f6f8;
  color: #1f2328;
}

.layout {
  display: flex;
  height: 100vh;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(160deg, #eef2ff 0%, #f5f6f8 45%, #eef6f3 100%);
}

.login-card {
  width: 360px;
  background: #fff;
  border: 1px solid #e9ebef;
  border-radius: 16px;
  padding: 36px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 12px 32px rgba(16, 24, 40, 0.08);
}

.login-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.login-card h1 {
  font-size: 18px;
  margin: 0;
  text-align: center;
  color: #111827;
}

.login-subtitle {
  font-size: 13px;
  color: #6b7280;
  text-align: center;
  margin: 6px 0 20px;
  line-height: 1.4;
}

.login-card label {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  margin-top: 12px;
}

.login-card input {
  padding: 10px 12px;
  border: 1px solid #d7dade;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 4px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.login-card button {
  margin-top: 24px;
  padding: 11px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.login-card button:hover:not(:disabled) {
  background: #1d4ed8;
}

.login-card button:disabled {
  background: #9ab4ec;
  cursor: default;
}

.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 4px;
}

.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e2e5e9;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sidebar-header h2 {
  font-size: 16px;
  margin: 0;
}

.sync-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.sync-btn:disabled {
  background: #9ab4ec;
  cursor: default;
}

.sync-state {
  font-size: 12px;
  color: #6b7280;
  min-height: 16px;
  margin-bottom: 8px;
}

.doc-summary {
  font-size: 12px;
  color: #374151;
  background: #f0f4f9;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

.doc-search {
  width: 100%;
  padding: 7px 10px;
  margin-bottom: 12px;
  border: 1px solid #d7dade;
  border-radius: 6px;
  font-size: 13px;
}

.doc-empty {
  font-size: 12px;
  color: #9aa0a6;
  padding: 8px 0;
}

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8a8f98;
  margin: 14px 0 6px;
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
}

.doc-item {
  padding: 8px 0;
  border-bottom: 1px solid #f0f1f3;
  cursor: pointer;
}

.doc-item:hover {
  background: #f7f9fc;
}

.doc-item.not-synced .doc-name {
  color: #9a3412;
}

.doc-reason {
  font-size: 11px;
  color: #b45309;
  margin-top: 2px;
}

.doc-name {
  font-size: 13px;
  font-weight: 600;
  word-break: break-word;
}

.doc-meta {
  font-size: 11px;
  color: #8a8f98;
  margin-top: 2px;
  word-break: break-word;
}

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid #e2e5e9;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header h1 {
  margin: 0;
  font-size: 18px;
}

.logout-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  color: #4b5563;
  border: 1px solid #e2e5e9;
  border-radius: 999px;
  padding: 7px 14px 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 10px rgba(16, 24, 40, 0.06);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.logout-btn:hover {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

.logout-btn svg {
  flex-shrink: 0;
}

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

.message {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 10px;
  line-height: 1.45;
  font-size: 14px;
}

.message.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  white-space: pre-wrap;
}

.message.assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e2e5e9;
}

.message.assistant > :first-child {
  margin-top: 0;
}

.message.assistant > :last-child {
  margin-bottom: 0;
}

.message.assistant p,
.message.assistant ul,
.message.assistant ol {
  margin: 8px 0;
}

.message.assistant ul,
.message.assistant ol {
  padding-left: 22px;
}

.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
  font-size: 15px;
  margin: 12px 0 6px;
}

.message.assistant code {
  background: #f0f1f3;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
}

.message.assistant pre {
  background: #f0f1f3;
  border-radius: 6px;
  padding: 8px 10px;
  overflow-x: auto;
}

.message.assistant table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}

.message.assistant th,
.message.assistant td {
  border: 1px solid #e2e5e9;
  padding: 4px 8px;
  text-align: left;
}

.message.assistant a {
  color: #2563eb;
}

.message.assistant.pending {
  color: #9aa0a6;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid #e2e5e9;
  background: #fff;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #d7dade;
  border-radius: 8px;
  font-size: 14px;
}

#send-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
}

#send-btn:disabled {
  background: #9ab4ec;
  cursor: default;
}

.viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 23, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.viewer-overlay.hidden {
  display: none;
}

.viewer-panel {
  width: 85vw;
  height: 85vh;
  background: #fff;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid #e2e5e9;
  font-size: 13px;
  font-weight: 600;
}

.viewer-close {
  background: #f0f1f3;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

.viewer-frame {
  flex: 1;
  border: none;
}
