:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e4e7ec;
  --brand: #2358d8;
  --brand-dark: #183fa3;
  --brand-soft: #eaf0ff;
  --success-soft: #ecfdf3;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(35, 88, 216, 0.12), transparent 34%),
    linear-gradient(135deg, #f8fafc 0%, var(--bg) 55%, #eef2f7 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  padding: 10px 15px;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

button:hover {
  background: var(--brand-dark);
  box-shadow: 0 8px 18px rgba(35, 88, 216, 0.2);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: #344054;
  box-shadow: none;
}

button.secondary:hover {
  background: var(--panel-soft);
  box-shadow: none;
}

.app {
  min-height: 100vh;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  margin-bottom: 18px;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #6388ff);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.login-panel {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  border: 1px solid rgba(228, 231, 236, 0.9);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  padding: 34px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.login-card h1 {
  margin: 0 0 10px;
  font-size: 30px;
  line-height: 1.18;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.login-card form {
  display: grid;
  gap: 11px;
  margin-top: 24px;
}

label {
  color: #344054;
  font-size: 14px;
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #fff;
  color: var(--text);
  padding: 12px 13px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input:focus,
textarea:focus {
  border-color: rgba(35, 88, 216, 0.55);
  box-shadow: 0 0 0 4px rgba(35, 88, 216, 0.1);
}

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

.error {
  margin: 0;
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 370px) minmax(0, 1fr);
  height: 100vh;
  padding: 14px;
  gap: 14px;
}

.sidebar,
.chat {
  min-height: 0;
  border: 1px solid rgba(228, 231, 236, 0.85);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.sidebar h2,
.chat h1 {
  margin: 0;
  color: #111827;
}

.sidebar h2 {
  font-size: 22px;
}

.chat h1 {
  font-size: 24px;
}

.sidebar p,
.chat-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.select-box {
  position: relative;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
  background: #fff;
}

.controls.compact {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.picker-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  background: #fff;
  color: #1d2939;
  box-shadow: none;
  text-align: left;
}

.picker-toggle:hover {
  background: var(--panel-soft);
  box-shadow: none;
}

.chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--faint);
  border-bottom: 2px solid var(--faint);
  transform: rotate(45deg);
  transition: transform 0.16s ease;
}

.picker-toggle.open .chevron {
  transform: rotate(-135deg);
}

.document-list {
  display: none;
  overflow: auto;
  max-height: calc(100vh - 245px);
  padding: 12px 14px 14px;
}

.document-list.open {
  display: block;
}

.doc-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  align-items: start;
  border: 1px solid transparent;
  border-radius: 9px;
  margin: 0 8px 8px;
  padding: 9px 9px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.doc-item:hover {
  border-color: var(--line);
  background: #fbfcfe;
}

.doc-item input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--brand);
}

.doc-item:has(input:checked) {
  border-color: rgba(35, 88, 216, 0.18);
  background: var(--brand-soft);
}

.doc-title {
  display: block;
  color: #1d2939;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.doc-path {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-header {
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.94));
  padding: 18px 22px;
}

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

.message {
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(840px, 88%);
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  padding: 14px 16px;
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.04);
  color: #1f2937;
  line-height: 1.7;
}

.message.assistant .bubble {
  border-top-left-radius: 5px;
}

.message.user .bubble {
  border-color: transparent;
  border-top-right-radius: 5px;
  background: linear-gradient(135deg, var(--brand), #476ff0);
  color: #fff;
  box-shadow: 0 10px 24px rgba(35, 88, 216, 0.18);
}

.sources {
  margin-top: 12px;
  border-top: 1px solid rgba(228, 231, 236, 0.85);
  padding-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.bubble p {
  margin: 0 0 10px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble h3,
.bubble h4,
.bubble h5 {
  margin: 4px 0 8px;
  color: #111827;
  line-height: 1.35;
}

.bubble ul {
  margin: 8px 0 12px;
  padding-left: 20px;
}

.bubble li {
  margin: 5px 0;
}

.bubble strong {
  font-weight: 800;
}

.bubble code {
  border-radius: 5px;
  background: #f2f4f7;
  color: #344054;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
  padding: 2px 5px;
}

.message.user .bubble p,
.message.user .bubble ul {
  margin: 0;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  padding: 16px;
}

.composer textarea {
  min-height: 72px;
  max-height: 200px;
  border-radius: 12px;
}

.composer button {
  align-self: stretch;
  min-width: 86px;
  border-radius: 12px;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    max-height: 46vh;
  }

  .composer {
    grid-template-columns: 1fr;
  }
}
