:root {
  --bg: #0f1c2d;
  --surface: #16263b;
  --surface-2: #20324b;
  --surface-3: #101d2d;
  --border: #324861;
  --text: #f2f6fb;
  --muted: #9fb1c7;
  --accent: #2d7ff9;
  --accent-soft: #284978;
  --warning: #f0aa1c;
  --warning-soft: #45340e;
  --success: #38c974;
  --success-soft: #183c2a;
  --danger: #ff7d6b;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(180deg, #112037 0%, #0b1523 100%);
  color: var(--text);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.topbar,
.controlbar,
.panel,
.details-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
}

.topbar-title h1,
.focus-header h2,
.review-header h2,
.panel h2,
.policy-card h3 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--muted);
}

.subtle {
  color: var(--muted);
}

.topbar-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.confidence-view-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.82rem;
}

.confidence-view-switch select {
  width: auto;
  min-width: 108px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-3);
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.82rem;
  white-space: nowrap;
}

.chip.warning {
  background: var(--warning-soft);
  color: #ffd565;
}

.chip.success {
  background: var(--success-soft);
  color: #92f2b8;
}

.subtle-chip {
  color: var(--muted);
}

.controlbar {
  display: grid;
  grid-template-columns:
    minmax(180px, 0.95fr)
    minmax(180px, 0.95fr)
    minmax(220px, 1.2fr)
    120px
    minmax(220px, 1fr)
    minmax(240px, 1fr)
    auto;
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
}

.control-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

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

input,
select,
textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  padding: 10px 12px;
}

button {
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
}

button.secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

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

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

.status-line {
  margin: 0 4px;
  min-height: 20px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(360px, 0.9fr);
  gap: 12px;
  min-height: 0;
}

.viewer-pane,
.review-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.viewer-pane {
  display: flex;
  flex-direction: column;
}

.viewer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #182b44;
  border-bottom: 1px solid var(--border);
}

.viewer-actions,
.viewer-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.viewer-surface {
  background: #0d1725;
  min-height: 760px;
  position: relative;
  display: flex;
}

.page-viewer {
  width: 100%;
  min-height: 760px;
  background: #f8fafc;
  overflow: auto;
}

.page-stage {
  position: relative;
  width: 100%;
  display: inline-block;
  min-width: 100%;
}

.page-viewer img {
  width: 100%;
  display: block;
}

.page-viewer.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--muted);
  background: #0d1725;
}

.page-viewer.empty img,
.page-viewer.empty .page-overlay-box {
  display: none;
}

.page-overlay-box {
  position: absolute;
  border: 3px solid #ffc940;
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(255, 201, 64, 0.12), 0 0 26px rgba(255, 201, 64, 0.35);
  background: rgba(255, 201, 64, 0.08);
  display: none;
  pointer-events: none;
  z-index: 3;
}

.page-overlay-box.visible {
  display: block;
}

.viewer-evidence-bar {
  border-top: 1px solid var(--border);
  padding: 14px;
  background: #132033;
  display: flex;
  justify-content: center;
}

.viewer-evidence-snippet {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  text-align: center;
  max-width: 72ch;
  width: 100%;
  overflow-wrap: anywhere;
}

.review-pane {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

.review-pane-head,
.claims-pane-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}

.review-pane-head h2,
.claims-pane-head h2 {
  margin: 0;
}

.claims-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.claims-pane-head {
  align-items: flex-start;
}

.review-section {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(9, 18, 31, 0.28);
  overflow: hidden;
}

.review-section summary {
  list-style: none;
  cursor: pointer;
}

.review-section summary::-webkit-details-marker {
  display: none;
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: #122033;
}

.review-header.second {
  margin-top: 0;
}

.field-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 12px 12px;
}

.field-row {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  overflow: hidden;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.field-row:hover {
  border-color: #4c6f98;
  background: #243a59;
}

.field-row.selected {
  border-color: #6ba1ff;
  box-shadow: inset 0 0 0 1px rgba(107, 161, 255, 0.45);
}

.field-main {
  display: grid;
  grid-template-columns: minmax(112px, 0.9fr) minmax(0, 1.45fr) 58px 132px;
  gap: 10px;
  align-items: center;
  padding: 12px;
  cursor: pointer;
}

.field-name-block {
  min-width: 0;
}

.field-name {
  font-weight: 700;
}

.field-group {
  margin-top: 4px;
  font-size: 0.78rem;
}

.field-value {
  color: #f7fbff;
  word-break: break-word;
  min-width: 0;
}

.field-confidence {
  color: var(--muted);
  font-size: 0.86rem;
  text-align: right;
}

.field-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  min-width: 132px;
}

.icon-btn {
  min-width: 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  font-weight: 700;
}

.locate-btn {
  color: #ffd565;
  border-color: rgba(240, 170, 28, 0.35);
}

.edit-btn {
  color: #9bd0ff;
  border-color: rgba(107, 161, 255, 0.32);
}

.accept-btn {
  background: var(--accent);
}

.icon-btn.accepted {
  background: var(--success);
}

.field-editor {
  border-top: 1px solid var(--border);
  background: #18283d;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.field-editor label {
  color: var(--muted);
  font-size: 0.8rem;
}

.editor-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

.claim-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 12px 12px;
  min-width: 1660px;
}

.claim-table-head,
.claim-row-main {
  display: grid;
  grid-template-columns: 220px 180px 150px 120px 110px 110px 120px 95px 110px 110px 120px;
  gap: 8px;
  align-items: center;
}

.claim-table-head {
  padding: 0 12px 2px;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.claim-row {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  overflow: hidden;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.claim-row:hover {
  border-color: #4c6f98;
  background: #243a59;
}

.claim-row.selected {
  border-color: #6ba1ff;
  box-shadow: inset 0 0 0 1px rgba(107, 161, 255, 0.45);
}

.claim-row-main {
  padding: 12px;
  cursor: pointer;
}

.claim-cell.clickable {
  cursor: pointer;
}

.claim-cell.selected-cell {
  color: #ffffff;
  text-shadow: 0 0 0 transparent;
}

.claim-cell.selected-cell,
.claim-cell.selected-cell .claim-subline {
  color: #ffffff;
}

.claim-cell {
  min-width: 0;
  word-break: break-word;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.01);
}

.claim-cell-strong {
  font-weight: 700;
}

.claim-cell.band-high {
  border-color: rgba(56, 201, 116, 0.28);
  background: rgba(56, 201, 116, 0.08);
}

.claim-cell.band-medium {
  border-color: rgba(240, 170, 28, 0.28);
  background: rgba(240, 170, 28, 0.08);
}

.claim-cell.band-low {
  border-color: rgba(255, 125, 107, 0.24);
  background: rgba(255, 125, 107, 0.08);
}

.claim-subline {
  margin-top: 4px;
  font-size: 0.78rem;
  font-weight: 400;
}

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

.claim-editor {
  border-top: 1px solid var(--border);
  background: #18283d;
  padding: 12px;
  display: grid;
  gap: 12px;
}

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

.claim-editor-grid label,
.claim-review-controls label {
  display: grid;
  gap: 6px;
}

.claim-editor-grid span,
.claim-review-controls span {
  color: var(--muted);
  font-size: 0.8rem;
}

.claim-review-controls {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 10px;
}

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

.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.details-panel {
  padding: 10px 14px 14px;
}

.details-panel summary {
  cursor: pointer;
  color: var(--muted);
  margin-bottom: 12px;
}

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

.panel {
  padding: 14px;
}

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

.policy-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.policy-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  padding: 12px;
}

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

.kv {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-3);
}

.kv span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.kv strong {
  display: block;
  margin-top: 4px;
}

.json-box {
  margin: 0;
  min-height: 320px;
  overflow: auto;
  background: #0f1826;
  border-radius: 12px;
  padding: 12px;
  color: #d8e6f5;
}

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

@media (max-width: 1400px) {
  .controlbar {
    grid-template-columns: 1fr 1fr;
  }

  .control-actions {
    grid-column: 1 / -1;
  }

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

@media (max-width: 900px) {
  .topbar,
  .controlbar,
  .viewer-toolbar,
  .details-grid,
  .policy-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .viewer-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .field-main {
    grid-template-columns: 1fr;
    align-items: flex-start;
    cursor: default;
  }

  .field-actions {
    justify-content: flex-start;
    min-width: 0;
  }

  .claim-review-controls,
  .claim-editor-grid {
    grid-template-columns: 1fr;
  }
}
