:root {
  --ink: #0c1622;
  --ink-soft: #243447;
  --paper: #f3efe6;
  --paper-2: #e8e2d4;
  --steel: #1a6b8a;
  --steel-deep: #0f4a63;
  --amber: #d97706;
  --amber-soft: #f59e0b;
  --ok: #0f7a4f;
  --ok-bg: #d8f3e7;
  --warn: #a35b00;
  --warn-bg: #ffe8c7;
  --miss: #9b1c1c;
  --miss-bg: #fde2e2;
  --line: rgba(12, 22, 34, 0.12);
  --shadow: 0 18px 50px rgba(12, 22, 34, 0.12);
  --radius: 18px;
  --font: "Source Sans 3", system-ui, sans-serif;
  --display: "Archivo", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
}

body {
  position: relative;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(26, 107, 138, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(26, 107, 138, 0.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 30% 0%, #000 20%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  width: 55vw;
  height: 55vw;
  top: -18vw;
  right: -12vw;
  background: radial-gradient(circle, rgba(217, 119, 6, 0.18), transparent 65%);
  pointer-events: none;
  z-index: 0;
  animation: drift 14s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(-4%, 6%) scale(1.08); }
}

.topbar,
.layout,
.loading-overlay,
.toast,
.modal {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  background: rgba(243, 239, 230, 0.82);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 0.7rem;
  background:
    linear-gradient(145deg, var(--steel) 0%, var(--steel-deep) 55%, #072636 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 28% 22% 22% 22%;
  border: 2px solid rgba(255, 214, 140, 0.95);
  border-radius: 4px;
  border-top-color: transparent;
  transform: rotate(-12deg);
}

.brand-name {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  line-height: 1;
}

.topbar-actions {
  display: flex;
  gap: 0.55rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem 1.5rem 2.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: rgba(255, 252, 246, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem 1.25rem;
  box-shadow: var(--shadow);
  animation: rise 0.55s ease both;
}

.panel:nth-child(2) { animation-delay: 0.06s; }
.panel:nth-child(3) { animation-delay: 0.12s; }
.panel:nth-child(4) { animation-delay: 0.18s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.work-panel,
.preview-panel {
  grid-column: 1 / -1;
}

h2 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hint {
  margin: 0 0 0.9rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.4;
}

.hint.tight { margin-bottom: 0.6rem; }
.hint.tiny { font-size: 0.78rem; margin-top: 0.4rem; }

.linkish {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  color: var(--steel-deep);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.dropzone {
  display: grid;
  place-items: center;
  gap: 0.25rem;
  min-height: 7.5rem;
  border: 1.5px dashed rgba(15, 74, 99, 0.35);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(26, 107, 138, 0.06), rgba(26, 107, 138, 0.02));
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--steel);
  background: rgba(26, 107, 138, 0.1);
  transform: translateY(-1px);
}

.drop-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1rem;
}

.drop-sub {
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.file-meta {
  margin-top: 0.75rem;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  background: var(--ok-bg);
  color: var(--ok);
  font-size: 0.88rem;
  font-family: var(--mono);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-top: 0.85rem;
}

.field-row label,
.block-label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
}

input[type="number"],
input[type="text"],
input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font: 500 0.95rem var(--mono);
  background: #fff;
  color: var(--ink);
}

.img-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.thumb-strip {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 0.65rem;
  max-height: 220px;
  overflow: auto;
  padding: 0.15rem;
}

.thumb-wrap {
  position: relative;
  flex: 0 0 auto;
}

.thumb {
  width: 72px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  display: block;
  transition: transform 0.2s, border-color 0.2s;
}

.thumb:hover { transform: scale(1.04); }
.thumb.active { border-color: var(--steel); }

.thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.work-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.work-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.work-split {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) 1.15fr;
  gap: 1rem;
  min-height: 420px;
}

.image-stage {
  border-radius: 14px;
  background: #111820;
  overflow: auto;
  min-height: 420px;
  display: grid;
  place-items: center;
  position: relative;
}

.image-stage img {
  width: 100%;
  height: auto;
  display: block;
}

.empty-stage {
  color: rgba(243, 239, 230, 0.55);
  text-align: center;
  padding: 2rem;
  margin: 0;
}

.extract-side {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.stat {
  background: var(--paper-2);
  border-radius: 12px;
  padding: 0.65rem 0.7rem;
  text-align: center;
}

.stat span {
  display: block;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  line-height: 1;
}

.stat label {
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat.ok span { color: var(--ok); }
.stat.warn span { color: var(--warn); }

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-height: 360px;
  background: #fff;
}

.table-wrap.tall { max-height: 320px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table.mono { font-family: var(--mono); font-size: 0.82rem; }

.data-table th,
.data-table td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  position: sticky;
  top: 0;
  background: #f7f3ea;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  z-index: 1;
}

.data-table input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 0.25rem 0.3rem;
  border-radius: 6px;
  font: 500 0.9rem var(--mono);
}

.data-table input:focus {
  outline: none;
  border-color: var(--steel);
  background: #fff;
}

.placeholder-row td {
  color: var(--ink-soft);
  text-align: center;
  padding: 1.4rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge.match { background: var(--ok-bg); color: var(--ok); }
.badge.miss { background: var(--miss-bg); color: var(--miss); }
.badge.pending { background: var(--paper-2); color: var(--ink-soft); }
.badge.filled {
  background: #dbeafe;
  color: #075985;
  animation: pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes pop {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.row-filled {
  background: linear-gradient(90deg, rgba(15, 122, 79, 0.12), transparent 55%);
  animation: flash-row 0.8s ease;
}

@keyframes flash-row {
  0% { background-color: rgba(245, 158, 11, 0.35); }
  100% { background-color: transparent; }
}

.btn-icon {
  border: none;
  background: transparent;
  color: var(--miss);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
}

.btn-icon:hover { background: var(--miss-bg); }

.missed-box {
  border-radius: 12px;
  background: var(--warn-bg);
  padding: 0.75rem 0.9rem;
}

.missed-box h3 {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  color: var(--warn);
}

.missed-box ul {
  margin: 0;
  padding-left: 1.1rem;
  font-family: var(--mono);
  font-size: 0.82rem;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, background 0.15s;
}

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

.btn:not(:disabled):hover { transform: translateY(-1px); }

.btn.primary {
  background: linear-gradient(135deg, var(--steel), var(--steel-deep));
  color: #fff;
}

.btn.secondary {
  background: linear-gradient(135deg, var(--amber-soft), var(--amber));
  color: #1a1005;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  max-width: min(420px, 90vw);
  z-index: 40;
  animation: rise 0.3s ease;
}

.toast[hidden] {
  display: none !important;
}

.modal {
  border: none;
  border-radius: 18px;
  padding: 0;
  background: transparent;
  max-width: 440px;
  width: calc(100% - 2rem);
}

.modal::backdrop {
  background: rgba(12, 22, 34, 0.45);
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--paper);
  border-radius: 18px;
  padding: 1.25rem;
  border: 1px solid var(--line);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 22, 34, 0.55);
  display: none;
  place-items: center;
  align-content: center;
  gap: 0.75rem;
  z-index: 50;
  color: #fff;
  font-family: var(--display);
  padding: 1.5rem;
}

.loading-overlay.is-on {
  display: grid;
}

.loading-overlay[hidden] {
  display: none !important;
}

.loading-overlay #loading-text {
  margin: 0;
  text-align: center;
  max-width: 320px;
}

.progress-wrap {
  width: min(280px, 70vw);
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--amber-soft), #fbbf24);
  transition: width 0.25s ease;
}

.progress-pct {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--amber-soft);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 1rem; }
  .work-split { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr; }
}
