:root {
  --bg: #111a2e;
  --card: #111a2e;
  --text: #e8eefc;
  --muted: #a9b7d0;
  --border: #22314f;
  --accent: #4da3ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
}

/* CONTENEDOR */
.container {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 16px;
}

/* CABECERA (logo + título) */
.header {
  display: flex;
  align-items: center;
  justify-content: flex-start; /* izquierda */
  gap: 14px;
  margin: 6px 0 18px;
  width: 100%;
}

.header h1 {
  margin: 0;
  font-size: 26px;
}

.logo {
  height: 40px;
  width: auto;
  display: block;
}

/* TARJETAS */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
}

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

input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c1428;
  color: var(--text);
  outline: none;
}

button {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #071022;
  font-weight: 700;
  cursor: pointer;
}

button.secondary {
  background: transparent;
  color: var(--text);
}

.status {
  margin: 10px 0 0;
  color: var(--muted);
}

/* =========================
   TABLA (DESKTOP centrada)
   ========================= */

/* Contenedor centrador + scroll si hace falta */
.table-wrap {
  display: flex;
  justify-content: center;     /* ✅ centra la tabla como antes */
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Tabla compacta y centrada */
.table-wrap table {
  width: 100%;
  max-width: 980px;            /* ✅ ajusta si quieres más/menos ancho */
  border-collapse: collapse;
  table-layout: fixed;
}

th, td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
}

/* Anchos de columnas (desktop) */
th.col-codigo, td.col-codigo { width: 110px; }
th.col-nombre, td.col-nombre { width: auto; }
th.col-stock,  td.col-stock  { width: 90px; }
th.col-pvp,    td.col-pvp    { width: 110px; }
th.col-udx,    td.col-udx    { width: 70px; }

/* Truncar texto largo en Nombre (desktop) */
td.col-nombre {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ===================================================
   ✅ MÓVIL VERTICAL → MODO TARJETAS (NO SE ROMPE)
   =================================================== */
@media (max-width: 640px) and (orientation: portrait) {

  /* Header en móvil */
  .header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .header h1 {
    font-size: 22px;
  }

  .logo {
    height: 34px;
  }

  /* Buscador en vertical */
  .row {
    flex-wrap: wrap;
  }

  .row input {
    flex: 1 1 100%;
  }

  .row button {
    flex: 1 1 calc(50% - 5px);
  }

  /* La tabla se convierte en bloques (tarjetas) */
  .table-wrap {
    overflow-x: visible;
  }

  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap th,
  .table-wrap td,
  .table-wrap tr {
    display: block;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap tbody tr {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin: 12px 0;
    padding: 12px;
  }

  .table-wrap tbody td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    width: 100% !important;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

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

  /* Etiqueta a la izquierda usando data-label */
  .table-wrap tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    flex: 0 0 80px;
  }

  /* Nombre puede ocupar varias líneas */
  td.col-nombre {
    white-space: normal;
  }
}

/* ===================================================
   ✅ MÓVIL HORIZONTAL / TABLET
   =================================================== */
@media (max-width: 900px) and (orientation: landscape) {
  /* En horizontal sigue siendo tabla, con scroll si no cabe */
  .table-wrap table {
    min-width: 720px;
    table-layout: auto;
  }
}
