:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-muted: #f7f8f9;
  --line: #dde2e7;
  --line-strong: #cdd5dc;
  --text: #17212b;
  --muted: #66717d;
  --navy: #071a2f;
  --blue: #103a62;
  --gold: #b9985a;
  --accent: #071a2f;
  --accent-strong: #103a62;
  --accent-soft: #f8f3e8;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --danger: #a63a3a;
  --danger-soft: #fae4e4;
  --ok: #26734d;
  --ok-soft: #dff1e8;
  --shadow: 0 14px 40px rgba(7, 26, 47, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

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

.sidebar {
  background: var(--navy);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 22px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 6px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--gold);
  color: var(--navy);
  font-weight: 800;
  border-radius: 6px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.sidebar-footer span:last-child {
  color: #b8c2ce;
  font-size: 12px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: #d6dde6;
  height: 42px;
  padding: 0 10px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}

.nav-item svg,
.icon-button svg,
.primary-button svg,
.wide-button svg,
.secondary-button svg,
.doc-list svg,
.dropzone svg,
.search-box svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 10px 6px;
}

.env-pill {
  width: fit-content;
  background: rgba(185, 152, 90, 0.22);
  color: #fff1d4;
  border: 1px solid rgba(255, 241, 212, 0.25);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 18px;
  display: grid;
  gap: 14px;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.status-band,
.panel,
.review-pane {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  background: var(--navy);
  color: #fff;
  border: 1px solid rgba(7, 26, 47, 0.4);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  min-height: 78px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-radius: 8px;
}

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

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

h1 {
  color: inherit;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  line-height: 1.25;
}

h2 {
  font-size: 15px;
  line-height: 1.25;
}

.panel-header p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

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

.icon-button,
.primary-button,
.wide-button,
.secondary-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.topbar .icon-button {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}

.topbar .primary-button {
  background: var(--gold);
  color: var(--navy);
  border-color: var(--gold);
}

.icon-button {
  width: 38px;
}

.icon-button.compact {
  width: 32px;
  height: 32px;
}

.primary-button,
.wide-button {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  padding: 0 12px;
  font-weight: 700;
}

.primary-button:hover,
.wide-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  width: 100%;
  padding: 0 10px;
  margin-top: 8px;
}

.status-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-radius: 8px;
  overflow: hidden;
}

.status-band div {
  padding: 12px 14px;
  border-right: 1px solid var(--line);
  display: grid;
  gap: 3px;
}

.status-band div:last-child {
  border-right: 0;
}

.status-band span {
  color: var(--muted);
  font-size: 12px;
}

.status-band strong {
  font-size: 14px;
}

.ok-text {
  color: var(--ok);
}

.main-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 286px minmax(420px, 1fr) 340px;
  gap: 14px;
}

.left-pane,
.right-pane {
  min-width: 0;
  display: grid;
  gap: 14px;
  align-content: start;
}

.panel,
.review-pane {
  border-radius: 8px;
  min-width: 0;
}

.panel {
  padding: 14px;
}

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

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

.template-item {
  display: grid;
  gap: 5px;
  text-align: left;
  background: var(--surface-muted);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  min-height: 78px;
}

.template-item.selected {
  background: var(--accent-soft);
  border-color: rgba(185, 152, 90, 0.45);
}

.template-type {
  color: var(--gold);
  font-weight: 800;
  font-size: 11px;
  text-transform: uppercase;
}

.template-item small {
  color: var(--muted);
}

.dropzone {
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  min-height: 74px;
  display: grid;
  place-items: center;
  gap: 4px;
  color: var(--muted);
  background: #fafbfc;
}

.extraction-panel {
  display: grid;
  gap: 10px;
}

.extract-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.case-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  gap: 8px;
  align-items: center;
}

.case-row input {
  min-width: 0;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  outline: 0;
}

.case-row input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(185, 152, 90, 0.16);
}

.extraction-panel textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  color: var(--text);
  background: #fff;
  outline: 0;
  line-height: 1.45;
}

.extraction-panel textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(185, 152, 90, 0.16);
}

.extract-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.wide-button:disabled {
  opacity: 0.68;
  cursor: wait;
}

.doc-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}

.doc-list li {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.doc-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-list em {
  font-style: normal;
  color: var(--muted);
  font-size: 11px;
}

.review-pane {
  min-height: 640px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.review-toolbar {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 10px;
}

.segmented {
  display: flex;
  overflow-x: auto;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px;
}

.segmented button {
  border: 0;
  min-height: 32px;
  padding: 0 10px;
  background: transparent;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(20, 30, 40, 0.08);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  height: 40px;
}

.search-box input {
  border: 0;
  outline: 0;
  min-width: 0;
  width: 100%;
}

.field-table {
  overflow: auto;
}

.field-row {
  display: grid;
  grid-template-columns: 28px minmax(150px, 1fr) 118px 98px 92px;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

.field-row:hover {
  background: #fbfcfd;
}

.field-index {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.field-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.field-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-main small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 0 8px;
}

.approved {
  color: var(--ok);
  background: var(--ok-soft);
}

.pending {
  color: var(--warn);
  background: var(--warn-soft);
}

.conflict {
  color: var(--danger);
  background: var(--danger-soft);
}

.review-action {
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  min-height: 30px;
  cursor: pointer;
}

.document-panel {
  min-height: 400px;
}

.paper-preview {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #eee8dd;
}

.paper-toolbar {
  min-height: 34px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  background: #f7f8f9;
  border-bottom: 1px solid var(--line);
}

.paper-toolbar strong {
  color: var(--ok);
}

.paper-preview article {
  position: relative;
  width: min(100%, 260px);
  min-height: 315px;
  margin: 14px auto;
  background: #fff;
  box-shadow: 0 12px 34px rgba(7, 26, 47, 0.12);
  padding: 24px 22px;
  font-family: "Times New Roman", Times, serif;
  font-size: 9px;
  line-height: 1.5;
  overflow: hidden;
}

.paper-preview article::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--navy) 0 72%, var(--gold) 72%);
}

.paper-preview article::after {
  content: "LATAMLEX";
  position: absolute;
  right: -28px;
  bottom: 58px;
  color: rgba(7, 26, 47, 0.035);
  font: 700 34px/1 Georgia, serif;
  letter-spacing: 0.08em;
  transform: rotate(-90deg);
}

.paper-preview h3 {
  font-size: 9px;
  text-align: center;
  margin-bottom: 12px;
  color: var(--navy);
}

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

mark.active-token {
  background: #f2d58b;
  outline: 1px solid var(--gold);
}

.checks {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.checks label {
  display: flex;
  gap: 8px;
  font-size: 13px;
  align-items: center;
}

.wide-button {
  width: 100%;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #1f2933;
  color: white;
  min-height: 42px;
  display: none;
  align-items: center;
  padding: 0 14px;
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.toast.show {
  display: flex;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 78px minmax(0, 1fr);
  }

  .brand div:last-child,
  .nav-item span,
  .sidebar-footer span:last-child {
    display: none;
  }

  .main-grid {
    grid-template-columns: 260px minmax(360px, 1fr);
  }

  .right-pane {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    min-height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }

  .brand {
    border-bottom: 0;
    padding: 0;
  }

  .nav-list {
    display: flex;
  }

  .topbar,
  .status-band,
  .main-grid,
  .right-pane,
  .review-toolbar {
    grid-template-columns: 1fr;
  }

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

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

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

  .status-band div:last-child {
    border-bottom: 0;
  }

  .field-row {
    grid-template-columns: 28px minmax(120px, 1fr) 92px;
  }

  .field-row .field-source,
  .field-row .field-confidence {
    display: none;
  }
}
