/* =====================================================
   SuPapelera Gestión Web — Estilos
   Paleta de colores igual a la app de escritorio
   ===================================================== */

:root {
  --color-clientes:  #ffc0c0;   /* LightCoral del escritorio */
  --color-articulos: #90ee90;   /* PaleGreen del escritorio  */
  --color-pedidos:   #ffc0c0;
  --color-ventas:    #b8e7ff;
  --color-abm:       #90ee90;
  --color-admin:     #ffff80;   /* Amarillo del escritorio   */
  --sidebar-bg:      #2c3e50;
  --sidebar-active:  #1a252f;
  --sidebar-hover:   #34495e;
  --sidebar-text:    #ecf0f1;
  --body-bg:         #f0f2f5;
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--body-bg);
  font-size: 14px;
  margin: 0;
}

/* ── Sidebar ─────────────────────────────────────────── */
#sidebar {
  width: 200px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 8px rgba(0,0,0,.18);
}

.sidebar-header {
  background: var(--sidebar-active);
  padding: 18px 12px 14px;
  text-align: center;
  overflow: hidden;
}
.sidebar-header .app-icon { font-size: 36px; line-height: 1; }
.logo-clip {
  width: 176px;
  height: 48px;
  margin: 0 auto;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: #fff;
  border-radius: 2px;
  transition: width .18s ease, height .18s ease;
}
.sidebar-logo {
  width: 205px;
  max-width: none;
  height: 48px;
  object-fit: contain;
  object-position: left center;
  flex: 0 0 auto;
  display: block;
}
body.is-scrolled #sidebar .logo-clip {
  width: 72px;
}
.sidebar-header h5 {
  color: var(--sidebar-text);
  margin: 6px 0 2px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .4px;
}
.sidebar-header small { color: #8e9faf; font-size: 11px; }

.sidebar-user {
  padding: 8px 14px;
  background: rgba(0,0,0,.15);
  color: #8e9faf;
  font-size: 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-nav {
  padding: 10px 8px;
  flex: 1;
}

/* Botones de navegación — réplica de los botones del ControlRemoto */
.nav-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  margin: 3px 0;
  padding: 9px 12px;
  border: none;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: filter .15s, transform .1s, box-shadow .15s;
  line-height: 1.2;
}
.nav-btn:hover { filter: brightness(.9); transform: translateX(3px); text-decoration: none; }
.nav-btn.active { filter: brightness(.8); transform: translateX(4px); font-weight: 700; box-shadow: inset 3px 0 0 rgba(0,0,0,.3); }

.nav-btn-dashboard { background: #dee2e6; color: #2c3e50; }
.nav-btn-clientes  { background: var(--color-clientes);  color: #5a0000; }
.nav-btn-articulos { background: var(--color-articulos); color: #1a4f00; }
.nav-btn-pedidos   { background: var(--color-pedidos);   color: #5a0000; }
.nav-btn-abm       { background: var(--color-abm);       color: #1a4f00; }
.nav-btn-vendedores { background: var(--color-admin);     color: #5a5200; }
.nav-btn-admin     { background: var(--color-admin);     color: #5a5200; }
.nav-btn-salir     { background: #e9ecef; color: #495057; }

.sidebar-nav hr { border-color: rgba(255,255,255,.1); margin: 8px 0; }

/* ── Contenido principal ─────────────────────────────── */
#main-content {
  margin-left: 200px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#topbar {
  background: #fff;
  border-bottom: 1px solid #dee2e6;
  padding: 10px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 900;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
#topbar h4 { margin: 0; font-size: 16px; font-weight: 700; color: #2c3e50; }

#page-content { padding: 20px; flex: 1; }

/* ── Encabezados de sección (mismos colores que el escritorio) ─ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-radius: 8px 8px 0 0;
}
.section-header h5 { margin: 0; font-size: 15px; font-weight: 700; color: #2c3e50; }
.section-header-clientes  { background: var(--color-clientes); }
.section-header-articulos { background: var(--color-articulos); }
.section-header-pedidos   { background: var(--color-pedidos); }
.section-header-abm       { background: var(--color-abm); }
.section-header-admin     { background: var(--color-admin); }

/* ── Cards ───────────────────────────────────────────── */
.card {
  border: none;
  box-shadow: 0 1px 5px rgba(0,0,0,.08);
  border-radius: 8px;
}
.card-table { border-radius: 8px; overflow: hidden; }
.card-body-tight { padding: 0; }

/* ── Tablas ──────────────────────────────────────────── */
.table { margin: 0; font-size: 13.5px; }
.table thead th {
  background: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #6c757d;
  white-space: nowrap;
  padding: 10px 14px;
}
.table tbody td { padding: 9px 14px; vertical-align: middle; }
.table tbody tr:hover { background: #f5f8ff; cursor: pointer; }
.table tbody tr.selected { background: #e8f4fd; }

.ticket-row-nuevo > td { background: #e7f6e7 !important; }
.ticket-row-nuevo:hover > td { background: #d8efd8 !important; }
.ticket-row-pendiente > td { background: #fff4ce !important; }
.ticket-row-pendiente:hover > td { background: #ffeaa3 !important; }
.ticket-row-alta > td { background: #ffd9d9 !important; }
.ticket-row-alta:hover > td { background: #ffc7c7 !important; }
.ticket-row-resuelto > td {
  background: #eeeeee !important;
  color: #6c757d;
}
.ticket-row-resuelto:hover > td { background: #e2e2e2 !important; }
.tickets-resueltos-card {
  opacity: .86;
}

/* ── Barra de búsqueda ───────────────────────────────── */
.search-bar {
  background: #fff;
  padding: 10px 16px;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.table-pagination {
  background: #fff;
  border-top: 1px solid #dee2e6;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Tarjetas de estadísticas (dashboard) ─────────────── */
.stat-card {
  border-radius: 10px;
  padding: 22px 20px;
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  transition: transform .15s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card .stat-number { font-size: 40px; font-weight: 800; line-height: 1; }
.stat-card .stat-label { font-size: 13px; margin-top: 4px; opacity: .7; font-weight: 600; }
.stat-card .stat-icon { font-size: 32px; opacity: .5; }
.stat-card-clientes  { background: var(--color-clientes); }
.stat-card-articulos { background: var(--color-articulos); }
.stat-card-pedidos   { background: var(--color-pedidos); }
.stat-card-ventas    { background: var(--color-ventas); }
.stat-finance-lines {
  display: grid;
  gap: 7px;
  min-width: 0;
}
.stat-finance-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}
.stat-finance-line strong {
  font-size: 18px;
  font-weight: 800;
}

/* ── Badges de estado (en tabla) ─────────────────────── */
.estado-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(0,0,0,.12);
  white-space: nowrap;
  user-select: none;
}
.estado-dot {
  width: 13px; height: 13px;
  border-radius: 3px;
  display: inline-block;
  border: 1px solid rgba(0,0,0,.15);
  flex-shrink: 0;
}

/* ── Botones de estado (en modal) ────────────────────── */
.estado-selector {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.btn-estado {
  padding: 7px 14px;
  border: 2px solid transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .12s, transform .1s, border-color .1s;
  opacity: .55;
  line-height: 1.2;
}
.btn-estado:hover  { opacity: .85; }
.btn-estado.active { opacity: 1; border-color: rgba(0,0,0,.4); transform: scale(1.07); box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.btn-estado-vacio    { background: #e9ecef; color: #6c757d; }
.btn-estado-imprimir { background: #DDA0DD; color: #4a0050; }
.btn-estado-bobinas  { background: #FFFF00; color: #665500; }
.btn-estado-1        { background: #32CD32; color: #0a3d00; }
.btn-estado-2        { background: #DC143C; color: #ffffff; }
.btn-estado-3        { background: #C0C0C0; color: #404040; }
.btn-estado-pagado   { background: #0d6efd; color: #ffffff; }

#modalPedido .modal-dialog {
  max-width: min(1280px, calc(100vw - 18px));
}
#modalPedido .modal-body {
  padding: 16px 18px 12px;
}
#modalPedido .form-label {
  margin-bottom: 5px;
}
#modalPedido #ped-notas {
  min-height: 81px;
  resize: vertical;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
}

/* ── Login ───────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ffc0c0 0%, #90ee90 100%);
}
.login-card {
  width: 390px;
  max-width: 95vw;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.login-card .card-header {
  background: #2c3e50;
  color: #fff;
  text-align: center;
  padding: 28px 20px 20px;
  border-radius: 16px 16px 0 0;
}

/* ── Pedido: encabezado de líneas ─────────────────────── */
.lineas-header {
  display: grid;
  grid-template-columns: 190px 76px 68px minmax(260px, 1fr) 104px 112px 86px;
  gap: 7px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: #6c757d;
  background: #f8f9fa;
  border-radius: 6px;
  margin-bottom: 4px;
}

/* ── Pedido: líneas de productos ─────────────────────── */
.linea-producto {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 5px;
  padding: 7px 8px;
  margin-bottom: 6px;
  display: grid;
  grid-template-columns: 190px 76px 68px minmax(260px, 1fr) 104px 112px 86px;
  grid-auto-rows: 36px;
  gap: 7px;
  align-items: center;
  font-size: 13px;
}
.linea-ultimo-col,
.linea-ultimo-precio {
  display: none !important;
}
#modalPedido.mostrar-ultimo-precio .lineas-header,
#modalPedido.mostrar-ultimo-precio .linea-producto {
  grid-template-columns: 180px 74px 64px minmax(230px, 1fr) 128px 96px 108px 86px;
}
#modalPedido.mostrar-ultimo-precio .linea-ultimo-col,
#modalPedido.mostrar-ultimo-precio .linea-ultimo-precio {
  display: flex !important;
}
.linea-ultimo-precio {
  min-height: 30px;
  padding: 3px 6px;
  border: 1px dashed #b6c2cf;
  border-radius: 6px;
  background: #eef6ff;
  color: #0b5ed7;
  font-size: 11px;
}
.linea-ultimo-precio.ultimo-precio-igual {
  background: #fff7cc;
  border-color: #e7c84f;
  color: #6f5600;
}
.linea-ultimo-precio.ultimo-precio-menor {
  background: #ffe8cc;
  border-color: #f0a24d;
  color: #8a4300;
}
.linea-ultimo-precio.ultimo-precio-mayor {
  background: #ffd6d6;
  border-color: #ef7777;
  color: #8f1111;
}
.linea-producto input, .linea-producto select {
  font-size: 13px;
  padding: 5px 8px;
  min-height: 34px;
}
.linea-producto .ac-wrap { grid-column: 1; grid-row: 1; }
.linea-producto .linea-cantidad { grid-column: 2; grid-row: 1; }
.linea-producto .linea-um { grid-column: 3; grid-row: 1; }
.linea-producto .linea-desc { grid-column: 4; grid-row: 1; }
.linea-producto .linea-precio { grid-column: 5; grid-row: 1; }
.linea-producto .linea-sub { grid-column: 6; grid-row: 1; }
.linea-producto .linea-acciones { grid-column: 7; grid-row: 1; }
.linea-producto .linea-stock-alerta {
  display: none;
  grid-column: 1 / -1;
  grid-row: 2;
  color: #c1121f;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  padding: 0 2px;
}
.linea-producto .linea-stock-alerta.visible {
  display: block;
}
.linea-producto.stock-insuficiente {
  grid-auto-rows: 36px auto;
}
#modalPedido.mostrar-ultimo-precio .linea-producto .linea-ultimo-precio { grid-column: 5; grid-row: 1; }
#modalPedido.mostrar-ultimo-precio .linea-producto .linea-precio { grid-column: 6; grid-row: 1; }
#modalPedido.mostrar-ultimo-precio .linea-producto .linea-sub { grid-column: 7; grid-row: 1; }
#modalPedido.mostrar-ultimo-precio .linea-producto .linea-acciones { grid-column: 8; grid-row: 1; }
.linea-producto .linea-cantidad {
  font-weight: 700;
  font-size: 13px;
}
.linea-producto .linea-desc,
.linea-producto .linea-um,
.linea-producto .linea-sub,
.linea-producto .linea-ultimo-precio {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.linea-producto .tap-btn {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  height: 32px;
  padding-left: 0;
  padding-right: 0;
}
.linea-acciones {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}
.lineas-scroll {
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: 4px;
  position: relative;
}
#lineas-container {
  overflow: visible;
}
.total-pedido {
  font-size: 24px;
  font-weight: 800;
  color: #2c3e50;
}

/* ── Toast container ─────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  pointer-events: none;
}
#toast-container > * { pointer-events: all; }

/* ── Tap targets ──────────────────────────────────────── */
.tap-btn {
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
  #modalPedido .modal-dialog {
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    margin: 0;
  }
  #modalPedido .modal-content {
    min-height: 100vh;
    border-radius: 0;
  }
  #modalPedido .modal-body {
    padding: 14px 12px 10px;
  }

  #sidebar { width: 56px; }
  #sidebar .sidebar-header { padding: 10px 6px; }
  #sidebar .logo-clip {
    width: 44px;
    height: 44px;
    margin: 0;
  }
  #sidebar .sidebar-logo {
    width: 190px;
    height: 44px;
  }
  body.is-scrolled #sidebar .logo-clip { width: 44px; }
  #sidebar .sidebar-header h5,
  #sidebar .sidebar-header small,
  #sidebar .sidebar-user,
  .nav-btn .nav-label { display: none; }
  .nav-btn { justify-content: center; padding: 10px 4px; }
  .nav-btn .nav-icon { margin: 0; }
  #main-content { margin-left: 56px; }
  #page-content { padding: 10px; }
  .stat-card .stat-number { font-size: 28px; }

  /* Tables: increase row touch area */
  .table tbody td { padding: 11px 10px; }
  .table thead th { padding: 9px 10px; }

  /* Pedido lines: compact horizontal rows on phone */
  .lineas-header {
    display: grid !important;
    grid-template-columns: 180px 70px 60px 250px 96px 104px 78px;
    min-width: 880px;
    padding-left: 6px;
    padding-right: 6px;
  }
  .linea-producto {
    grid-template-columns: 180px 70px 60px 250px 96px 104px 78px;
    min-width: 880px;
    grid-auto-rows: 34px;
    padding: 4px 6px;
  }
  #modalPedido.mostrar-ultimo-precio .lineas-header,
  #modalPedido.mostrar-ultimo-precio .linea-producto {
    grid-template-columns: 170px 68px 58px 230px 116px 92px 104px 78px;
    min-width: 970px;
  }
  .linea-producto .linea-acciones {
    align-self: center;
    flex-direction: row;
  }
  .linea-producto .tap-btn {
    width: 30px;
    min-width: 30px;
    height: 30px;
    min-height: 30px;
  }

  /* Modal fullscreen already handled by Bootstrap modal-fullscreen-sm-down */
  .modal-fullscreen-sm-down .modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }

  /* Estado buttons: slightly smaller on very small screens */
  .btn-estado { padding: 8px 11px; font-size: 13px; }

  /* Search bar wraps nicely */
  .search-bar { gap: 6px; padding: 8px 12px; }
  .search-bar .form-control, .search-bar .form-select { font-size: 14px; }
}

@media (max-width: 480px) {
  .total-pedido { font-size: 20px; }
  #page-content { padding: 8px; }
}

/* ── Autocomplete ────────────────────────────────────── */
.ac-wrap { position: relative; }
.ac-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0; right: 0;
  background: #fff;
  border: 1px solid #ced4da;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,.13);
  z-index: 2000;
  max-height: min(320px, calc(100vh - 24px));
  overflow-y: auto;
}
.ac-item {
  padding: 8px 13px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f3f3f3;
  line-height: 1.3;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.ac-active { background: #e8f4fd; }
.ac-item mark {
  background: #ffe066;
  padding: 0;
  border-radius: 2px;
  font-weight: 700;
}
.ac-secondary { font-size: 11px; color: #6c757d; display: block; }
.ac-dropdown-productos .ac-item {
  white-space: nowrap;
}
.ac-dropdown-productos .ac-secondary {
  display: inline;
  margin-left: 8px;
}

/* ── Utilidades ──────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.fw-600 { font-weight: 600; }
.bg-clientes  { background-color: var(--color-clientes) !important; }
.bg-articulos { background-color: var(--color-articulos) !important; }
.bg-pedidos   { background-color: var(--color-pedidos) !important; }

/* Articulos: formulario compacto con precios y foto */
#modalProducto .producto-form {
  font-size: 13px;
}
#modalProducto .modal-body {
  overflow-x: hidden;
}
#modalProducto .producto-form > [class*="col-"] {
  min-width: 0;
}
#modalProducto .producto-form .form-label {
  margin-bottom: 3px;
  font-size: 12.5px;
}
#modalProducto .producto-form .form-control,
#modalProducto .producto-form .form-select,
#modalProducto .producto-form .input-group-text {
  font-size: 13px;
  padding-top: 5px;
  padding-bottom: 5px;
}
.precios-lista-compacta {
  max-height: 310px;
  overflow-y: auto;
}
.precios-lista-compacta .table > :not(caption) > * > * {
  padding: 4px 7px;
  font-size: 12px;
}
.precios-lista-compacta .form-control {
  min-height: 28px;
  padding: 2px 6px !important;
  font-size: 12px !important;
}
.foto-producto-box {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 220px;
  max-height: min(480px, 45vh);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid #dee2e6;
  border-radius: 7px;
  background: #f8f9fa;
}
.foto-producto-box img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.foto-producto-vacia {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #adb5bd;
}
.foto-producto-vacia i {
  font-size: 38px;
}
.foto-crop-inline {
  display: none;
  width: 100%;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  overflow: hidden;
  padding: 10px;
  border: 1px solid #ced4da;
  border-radius: 10px;
  background: #f8f9fa;
}
.foto-crop-inline.visible {
  display: block;
}
#foto-crop-canvas {
  display: block;
  width: 100%;
  max-width: 480px;
  max-height: min(480px, 45vh);
  object-fit: contain;
  height: auto;
  margin: 0 auto;
  border: 1px solid #adb5bd;
  border-radius: 6px;
  background: #e9ecef;
  cursor: grab;
  touch-action: none;
}
#foto-crop-canvas.arrastrando {
  cursor: grabbing;
}
