/*
 * Theme tokens — Meyer Logistics inspired palette.
 * Swap values here (or override on html[data-theme="…"]) to re-skin the app.
 */
:root {
  /* Brand anchors (from logo: Meyer blue + logistics red) */
  --brand-blue: #0050c8;
  --brand-blue-dark: #003d9b;
  --brand-blue-soft: #e8f0fc;
  --brand-red: #e30613;
  --brand-red-soft: #fde8ea;
  --brand-ink: #0b1220;

  /* Semantic UI tokens (map to brand; keep neutral neutrals) */
  --bg: #f3f6fb;
  --surface: #ffffff;
  --text: var(--brand-ink);
  --muted: #5a6573;
  --border: #d5dde8;
  --primary: var(--brand-blue);
  --primary-hover: var(--brand-blue-dark);
  --primary-soft: var(--brand-blue-soft);
  --accent: var(--brand-red);
  --accent-soft: var(--brand-red-soft);
  --danger: var(--brand-red);
  --success: #1b7a3d;
  --success-soft: #e8f6ec;
  --warning: #c45c00;
  --warning-soft: #fff4e5;

  --radius: 10px;
  --shadow: 0 8px 24px rgba(11, 18, 32, 0.08);
  --header-accent-height: 3px;

  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* Optional alternate scheme example — not applied by default:
html[data-theme="neutral"] {
  --brand-blue: #1f4b7a;
  --brand-red: #9b1c1c;
  --primary: var(--brand-blue);
  --primary-hover: #16385c;
  --accent: var(--brand-red);
  --danger: var(--brand-red);
}
*/

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

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

.hint {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

/* Brand / logo */
.brand-link {
  display: inline-flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-logo {
  display: block;
  height: 40px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
  background: transparent;
}

.brand-logo--auth {
  height: 52px;
  max-width: 260px;
  margin: 0 auto 1rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  line-height: 1.2;
}

.brand-product {
  font-size: 1.05rem;
  color: var(--primary);
}

.brand-user {
  font-size: 0.8rem;
}

/* Auth / landing */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    linear-gradient(180deg, var(--primary-soft) 0%, var(--bg) 42%, var(--bg) 100%);
}

.auth-card {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  border-top: 3px solid var(--primary);
}

.auth-header {
  text-align: center;
}

.auth-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  color: var(--primary);
}

.auth-header .subtitle {
  margin: 0 0 1.5rem;
  color: var(--muted);
}

.auth-form label {
  display: block;
  margin: 0.75rem 0 0.35rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.auth-form input[type="text"],
.auth-form input[type="password"] {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.auth-form .btn {
  width: 100%;
  margin-top: 1.25rem;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: #e9eef3;
  color: var(--text);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--primary-soft);
  border-color: color-mix(in srgb, var(--primary) 25%, var(--border));
}

/* Alerts / messages */
.alert,
.messages {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.alert,
.message {
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, #fff);
}

/* App shell */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  /* Dual accent stripe like the Meyer logo lines: blue above, red below */
  box-shadow:
    inset 0 calc(-1 * var(--header-accent-height)) 0 0 var(--accent),
    inset 0 calc(-2 * var(--header-accent-height)) 0 0 var(--primary);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.app-header-sub {
  width: min(100%, 1100px);
  margin: 0 auto;
  padding: 0.5rem 1rem 0;
}

.app-main--wide + .app-header-sub,
.app-main--wide .app-header-sub {
  width: min(100%, 1440px);
}

.app-main {
  width: min(100%, 1100px);
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

.app-main--wide {
  width: min(100%, 1440px);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.tab {
  padding: 0.75rem 1rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 600;
}

.tab:hover {
  color: var(--primary);
}

.tab-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel h2 {
  margin-top: 0;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  padding: 2.5rem 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  margin: 1rem 0;
}

.dropzone:hover,
.dropzone-active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.dropzone-title {
  margin: 0 0 0.35rem;
  font-weight: 600;
}

.file-list {
  list-style: none;
  margin: 1rem auto 0;
  padding: 0;
  max-width: 28rem;
  text-align: left;
}

.file-list li {
  padding: 0.35rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.95rem;
}

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* Avoid nested horizontal scrollbars; layout stays within page width */
  overflow: visible;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table th,
.data-table td {
  padding: 0.45rem 0.55rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  vertical-align: middle;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.data-table th {
  background: #f7f9fb;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
  font-weight: 600;
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* Compact extraction detail / overview tables */
.data-table--compact th,
.data-table--compact td {
  padding: 0.32rem 0.45rem;
  font-size: 0.78rem;
  line-height: 1.3;
}

.data-table--compact th {
  font-size: 0.68rem;
}

.data-table--compact .conf-badge {
  font-size: 0.72rem;
  padding: 0.12rem 0.4rem;
  gap: 0.25rem;
}

.data-table--compact .conf-icon {
  width: 0.95rem;
  height: 0.95rem;
  font-size: 0.65rem;
}

.data-table--compact .field-input {
  padding: 0.28rem 0.4rem;
  font-size: 0.78rem;
  min-width: 0;
  border-radius: 6px;
}

.data-table--compact textarea.field-input {
  min-height: 2.2rem;
}

.data-table--overview col.col-id { width: 2.8rem; }
.data-table--overview col.col-status { width: 7.5rem; }
.data-table--overview col.col-order { width: 11%; }
.data-table--overview col.col-client { width: 12%; }
.data-table--overview col.col-lade { width: 10%; }
.data-table--overview col.col-liefer { width: 10%; }
.data-table--overview col.col-review { width: 5.5rem; }
.data-table--overview col.col-xml { width: 7rem; }
.data-table--overview col.col-date { width: 7rem; }

.output-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.output-page-title {
  margin: 0 0 0.15rem;
}

.output-page-subtitle {
  margin: 0;
  font-size: 0.9rem;
}

.overview-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  font-size: 0.72rem;
  line-height: 1.25;
}

.overview-legend li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
}

.overview-legend .conf-badge {
  font-size: 0.68rem;
  padding: 0.1rem 0.35rem;
  gap: 0.2rem;
}

.overview-legend .conf-icon {
  width: 0.85rem;
  height: 0.85rem;
  font-size: 0.6rem;
}

.overview-legend-desc {
  color: var(--muted);
  white-space: nowrap;
}

.output-section {
  margin-bottom: 1.75rem;
}

.output-section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.55rem;
}

.output-section-title {
  margin: 0 0 0.15rem;
  font-size: 1.05rem;
}

.output-section-count {
  font-weight: 500;
  font-size: 0.9rem;
}

.output-section-hint {
  margin: 0;
  font-size: 0.85rem;
}

.output-section-header .btn-xml-download {
  flex-shrink: 0;
  align-self: flex-start;
}

.output-section--recent {
  margin-top: 0.25rem;
  padding: 0.75rem 0.85rem 0.9rem;
  background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.output-section--recent .table-wrap {
  background: var(--surface);
}

.recent-strip {
  margin-bottom: 0.5rem;
}

.recent-strip-empty {
  margin: 0;
  font-size: 0.85rem;
}

/* Allowed senders management */
.sender-add-card {
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.sender-form-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto auto;
  gap: 0.75rem 1rem;
  align-items: end;
}

@media (max-width: 800px) {
  .sender-form-grid {
    grid-template-columns: 1fr;
  }
}

.sender-field label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.sender-field .field-input {
  width: 100%;
}

.checkbox-label {
  display: inline-flex !important;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem !important;
  color: var(--text) !important;
  font-weight: 500 !important;
  margin-bottom: 0.45rem !important;
  cursor: pointer;
}

.field-error {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--danger);
}

.sender-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.inline-form {
  display: inline;
  margin: 0;
}

.btn-danger-text {
  color: var(--danger);
}

.btn-danger-text:hover {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--border));
}

/* Clients + field rules */
.header-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.client-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  align-items: start;
}

@media (max-width: 700px) {
  .client-form-grid {
    grid-template-columns: 1fr;
  }
}

.client-form-full {
  grid-column: 1 / -1;
}

.field-hint {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
}

.rule-params {
  max-width: 18rem;
  word-break: break-word;
}

.rule-params code {
  font-size: 0.8rem;
}

.rule-priority {
  font-weight: 600;
  display: block;
  margin-bottom: 0.2rem;
}

.rule-move {
  display: flex;
  gap: 0.15rem;
}

.btn-xs {
  padding: 0.1rem 0.35rem;
  font-size: 0.75rem;
  min-height: 0;
  line-height: 1.2;
}

.rule-params-title {
  margin-top: 1.25rem;
}

.small {
  font-size: 0.8rem;
}

/* Result detail: client + rules */
.client-apply-bar {
  margin: 0.75rem 0 0.5rem;
  padding: 0.75rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.client-apply-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
}

.client-apply-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.client-apply-select {
  min-width: 16rem;
  max-width: 100%;
}

.client-apply-hint {
  margin: 0.45rem 0 0;
  font-size: 0.85rem;
}

.rule-violations-box {
  margin: 0.5rem 0 0.75rem;
  padding: 0.65rem 0.85rem;
  border-left: 3px solid var(--warning);
  background: var(--warning-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
}

.rule-violations-box ul {
  margin: 0.35rem 0 0;
  padding-left: 1.2rem;
}

.source-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
}

.source-badge--ocr {
  background: #e8eef5;
  color: #3d4f66;
}

.source-badge--rule {
  background: #e0f2fe;
  color: #0369a1;
}

.source-badge--fail {
  background: var(--warning-soft);
  color: var(--warning);
}

.source-badge--manual {
  background: #ede9fe;
  color: #5b21b6;
}

.field-row--rule td {
  background: color-mix(in srgb, #e0f2fe 35%, transparent);
}

.field-row--rule-fail td {
  background: color-mix(in srgb, var(--warning-soft) 55%, transparent);
}

.ocr-original {
  margin-top: 0.25rem;
  font-size: 0.78rem;
  word-break: break-word;
}

.col-source {
  width: 5.5rem;
}

.rules-log-panel {
  margin-top: 1.25rem;
}

.rule-event-row--failed {
  background: color-mix(in srgb, var(--warning-soft) 40%, transparent);
}

.rule-event-row--applied {
  background: color-mix(in srgb, #e0f2fe 30%, transparent);
}

.rule-val {
  max-width: 12rem;
  word-break: break-word;
  font-size: 0.85rem;
}

tr.clickable-row {
  cursor: pointer;
  transition: background-color 0.12s ease;
}

tr.clickable-row:hover {
  background: var(--primary-soft);
}

tr.clickable-row:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent);
  outline-offset: -2px;
}

tr.clickable-row a.row-stop-nav {
  position: relative;
  z-index: 1;
}

.data-table--detail col.col-rating { width: 8.5rem; }
.data-table--detail col.col-field { width: 7.5rem; }
.data-table--detail col.col-value { width: auto; }
.data-table--detail col.col-actions { width: 5.5rem; }
.data-table--detail col.col-conf { width: 3.5rem; }

/* ---- Detail review: document + fields side by side ---- */
.detail-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.detail-top-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.detail-back {
  margin: 0 0 0.35rem;
  padding-left: 0.35rem;
  padding-right: 0.5rem;
}

.detail-title {
  margin: 0 0 0.15rem;
  font-size: 1.25rem;
}

.detail-meta-line {
  margin: 0;
  font-size: 0.85rem;
}

.detail-top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
}

.review-summary-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  position: relative;
}

.review-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-popover-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.btn-info-icon {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

.btn-info-icon:hover,
.btn-info-icon[aria-expanded="true"] {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  background: var(--primary-soft);
}

.legend-popover {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 40;
  width: min(20rem, calc(100vw - 2rem));
  padding: 0.75rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.legend-popover-title {
  margin: 0 0 0.55rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.legend-popover-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.legend-popover-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.8rem;
}

.legend-desc {
  color: var(--muted);
}

.legend-popover-note {
  margin: 0.65rem 0 0;
  font-size: 0.75rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.fields-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.fields-pane-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin: 0 0 0.35rem;
}

.btn-xml-download {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  border-color: var(--border);
  color: var(--primary);
  font-weight: 600;
}

.btn-xml-download:hover {
  background: var(--primary-soft);
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}

.btn-xml-download .xml-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.btn-xml-download .xml-icon svg {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
}

.export-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  max-width: 22rem;
}

.export-gate-hint {
  margin: 0;
  font-size: 0.75rem;
  text-align: right;
  line-height: 1.35;
}

.export-gate-hint--block {
  color: var(--danger);
}

.btn-xml-download--warn {
  border-color: color-mix(in srgb, var(--warning) 45%, var(--border));
  color: var(--warning);
}

.btn-xml-download:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.multi-badge {
  display: inline-block;
  margin-left: 0.2rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.65rem;
  font-weight: 700;
  vertical-align: middle;
}

.multi-group-bar {
  margin-top: 0.55rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--primary-soft);
  font-size: 0.85rem;
}

.multi-group-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--primary-hover);
}

.multi-sibling-list {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.multi-sibling {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.multi-sibling-current {
  border-color: var(--primary);
  font-weight: 700;
}

.multi-confirm-form {
  margin: 0;
}

.keyboard-hint {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
}

.keyboard-hint kbd {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  font-size: 0.75rem;
  font-family: inherit;
}

.review-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.05fr);
  gap: 0.85rem;
  align-items: start;
  min-height: 60vh;
}

@media (max-width: 960px) {
  .review-layout {
    grid-template-columns: 1fr;
  }

  .doc-pane {
    position: static !important;
    max-height: 50vh;
  }
}

.doc-pane {
  position: sticky;
  top: 0.5rem;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 420px;
  max-height: calc(100vh - 6rem);
}

.doc-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
  background: var(--primary-soft);
  font-size: 0.85rem;
}

.doc-pane-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #1a1a1a;
}

.doc-frame {
  flex: 1;
  width: 100%;
  min-height: 420px;
  height: calc(100vh - 12rem);
  border: 0;
  background: #525659;
}

.doc-image-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0.5rem;
  max-height: calc(100vh - 12rem);
}

.doc-image {
  max-width: 100%;
  height: auto;
  display: block;
  background: #fff;
  box-shadow: var(--shadow);
}

.doc-hint,
.empty-doc {
  margin: 0;
  padding: 0.4rem 0.65rem;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.75rem;
}

/* Email source pane (gateway) */
.doc-pane--email {
  background: var(--surface);
}

.doc-pane-body--email {
  background: var(--surface);
  color: var(--text);
  overflow: auto;
  padding: 0.75rem 0.9rem 1rem;
  max-height: calc(100vh - 12rem);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.email-meta {
  margin: 0;
  display: grid;
  gap: 0.4rem;
  font-size: 0.82rem;
}

.email-meta > div {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.35rem;
}

.email-meta dt {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.email-meta dd {
  margin: 0;
  word-break: break-word;
}

.email-section-title {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.email-attachment-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
  font-size: 0.85rem;
}

.email-attachment-list li,
.email-attachment-item {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafbfc;
  position: relative;
}

.email-attachment-item--active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
  font-weight: 600;
}

.email-source-badge {
  display: inline-block;
  margin: 0 0.35rem 0.15rem 0;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: middle;
}

.email-body--active .email-body-text {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary-soft) 70%, #fff);
  box-shadow: inset 3px 0 0 var(--primary);
}

.email-body--active .email-section-title {
  color: var(--primary-hover);
}

.email-body-text {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 50vh;
  overflow: auto;
}

.email-empty {
  margin: 0;
  font-size: 0.85rem;
}

.fields-pane .table-wrap {
  max-height: calc(100vh - 10rem);
  overflow: auto;
}

.field-row-active {
  outline: 2px solid color-mix(in srgb, var(--primary) 50%, transparent);
  outline-offset: -2px;
}

.field-row-saved {
  animation: row-flash-ok 0.9s ease;
}

.field-row-error {
  animation: row-flash-err 0.9s ease;
}

@keyframes row-flash-ok {
  0% { background: color-mix(in srgb, var(--success) 25%, transparent); }
  100% { background: transparent; }
}

@keyframes row-flash-err {
  0% { background: color-mix(in srgb, var(--danger) 25%, transparent); }
  100% { background: transparent; }
}

.cell-actions {
  white-space: nowrap;
}

.fields-pane .field-input {
  font-size: 0.8rem;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem !important;
}

/* Flash messages */
.flash-messages {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.flash {
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f7f9fb;
}

.flash-success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 35%, #fff);
  color: var(--success);
}

.flash-error {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, #fff);
  color: var(--danger);
}

.flash-info,
.flash-warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 35%, #fff);
  color: var(--warning);
}

/* Status badges */
.status {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #eef2f6;
  color: var(--muted);
  white-space: nowrap;
}

.status-success {
  background: var(--success-soft);
  color: var(--success);
}

.status-failed {
  background: var(--accent-soft);
  color: var(--danger);
}

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

.conf {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.btn-sm {
  padding: 0.22rem 0.45rem;
  font-size: 0.75rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem 1rem;
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.meta-grid dt {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.meta-grid dd {
  margin: 0.2rem 0 0;
  font-weight: 600;
}

.raw-json {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.raw-json summary {
  cursor: pointer;
  font-weight: 600;
}

.raw-json pre {
  margin: 0.75rem 0 0;
  overflow-x: auto;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Extraction debug panel (LLM chain) */
.extract-debug {
  margin-top: 1.75rem;
}

.extract-debug-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem 1rem;
}

.extract-debug-summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 1.05rem;
  list-style-position: outside;
}

.extract-debug-hint {
  display: block;
  font-weight: 400;
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.extract-debug-block {
  margin: 0.85rem 0;
  padding: 0.65rem 0.75rem;
  background: rgba(0, 0, 0, 0.03);
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border);
}

.extract-debug-block h4,
.extract-debug-step h5 {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
}

.extract-debug-rationale {
  border-left: 3px solid #3b82f6;
}

.extract-debug-step {
  margin: 0.55rem 0;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: #fafafa;
}

.extract-debug-step > summary {
  cursor: pointer;
  font-size: 0.95rem;
}

.extract-debug-pre {
  margin: 0.45rem 0 0;
  padding: 0.55rem 0.65rem;
  max-height: 28rem;
  overflow: auto;
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  background: #111827;
  color: #e5e7eb;
  border-radius: 6px;
}

.extract-debug-pre--emphasis {
  border-left: 3px solid #60a5fa;
}

.extract-debug-kv {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;
  font-size: 0.85rem;
}

.extract-debug-kv li {
  display: grid;
  grid-template-columns: 12rem 1fr;
  gap: 0.5rem;
  align-items: start;
}

.extract-debug-kv li span {
  color: var(--muted);
  font-weight: 600;
}

.extract-debug-kv code {
  font-size: 0.8rem;
  word-break: break-word;
}

/* Confidence review badges */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
  margin: 0 0 0.65rem;
}

.conf-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.conf-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1;
  flex-shrink: 0;
}

.conf-must-review {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--danger) 40%, #fff);
  color: var(--danger);
}

.conf-must-review .conf-icon {
  background: var(--danger);
  color: #fff;
}

.conf-review {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 40%, #fff);
  color: var(--warning);
}

.conf-review .conf-icon {
  background: var(--warning);
  color: #fff;
}

.conf-good {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 35%, #fff);
  color: var(--success);
}

.conf-good .conf-icon {
  background: var(--success);
  color: #fff;
}

.conf-verified {
  background: var(--primary-soft);
  border-color: color-mix(in srgb, var(--primary) 35%, #fff);
  color: var(--primary-hover);
}

.conf-verified .conf-icon {
  background: var(--primary);
  color: #fff;
}

.field-row.conf-must-review {
  background: #fff8f8;
}

.field-row.conf-review {
  background: #fffbf5;
}

.field-row.conf-good {
  background: #f7fbf7;
}

.field-row.conf-verified {
  background: #f1faf3;
}

.field-input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.field-input:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent);
  border-color: var(--primary);
}

textarea.field-input {
  resize: vertical;
}

.form-actions {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

.form-actions .hint {
  margin: 0;
}

/* Overview: red / orange field counts */
.count-badges {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
}

.count-pill-must {
  background: var(--danger);
}

.count-pill-review {
  background: var(--warning);
}

.count-pill-good {
  background: var(--success);
}

.count-pill-verified {
  background: var(--primary);
}

.btn-save:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-save.is-dirty:not(:disabled) {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent);
}

.field-row-dirty {
  box-shadow: inset 3px 0 0 var(--primary);
}

.btn-verify,
.btn-save {
  min-width: 4.5rem;
}

.btn-save.is-busy {
  opacity: 0.7;
}
