:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --paper: #f5f7fb;
  --nav: #25313f;
  --accent: #c21f32;
  --accent-dark: #a81a2b;
  --accent-darker: #8d1623;
  --accent-2: #087f5b;
  --warning: #b7791f;
  --error: #c53030;
  --shadow: 0 14px 32px rgba(31, 41, 51, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.endpoint-url {
  display: block;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  padding: 10px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.endpoint-status {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.toggle-btn {
  margin-top: 10px;
  min-height: 32px;
  padding: 0 12px;
  font-size: 0.85rem;
}

/* Pressed = the processed-only view is active. */
.toggle-btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.inbox-empty {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

.received-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  /* Show every received PO, scrolling within the panel instead of growing the sidebar. */
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.received-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-2);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
}

/* The info area of a card opens the PO; styled as plain clickable text, not a button. */
.received-open {
  min-height: 0;
  width: 100%;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

/* Opening a PO is a button too — keep it looking like text, but still react to the click. */
.received-open:hover {
  background: rgba(31, 41, 51, 0.05);
  border-color: transparent;
}

.received-open:active {
  background: rgba(31, 41, 51, 0.1);
  border-color: transparent;
  box-shadow: none;
}

.received-open.is-busy::after {
  margin-left: 6px;
  width: 10px;
  height: 10px;
}

/* Small per-card "Mark processed / Mark unprocessed" action, bottom-right of the card. */
.received-mark {
  align-self: flex-end;
  min-height: 26px;
  padding: 0 8px;
  font-size: 0.72rem;
  white-space: nowrap;
}

.received-item.rejected {
  border-left-color: var(--error);
}

.received-item.accepted_with_warnings {
  border-left-color: var(--warning);
}

.received-item strong,
.received-item span {
  display: block;
}

.received-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

/* Inbox badge marking an 860 PO-change record apart from an 850 PO. */
.received-item .doc-type {
  display: inline-block;
  margin: 0 0 0 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  vertical-align: middle;
}

/* POC02 change-code chip shown on 860 line rows. */
.change-code {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(8, 127, 91, 0.12);
  color: var(--accent-2);
  font-size: 0.72rem;
  font-weight: 700;
}

button {
  position: relative;
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    box-shadow 120ms ease,
    transform 60ms ease;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

/* The press itself: the button sinks a pixel and darkens, so a click is never silent. */
button:active {
  transform: translateY(1px);
  background: var(--accent-darker);
  border-color: var(--accent-darker);
  box-shadow: inset 0 2px 4px rgba(31, 41, 51, 0.25);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled,
button[aria-busy="true"] {
  cursor: not-allowed;
  opacity: 0.65;
  transform: none;
  box-shadow: none;
}

button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

button.secondary:hover {
  border-color: var(--muted);
  background: #f1f4f9;
}

button.secondary:active {
  background: #e3e8f0;
  border-color: var(--muted);
}

/* Busy state for buttons that wait on the server: the label stays put and a spinner
   joins it, so the button keeps its width and the click is visibly still working. */
button.is-busy::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  vertical-align: -1px;
  animation: button-spin 600ms linear infinite;
}

@keyframes button-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  button {
    transition: none;
  }

  button:active {
    transform: none;
  }

  button.is-busy::after {
    animation-duration: 2s;
  }
}

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

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

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 2px solid #f2c94c;
  border-radius: 8px;
  background: #cf2638;
  color: #fff;
  font-weight: 800;
}

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

.brand-block h1 {
  font-size: 1.35rem;
}

.brand-block p,
.eyebrow,
small {
  color: var(--muted);
}

.sidebar .brand-block p,
.sidebar small {
  color: #c7d1df;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 16px;
  box-shadow: var(--shadow);
}

.sidebar .panel {
  box-shadow: none;
}

.panel-heading,
.topbar,
.compliance-header,
.export-actions,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel h2,
.panel h3,
.compliance-header h3 {
  font-size: 1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  background: #edf2f7;
  color: var(--ink);
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.status-pill.ok {
  background: #dff7ed;
  color: #146c43;
}

.status-pill.bad {
  background: #ffe5e7;
  color: var(--error);
}

.status-pill.warn {
  background: #fff3cd;
  color: var(--warning);
}

.drop-zone {
  display: grid;
  place-items: center;
  gap: 7px;
  min-height: 150px;
  margin-top: 14px;
  border: 1px dashed #9fb0c4;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
}

.drop-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: #fff5f6;
}

.drop-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.35rem;
}

.button-row {
  margin-top: 12px;
}

textarea {
  width: 100%;
  min-height: 210px;
  margin-top: 12px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  color: var(--ink);
  line-height: 1.45;
}

.workspace {
  min-width: 0;
  padding: 26px;
}

.topbar {
  min-height: 86px;
}

.eyebrow {
  margin-bottom: 5px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar h2 {
  font-size: clamp(1.3rem, 2vw, 2rem);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  gap: 10px;
}

.scoreboard div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  text-align: right;
}

.scoreboard span {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
}

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

/* Tabs are buttons, so they need to opt out of the filled hover/press treatment and
   get their own: a tinted strip plus the same one-pixel sink on press. */
.tab:hover {
  border-bottom-color: var(--line);
  background: #eef1f6;
  color: var(--ink);
}

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

.tab:active {
  background: #e3e8f0;
  box-shadow: none;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

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

.metric {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.metric strong {
  display: block;
  margin-top: 9px;
  overflow-wrap: anywhere;
  font-size: 1.18rem;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 14px;
  margin-top: 14px;
}

.detail-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 10px 16px;
  margin: 12px 0 0;
}

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

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.party-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.party {
  border-left: 4px solid var(--accent);
  background: #f8fafc;
  padding: 10px 12px;
}

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

.party span {
  color: var(--muted);
  margin-top: 3px;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.table-shell.compact table {
  min-width: 620px;
}

.table-shell input,
.table-shell select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #eef2f7;
  color: #344054;
  font-size: 0.82rem;
}

td code {
  font-size: 0.86rem;
}

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

.issue-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.issue {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 8px;
  background: #fff;
  padding: 12px 14px;
}

.issue.error {
  border-left-color: var(--error);
}

.issue.warning {
  border-left-color: var(--warning);
}

.issue strong {
  display: block;
  margin-bottom: 4px;
}

#jsonPreview {
  overflow: auto;
  max-height: 620px;
  margin: 14px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101828;
  color: #e8eef7;
  padding: 16px;
}

#ackPreview,
#asnPreview {
  overflow: auto;
  max-height: 520px;
  margin: 14px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101828;
  color: #e8eef7;
  padding: 16px;
}

.ack-layout {
  display: grid;
  gap: 14px;
}

.ack-actions {
  justify-content: flex-start;
  margin-top: 14px;
}

.editor-block {
  margin-top: 16px;
}

.editor-block h4 {
  margin: 0 0 10px;
}

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

.form-grid label {
  display: grid;
  gap: 6px;
}

.form-grid label.wide {
  grid-column: span 2;
}

.form-grid span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.form-grid input,
.form-grid select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 7px 10px;
}

@media (max-width: 980px) {
  .app-shell,
  .two-column {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .panel-heading,
  .compliance-header,
  .export-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .scoreboard,
  .summary-grid,
  .form-grid {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .form-grid label.wide {
    grid-column: span 1;
  }

  .tabs {
    overflow-x: auto;
  }
}

.label-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
}

.label-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}

.label-caption {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
  word-break: break-all;
}

.label-svg svg {
  width: 240px;
  height: auto;
  display: block;
}

/* The product/intermediate label is the 4in x 2in layout rotated onto 2in x 4in portrait
   stock, so it previews narrower than the 4in x 6in logistic label -- a little wider than
   that label's scale to keep the rotated text legible. */
.label-card.product .label-svg svg {
  width: 160px;
}

/* --- Session bar (sidebar) --- */
.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
  color: #c7d1df;
}

.session-bar .user-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-bar button {
  min-height: 30px;
  padding: 0 12px;
  font-size: 0.8rem;
}

/* --- Login page --- */
.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card .brand-block p {
  color: var(--muted);
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.login-card label span {
  color: var(--muted);
  font-weight: 600;
}

.login-card input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}

.login-card input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.login-card .password-field {
  position: relative;
  display: flex;
  align-items: center;
}

/* Leave room for the Show/Hide button so typed text never runs under it. */
.login-card .password-field input {
  width: 100%;
  padding-right: 62px;
}

.login-card .password-toggle {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  min-height: 28px;
  margin: 0;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.login-card .password-toggle:hover {
  color: var(--ink);
}

.login-card .password-toggle:active {
  color: var(--accent);
}

.login-card .password-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.login-card button {
  margin-top: 4px;
}

.login-error {
  margin: 0;
  color: var(--error);
  font-size: 0.9rem;
}
