.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 18rem) minmax(0, 1fr);
  align-items: stretch;
  gap: 1rem;
}

.invoice-panel, .conversion-rail {
  min-width: 0;
  border: 1px solid rgba(197, 213, 221, 0.94);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.invoice-panel { display: flex; height: min(47rem, calc(100dvh - 5.5rem)); min-height: 38rem; flex-direction: column; overflow: hidden; background: rgba(255,255,255,0.88); }

.source-panel { border-top: 4px solid #55788d; }
.target-panel { border-top: 4px solid var(--teal); }

.panel-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: 2.25rem auto;
  align-items: center;
  gap: 0.4rem 0.8rem;
  padding: 1.1rem 1.2rem 0.8rem;
}

.panel-heading .panel-step { grid-row: 1; grid-column: 1; }
.panel-heading .header-action-button, .panel-heading .result-badge { grid-row: 1; grid-column: 2; }
.panel-heading h2 { grid-row: 2; grid-column: 1; }
.panel-heading .panel-expand { grid-row: 2; grid-column: 2; justify-self: end; }
.panel-step { display: flex; min-width: 0; align-items: center; gap: 0.55rem; }
.panel-step .panel-kicker { margin: 0; color: #496373; font-size: 0.72rem; white-space: nowrap; }
.step-badge, .conversion-number {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 2.25rem;
  place-items: center;
  border: 1px solid #0f766e;
  border-radius: 50%;
  color: #fff;
  background: #0f766e;
  box-shadow: none;
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0.02em;
}

.panel-heading h2, .conversion-rail h2 { margin: 0; align-self: center; font-size: 1.2rem; line-height: 2.25rem; }
.panel-heading .quiet-button, .panel-heading .result-badge { justify-self: end; }
.header-action-button {
  min-height: 2.25rem;
  border: 1px solid #407084;
  color: #294d60;
  background: #fff;
  box-shadow: 0 0.15rem 0.35rem rgba(33, 63, 80, 0.08);
}
.header-action-button:hover { border-color: var(--teal); color: var(--teal); background: #e8f8f4; }
.panel-expand { display: grid; width: 2.25rem; height: 2.25rem; place-items: center; border: 1px solid #cfdee4; border-radius: 0.58rem; color: #3c5d6c; background: #f6fafb; font-size: 1.05rem; font-weight: 800; }
.panel-expand:hover:not(:disabled) { color: var(--teal); border-color: #a8d5ce; background: #e5f8f3; }

.format-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1.2rem 0.75rem;
}

.format-strip span, .target-chip {
  display: inline-flex;
  max-width: 100%;
  overflow: hidden;
  padding: 0.27rem 0.5rem;
  border-radius: 0.35rem;
  color: #506677;
  background: #edf3f6;
  font-family: inherit;
  font-size: 0.69rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.target-format span { color: #0b665e; background: #e2f5f1; }

.tab-list { display: flex; gap: 0.2rem; padding: 0 1.2rem; border-bottom: 1px solid var(--line); }

.tab-button { border: 0; padding: 0.6rem 0.65rem 0.65rem; color: var(--muted); background: transparent; font-size: 0.82rem; font-weight: 750; }
.tab-button:hover { color: var(--ink); }
.tab-button.is-active { color: var(--teal); box-shadow: inset 0 -2px 0 var(--teal); }

.panel-content { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 0.85rem; padding: 1rem 1.2rem 1.2rem; overflow: hidden; }

.source-review-action { flex: 0 0 auto; padding: 0.8rem 1.2rem 1.2rem; border-top: 1px solid var(--line); background: rgba(255,255,255,0.96); }
.source-review-action .download-button { width: 100%; margin: 0; }

.drop-zone {
  display: flex;
  min-height: 31rem;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 2rem;
  border: 1.5px dashed #9eb5c2;
  border-radius: 0.82rem;
  color: var(--muted);
  background: linear-gradient(145deg, #f8fbfc, #edf5f7);
  text-align: center;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.drop-zone.is-dragging { border-color: var(--teal); background: #e5f8f3; transform: scale(1.01); }
.drop-zone input { display: none; }
.drop-zone h3 { margin-top: 0.65rem; color: var(--ink); font-size: 1.15rem; }
.drop-zone p { margin-bottom: 1.2rem; line-height: 1.55; font-size: 0.9rem; }
.drop-zone small { margin-top: 0.85rem; color: #718293; font-size: 0.72rem; }

.drop-icon, .empty-symbol { display: grid; width: 3.2rem; height: 3.2rem; place-items: center; border-radius: 0.9rem; color: var(--teal); background: #dff5f0; font-size: 1.4rem; font-weight: 800; }

.conversion-rail {
  position: relative;
  display: flex;
  min-height: 30rem;
  flex-direction: column;
  padding: 1.1rem 1.2rem 1.2rem;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(158deg, #173243 0%, #12202e 68%, #0b5c58 150%);
}

.conversion-rail::after { position: absolute; right: -4rem; bottom: -5rem; width: 14rem; height: 14rem; border: 1px solid rgba(126,231,215,0.25); border-radius: 50%; content: ""; }
.conversion-rail > * { position: relative; z-index: 1; }
.conversion-rail .panel-step { min-height: 2.25rem; }
.conversion-rail .panel-step .panel-kicker { color: #d5eee9; }
.conversion-rail h2 { margin-bottom: 0.75rem; }
.conversion-rail .panel-kicker { color: #a6c2ce; }
.conversion-number { border-color: #7ee7d7; color: var(--navy); background: #7ee7d7; box-shadow: none; }
.target-chip { width: max-content; color: #c5fff3; background: rgba(126,231,215,0.12); }

.conversion-status { display: flex; align-items: center; gap: 0.5rem; margin: 1.5rem 0 0.8rem; padding: 0.68rem 0; border-top: 1px solid rgba(255,255,255,0.12); color: #dce9ed; font-size: 0.82rem; font-weight: 700; }
.conversion-status .status-dot { background: #91aab5; }
.conversion-status[data-status="working"] .status-dot { background: #fbbf24; animation: pulse 1.15s infinite; }
.conversion-status[data-status="passed"] .status-dot { background: var(--mint); }
.conversion-status[data-status="review"] .status-dot { background: #fbbf24; }

.rail-note { margin-top: auto; padding-top: 1.1rem; border-top: 1px solid rgba(255,255,255,0.14); color: #d3e1e6; font-size: 0.76rem; line-height: 1.48; }
.rail-note strong { color: var(--mint); font-size: 0.71rem; letter-spacing: 0.08em; text-transform: uppercase; }
.rail-note p { margin: 0.3rem 0 0; }
.download-button { margin-top: 0.7rem; border: 1px solid var(--mint); color: var(--navy); background: var(--mint); }
.download-button:hover { transform: translateY(-1px); background: #b1fff1; }

.result-badge { display: inline-flex; align-items: center; min-height: 2.25rem; padding: 0 0.7rem; border: 1px solid #c5d8df; border-radius: 0.58rem; color: #526c7a; background: #f5f9fa; font-size: 0.72rem; font-weight: 800; }
.result-badge[data-passed="true"] { border-color: #92d3c4; color: var(--green); background: var(--green-bg); }

.empty-target { align-items: center; justify-content: center; }
.empty-state { display: flex; max-width: 20rem; align-items: center; flex-direction: column; color: var(--muted); text-align: center; }
.empty-state h3 { margin-top: 0.85rem; color: var(--ink); font-size: 1rem; }
.empty-state p { margin-bottom: 0; font-size: 0.86rem; line-height: 1.55; }

.attachment-list { overflow: hidden; border: 1px solid #dbe5e9; border-radius: 0.65rem; background: #f9fbfc; }
.attachment-list > div { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.65rem 0.75rem; color: #425768; border-bottom: 1px solid #e1eaed; font-size: 0.74rem; }
.attachment-list > div span { color: var(--muted); }
.attachment-list ul { display: grid; gap: 0.35rem; margin: 0; padding: 0.6rem 0.75rem; list-style: none; }
.attachment-list li { display: grid; grid-template-columns: 1rem minmax(0,1fr) auto; gap: 0.3rem; color: #465b6a; font-size: 0.78rem; }
.attachment-list li small { color: var(--muted); }

.invoice-paper { overflow: hidden; border: 1px solid #d5dfe4; border-radius: 0.6rem; background: #fff; box-shadow: 0 0.5rem 1rem rgba(22,37,52,0.06); }
.paper-topline { display: flex; justify-content: space-between; padding: 0.65rem 0.8rem; color: #fff; background: #254256; font-size: 0.68rem; font-weight: 760; letter-spacing: 0.07em; text-transform: uppercase; }
.target-panel .paper-topline { background: var(--teal); }
.paper-addresses { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 1.1rem 0.8rem 0.9rem; }
.paper-addresses p { margin-bottom: 0.25rem; color: var(--muted); font-size: 0.68rem; font-weight: 750; text-transform: uppercase; }
.paper-addresses strong, .paper-addresses span { display: block; font-size: 0.76rem; line-height: 1.45; }
.paper-addresses strong { margin-bottom: 0.2rem; }
.paper-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; padding: 0.65rem 0.8rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #f7fafb; }
.paper-meta span { display: flex; flex-direction: column; color: #536979; font-size: 0.7rem; }
.paper-meta b { margin-bottom: 0.16rem; color: var(--muted); font-size: 0.62rem; letter-spacing: 0.05em; text-transform: uppercase; }
.line-table-wrap { overflow-x: auto; }
.line-table { width: 100%; border-collapse: collapse; font-size: 0.72rem; }
.line-table th { padding: 0.55rem 0.8rem; color: var(--muted); background: #edf3f5; text-align: left; font-size: 0.64rem; letter-spacing: 0.05em; text-transform: uppercase; }
.line-table td { padding: 0.55rem 0.8rem; border-bottom: 1px solid #edf1f3; vertical-align: top; }
.line-table td:nth-last-child(-n+2), .line-table th:nth-last-child(-n+2) { text-align: right; white-space: nowrap; }
.line-table td:nth-child(2) { min-width: 13rem; }
.line-table td b { display: block; margin-bottom: 0.18rem; color: #607484; font-size: 0.64rem; }
.paper-total { display: flex; justify-content: flex-end; gap: 1.5rem; padding: 0.85rem 0.8rem; color: var(--navy); background: #f8fafb; font-size: 0.82rem; }
.paper-total strong { min-width: 6rem; text-align: right; }

.snapshot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.snapshot-grid div { padding: 0.65rem; border: 1px solid #dce6eb; border-radius: 0.55rem; background: #fbfcfd; }
.snapshot-grid span, .snapshot-grid b { display: block; }
.snapshot-grid span { margin-bottom: 0.25rem; color: var(--muted); font-size: 0.67rem; }
.snapshot-grid b { overflow: hidden; font-size: 0.78rem; text-overflow: ellipsis; white-space: nowrap; }

.xml-view { display: flex; min-height: 0; flex: 1; flex-direction: column; overflow: hidden; border: 1px solid #d5e1e6; border-radius: 0.6rem; background: #10222f; }
.xml-caption { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.65rem 0.8rem; color: #d8e9ed; background: #183646; font-size: 0.72rem; }
.xml-caption span { color: #a7c3cc; text-align: right; }
.xml-view pre { min-width: max-content; margin: 0; padding: 0.8rem; overflow: auto; color: #c5eee7; font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.72rem; line-height: 1.5; }

.review-list { display: grid; align-content: start; gap: 0.6rem; }
.review-heading { padding-bottom: 0.3rem; }
.review-heading p { margin-bottom: 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.review-item { display: grid; grid-template-columns: 1.7rem 1fr; gap: 0.55rem; padding: 0.75rem; border: 1px solid #dce6eb; border-radius: 0.65rem; background: #fbfcfd; }
.review-item.warning { border-color: #f1d29a; background: var(--orange-bg); }
.review-item.passed { border-color: #bee8d8; background: var(--green-bg); }
.review-item.info { border-color: #cfe0ea; background: #f5fafc; }
.review-marker { display: grid; width: 1.35rem; height: 1.35rem; place-items: center; border-radius: 50%; color: #486473; background: #e2edf2; font-size: 0.72rem; font-weight: 850; }
.warning .review-marker { color: var(--orange); background: #ffecbf; }
.passed .review-marker { color: var(--green); background: #cbeede; }
.review-item b { display: block; margin-bottom: 0.18rem; font-size: 0.83rem; }
.review-item p { margin: 0; color: #526777; font-size: 0.77rem; line-height: 1.42; }

.review-dialog { width: min(44rem, calc(100vw - 1.5rem)); max-height: calc(100vh - 2rem); padding: 0; border: 0; border-radius: 1rem; color: var(--ink); background: #fff; box-shadow: 0 2rem 6rem rgba(5,23,37,0.35); }
.review-dialog::backdrop { background: rgba(10,31,43,0.52); backdrop-filter: blur(3px); }
.review-dialog form { display: flex; max-height: calc(100vh - 2rem); flex-direction: column; }
.dialog-heading { display: flex; justify-content: space-between; gap: 0.8rem; padding: 1.25rem 1.4rem 0.65rem; }
.dialog-heading h2 { font-size: 1.25rem; }
.icon-button { width: 2.3rem; height: 2.3rem; border: 0; border-radius: 50%; color: var(--muted); background: #eef3f5; font-size: 1.5rem; line-height: 1; }
.dialog-intro { margin: 0 1.4rem 0.75rem; color: var(--muted); font-size: 0.85rem; line-height: 1.48; }
.review-fields { display: grid; gap: 1rem; padding: 0.5rem 1.4rem 1.25rem; overflow: auto; }
.field-group { padding: 0.9rem; border: 1px solid #dce6eb; border-radius: 0.7rem; background: #fbfcfd; }
.field-group h3 { font-size: 0.92rem; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.field-label, .unit-field { display: grid; gap: 0.35rem; color: #506674; font-size: 0.76rem; font-weight: 700; }
.field-label input, .unit-field select { width: 100%; min-height: 2.5rem; border: 1px solid #c9d7de; border-radius: 0.5rem; padding: 0 0.65rem; color: var(--ink); background: #fff; font-weight: 500; }
.field-help { margin-bottom: 0.75rem; color: var(--muted); font-size: 0.76rem; }
.unit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; padding: 0.95rem 1.4rem; border-top: 1px solid var(--line); }
.dialog-actions .primary-button { width: auto; padding: 0 1rem; }

.loading-orbit { width: 2.4rem; height: 2.4rem; border: 3px solid #cfe6e2; border-top-color: var(--teal); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { transform: scale(1.35); opacity: 0.55; } }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .conversion-rail { grid-row: 2; grid-column: span 2; min-height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.55rem 1rem; }
  .conversion-rail .conversion-number { margin: 0; }
  .conversion-rail h2, .conversion-rail .panel-kicker { margin: 0; }
  .conversion-rail .target-chip { margin-right: auto; }
  .conversion-status { margin: 0; padding: 0; border: 0; }
  .conversion-rail .primary-button { width: auto; padding: 0 1rem; }
  .conversion-rail .text-button { width: auto; padding: 0 0.7rem; }
  .rail-note { display: none; }
  .download-button { margin: 0; padding: 0 0.9rem; }
}

@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
  .conversion-rail { grid-row: auto; grid-column: auto; }
  .invoice-panel { height: 38rem; min-height: 0; }
  .panel-heading, .format-strip, .tab-list, .panel-content, .source-review-action { padding-left: 0.85rem; padding-right: 0.85rem; }
  .drop-zone { min-height: 25rem; padding: 1.25rem; }
  .field-grid, .unit-grid { grid-template-columns: 1fr; }
  .dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .dialog-actions .primary-button { width: 100%; }
}

@media (min-width: 1181px) and (min-aspect-ratio: 4 / 3) {
  .workspace { height: 100%; min-height: 0; grid-template-rows: minmax(0, 1fr); }
  .invoice-panel, .conversion-rail { height: 100%; min-height: 0; }
}
