:root {
  --ink: #0e0e0c;
  --paper: #f5f2eb;
  --vellum: #faf8f3;
  --marginalia: #6b6760;
  --muted: #6b6760;
  --line: rgba(14, 14, 12, 0.16);
  --surface: #faf8f3;
  --soft: #f0ece2;
  --blue: #a8501e;
  --blue-strong: #7b3716;
  --teal: #1f6f67;
  --green: #167047;
  --amber: #a8501e;
  --red: #8a1c1c;
  --black: #0e0e0c;
  --display-font: Georgia, "Times New Roman", serif;
  --mono-font: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  --shadow: 0 18px 42px rgba(14, 14, 12, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  background: #eee8dd;
  color: var(--ink);
  display: grid;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  grid-template-columns: 256px minmax(0, 1fr);
  margin: 0;
  min-height: 100vh;
}

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

button,
.link-button {
  align-items: center;
  background: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 750;
  justify-content: center;
  min-height: 40px;
  padding: 10px 14px;
  text-decoration: none;
}

button:hover {
  background: var(--blue-strong);
}

button.ghost,
.link-button.secondary {
  background: var(--vellum);
  border-color: var(--line);
  color: var(--ink);
}

button.danger {
  border-color: #d8aaa0;
  color: var(--red);
}

input,
select,
textarea {
  background: var(--vellum);
  border: 1px solid rgba(14, 14, 12, 0.22);
  border-radius: 5px;
  color: var(--ink);
  min-height: 40px;
  padding: 10px 11px;
  width: 100%;
}

textarea {
  line-height: 1.45;
  resize: vertical;
}

input[type="color"] {
  min-height: 44px;
  padding: 4px;
}

label {
  color: #403d36;
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 7px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  padding: 11px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-family: var(--mono-font);
  font-size: 12px;
}

pre {
  background: var(--ink);
  border-radius: 5px;
  color: #f5f2eb;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.sidebar {
  background: var(--ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
  padding: 24px 18px;
  position: sticky;
  top: 0;
}

body.operator-mode .sidebar {
  background: #101010;
}

.brand {
  align-items: center;
  border-bottom: 1px solid rgba(245, 242, 235, 0.16);
  display: flex;
  gap: 12px;
  padding: 8px 8px 18px;
}

.brand-mark {
  align-items: center;
  background: var(--amber);
  background-position: center;
  background-size: cover;
  border-radius: 5px;
  color: #fff;
  display: flex;
  font-size: 20px;
  font-weight: 800;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.brand-mark.brand-image {
  border: 1px solid rgba(255, 255, 255, 0.38);
}

.brand-mark.docint-mark {
  background-image: url("/static/assets/docint-icon.svg");
}

body.operator-mode .brand-mark:not(.brand-image) {
  background: #161616;
  border: 1px solid var(--red);
  color: #ff3038;
  font-size: 16px;
}

.brand strong {
  display: block;
  font-size: 17px;
}

.brand span,
.session-card span {
  color: #b8afa2;
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

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

.nav-link {
  border-radius: 5px;
  color: #d9d2c7;
  font-size: 14px;
  font-weight: 650;
  padding: 11px 12px;
  text-decoration: none;
}

.nav-link.active {
  background: var(--paper);
  color: var(--ink);
}

body.operator-mode .nav-link.active {
  background: var(--red);
  color: #fff;
}

.session-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(245, 242, 235, 0.16);
  border-radius: 5px;
  margin-top: auto;
  padding: 14px;
}

.session-card strong {
  display: block;
  margin: 4px 0;
}

.workspace {
  display: grid;
  gap: 18px;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
}

.topbar {
  align-items: center;
  background: rgba(245, 242, 235, 0.96);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 20px 28px;
}

.topbar-actions,
.toolbar,
.actions,
.split,
.section-head {
  align-items: center;
  display: flex;
  gap: 12px;
}

.section-head,
.topbar {
  justify-content: space-between;
}

.topbar h1,
.panel h2,
.login-copy h2 {
  font-family: var(--display-font);
  font-weight: 600;
  letter-spacing: 0;
  margin: 0;
}

.topbar h1 {
  font-size: 28px;
  margin-top: 3px;
}

.topbar p,
.panel p,
.login-copy p,
.muted {
  color: var(--muted);
}

.eyebrow {
  color: var(--blue-strong);
  display: inline-block;
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin-bottom: 6px;
}

body.operator-mode .eyebrow {
  color: var(--red);
}

.login-shell {
  background: #ebe4d8;
  border-bottom: 1px solid rgba(14, 14, 12, 0.16);
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 0.9fr) minmax(340px, 1fr);
  padding: 22px 28px;
}

.login-card,
.panel,
.metric,
.data-card,
.citation,
.setup-step,
.row-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
}

.login-card,
.panel,
.metric {
  box-shadow: var(--shadow);
}

.login-card,
.panel {
  padding: 18px;
}

.segmented {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px;
}

.segment {
  background: transparent;
  border: 0;
  color: var(--muted);
}

.segment.active {
  background: var(--paper);
  box-shadow: 0 1px 5px rgba(14, 14, 12, 0.12);
  color: var(--ink);
}

.auth-pane {
  display: none;
  gap: 12px;
  margin-top: 14px;
}

.auth-pane.active {
  display: grid;
}

.identity-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.dashboard {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  padding: 20px 28px 0;
}

.metric {
  padding: 16px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.metric strong {
  display: block;
  font-family: var(--display-font);
  font-size: 26px;
  margin-top: 6px;
}

.view {
  display: none;
  gap: 18px;
  padding: 6px 28px 32px;
}

.view.active {
  display: grid;
}

#ask.view.active,
#admin.view.active,
#control-plane.view.active {
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 0.7fr);
}

.full-width,
#documents.view.active,
#facts.view.active,
#annotations.view.active,
#operations.view.active {
  grid-template-columns: minmax(0, 1fr);
}

.section-head {
  margin-bottom: 14px;
}

.askbox {
  min-height: 112px;
}

.toolbar {
  flex-wrap: wrap;
}

.toolbar > * {
  flex: 1;
  min-width: 150px;
}

.compact-toolbar > * {
  flex: 0 1 auto;
  min-width: 120px;
}

.vertical {
  align-items: stretch;
  flex-direction: column;
}

.split > * {
  flex: 1;
}

.wrap {
  flex-wrap: wrap;
}

.answer-card,
.status-line,
.cards {
  margin-top: 14px;
}

.answer-card,
.status-line {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 14px;
}

.answer-card {
  min-height: 120px;
}

.answer-text {
  font-family: var(--display-font);
  font-size: 16px;
  line-height: 1.6;
  margin: 0;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.pill {
  background: rgba(168, 80, 30, 0.11);
  border: 1px solid rgba(168, 80, 30, 0.28);
  border-radius: 999px;
  color: var(--blue-strong);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
}

.pill.warning {
  background: #f7ead8;
  border-color: #e1bf91;
  color: var(--amber);
}

.pill.success {
  background: #e8f2e6;
  border-color: #bdd7b6;
  color: var(--green);
}

.pill.danger {
  background: #f4ded8;
  border-color: #d8aaa0;
  color: var(--red);
}

.citation-list,
.cards,
.setup-steps {
  display: grid;
  gap: 10px;
}

.citation,
.data-card,
.row-card {
  padding: 12px;
}

.citation-actions,
.source-preview {
  margin-top: 10px;
}

.citation-inspector {
  border-style: solid;
}

.meta-grid {
  display: grid;
  gap: 8px 12px;
  grid-template-columns: minmax(80px, 0.32fr) 1fr;
}

.meta-grid span {
  color: var(--muted);
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.meta-grid strong,
.breakable {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.source-chunk.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(168, 80, 30, 0.14);
}

.identity-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.compact-cards {
  max-height: 360px;
  overflow: auto;
}

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

.source-preview-panel {
  background: var(--paper);
  border: 1px dashed rgba(14, 14, 12, 0.26);
  border-radius: 5px;
  display: grid;
  gap: 10px;
  margin-top: 14px;
  min-height: 74px;
  padding: 14px;
}

.source-preview-panel .source-preview {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.source-chunk p {
  margin-bottom: 0;
  white-space: pre-wrap;
}

.compact-head {
  align-items: start;
}

.row-card {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.setup-steps {
  margin-bottom: 16px;
}

.setup-step {
  display: grid;
  gap: 6px;
  grid-template-columns: 34px 1fr auto;
  padding: 14px;
}

.setup-step.complete {
  background: #e8f2e6;
  border-color: #bdd7b6;
}

.setup-section {
  background: var(--vellum);
  border: 1px solid var(--line);
  border-radius: 5px;
  display: grid;
  gap: 12px;
  margin: 14px 0;
  padding: 16px;
}

.setup-section h3 {
  font-size: 18px;
  margin: 0;
}

.setup-section p {
  margin: -4px 0 2px;
}

.step-label {
  color: var(--blue-strong);
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.step-number {
  align-items: center;
  background: rgba(168, 80, 30, 0.12);
  border-radius: 5px;
  color: var(--blue);
  display: inline-flex;
  font-weight: 800;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.document-actions,
.api-entitlement {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 14px;
}

.advanced-settings {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 5px;
  display: grid;
  gap: 12px;
  padding: 12px;
}

.advanced-settings summary {
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.advanced-settings[open] summary {
  margin-bottom: 10px;
}

.status-line {
  color: var(--muted);
  min-height: 42px;
  white-space: pre-wrap;
}

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

.toggle-row {
  align-items: center;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  display: flex;
  gap: 10px;
  margin: 10px 0;
  padding: 12px;
}

.toggle-row input {
  width: auto;
}

.operator-footer {
  align-items: center;
  background: rgba(14, 14, 12, 0.96);
  border-top: 1px solid rgba(245, 242, 235, 0.16);
  bottom: 0;
  color: #fff;
  display: flex;
  gap: 9px;
  grid-column: 1 / -1;
  justify-content: center;
  left: 0;
  min-height: 42px;
  padding: 8px 16px;
  position: fixed;
  right: 0;
  z-index: 4;
}

.operator-footer[hidden],
[hidden] {
  display: none !important;
}

.operator-footer img {
  border-radius: 6px;
  height: 24px;
  object-fit: cover;
  width: 24px;
}

body.has-operator-footer {
  padding-bottom: 42px;
}

.toast {
  background: var(--ink);
  border-radius: 5px;
  bottom: 22px;
  color: #fff;
  display: none;
  max-width: 420px;
  padding: 13px 15px;
  position: fixed;
  right: 22px;
  z-index: 5;
}

.toast.show {
  display: block;
}

.empty,
.empty-state {
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.empty-state {
  background: var(--paper);
  border: 1px dashed rgba(14, 14, 12, 0.26);
  border-radius: 5px;
  line-height: 1.5;
}

@media (max-width: 1080px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: static;
  }

  .login-shell,
  #ask.view.active,
  #admin.view.active,
  #control-plane.view.active {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar,
  .section-head,
  .split,
  .identity-grid,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .identity-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

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

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

  .view,
  .dashboard,
  .topbar,
  .login-shell {
    max-width: 100%;
    min-width: 0;
    padding-left: 16px;
    padding-right: 16px;
  }

  .toolbar > *,
  .compact-toolbar > *,
  .split > * {
    min-width: 0;
  }

  input[type="file"] {
    max-width: 100%;
  }
}
