:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --soft: #f4f7fb;
  --accent: #116466;
  --accent-strong: #0b4f50;
  --warn: #9a3412;
  --shadow: 0 8px 24px rgba(20, 32, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

body.logged-out {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(17, 100, 102, 0.12), transparent 38%),
    linear-gradient(315deg, rgba(42, 56, 75, 0.08), transparent 34%),
    #f6f8fb;
}

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

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
}

button.secondary,
button.icon-button {
  background: white;
  color: var(--accent-strong);
}

button.full {
  width: 100%;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  height: 100vh;
}

.logged-out .app-shell {
  min-height: 100vh;
  height: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 24px;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #eef3f8;
  padding: 18px;
  overflow: auto;
}

.logged-out .sidebar {
  width: min(440px, 100%);
  border: 0;
  background: transparent;
  padding: 0;
  overflow: visible;
}

.logged-out .main-panel {
  display: none;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.logged-out .brand {
  justify-content: center;
  margin-bottom: 20px;
}

.logged-out .brand strong {
  font-size: 18px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.brand small,
#status-line,
.sidebar-section h2,
.document-card small,
.message-meta {
  color: var(--muted);
}

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

.auth-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.logged-out .auth-panel,
.logged-out .mfa-panel {
  padding: 22px;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(20, 32, 45, 0.14);
}

.login-copy {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.login-copy strong {
  font-size: 20px;
}

.login-copy small {
  color: var(--muted);
  line-height: 1.35;
}

.logged-out .button-row {
  grid-template-columns: 1fr;
}

.mfa-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  margin-bottom: 14px;
}

.mfa-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.mfa-enroll {
  display: grid;
  gap: 10px;
}

.mfa-qr {
  width: 180px;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 8px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.workspace {
  display: grid;
  gap: 12px;
}

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

.select-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-section h2 {
  margin: 12px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.list {
  display: grid;
  gap: 6px;
}

.list-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  text-align: left;
  background: white;
  color: var(--ink);
  border-color: var(--line);
}

.list-item.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.main-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: white;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.content-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 16px;
}

.chat-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

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

.message {
  max-width: 820px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  white-space: pre-wrap;
  line-height: 1.45;
}

.message.user {
  align-self: flex-end;
  background: #e7f3f3;
}

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

.message-meta {
  margin-bottom: 6px;
  font-size: 12px;
}

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

.documents-panel {
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.documents-panel h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.document-form {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.document-list {
  display: grid;
  gap: 8px;
}

.document-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
}

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

.source-admin {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

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

.source-summary span,
.source-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1.2;
}

.source-card {
  display: grid;
  gap: 6px;
}

.source-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.source-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-badge.ok {
  border-color: #86c7a7;
  background: #edf8f2;
  color: #176143;
}

.source-badge.warn {
  border-color: #f2b48a;
  background: #fff7ed;
  color: var(--warn);
}

.source-badge.info {
  border-color: #9fc3df;
  background: #eef7ff;
  color: #205b84;
}

.source-badge.muted {
  border-color: var(--line);
  background: white;
  color: var(--muted);
}

.job-list {
  display: grid;
  gap: 6px;
}

.job-item {
  border-left: 3px solid var(--accent);
  background: #f8fafc;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .app-shell,
  .content-grid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content-grid {
    grid-template-rows: minmax(520px, 65vh) auto;
  }
}
