/* Vaca Orders: components. Uses semantic tokens from tokens.css only. */

*, *::before, *::after { box-sizing: border-box; }

html {
  font-family: var(--font-sans);
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--border-input) var(--surface-ground);
}

body {
  margin: 0;
  background: var(--surface-ground);
  color: var(--text);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}

::selection { background: var(--filled-line); color: var(--text); }
input, textarea, select { caret-color: var(--action); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--action); }

:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.num, .tnum { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.icon {
  width: 1rem; height: 1rem; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--control-height); padding: 0 var(--space-3);
  border: 1px solid var(--border-input); border-radius: var(--radius-md);
  background: var(--surface-raised); color: var(--text);
  font: inherit; font-size: var(--text-base); font-weight: var(--weight-medium); line-height: 1;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
}
.btn:hover, .btn.is-hover { background: var(--surface-sunken); }
.btn:active { background: var(--border); }
.btn.is-focus { box-shadow: var(--focus-ring); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--text-on-action); }
.btn--primary:hover, .btn--primary.is-hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--primary:active { background: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--action); }
.btn--ghost:hover, .btn--ghost.is-hover { background: var(--surface-selected); }
.btn--danger { background: var(--surface-raised); border-color: var(--danger-line); color: var(--danger); }
.btn--danger:hover, .btn--danger.is-hover { background: var(--danger-wash); }
.btn--sm { height: var(--control-height-sm); padding: 0 var(--space-2); font-size: var(--text-sm); }
.btn--lg { height: var(--control-height-lg); padding: 0 var(--space-4); font-size: var(--text-md); }
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"]::before {
  content: ""; width: 0.875rem; height: 0.875rem; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* AI actions (Dictar venta, Analizar y completar): a soft sheen crosses the button now and then, in the same tint that
   marks values the system read. Idle and enabled only; it rests on hover, focus and while busy, and is off under
   reduced motion. */
.btn--ai { position: relative; isolation: isolate; overflow: hidden; }
.btn--ai::after {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(105deg, transparent 38%, color-mix(in oklch, var(--filled-line) 60%, transparent) 50%, transparent 62%);
  transform: translateX(-100%);
  animation: ai-sheen 6s linear 1.5s infinite;
}
.btn--ai:disabled::after, .btn--ai:hover::after, .btn--ai:focus-visible::after, .btn--ai[aria-busy="true"]::after { animation: none; opacity: 0; }
@keyframes ai-sheen { 0% { transform: translateX(-100%); } 28%, 100% { transform: translateX(100%); } }

/* Fields */
.field { display: grid; gap: var(--space-1); }
.field__label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text); }
.field__hint { font-size: var(--text-sm); color: var(--text-muted); }
.field__error {
  display: flex; align-items: center; gap: var(--space-1);
  font-size: var(--text-sm); color: var(--danger);
}
.input, .select, .textarea {
  width: 100%; height: var(--control-height); padding: 0 var(--space-3);
  border: 1px solid var(--border-input); border-radius: var(--radius-md);
  background: var(--surface-raised); color: var(--text);
  font: inherit; font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease-out);
}
.textarea { height: auto; min-height: 7rem; padding: var(--space-2) var(--space-3); resize: vertical; line-height: var(--leading-normal); }
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { box-shadow: var(--focus-ring); border-color: var(--action); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-sunken); color: var(--text-subtle); cursor: not-allowed; }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-wash); }
.check { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-base); cursor: pointer; }
.check input { width: 1rem; height: 1rem; margin: 0; }

/* Status badge: always icon plus text, never colour alone */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  height: 1.375rem; padding: 0 var(--space-2);
  border: 1px solid var(--border-emphasis); border-radius: var(--radius-sm);
  background: var(--surface-sunken); color: var(--text-muted);
  font-size: var(--text-xs); font-weight: var(--weight-semibold); white-space: nowrap;
}
.badge .icon { width: 0.8125rem; height: 0.8125rem; }
.badge--filled { background: var(--filled-wash); border-color: var(--filled-line); color: var(--filled); }
.badge--warn { background: var(--warn-wash); border-color: var(--warn-line); color: var(--warn); }
.badge--ok { background: var(--ok-wash); border-color: var(--ok-line); color: var(--ok); }
.badge--danger { background: var(--danger-wash); border-color: var(--danger-line); color: var(--danger); }
.badge--void {
  background: transparent; color: var(--danger);
  border: 1px solid var(--danger); outline: 1px solid var(--danger); outline-offset: 1px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.flag {
  display: inline-flex; align-items: center; height: 1.25rem; padding: 0 var(--space-2);
  border-radius: var(--radius-sm); background: var(--surface-sunken); color: var(--text-muted);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
}

/* Alerts */
.alert {
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-3); align-items: start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-emphasis); border-radius: var(--radius-md);
  background: var(--surface-sunken); color: var(--text);
}
.alert .icon { margin-top: 0.125rem; }
.alert__title { margin: 0; font-size: var(--text-base); font-weight: var(--weight-semibold); }
.alert__text { margin: var(--space-1) 0 0; font-size: var(--text-base); color: var(--text-muted); }
.alert__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.alert--info { background: var(--filled-wash); border-color: var(--filled-line); }
.alert--info .icon { color: var(--filled); }
.alert--warn { background: var(--warn-wash); border-color: var(--warn-line); }
.alert--warn .icon, .alert--warn .alert__title { color: var(--warn); }
.alert--danger { background: var(--danger-wash); border-color: var(--danger-line); }
.alert--danger .icon, .alert--danger .alert__title { color: var(--danger); }
.alert--ok { background: var(--ok-wash); border-color: var(--ok-line); }
.alert--ok .icon, .alert--ok .alert__title { color: var(--ok); }

/* Table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border-emphasis); border-radius: var(--radius-md); background: var(--surface-raised); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.table th, .table td { height: var(--row-height); padding: 0 var(--space-3); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table thead th { position: sticky; top: 0; background: var(--surface-header); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-muted); border-bottom-color: var(--border-emphasis); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-sunken); }
.table tbody tr[aria-selected="true"] { background: var(--surface-selected); }
.table .num, .table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.table .cell-id { font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .cell-id .flag { margin-left: var(--space-1); font-weight: var(--weight-medium); }
.table td.nowrap { white-space: nowrap; }
.table td.cell-clip { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .cell-muted { color: var(--text-muted); }
.sort-btn {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer;
}
.sort-btn:hover { color: var(--text); }
.sort-btn .icon { width: 0.8125rem; height: 0.8125rem; opacity: 0.55; }
th[aria-sort="ascending"] .sort-btn, th[aria-sort="descending"] .sort-btn { color: var(--text); }
th[aria-sort="ascending"] .icon, th[aria-sort="descending"] .icon { opacity: 1; color: var(--action); }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding: var(--space-2) var(--space-3); font-size: var(--text-sm); color: var(--text-muted); border-top: 1px solid var(--border); }

/* Tabs */
.tabs { display: flex; gap: var(--space-4); border-bottom: 1px solid var(--border-emphasis); }
.tab {
  position: relative; padding: var(--space-2) 0; border: 0; background: none;
  font: inherit; font-size: var(--text-base); color: var(--text-muted); cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-pressed="true"] { color: var(--text); font-weight: var(--weight-semibold); }
.tab[aria-pressed="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent); }
.tab .count { margin-left: var(--space-1); color: var(--text-subtle); font-variant-numeric: tabular-nums; }

/* Extracted field: the signature. A value read from the message is struck
   in carbon blue on the copy, and its source span lights up in the original. */
.ledger { margin: 0; padding: 0; list-style: none; border: 1px solid var(--border-emphasis); border-radius: var(--radius-md); background: var(--surface-raised); }
.fld {
  display: grid; grid-template-columns: 8.5rem 1fr auto; gap: var(--space-3); align-items: baseline;
  padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border);
}
.fld:last-child { border-bottom: 0; }
.fld:hover, .fld:focus-visible, .fld.is-active { background: var(--filled-wash); }
.fld:focus-visible, .fld.is-focus { box-shadow: inset 0 0 0 2px var(--action); }
.fld__label { font-size: var(--text-sm); color: var(--text-muted); }
.fld__value { color: var(--filled); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fld__value small { display: block; font-weight: var(--weight-regular); color: var(--text-muted); font-size: var(--text-sm); }
.fld__state { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }
.fld[data-state="missing"] .fld__value { color: var(--warn); font-weight: var(--weight-regular); }
.fld[data-state="missing"] .fld__state { color: var(--warn); }
.fld[data-state="conflict"] .fld__value { color: var(--danger); }
.fld[data-state="conflict"] .fld__state { color: var(--danger); }
.fld[data-state="edited"] .fld__state { color: var(--text); }
.fld--total { border-top: 1px solid var(--border-input); }
.fld--total .fld__value { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.src {
  border-radius: var(--radius-sm);
  text-decoration: underline; text-decoration-color: var(--filled-line); text-decoration-thickness: 1px; text-underline-offset: 0.25em;
  transition: background var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.src--warn { text-decoration-color: var(--warn-line); }
.src--danger { text-decoration-color: var(--danger-line); }
.src.is-lit { background: var(--filled-wash); box-shadow: 0 0 0 1px var(--filled-line); color: var(--text); }
.src.is-lit-warn { background: var(--warn-wash); box-shadow: 0 0 0 1px var(--warn-line); }
.src.is-lit-danger { background: var(--danger-wash); box-shadow: 0 0 0 1px var(--danger-line); }

/* Original message pane */
.msg {
  margin: 0; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-emphasis); border-radius: var(--radius-md); background: var(--surface-raised);
  font: inherit; font-size: var(--text-base); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg__meta { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); font-size: var(--text-sm); color: var(--text-muted); }

/* States: empty, loading, error */
.state { display: grid; justify-items: start; gap: var(--space-2); padding: var(--space-5); border: 1px dashed var(--border-input); border-radius: var(--radius-md); background: var(--surface-raised); }
.state__title { margin: 0; font-size: var(--text-md); font-weight: var(--weight-semibold); }
.state__text { margin: 0; color: var(--text-muted); max-width: 52ch; }
.skeleton { display: block; height: 0.75rem; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-sunken), var(--border), var(--surface-sunken)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .btn[aria-busy="true"]::before { animation-duration: 2s; } .btn--ai::after { animation: none; opacity: 0; } }

/* Progress: delivery steps */
.steps { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.step { display: grid; gap: var(--space-1); padding-top: var(--space-2); border-top: 2px solid var(--border-emphasis); font-size: var(--text-sm); color: var(--text-muted); }
.step[data-state="done"] { border-top-color: var(--action); color: var(--text); }
.step[data-state="current"] { border-top-color: var(--action); color: var(--text); font-weight: var(--weight-semibold); }
.step[data-state="problem"] { border-top-color: var(--danger); color: var(--danger); font-weight: var(--weight-semibold); }
.step small { font-weight: var(--weight-regular); color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Shell */
.shell { display: grid; grid-template-columns: var(--rail-width) minmax(0, 1fr); min-height: 100%; background: var(--surface-ground); }
.rail { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-3); background: var(--surface-shell); color: var(--text-on-shell); }
.rail__title { padding: var(--space-2) var(--space-2) var(--space-3); font-size: var(--text-md); font-weight: var(--weight-semibold); }
.rail__link {
  display: flex; align-items: center; gap: var(--space-2); height: var(--control-height); padding: 0 var(--space-2);
  border-radius: var(--radius-md); color: var(--text-on-shell-muted); text-decoration: none; font-size: var(--text-base);
  transition: background var(--duration-fast) var(--ease-out);
}
.rail__link:hover { background: var(--surface-shell-hover); color: var(--text-on-shell); }
.rail__link[aria-current="page"] { background: var(--surface-shell-hover); color: var(--text-on-shell); font-weight: var(--weight-semibold); }
.rail__link:focus-visible { box-shadow: 0 0 0 2px var(--surface-shell), 0 0 0 4px var(--text-on-shell); }
.rail__link .count { margin-left: auto; font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.topbar { display: flex; align-items: center; gap: var(--space-3); min-height: var(--topbar-height); padding: var(--space-2) var(--space-4); background: var(--surface-raised); border-bottom: 1px solid var(--border-emphasis); }
.topbar__search { position: relative; flex: 1; max-width: 26rem; }
.topbar__search .icon { position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%); color: var(--text-subtle); pointer-events: none; }
.topbar__search .input { padding-left: 2.125rem; }
.topbar__spacer { flex: 1; }
/* Brand: the supplied wordmark is an opaque light JPEG, so on the dark rail it sits on a nameplate in the file's own
   background colour. The PNGs are uniform crops of the supplied files, scaled to the exact CSS size for 1x, 2x and 3x
   screens (provenance in design-system/brand/README.md); the originals are never edited. Narrow screens swap to the
   round badge, whose matte is transparent. */
.brand { display: block; margin-bottom: var(--space-2); padding: var(--space-2) var(--space-3); background: var(--surface-logo); border-radius: var(--radius-md); line-height: 0; }
.brand:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--surface-shell), 0 0 0 4px var(--text-on-shell); }
.brand__mark { display: block; width: 11rem; height: auto; aspect-ratio: 176 / 46; }
.page { padding: var(--space-4); display: grid; gap: var(--space-4); align-content: start; }
.page__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.page__title { margin: 0; font-size: var(--text-xl); line-height: var(--leading-tight); font-weight: var(--weight-semibold); text-wrap: balance; }
.page__sub { margin: var(--space-1) 0 0; color: var(--text-muted); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.panel-title { margin: 0 0 var(--space-2); font-size: var(--text-base); font-weight: var(--weight-semibold); }

@media (max-width: 56rem) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { flex-direction: row; align-items: center; overflow-x: auto; padding: var(--space-2) var(--space-3); }
  .rail__title { padding: 0 var(--space-3) 0 0; }
  .brand { flex: none; margin: 0 var(--space-3) 0 0; padding: 0; background: none; border-radius: 50%; }
  .brand__mark { width: 2rem; height: 2rem; aspect-ratio: 1; }
  .hide-md { display: none; }
  .fld { grid-template-columns: 1fr auto; }
  .fld__label { grid-column: 1 / -1; }
}

@media (max-width: 44rem) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .ledger .fld__value .fld__src { display: block; }
}

@media (max-width: 40rem) {
  .hide-sm { display: none; }
  .rail__title { display: none; }
  .rail__link .count { display: none; }
  .topbar { flex-wrap: wrap; }
  .topbar__search { flex: 1 1 100%; max-width: none; order: 1; }
  .topbar__spacer { display: none; }
  .alert { grid-template-columns: auto 1fr; }
  .alert__actions { grid-column: 1 / -1; }
  .page__head .row { width: 100%; }
}

/* Order pad: the original sheet and its carbon copy */
.sheet { border: 1px solid var(--border-emphasis); border-radius: var(--radius-md); background: var(--surface-raised); overflow: hidden; }
.sheet__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); padding: var(--space-2) var(--space-4); background: var(--surface-header); border-bottom: 1px solid var(--border-emphasis); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-muted); }
.sheet--copy { background: var(--surface-sunken); border-top: 2px solid var(--accent); }
.sheet--copy .sheet__head { color: var(--filled); }
.sheet .msg, .sheet .ledger { border: 0; border-radius: 0; background: transparent; }
.sheet--copy .fld { border-bottom-color: var(--border-emphasis); }
.sheet--copy .fld:hover, .sheet--copy .fld:focus-visible, .sheet--copy .fld.is-active { background: var(--surface-raised); }
.fld__value .fld__src { display: none; margin-top: var(--space-1); color: var(--text-muted); font-size: var(--text-xs); font-weight: var(--weight-regular); font-style: italic; overflow-wrap: anywhere; }
.reconcile { margin: 0; padding: var(--space-2) var(--space-4); border-top: 1px solid var(--border-emphasis); font-size: var(--text-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Links, hidden text, floating layer */
.row-link { color: inherit; font-weight: inherit; text-decoration: none; border-radius: var(--radius-sm); }
.row-link:hover { color: var(--action); text-decoration: underline; text-underline-offset: 0.2em; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.menu { display: grid; min-width: 13rem; padding: var(--space-1); border: 1px solid var(--border-emphasis); border-radius: var(--radius-md); background: var(--surface-raised); box-shadow: var(--shadow-overlay); }
.menu__item { display: flex; align-items: center; gap: var(--space-2); height: var(--control-height); padding: 0 var(--space-2); border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); font: inherit; font-size: var(--text-base); text-align: left; cursor: pointer; }
.menu__item:hover, .menu__item.is-hover { background: var(--surface-sunken); }
.menu__item--danger { color: var(--danger); }
.menu__sep { height: 1px; margin: var(--space-1) 0; background: var(--border); }

/* Alerts inside a narrow column: actions drop below the text */
.split .alert { grid-template-columns: auto 1fr; }
.split .alert__actions { grid-column: 1 / -1; }
.page__head > div:first-child { flex: 1 1 18rem; }
