:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #5d6b78;
  --line: #d9e1e8;
  --paper: #ffffff;
  --soft: #f4f7f8;
  --blue: #1769aa;
  --teal: #008477;
  --amber: #ad6b00;
  --red: #b42318;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #eef3f5;
  color: var(--ink);
  overflow-x: hidden;
}

button, input {
  font: inherit;
}

.topbar {
  min-height: 86px;
  padding: 18px clamp(18px, 4vw, 48px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(25px, 4vw, 38px);
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 32px) 40px;
}

.panel {
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.native-upload-shell {
  background: #dfeaf0;
  border-bottom: 1px solid var(--line);
  padding: 12px clamp(18px, 4vw, 48px);
}

.native-upload-form {
  width: min(1440px, 100%);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.native-upload-form strong {
  margin-right: auto;
}

.upload-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
}

.upload-panel p,
.notice,
.detail p {
  color: var(--muted);
}

.primary-button,
.ghost-button,
.inline-form button {
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: white;
  padding: 11px 14px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.compact {
  padding: 8px 10px;
  font-size: 13px;
}

.ghost-button {
  background: #e8f2f8;
  color: var(--blue);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.danger-button {
  border: 0;
  border-radius: 6px;
  background: #fde8e5;
  color: var(--red);
  cursor: pointer;
  font-weight: 800;
}

.upload-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.file-input {
  width: min(420px, 100%);
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.selected-files {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.selected-file {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 9px 10px;
  font-size: 13px;
}

.selected-file span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.selected-file b {
  flex: 0 0 auto;
  color: var(--muted);
}

.selected-file-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.remove-file-button {
  width: 24px;
  height: 24px;
  border: 1px solid #f3c1ba;
  border-radius: 999px;
  background: #fde8e5;
  color: var(--red);
  cursor: pointer;
  font-weight: 900;
  line-height: 1;
}

.remove-file-button:hover,
.remove-file-button:focus {
  border-color: var(--red);
}

.selected-file-summary {
  background: #eaf5f1;
  border-color: #b8d8cf;
}

.notice {
  grid-column: 1 / -1;
  margin: 0;
  overflow-wrap: anywhere;
}

.queue {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.queue-header,
.queue-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.queue-header {
  margin-bottom: 10px;
}

.queue-header span {
  color: var(--muted);
  font-size: 13px;
}

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

.queue-item {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 10px;
}

.queue-empty {
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  color: var(--muted);
  padding: 12px;
  font-size: 13px;
}

.queue-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.queue-state {
  border-radius: 999px;
  background: #e8f2f8;
  color: var(--blue);
  padding: 4px 8px;
  font-size: 11px;
  text-transform: uppercase;
}

.queue-state.processed {
  background: #e5f6ef;
  color: var(--teal);
}

.queue-state.failed {
  background: #fde8e5;
  color: var(--red);
}

.queue-state.needs_confirmation {
  background: #fff0d6;
  color: var(--amber);
}

.queue-item.needs_confirmation {
  border-color: #f2d59b;
  background: #fffaf0;
}

.queue-confirm-button {
  margin-top: 10px;
}

.progress-track {
  height: 8px;
  margin: 8px 0 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4ebef;
}

.progress-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--blue));
  transition: width 240ms ease;
}

.fill-0 { width: 0%; }
.fill-5 { width: 5%; }
.fill-10 { width: 10%; }
.fill-15 { width: 15%; }
.fill-20 { width: 20%; }
.fill-25 { width: 25%; }
.fill-30 { width: 30%; }
.fill-35 { width: 35%; }
.fill-40 { width: 40%; }
.fill-45 { width: 45%; }
.fill-50 { width: 50%; }
.fill-55 { width: 55%; }
.fill-60 { width: 60%; }
.fill-65 { width: 65%; }
.fill-70 { width: 70%; }
.fill-75 { width: 75%; }
.fill-80 { width: 80%; }
.fill-85 { width: 85%; }
.fill-90 { width: 90%; }
.fill-95 { width: 95%; }
.fill-100 { width: 100%; }

.queue-item small {
  display: block;
  min-height: 17px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.metric {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

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

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 30px;
}

.workspace {
  display: grid;
  gap: 14px;
  align-items: start;
}

.insights-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

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

input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  background: #fbfcfd;
}

.answer {
  min-width: 0;
  background: #eef8f6;
  border-left: 4px solid var(--teal);
  padding: 12px;
  margin: 10px 0;
  color: #183f3a;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.answer h3,
.answer h4,
.answer h5 {
  margin: 0 0 8px;
  font-size: 16px;
}

.answer h4 {
  font-size: 15px;
}

.answer h5 {
  font-size: 14px;
}

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

.answer ul,
.answer ol {
  margin: 0 0 10px 18px;
  padding: 0;
}

.answer li {
  margin: 0 0 8px;
  overflow-wrap: anywhere;
}

.answer blockquote {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-left: 3px solid #94c9c0;
  background: #f7fbfa;
  color: #31544f;
}

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

.answer pre {
  max-width: 100%;
  margin: 0 0 10px;
  overflow-x: auto;
  border: 1px solid #cfe1de;
  border-radius: 6px;
  background: #10201d;
  color: #e7f5f2;
  padding: 12px;
}

.answer code {
  border-radius: 4px;
  background: #dcefeb;
  color: #123d38;
  padding: 2px 5px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.answer pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.answer a {
  color: var(--blue);
  font-weight: 700;
}

.answer hr {
  border: 0;
  border-top: 1px solid #cfe1de;
  margin: 12px 0;
}

.citation-wrap {
  position: relative;
  display: inline-flex;
  vertical-align: super;
}

.citation {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  margin-left: 3px;
  border-radius: 999px;
  background: #d8ece8;
  color: #0d5f55;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
}

.citation-popover {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 20;
  width: min(360px, calc(100vw - 32px));
  max-height: min(340px, 60vh);
  overflow: auto;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 14px 34px rgba(23, 32, 42, 0.18);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  padding: 10px;
  pointer-events: none;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  opacity: 0;
  visibility: hidden;
}

.citation-popover strong,
.citation-popover span {
  display: block;
  margin-bottom: 6px;
}

.citation-popover .citation-excerpt {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 8;
}

.citation-wrap:hover .citation-popover,
.citation-wrap:focus-within .citation-popover {
  opacity: 1;
  visibility: visible;
}

.result-list {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.result {
  width: 100%;
  min-width: 0;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 12px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.result strong,
.result p {
  overflow-wrap: anywhere;
}

.result span {
  display: block;
  color: var(--muted);
  margin: 4px 0;
}

mark {
  background: #ffe7a3;
  padding: 0 2px;
}

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

.analytics-panel {
  display: grid;
  gap: 14px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.section-heading h2 {
  margin-bottom: 0;
}

.section-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.analytics-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.analytics-summary div,
.risk-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 10px;
}

.analytics-summary span,
.risk-tile span,
.risk-tile small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.analytics-summary strong,
.risk-tile strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.analytics-block {
  display: grid;
  gap: 10px;
}

.analytics-block h3 {
  margin: 0;
  font-size: 14px;
}

.risk-mix {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.risk-tile.critical,
.risk-tile.high {
  border-color: #f3c1ba;
  background: #fff6f4;
}

.risk-tile.medium {
  border-color: #f2d59b;
  background: #fffaf0;
}

.risk-tile.low {
  border-color: #b8d8cf;
  background: #f2faf7;
}

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

.muted-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 120px) minmax(0, 1fr) 28px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bar-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row div {
  height: 11px;
  background: var(--soft);
  border-radius: 99px;
  overflow: hidden;
}

.bar-row i {
  display: block;
  height: 100%;
  background: var(--teal);
}

.document-panel {
  min-width: 0;
}

.document-register-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 14px;
  align-items: start;
  min-width: 0;
}

.table {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.document-list {
  min-width: 0;
  max-height: 680px;
  overflow: auto;
  padding-right: 2px;
}

.row {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 130px) minmax(0, 100px) minmax(0, 90px);
  gap: 10px;
  align-items: center;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 10px;
  color: inherit;
  cursor: pointer;
}

.row.active {
  border-color: var(--blue);
  background: #eef6fc;
}

.row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.risk {
  font-weight: 800;
}

.risk.low { color: var(--teal); }
.risk.medium { color: var(--amber); }
.risk.high,
.risk.critical { color: var(--red); }

.detail {
  margin: 0;
  min-width: 0;
}

.detail-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.detail-title h3 {
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.document-detail-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 16px;
  min-height: 360px;
  overflow-wrap: anywhere;
}

.empty-detail {
  color: var(--muted);
  font-weight: 700;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chips span,
.status-pill {
  min-width: 0;
  max-width: 100%;
  border-radius: 999px;
  background: #e8f2f8;
  color: var(--blue);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

dl {
  display: grid;
  grid-template-columns: minmax(0, 130px) minmax(0, 1fr);
  gap: 7px 12px;
  margin: 0;
  min-width: 0;
}

dt {
  color: var(--muted);
  text-transform: capitalize;
}

dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 920px) {
  .upload-panel,
  .workspace,
  .insights-grid,
  .document-register-layout,
  .analytics-columns,
  .metric-grid,
  .queue-list,
  .risk-mix,
  .selected-files {
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: 1fr 100px;
  }

  .detail-title {
    display: grid;
  }

  .detail-actions {
    justify-content: flex-start;
  }

  .row span:nth-child(3),
  .row span:nth-child(4) {
    display: none;
  }
}
