/* MALTRANA Automation · Libro de facturas — interfaz de herramienta,
   identidad navy/celeste de la agencia. Archivo (títulos) + IBM Plex Sans
   (cuerpo). Cifras con tabular-nums. Modo claro y oscuro. */

:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-hover: #e6f4fb;
  --text: #0a1220;
  --text-muted: #4f6b85;
  --text-faint: #7e93ad;
  --border: #dce6f0;
  --border-strong: #c3d3e2;
  --accent: #1690c9;
  --accent-weak: #e3f4fc;
  --positive: #157f3d;
  --danger: #c0362c;
  --danger-weak: #fbecea;

  --radius: 8px;
  --radius-sm: 6px;
  --col: 880px;
  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);

  --font:
    "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --font-display: "Archivo", var(--font);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #060b14;
    --surface: #0a1220;
    --surface-hover: #132a44;
    --text: #edf2f7;
    --text-muted: #b7c4d6;
    --text-faint: #7e93ad;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --accent: #4fc3f7;
    --accent-weak: rgba(79, 195, 247, 0.12);
    --positive: #4ac06f;
    --danger: #f87171;
    --danger-weak: rgba(248, 113, 113, 0.12);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--accent-weak);
  color: var(--text);
}

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

h1,
h2,
p,
ul,
ol {
  margin: 0;
}

h1,
h2 {
  font-family: var(--font-display);
}

button {
  font: inherit;
}

/* ---------- shell ---------- */

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand__name {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand__tag {
  color: var(--text-faint);
  font-size: 12px;
  white-space: nowrap;
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: 18px;
}

.stat {
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.stat__num {
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.stat__sep {
  margin: 0 6px;
  color: var(--text-faint);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.status__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  box-shadow: 0 0 0 3px transparent;
  transition: box-shadow 0.2s var(--ease);
}

.status[data-state="ok"] .status__dot {
  background: var(--positive);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--positive) 18%, transparent);
}

.status[data-state="off"] .status__dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
}

/* ---------- workspace ---------- */

.workspace {
  flex: 1;
  width: 100%;
  max-width: var(--col);
  margin: 0 auto;
  padding: 40px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- dropzone ---------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 34px 24px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  transition:
    border-color 0.15s var(--ease),
    background 0.15s var(--ease);
}

.dropzone:hover {
  border-color: var(--text-faint);
}

.dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-weak);
}

.dropzone__icon {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 4px;
}

.dropzone__title {
  color: var(--text);
  font-weight: 500;
}

.dropzone__hint {
  font-size: 12px;
  color: var(--text-faint);
}

/* ---------- progreso del lote ---------- */

.progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress__label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.progress__track {
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.progress__fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.35s var(--ease);
}

/* ---------- queue ---------- */

.queue {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.queue__item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 14px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.queue__name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue__state {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.queue__item::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  background: var(--accent);
  transform: scaleX(var(--progress, 0));
  transform-origin: left;
  transition: transform 0.4s var(--ease);
}

.queue__item[data-state="done"]::after {
  --progress: 1;
  opacity: 0;
  transition:
    transform 0.4s var(--ease),
    opacity 0.4s var(--ease) 0.2s;
}

.queue__item[data-state="done"] .queue__state {
  color: var(--positive);
}

.queue__item[data-state="error"]::after {
  --progress: 1;
  background: var(--danger);
}

.queue__item[data-state="error"] .queue__state {
  color: var(--danger);
}

.queue__error {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--danger);
  margin-top: 2px;
}

/* ---------- results ---------- */

.results {
  display: flex;
  flex-direction: column;
}

.results__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.results__title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.results__count {
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.linkbtn {
  margin-left: auto;
  background: none;
  border: none;
  padding: 2px 4px;
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  border-radius: 4px;
}

.linkbtn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

.table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 13px;
}

.table thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th.right,
.table td.right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.table tbody tr {
  transition: background 0.12s var(--ease);
}

.table tbody tr:hover {
  background: var(--surface-hover);
}

.cell-vendor {
  font-weight: 500;
  white-space: nowrap;
}

.cell-concept {
  color: var(--text-muted);
  max-width: 280px;
}

.cell-date {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cell-amount {
  font-weight: 500;
  white-space: nowrap;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11.5px;
  white-space: nowrap;
}

/* fila nueva: entra desde la cola */
@keyframes row-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.row--enter {
  animation: row-enter 0.18s var(--ease) both;
}

.row--enter td {
  position: relative;
}

.row--enter td::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  transform-origin: left;
  animation: row-underline 0.7s var(--ease) forwards;
}

@keyframes row-underline {
  0% {
    opacity: 1;
    transform: scaleX(0);
  }
  45% {
    opacity: 1;
    transform: scaleX(1);
  }
  100% {
    opacity: 0;
    transform: scaleX(1);
  }
}

/* skeleton mientras se extrae */
.row--skeleton td {
  padding-top: 16px;
  padding-bottom: 16px;
}

.skel {
  display: block;
  height: 9px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--surface-hover) 25%,
    var(--border) 37%,
    var(--surface-hover) 63%
  );
  background-size: 400% 100%;
  animation: skel-shimmer 1.4s ease infinite;
}

.skel--sm {
  width: 48px;
}
.skel--md {
  width: 90px;
}
.skel--lg {
  width: 70%;
}
.right .skel {
  margin-left: auto;
}

@keyframes skel-shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* ---------- totals ---------- */

.totals {
  align-self: flex-end;
  width: 100%;
  max-width: 320px;
  margin-top: 16px;
}

.totals__list {
  list-style: none;
  padding: 0;
}

.totals__list li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--text-muted);
}

.totals__list li span:last-child {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.totals__grand {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border-strong);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.totals__grand .amount {
  color: var(--positive);
}

/* ---------- action bar ---------- */

.actionbar {
  position: sticky;
  bottom: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-top: 1px solid var(--border);
}

.actionbar__inner {
  width: 100%;
  max-width: var(--col);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.actionbar__buttons {
  display: flex;
  gap: 10px;
}

.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.14s var(--ease),
    border-color 0.14s var(--ease),
    transform 0.1s var(--ease),
    opacity 0.14s var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

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

.btn--primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 88%, #000);
}

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

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

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

.actionbar__status {
  font-size: 12.5px;
  color: var(--text-muted);
  min-width: 0;
}

.actionbar__status a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.actionbar__status a:hover {
  border-bottom-color: currentColor;
}

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

.actionbar__status.is-error {
  color: var(--danger);
}

.actionbar__status .rejected {
  color: var(--danger);
}

/* ---------- responsive ---------- */

/* La barra de acciones envuelve sus botones en cualquier ancho: cuando
   Sheets / Correo / ERP están activos son hasta 4 y no caben en una fila. */
.actionbar__buttons {
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px 16px;
  }
  .topbar__meta {
    gap: 12px;
    flex-wrap: wrap;
  }
  .workspace {
    padding: 24px 16px;
  }
  .brand__tag {
    display: none;
  }
  .totals {
    max-width: none;
  }
  .actionbar__inner {
    padding: 12px 16px;
  }
  .actionbar__buttons {
    width: 100%;
  }
  .actionbar__buttons .btn {
    flex: 1 1 auto;
  }
  .cell-concept {
    max-width: 160px;
  }
}

@media (max-width: 380px) {
  .table .cell-concept {
    max-width: 120px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
