/* ── Reset & Variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0f0f13;
  --surface:    #18181f;
  --surface2:   #22222c;
  --border:     #2e2e3a;
  --border2:    #3a3a4a;
  --text:       #e8e8f0;
  --text-muted: #7a7a94;
  --text-dim:   #55556a;
  --accent:     #7c6af7;
  --accent-h:   #9585ff;
  --green:      #22c55e;
  --green-bg:   #14291e;
  --red:        #ef4444;
  --red-bg:     #2a1414;
  --yellow:     #eab308;
  --yellow-bg:  #292008;
  --radius:     10px;
  --radius-lg:  16px;
  --shadow:     0 4px 24px rgba(0,0,0,.45);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo svg { width: 32px; height: 32px; color: var(--accent); flex-shrink: 0; }
.logo-title { display: block; font-weight: 700; font-size: 15px; }
.logo-sub { display: block; font-size: 11px; color: var(--text-muted); letter-spacing: .04em; text-transform: uppercase; }

/* ── Main ──────────────────────────────────────────────────────── */
main { max-width: 1100px; margin: 0 auto; padding: 32px 20px 60px; }

/* ── Screens ───────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--radius);
  border: 1px solid transparent; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
  background: none; color: var(--text); white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:not(:disabled):hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-ghost { color: var(--text-muted); border-color: var(--border2); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.btn-danger:not(:disabled):hover { background: var(--red); color: #fff; }
.btn-lg { padding: 13px 28px; font-size: 15px; border-radius: var(--radius-lg); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── Upload ────────────────────────────────────────────────────── */
.upload-card { display: flex; flex-direction: column; align-items: center; gap: 24px; max-width: 480px; margin: 60px auto 0; }
.drop-zone {
  width: 100%; border: 2px dashed var(--border2); border-radius: var(--radius-lg);
  padding: 52px 32px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s; background: var(--surface);
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--accent); background: rgba(124,106,247,.06); }
.drop-icon { margin-bottom: 20px; }
.drop-icon svg { width: 56px; height: 56px; color: var(--accent); opacity: .7; }
.drop-title  { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.drop-sub    { color: var(--text-muted); margin-bottom: 12px; }
.drop-formats { font-size: 11px; color: var(--text-dim); letter-spacing: .04em; text-transform: uppercase; }
.file-preview {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px;
}
.preview-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.preview-file-icon { font-size: 28px; flex-shrink: 0; }
.preview-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.preview-size { font-size: 12px; color: var(--text-muted); }

/* ── Loading ───────────────────────────────────────────────────── */
.loading-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; min-height: 280px; text-align: center; }
.loading-text { font-size: 17px; font-weight: 600; }
.loading-sub  { color: var(--text-muted); }
.spinner { width: 44px; height: 44px; border: 3px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin .75s linear infinite; }
.spinner-sm { width: 18px; height: 18px; border-width: 2px; display: inline-block; vertical-align: middle; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Confirm Header ────────────────────────────────────────────── */
.confirm-header { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.confirm-meta { font-size: 13px; color: var(--text-muted); line-height: 1.8; }
.confirm-meta strong { color: var(--text); }
.confirm-actions-top { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Table ─────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--surface2); padding: 11px 14px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody tr.row-excluded { opacity: .4; }
/* opacity < 1 crea un contexto de apilamiento que atrapa el z-index de los
   desplegables por debajo de las filas siguientes — se neutraliza mientras se usan */
tbody tr.row-excluded.ref-active { opacity: 1; }
tbody td { padding: 11px 14px; vertical-align: middle; font-size: 13px; }

.col-check { width: 40px; text-align: center; }
.col-ref      { width: 160px; }
.col-qty      { width: 80px; }
.col-variante { width: 120px; }
.col-confidence { width: 90px; }

/* ── Buscador de atributos (modal crear) ────────────────────────── */
.attr-search-wrap  { position: relative; }
.attr-dropdown     {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  max-height: 180px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: var(--shadow);
}
.attr-dropdown.open { display: block; }
.attr-option {
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.attr-option:hover { background: var(--surface); color: var(--accent); }

/* ── Selector de atributo (columna) ─────────────────────────────── */
.col-variante { width: 140px; }
.variante-stack  { display: flex; flex-direction: column; gap: 5px; }
.variante-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 2px;
}
.variante-entry  { display: flex; flex-direction: column; gap: 3px; }
.variante-controls { display: flex; align-items: center; gap: 3px; }
.variante-sel, .variante-sel-1, .variante-sel-2 {
  flex: 1;
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 5px;
  padding: 3px 4px;
  font-size: 12px;
  cursor: pointer;
}
.variante-sel:focus, .variante-sel-1:focus, .variante-sel-2:focus { outline: none; border-color: var(--accent); }
.variante-qty {
  width: 42px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 5px;
  padding: 3px 4px;
  font-size: 12px;
  text-align: center;
}
.variante-qty:focus { outline: none; border-color: var(--accent); }
.btn-rm-variante {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 3px;
  border-radius: 3px;
  line-height: 1;
  flex-shrink: 0;
}
.btn-rm-variante:hover { color: var(--red); background: var(--red-bg); }
.btn-add-variante {
  align-self: flex-start;
  background: none;
  border: 1px dashed var(--border2);
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 2px;
}
.btn-add-variante:hover { border-color: var(--accent); color: var(--accent); }
.qty-total {
  display: block;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.row-check { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

/* ── Referencia selector ───────────────────────────────────────── */
.ref-wrapper { position: relative; }
.ref-input {
  width: 100%; background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text); border-radius: 6px; padding: 5px 8px; font-size: 12px;
  font-family: monospace; transition: border-color .15s; cursor: pointer;
}
.ref-input:focus { outline: none; border-color: var(--accent); }
.ref-input.sin-coincidencia { color: var(--red); border-color: var(--red-bg); }

.ref-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  background: var(--surface2); border: 1px solid var(--border2); border-radius: var(--radius);
  max-height: 220px; overflow-y: auto; box-shadow: var(--shadow); display: none;
}
.ref-dropdown.open { display: block; }
.ref-option {
  padding: 8px 12px; cursor: pointer; font-size: 12px; border-bottom: 1px solid var(--border);
}
.ref-option:last-child { border-bottom: none; }
.ref-option:hover, .ref-option.selected { background: rgba(124,106,247,.15); }
.ref-option-top   { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ref-option-ref   { font-family: monospace; color: var(--accent); }
.ref-option-precio { font-size: 11px; font-weight: 600; color: var(--text-muted); flex-shrink: 0; }
.ref-option-name  { color: var(--text-muted); font-size: 11px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ref-option.sin-coincidencia-opt { color: var(--red); font-weight: 600; }

/* ── Botón Crear ───────────────────────────────────────────────── */
.btn-crear {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--green-bg); color: var(--green); border: 1px solid var(--green);
  border-radius: 6px; padding: 4px 10px; font-size: 11px; font-weight: 600;
  cursor: pointer; margin-top: 6px; transition: background .15s;
}
.btn-crear:hover { background: var(--green); color: #fff; }

/* ── Match info ────────────────────────────────────────────────── */
.match-name   { font-weight: 500; }
.match-detail { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.match-none   { color: var(--red); font-size: 12px; }
.match-precio { font-size: 12px; font-weight: 600; color: var(--accent); margin-top: 2px; }
.col-precio { width: 80px; text-align: right; white-space: nowrap; }
.precio-cell { font-size: 13px; font-weight: 600; color: var(--accent); }
.match-nuevo  { color: var(--green); font-size: 12px; font-weight: 600; }

/* ── Badges ────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.alert-tag { display: inline-block; background: var(--yellow-bg); color: var(--yellow); font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; margin-left: 6px; vertical-align: middle; }
.nuevo-tag { display: inline-block; background: var(--green-bg); color: var(--green); font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; margin-left: 6px; vertical-align: middle; }

/* ── Quantity input ────────────────────────────────────────────── */
.qty-input { width: 70px; background: var(--surface2); border: 1px solid var(--border2); color: var(--text); border-radius: 6px; padding: 5px 8px; font-size: 14px; font-weight: 600; text-align: center; transition: border-color .15s; -moz-appearance: textfield; }
.qty-input:focus { outline: none; border-color: var(--accent); }
.qty-input::-webkit-outer-spin-button, .qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.variante-qty::-webkit-outer-spin-button, .variante-qty::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.variante-qty { -moz-appearance: textfield; }
#crearPrecio::-webkit-outer-spin-button, #crearPrecio::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#crearPrecio { -moz-appearance: textfield; }

/* ── Confirm Footer ────────────────────────────────────────────── */
.confirm-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 24px; flex-wrap: wrap; gap: 12px; }

/* ── Debug panel ───────────────────────────────────────────────── */
.debug-panel { border: 1px solid var(--border2); border-radius: var(--radius); background: var(--surface2); overflow: hidden; }
.debug-toggle { cursor: pointer; padding: 10px 14px; font-size: 12px; font-weight: 600; color: var(--text-muted); list-style: none; user-select: none; }
.debug-toggle:hover { color: var(--text); }
.debug-actions { padding: 8px 14px; border-top: 1px solid var(--border); }
.debug-content { padding: 12px 14px; font-size: 11px; line-height: 1.6; color: var(--text-muted); white-space: pre-wrap; word-break: break-all; max-height: 400px; overflow-y: auto; border-top: 1px solid var(--border); }

/* ── Result ────────────────────────────────────────────────────── */
.result-card { max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
.result-summary { text-align: center; padding: 28px; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); }
.result-summary .result-icon { font-size: 40px; margin-bottom: 12px; }
.result-summary h2 { font-size: 20px; margin-bottom: 6px; }
.result-summary p  { color: var(--text-muted); }
.result-summary.all-ok  { border-color: var(--green); background: var(--green-bg); }
.result-summary.has-err { border-color: var(--yellow); background: var(--yellow-bg); }
.result-list { display: flex; flex-direction: column; gap: 8px; }
.result-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); font-size: 13px; }
.result-item.ok  { border-left: 3px solid var(--green); }
.result-item.err { border-left: 3px solid var(--red); }
.result-item-left { min-width: 0; }
.result-item-ref  { color: var(--text-muted); font-size: 11px; }
.result-item-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-item-err  { color: var(--red); font-size: 11px; margin-top: 2px; }
.result-item-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.result-qty { font-size: 13px; font-weight: 700; color: var(--text-muted); }

/* ── Modal base ─────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.7); }
.modal-content { position: relative; background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius-lg); width: 100%; max-width: 780px; max-height: 80vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-crear { max-width: 540px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-header h3 { font-size: 15px; }
.modal-body { overflow-y: auto; padding: 20px; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }
.btn-close { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; padding: 2px 6px; border-radius: 4px; line-height: 1; }
.btn-close:hover { color: var(--text); background: var(--surface2); }

/* ── Modal Crear ─────────────────────────────────────────────────── */
.crear-detected { background: var(--surface2); border-radius: var(--radius); padding: 12px 16px; }
.crear-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.crear-valor { font-weight: 600; font-size: 14px; }
.crear-loading { display: flex; align-items: center; color: var(--text-muted); font-size: 13px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.form-input { background: var(--surface2); border: 1px solid var(--border2); color: var(--text); border-radius: var(--radius); padding: 9px 12px; font-size: 14px; transition: border-color .15s; }
.form-input:focus { outline: none; border-color: var(--accent); }
.form-select { background: var(--surface2); border: 1px solid var(--border2); color: var(--text); border-radius: var(--radius); padding: 9px 12px; font-size: 14px; cursor: pointer; }
.form-select:focus { outline: none; border-color: var(--accent); }
.atributos-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── WSDL ────────────────────────────────────────────────────────── */
.wsdl-loading { display: flex; align-items: center; color: var(--text-muted); padding: 20px 0; }
.wsdl-content { font-family: 'Courier New', monospace; font-size: 11px; color: var(--text-muted); white-space: pre-wrap; word-break: break-all; line-height: 1.6; }

/* ── Utilities ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 640px) {
  main { padding: 20px 12px 48px; }
  .upload-card { margin-top: 32px; }
  .drop-zone { padding: 36px 20px; }
  thead th.col-confidence, tbody td.col-confidence { display: none; }
  .confirm-footer { flex-direction: column; }
  .confirm-footer .btn { width: 100%; justify-content: center; }
  .atributos-grid { grid-template-columns: 1fr; }
}
