/* =========================================================
   MELOS COMPANIES — Inventario de Gomas
   Diseño profesional dashboard
   ========================================================= */

:root {
  --rojo: #d92121;
  --rojo-oscuro: #a51111;
  --rojo-suave: #fff1f1;

  --negro: #101114;
  --negro-2: #181a1f;

  --gris-bg: #f5f6f8;
  --gris-card: #ffffff;
  --gris-soft: #eef0f3;
  --gris-linea: #e3e6eb;
  --gris-texto: #6b7280;

  --blanco: #ffffff;
  --texto: #16181d;

  --sombra-card: 0 8px 24px rgba(16, 17, 20, 0.07);
  --sombra-fuerte: 0 24px 70px rgba(0, 0, 0, 0.28);

  --radio-sm: 8px;
  --radio-md: 14px;
  --radio-lg: 22px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--gris-bg);
  color: var(--texto);
  min-height: 100vh;
}

#appShell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* =========================================================
   Login
   ========================================================= */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at top left, rgba(217, 33, 33, 0.28), transparent 32%),
    radial-gradient(circle at bottom right, rgba(255, 255, 255, 0.08), transparent 28%),
    linear-gradient(135deg, #090a0d, #17181d 52%, #060607);
}

.login-card {
  width: 100%;
  max-width: 430px;
  background: rgba(255, 255, 255, 0.98);
  border-radius: var(--radio-lg);
  padding: 34px;
  box-shadow: var(--sombra-fuerte);
  border: 1px solid rgba(255, 255, 255, 0.55);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  background: linear-gradient(90deg, var(--rojo), #ff5a5a, var(--rojo-oscuro));
}

.login-brand {
  text-align: center;
  margin-bottom: 26px;
}

.login-brand img {
  max-width: 126px;
  max-height: 96px;
  object-fit: contain;
  margin-bottom: 14px;
}

.login-brand h1 {
  font-size: 1.45rem;
  letter-spacing: 1.8px;
  color: var(--negro);
  font-weight: 900;
}

.login-brand p {
  margin-top: 7px;
  color: var(--gris-texto);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  font-weight: 800;
}

.login-btn {
  width: 100%;
  margin-top: 12px;
  justify-content: center;
  min-height: 44px;
}

.login-error {
  background: #fff0f0;
  color: #9f1010;
  border: 1px solid #ffc2c2;
  padding: 11px 13px;
  border-radius: 12px;
  font-size: .9rem;
  margin-top: 10px;
  font-weight: 700;
}

/* =========================================================
   Header
   ========================================================= */

.topbar {
  background: linear-gradient(135deg, #111216, #191b21);
  color: var(--blanco);
  padding: 18px 32px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 22px;
  border-bottom: 4px solid var(--rojo);
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 250px;
}

.brand img {
  height: 70px;
  width: auto;
  border-radius: 14px;
  background: var(--blanco);
  padding: 5px;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
}

.brand h1 {
  font-size: 1.15rem;
  letter-spacing: 1.8px;
  font-weight: 900;
  line-height: 1.1;
}

.subtitle {
  display: inline-block;
  margin-top: 4px;
  color: #ff5656;
  font-weight: 800;
  font-size: .72rem;
  letter-spacing: 2.4px;
  text-transform: uppercase;
}

.user-box {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  padding: 8px 10px 8px 15px;
  color: var(--blanco);
  backdrop-filter: blur(8px);
}

.user-box span {
  font-size: .9rem;
  font-weight: 900;
  line-height: 1;
}

.user-box small {
  color: #c7c9cf;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .7px;
  font-weight: 800;
}

.user-box .btn {
  padding: 7px 12px;
  font-size: .7rem;
  border-radius: 999px;
}

/* Stats */

.stats {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}

.stat {
  background: rgba(255,255,255,.075);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 16px;
  padding: 13px 14px;
  text-align: left;
}

.stat span {
  display: block;
  color: var(--blanco);
  font-size: 1.55rem;
  font-weight: 950;
  line-height: 1;
}

.stat label {
  display: block;
  margin-top: 6px;
  color: #c3c6ce;
  font-size: .68rem;
  letter-spacing: .9px;
  text-transform: uppercase;
  font-weight: 800;
}

/* =========================================================
   Tabs
   ========================================================= */

.tabs {
  background: var(--negro-2);
  padding: 0 32px 16px;
  display: flex;
  gap: 10px;
}

.tab {
  background: rgba(255,255,255,.06);
  color: #c7c9cf;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 9px 22px;
  font-weight: 900;
  cursor: pointer;
  font-size: .84rem;
  letter-spacing: .4px;
  transition: .15s ease;
}

.tab.active {
  background: var(--rojo);
  color: var(--blanco);
  border-color: var(--rojo);
  box-shadow: 0 7px 18px rgba(217, 33, 33, .26);
}

.tab:hover:not(.active) {
  color: var(--blanco);
  border-color: rgba(255,255,255,.32);
  background: rgba(255,255,255,.10);
}

/* =========================================================
   Layout
   ========================================================= */

main {
  flex: 1;
  max-width: 1180px;
  width: 100%;
  margin: 26px auto;
  padding: 0 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--gris-card);
  border: 1px solid var(--gris-linea);
  border-radius: var(--radio-md);
  padding: 22px;
  box-shadow: var(--sombra-card);
  overflow-x: auto;
}

.form-card h2,
.ventas-header h2 {
  font-size: .98rem;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  margin-bottom: 16px;
  border-left: 5px solid var(--rojo);
  padding-left: 12px;
  font-weight: 950;
}

/* =========================================================
   Formulario
   ========================================================= */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(172px, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field.wide {
  grid-column: 1 / -1;
}

.field label {
  color: #3d414a;
  font-size: .72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .6px;
}

.field input,
.toolbar input,
.toolbar select {
  padding: 11px 13px;
  border: 1px solid var(--gris-linea);
  border-radius: 10px;
  font-size: .95rem;
  background: var(--blanco);
  color: var(--texto);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.field input:focus,
.toolbar input:focus,
.toolbar select:focus {
  outline: none;
  border-color: rgba(217, 33, 33, .65);
  box-shadow: 0 0 0 4px rgba(217, 33, 33, .10);
}

.form-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Nueva / Usada */

.condicion {
  display: flex;
  gap: 14px;
  align-items: center;
  height: 43px;
}

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: .9rem;
  font-weight: 750;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  color: #3f444d;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--rojo);
  cursor: pointer;
}

/* =========================================================
   Botones
   ========================================================= */

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 22px;
  font-size: .86rem;
  font-weight: 900;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: .45px;
  transition: transform .12s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.btn-red {
  background: linear-gradient(135deg, var(--rojo), var(--rojo-oscuro));
  color: var(--blanco);
  box-shadow: 0 8px 18px rgba(217, 33, 33, .22);
}

.btn-red:hover {
  background: linear-gradient(135deg, #e52a2a, #951010);
}

.btn-ghost {
  background: var(--blanco);
  color: var(--texto);
  border: 1px solid var(--gris-linea);
}

.btn-ghost:hover {
  border-color: #b8bec8;
  box-shadow: 0 5px 14px rgba(0,0,0,.07);
}

/* Botón vender */

.btn-vender {
  background: linear-gradient(135deg, var(--rojo), var(--rojo-oscuro)) !important;
  color: var(--blanco);
  border-radius: 999px;
  padding: 7px 12px !important;
  font-size: .68rem !important;
  font-weight: 950;
  letter-spacing: .5px;
  box-shadow: 0 5px 14px rgba(217, 33, 33, .20);
}

.btn-vender:hover {
  background: linear-gradient(135deg, #e22b2b, #8d0d0d) !important;
  transform: translateY(-1px) !important;
}

.btn-vender:disabled {
  background: #c7cbd3 !important;
  box-shadow: none;
  cursor: not-allowed;
}

/* =========================================================
   Toolbar
   ========================================================= */

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--blanco);
  border: 1px solid var(--gris-linea);
  border-radius: var(--radio-md);
  padding: 14px;
  box-shadow: var(--sombra-card);
}

.toolbar input {
  flex: 1;
  min-width: 250px;
}

.toolbar select {
  min-width: 165px;
}

/* =========================================================
   Tabla
   ========================================================= */

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}

#tabla {
  min-width: 1180px;
}

#vistaVentas table {
  min-width: 1280px;
}

#vistaLogs table {
  min-width: 920px;
}

th {
  background: #17191f;
  color: var(--blanco);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .9px;
  padding: 12px 12px;
  text-align: left;
  font-weight: 900;
}

th:first-child {
  border-radius: 10px 0 0 10px;
}

th:last-child {
  border-radius: 0 10px 10px 0;
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--gris-linea);
  font-size: .92rem;
  vertical-align: middle;
  background: var(--blanco);
}

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

tr:hover td {
  background: #fff8f8;
}

.center {
  text-align: center;
}

.marca-cell {
  font-weight: 900;
  color: #252934;
}

.medida-cell {
  font-family: Consolas, Monaco, monospace;
  font-weight: 800;
  color: #20242c;
}

.precio-cell {
  font-weight: 900;
  white-space: nowrap;
}

/* Badges */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 950;
  letter-spacing: .8px;
}

.badge-nueva {
  background: #17191f;
  color: var(--blanco);
}

.badge-usada {
  background: var(--rojo);
  color: var(--blanco);
}

/* Stock bajo */

.stock-bajo td {
  background: #fff3f3;
}

.stock-bajo:hover td {
  background: #ffecec;
}

.stock-bajo .marca-cell {
  color: var(--rojo-oscuro);
}

/* Cantidad */

.qty {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #f4f5f7;
  border: 1px solid var(--gris-linea);
  border-radius: 999px;
  padding: 3px;
}

.qty span {
  min-width: 30px;
  text-align: center;
  font-weight: 950;
  font-size: .98rem;
}

.qty button {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-weight: 950;
  font-size: .95rem;
  line-height: 1;
  transition: transform .12s ease, opacity .12s ease;
}

.qty .menos {
  background: #1b1d23;
  color: var(--blanco);
}

.qty .mas {
  background: var(--rojo);
  color: var(--blanco);
}

.qty button:hover {
  opacity: .9;
  transform: scale(1.06);
}

.qty-cero span {
  color: var(--rojo);
}

/* Acciones */

.acciones {
  white-space: nowrap;
}

.acciones button {
  border: 1px solid var(--gris-linea);
  background: var(--blanco);
  cursor: pointer;
  font-size: .95rem;
  padding: 6px 8px;
  border-radius: 8px;
  margin: 0 2px;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}

.acciones button:hover {
  transform: translateY(-1px);
  border-color: #c1c7d0;
  background: #f8f9fb;
}

/* =========================================================
   Modal venta
   ========================================================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 12, .62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 18px;
  backdrop-filter: blur(5px);
}

.modal {
  background: var(--blanco);
  border-radius: var(--radio-lg);
  padding: 26px;
  width: min(500px, 94vw);
  box-shadow: var(--sombra-fuerte);
  border: 1px solid rgba(255,255,255,.55);
  position: relative;
  overflow: hidden;
}

.modal::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  background: linear-gradient(90deg, var(--rojo), #ff5d5d, var(--rojo-oscuro));
}

.modal h2 {
  margin-bottom: 8px;
  font-size: 1.18rem;
  font-weight: 950;
}

.venta-detalle {
  font-size: .92rem;
  color: var(--gris-texto);
  margin-bottom: 16px;
  font-weight: 700;
  line-height: 1.45;
}

/* =========================================================
   Ventas
   ========================================================= */

.ventas-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.ventas-header h2 {
  margin-bottom: 0;
}

.stat-dark {
  min-width: 170px;
  background: #f7f8fa;
  border: 1px solid var(--gris-linea);
}

.stat-dark span {
  color: var(--rojo);
}

.stat-dark label {
  color: var(--gris-texto);
}

/* Toolbar dentro del header de ventas */

.ventas-toolbar {
  box-shadow: none;
  padding: 0;
  border: none;
  background: transparent;
  margin-left: auto;
}

.ventas-toolbar select {
  min-width: 210px;
  background: var(--blanco);
}

/* Resumen de ventas por usuario */

.seller-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.seller-card {
  background: linear-gradient(135deg, #ffffff, #fafafa);
  border: 1px solid var(--gris-linea);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 22px rgba(16, 17, 20, 0.06);
  position: relative;
  overflow: hidden;
}

.seller-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: linear-gradient(180deg, var(--rojo), var(--rojo-oscuro));
}

.seller-card h3 {
  font-size: 1rem;
  font-weight: 950;
  color: var(--negro);
  margin: 0;
  padding-left: 6px;
}

.seller-card p {
  margin: 4px 0 0;
  padding-left: 6px;
  color: var(--gris-texto);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .8px;
  font-weight: 850;
}

.seller-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.seller-metrics span {
  background: #f7f8fa;
  border: 1px solid var(--gris-linea);
  border-radius: 12px;
  padding: 11px 12px;
}

.seller-metrics b {
  display: block;
  color: var(--negro);
  font-size: 1rem;
  font-weight: 950;
  line-height: 1.1;
}

.seller-metrics small {
  display: block;
  margin-top: 4px;
  color: var(--gris-texto);
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .7px;
  font-weight: 850;
}

/* =========================================================
   Exportación CSV
   ========================================================= */

.export-actions {
  margin-top: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.export-actions .btn {
  padding: 9px 14px;
  font-size: .72rem;
  white-space: nowrap;
  border-radius: 999px;
}

#exportActionsInventario {
  margin-left: auto;
}

#exportActionsVentas {
  margin-left: auto;
}

.ventas-header .export-actions {
  margin-top: 0;
}

#btnExportInventario,
#btnExportVentas,
#btnExportVentasUsuario {
  background: #ffffff;
  color: var(--negro);
  border: 1px solid var(--gris-linea);
}

#btnExportInventario:hover,
#btnExportVentas:hover,
#btnExportVentasUsuario:hover {
  background: var(--rojo-suave);
  color: var(--rojo-oscuro);
  border-color: rgba(217, 33, 33, .35);
}

/* =========================================================
   Actividad
   ========================================================= */

.logs-toolbar {
  margin-bottom: 18px;
}

.logs-card td:first-child {
  white-space: nowrap;
  font-weight: 800;
  color: var(--gris-texto);
}

.logs-card td:nth-child(2),
.logs-card td:nth-child(3) {
  font-weight: 850;
}

.log-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 116px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: .67rem;
  font-weight: 950;
  letter-spacing: .6px;
  color: #17191f;
  background: #eef0f3;
  border: 1px solid #d9dde4;
}

.log-login {
  color: #104126;
  background: #eaf8ef;
  border-color: #bfe7cd;
}

.log-venta {
  color: #7b2f00;
  background: #fff1df;
  border-color: #ffd2a3;
}

.log-goma {
  color: #143d75;
  background: #eaf2ff;
  border-color: #c2d9ff;
}

.log-export {
  color: #433100;
  background: #fff7d6;
  border-color: #f1df91;
}

.log-delete {
  color: var(--rojo-oscuro);
  background: var(--rojo-suave);
  border-color: rgba(217, 33, 33, .32);
}

/* =========================================================
   Estados
   ========================================================= */

.vacio {
  text-align: center;
  padding: 34px;
  color: var(--gris-texto);
  font-weight: 700;
}

.hidden {
  display: none !important;
}

/* =========================================================
   Footer
   ========================================================= */

footer {
  text-align: center;
  padding: 16px;
  font-size: .76rem;
  color: #b8bbc2;
  background: #111216;
  margin-top: 24px;
}

footer code {
  color: #ff5b5b;
}

/* =========================================================
   Responsive
   ========================================================= */

@media (max-width: 960px) {
  .topbar {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .brand {
    width: 100%;
    min-width: 0;
  }

  .user-box {
    justify-self: stretch;
    width: 100%;
    justify-content: space-between;
    border-radius: 14px;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .tabs {
    padding: 0 18px 14px;
  }
}

@media (max-width: 720px) {
  main {
    margin: 18px auto;
    padding: 0 12px;
  }

  .card,
  .toolbar {
    padding: 16px;
  }

  .brand img {
    height: 62px;
  }

  .brand h1 {
    font-size: 1rem;
  }

  .subtitle {
    font-size: .66rem;
    letter-spacing: 1.8px;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .stat {
    padding: 12px;
  }

  .stat span {
    font-size: 1.25rem;
  }

  .tab {
    padding: 8px 18px;
    white-space: nowrap;
  }

  .tabs {
    overflow-x: auto;
  }

  table {
    min-width: 850px;
  }

  #tabla {
    min-width: 1180px;
  }

  #vistaVentas table {
    min-width: 1280px;
  }

  .card {
    overflow-x: auto;
  }

  td,
  th {
    padding: 10px 9px;
    font-size: .84rem;
  }

  .toolbar input,
  .toolbar select {
    width: 100%;
    min-width: 100%;
  }

  .seller-summary {
    grid-template-columns: 1fr;
  }

  .ventas-toolbar {
    width: 100%;
  }

  .ventas-toolbar select {
    width: 100%;
    min-width: 100%;
  }

  .export-actions {
    width: 100%;
    justify-content: stretch;
  }

  .export-actions .btn {
    width: 100%;
  }

  #exportActionsInventario,
  #exportActionsVentas {
    margin-left: 0;
  }
}

@media (max-width: 480px) {
  .login-card {
    padding: 28px 20px;
  }

  .login-brand h1 {
    font-size: 1.2rem;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .user-box {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .user-box .btn {
    width: 100%;
  }
}
