/* =========================
   NUBA - Post Order (Mobile First)
   ========================= */

/* Vars base (ajustá si ya tenés theme global) */
:root {
  --bg: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;

  --brand: #111111; /* negro NUBA */
  --brand-2: #0f172a; /* slate-900 */
  --accent: #111111;
  --success: #16a34a;
  --warn: #f59e0b;
  --danger: #ef4444;

  --card-bg: #fafafa;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.06);
}

/* Reset suave */
main.main {
  padding: 20px 16px 40px;
  background: var(--bg);
  color: var(--text);
  min-height: 60vh;
}

.title {
  font-size: 1.6rem;
  line-height: 1.2;
  margin: 0;
  color: var(--brand);
}

/* Header */
.postorder-header {
  display: grid;
  gap: 12px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.postorder-header .badge {
  width: max-content;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand);
}

.badge.success {
  border-color: color-mix(in srgb, var(--success) 40%, #fff);
  background: color-mix(in srgb, var(--success) 10%, #fff);
  color: var(--success);
}
.badge.warn {
  border-color: color-mix(in srgb, var(--warn) 40%, #fff);
  background: color-mix(in srgb, var(--warn) 10%, #fff);
  color: #b45309;
}

.order-code-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.95rem;
}
.order-code-row .order-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  border-radius: 8px;
  background: #fff;
  border: 1px dashed var(--line);
}

.btn-ghost {
  border: 1px solid var(--line);
  background: #fff;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease,
    transform 0.05s ease;
}
.btn-ghost:hover {
  background: #f9fafb;
}
.btn-ghost:active {
  transform: translateY(1px);
}

/* Meta */
.order-meta {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.95rem;
}
.order-meta span {
  color: var(--text);
  font-weight: 600;
  margin-right: 6px;
}

/* Info cards */
.info-cards {
  display: flex;
  flex-direction: column;
  width: 90%;
  max-width: 1000px;
  gap: 10px;
  justify-content: space-between;
  margin: 16px 0;
  margin-top: 18px;
}
.info-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  flex: 1;
}
.info-card strong {
  display: block;
  margin-bottom: 6px;
  color: var(--brand-2);
}

/* =========================
   Items table (responsive)
   ========================= */
.items-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.items-table td.type[data-mobile-express="1"] {
  color: var(--success);
}
/* -------- Mobile: tarjetas compactas con grilla 4 cols -------- */
@media (max-width: 768px) {
  .items-table thead {
    display: none;
  }

  .items-table tbody tr {
    display: grid;
    /* 1 columna flexible + 3 autos para la línea derecha */
    grid-template-columns: auto auto auto auto;
    grid-template-areas:
      "sku   .     .     type" /* fila 1: SKU izq, (badge) tipo a la derecha */
      "name  name   name     type" /* fila 2: Nombre + (badge) tipo */
      "qty   price total total"; /* fila 3: Cant, Precio y Total pegado a la derecha */
    gap: 6px 10px;
    padding: 10px 12px;
    margin: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    background: #fff;
  }

  .items-table td {
    display: block;
    padding: 0;
    border: 0;
  }
  .items-table td::before {
    content: none;
  }

  .items-table td.sku {
    grid-area: sku;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85rem;
    user-select: text;
    background: #f3f4f6;
    border: 1px dashed #e5e7eb;
    padding: 2px 6px;
    width: max-content;
    border-radius: 8px;
  }

  /* Badge SOLO si es express en mobile */
  .items-table td.type {
    grid-area: type;
    justify-self: end;
    align-self: start;
    font-size: 0; /* ocultar texto interno "Express/Estándar" */
  }

  .items-table td.type[data-mobile-express="1"]::after {
    content: "Producto Express";
    font-size: 0.85rem;

    white-space: nowrap;
    border: 1px solid var(--line);
    background: #fff;
    padding: 2px 8px;
    border-radius: 999px;
  }
  .items-table td.type[data-mobile-express="0"] {
    display: none; /* no mostrar nada si NO es express */
  }

  .items-table td.name {
    grid-area: name;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
  }

  .items-table td.qty {
    grid-area: qty;
    justify-self: start;
    font-size: 0.9rem;
    white-space: nowrap;
  }
  .items-table td.qty .qty-unit {
    display: inline;
  } /* mostrar "Un." en mobile */

  .items-table td.price {
    grid-area: price;
    justify-self: center;
    font-size: 0.9rem;
    white-space: nowrap;
  }
  .items-table td.total {
    grid-area: total;
    justify-self: end;
    font-size: 0.95rem;
    font-weight: 700;
    white-space: nowrap;
  }

  /* Totales bajo la tabla, ancho completo */
  .totals {
    width: 100%;
    margin-top: 6px;
  }
}

/* -------- Desktop: tabla clásica limpia -------- */
@media (min-width: 769px) {
  .items-table thead {
    display: table-header-group;
    background: #f8fafc;
  }
  .items-table tr {
    border-bottom: 1px solid var(--line);
  }
  .items-table th,
  .items-table td {
    display: table-cell;
    padding: 12px 14px;
    text-align: left;
    vertical-align: middle;
  }
  .items-table th {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
  }
  .items-table td::before {
    content: none;
  }

  /* SKU seleccionable en desktop también */
  .items-table td.sku {
    user-select: text;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: 0.2px;
  }

  /* Ocultar “Un.” en desktop si no querés verlo */
  .items-table td.qty .qty-unit {
    display: none;
  }

  /* Anchos sugeridos */
  .items-table {
    table-layout: auto;
  }
  .items-table th:nth-child(1),
  .items-table td:nth-child(1) {
    width: 140px;
  } /* SKU */
  .items-table th:nth-child(2),
  .items-table td:nth-child(2) {
    width: auto;
  } /* Producto */
  .items-table th:nth-child(3),
  .items-table td:nth-child(3) {
    width: 140px;
  } /* Tipo */
  .items-table th:nth-child(4),
  .items-table td:nth-child(4) {
    width: 90px;
  } /* Cant */
  .items-table th:nth-child(5),
  .items-table td:nth-child(5) {
    width: 130px;
  } /* Precio */
  .items-table th:nth-child(6),
  .items-table td:nth-child(6) {
    width: 130px;
  } /* Total */
}

/* Totales (alineados a la derecha) */
.totals {
  margin: 16px 0 8px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  width: min(360px, 100%);
}
.totals .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 1rem;
}
.totals .row.total {
  border-top: 1px dashed var(--line);
  margin-top: 4px;
  padding-top: 10px;
  font-weight: 700;
  color: var(--brand);
}

/* Actions */
.actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

.actions a,
.actions button {
  display: inline-block;
  padding: 10px 16px;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card-bg); /* fondo sutil */
  color: var(--text-color);
  transition: background 0.2s ease, transform 0.1s ease;
}

.actions a:hover,
.actions button:hover {
  background: #f3f4f6; /* un tono apenas más oscuro */
  color: var(--text-color);
}

/* Loader */
.postorder-loader {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  margin: 20px auto 0;
}
.postorder-loader .spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid #e5e7eb;
  border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Error state + form búsqueda por code */
.postorder-error {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 16px;
  box-shadow: var(--shadow);
  max-width: 560px;
  margin: 0 auto;
}
.postorder-error .title {
  margin-bottom: 6px;
}
.postorder-error .desc {
  color: var(--muted);
  margin-bottom: 14px;
}
.code-form {
  display: grid;
  gap: 8px;
  margin: 10px 0 16px;
}
.code-form label {
  font-size: 0.95rem;
  color: var(--muted);
}
.code-form .code-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.code-form input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-size: 1rem;
  letter-spacing: 0.5px;
}
.code-form input:focus {
  border-color: #cbd5e1;
  box-shadow: 0 0 0 4px rgba(17, 17, 17, 0.06);
}
.code-form .btn-primary {
  height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  cursor: pointer;
  border: none;
  background-color: rgb(240, 240, 240);
}

/* =========================
   Desktop enhancements (no toques tabla acá)
   ========================= */
@media (min-width: 768px) {
  main.main {
    padding: 28px 24px 56px;
  }

  .postorder-header {
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px 16px;
  }
  .order-meta {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .info-cards {
    flex-direction: row;
  }

  .actions {
    max-width: 560px;
  }
  .items-box,
  .totals {
    max-width: 100%;
  }
}

@media (min-width: 1024px) {
  .postorder-header {
    padding: 18px 20px;
  }
  .info-card {
    padding: 16px;
  }
  .items-table th,
  .items-table td {
    padding: 14px 16px;
  }
}
