:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --border: #d9e1ee;
  --text: #172033;
  --muted: #6b7588;
  --blue: #1456d9;
  --blue-dark: #103f9f;
  --danger: #d92d20;
  --soft: #eef2f8;
}

* {
  box-sizing: border-box;
}

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

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

.sidebar {
  background: #101827;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
  padding: 22px 16px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #2f6df6;
  font-size: 13px;
  font-weight: 800;
}

.brand h1 {
  font-size: 18px;
}

.brand p {
  color: #aab6c7;
  font-size: 13px;
  margin-top: 2px;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  padding: 10px;
}

.nav-item.active,
.nav-item:hover {
  background: #1f2b3f;
  color: #ffffff;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 800;
}

.sidebar-foot {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: #aab6c7;
  font-size: 12px;
  padding-top: 14px;
}

.app-version {
  color: #f8fafc;
  display: block;
  font-weight: 800;
  margin-bottom: 6px;
}

.logout-button {
  margin-top: 10px;
  width: 100%;
}

.admin-only {
  display: none;
}

.is-admin .admin-only {
  display: grid;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  margin-bottom: 22px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 16px;
  margin-bottom: 4px;
}

.topbar p,
.muted {
  color: var(--muted);
  margin-top: 5px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 18px;
}

button {
  border: 0;
  background: var(--blue);
  color: white;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 650;
  cursor: pointer;
}

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

button.secondary {
  background: var(--soft);
  color: #27364f;
}

button.danger {
  background: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font: inherit;
}

.upload-row,
.query-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}

.query-controls {
  width: 150px;
  display: grid;
  gap: 10px;
}

label {
  color: #35445c;
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

.toolbar-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.compare-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 170px;
  gap: 12px;
  margin-bottom: 14px;
}

.risk-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 12px;
  margin-bottom: 14px;
}

.compare-form + label,
.risk-form + label {
  margin-top: 4px;
}

#compareFocus,
#riskQuestionInput {
  margin-bottom: 12px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

.view-heading p {
  color: var(--muted);
  margin-top: 5px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.status-text {
  min-height: 24px;
  color: var(--muted);
  margin-top: 10px;
}

.grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
}

.split-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
}

.doc-item,
.hit {
  border-top: 1px solid #edf1f7;
  padding: 12px 0;
}

.doc-item:first-child,
.hit:first-child {
  border-top: 0;
}

.doc-item {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

.doc-main {
  min-width: 0;
}

.doc-name-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 5px;
}

.doc-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  background: #eef4ff;
  color: #1448a8;
  font-size: 12px;
  font-weight: 700;
}

.badge.error {
  background: #fff1f0;
  color: var(--danger);
}

.badge.working {
  background: #fff7df;
  color: #8a5600;
}

.query-panel {
  margin-bottom: 18px;
}

.result-panel {
  min-height: 320px;
}

.save-report {
  margin-top: 14px;
}

.answer {
  white-space: pre-wrap;
  font-family: inherit;
  line-height: 1.55;
  color: #243047;
}

.empty-state {
  color: var(--muted);
}

.hit-text {
  color: #334158;
  line-height: 1.45;
  margin-top: 8px;
  max-height: 170px;
  overflow: auto;
}

.chunk-item {
  border-top: 1px solid #edf1f7;
  padding: 14px 0;
}

.chunk-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.chunk-title {
  color: #27364f;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 8px;
}

.chunk-text {
  color: #334158;
  line-height: 1.5;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}

.report-item {
  border-top: 1px solid #edf1f7;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px 0;
}

.user-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 140px auto;
  gap: 12px;
  align-items: end;
}

.user-item {
  border-top: 1px solid #edf1f7;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 12px 0;
}

.user-item:first-child {
  border-top: 0;
}

.user-actions {
  display: grid;
  grid-template-columns: 100px auto auto auto;
  gap: 8px;
  align-items: center;
}

.login-body {
  background: #101827;
}

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

.login-panel {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  max-width: 420px;
  padding: 26px;
  width: 100%;
}

.login-brand {
  color: var(--text);
}

.login-brand p {
  color: var(--muted);
}

.login-panel input {
  margin-bottom: 14px;
}

.login-panel button {
  width: 100%;
}

.report-item:first-child {
  border-top: 0;
}

.report-item > button:first-child {
  background: transparent;
  color: var(--text);
  padding: 0;
  text-align: left;
}

.report-item span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 4px;
}

button.compact {
  align-self: start;
  padding: 7px 10px;
}

.settings-grid {
  display: grid;
  gap: 18px;
}

.settings-section {
  display: grid;
  gap: 12px;
}

.settings-grid-inner {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.setting-card {
  border: 1px solid #edf1f7;
  border-radius: 8px;
  padding: 12px;
}

.setting-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 6px;
}

.setting-card strong {
  color: #27364f;
  display: block;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.usage-card {
  border-color: #dce8ff;
  background: #f7faff;
}

.table-wrap {
  overflow-x: auto;
}

.usage-table {
  border-collapse: collapse;
  width: 100%;
}

.usage-table th,
.usage-table td {
  border-bottom: 1px solid #edf1f7;
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

.usage-table th {
  color: #35445c;
  font-size: 12px;
}

@media (max-width: 840px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    gap: 16px;
  }

  .side-nav {
    grid-template-columns: 1fr 1fr;
  }

  .workspace {
    padding: 20px;
  }

  .view-heading,
  .upload-row,
  .query-row,
  .toolbar-row,
  .compare-form,
  .risk-form,
  .user-form,
  .user-item,
  .user-actions,
  .split-layout,
  .settings-grid-inner,
  .grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .query-controls {
    width: 100%;
  }

  .doc-item {
    align-items: stretch;
    display: grid;
  }
}

@media (max-width: 560px) {
  .side-nav {
    grid-template-columns: 1fr;
  }
}
