:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #64748b;
  --line: #d7dee8;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #be123c;
  --soft: #e8f3f1;
  --shadow: 0 12px 40px rgba(21, 32, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.hidden {
  display: none !important;
}

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

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-panel h1 {
  font-size: 2.4rem;
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: clamp(2rem, 4vw, 4rem);
}

h2 {
  font-size: 1rem;
}

.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.88rem;
}

.admin-bar {
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 10px;
  align-items: center;
}

.layout {
  display: grid;
  grid-template-columns: 330px 340px minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.settings-panel,
.knowledge-panel {
  display: grid;
  gap: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--soft);
}

.grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.primary,
.secondary,
.danger {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
}

.primary {
  background: var(--brand);
  color: #ffffff;
}

.primary:hover {
  background: var(--brand-dark);
}

.secondary {
  background: #eef2f6;
  border-color: var(--line);
  color: var(--text);
}

.secondary:hover {
  background: #e2e8f0;
}

.danger {
  background: var(--accent);
  color: #ffffff;
}

.toggle {
  display: flex;
  grid-template-columns: auto;
  align-items: center;
  gap: 8px;
}

.toggle input {
  width: auto;
}

.inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 8px;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.knowledge-picker {
  display: grid;
  gap: 8px;
}

.knowledge-picker h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.check-list {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdff;
}

.check-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
}

.check-row input {
  width: auto;
  margin-top: 3px;
}

.chat-panel {
  min-height: calc(100vh - 134px);
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 4px 2px 12px;
}

.message {
  max-width: min(720px, 92%);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--brand);
  color: #ffffff;
}

.message.assistant {
  align-self: flex-start;
  background: #edf2f7;
}

.sources {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.documents {
  display: grid;
  gap: 10px;
}

.document {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.document strong {
  display: block;
  margin-bottom: 4px;
}

.document span {
  color: var(--muted);
  font-size: 0.82rem;
}

.document button {
  margin-top: 10px;
  min-height: 34px;
}

.document-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

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

  .chat-panel {
    min-height: auto;
  }
}

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

  .topbar,
  .admin-bar,
  .composer {
    grid-template-columns: 1fr;
    display: grid;
  }

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

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