/* =========================
   LAYOUT PERFIL
   ========================= */
.profile-layout {
  display: flex;
  min-height: 80vh;
  background-color: var(--bg, #f5ede0);
}

/* SIDEBAR */
.profile-sidebar {
  width: 220px;
  min-width: 220px;
  background-color: var(--tierra-800, #5b3a1b);
  padding: 28px 14px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-self: stretch; /* llena toda la altura del layout */
}

.profile-menu-title {
  color: var(--tierra-200, #f2ba81);
  font-weight: 800;
  font-size: 20px;
  font-style: italic;
  margin-top: 0;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(242,186,129,.25);
}

.profile-menu-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  color: rgba(255,255,255,.7);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  border-radius: 8px;
  transition: all 0.18s;
  margin-bottom: 3px;
}
.profile-menu-link:hover {
  background-color: rgba(255,255,255,.1);
  color: #fff;
  text-decoration: none;
}
.profile-menu-link.active {
  background-color: var(--tierra-600, #8b5a2b);
  color: #fff;
}
.profile-menu-link svg { flex-shrink: 0; opacity: .8; }
.profile-menu-link.active svg, .profile-menu-link:hover svg { opacity: 1; }

.profile-logout-wrap {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.profile-menu-link.logout { color: var(--rosa-400, #f49b9d); }
.profile-menu-link.logout:hover { background-color: rgba(244,155,157,.15); color: var(--rosa-200, #f9c4c5); }

/* CONTENIDO */
.profile-content {
  flex: 1;
  min-width: 0;
  padding: 30px 40px;
  background: var(--bg, #f5ede0);
}

/* TABLA CONTAINER */
.table-container {
  background: #fff;
  border-radius: 12px;
  border: 1px solid rgba(139,90,43,.12);
  overflow: hidden;
  box-shadow: var(--shadow, 0 4px 16px rgba(91,58,27,.10));
}

.table-header {
  padding: 20px;
  border-bottom: 1px solid rgba(139,90,43,.10);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
}

.section-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--tierra-900, #3d2b1f);
  margin: 0;
}

.table-actions {
  display: flex;
  gap: 15px;
  font-size: 13px;
  color: #666;
}
.action-link {
  cursor: pointer;
  font-weight: 600;
  color: var(--tierra-600, #8b5a2b);
  transition: 0.2s;
  user-select: none;
}
.action-link:hover { text-decoration: underline; }

/* --- PANEL DE FILTROS --- */
.filter-panel {
  background-color: #fafafa;
  border-bottom: 1px solid #eee;
  padding: 20px;
  animation: slideDown 0.2s ease-out;
}
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.filter-type-row {
  display: flex;
  gap: 20px;
  margin-bottom: 15px;
  flex-wrap: wrap;
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  color: #555;
}
.radio-label input {
  cursor: pointer;
}

.filter-inputs-row {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 40px;
}
.f-input-group {
  display: flex;
  align-items: center;
  gap: 5px;
}
.f-input-group input,
.f-input-group select {
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}
.prefix {
  font-weight: bold;
  color: #999;
}

.btn-small-action {
  background: var(--tierra-600, #8b5a2b);
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
}
.hidden {
  display: none !important;
}

/* --- TABLA PRINCIPAL --- */
.custom-table {
  width: 100%;
  border-collapse: collapse;
}
.custom-table th {
  background: var(--tierra-50, #fdf7f0);
  padding: 13px 20px;
  text-align: left;
  font-size: 11px;
  color: var(--tierra-600, #8b5a2b);
  text-transform: uppercase;
  font-weight: 700;
  border-bottom: 1px solid rgba(139,90,43,.12);
  letter-spacing: 0.5px;
}
.custom-table td {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(139,90,43,.07);
  font-size: 14px;
  color: var(--tierra-900, #3d2b1f);
  vertical-align: middle;
}
.custom-table tr:hover { background-color: var(--tierra-50, #fdf7f0); }

.btn-ver-pedido {
  background: none;
  border: 1px solid rgba(139,90,43,.25);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  transition: all 0.2s;
  color: var(--tierra-600, #8b5a2b);
}
.btn-ver-pedido:hover {
  background-color: var(--tierra-600, #8b5a2b);
  color: white;
  border-color: var(--tierra-600, #8b5a2b);
}

/* Badges */
.badge-status {
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  display: inline-block;
}
.st-nuevo {
  background: #e3f2fd;
  color: #1565c0;
}
.st-recibido {
  background: #e8f5e9;
  color: #2e7d32;
}
.st-aprobado {
  background: #dce775;
  color: #827717;
}
.st-enviado {
  background: #d1c4e9;
  color: #512da8;
}
.st-cancelado {
  background: #ffebee;
  color: #c62828;
}

/* =========================================
   MODAL DETALLE - DISEÑO AVANZADO
   ========================================= */
.modal-detalle-panel {
  max-width: 800px;
  width: 100%;
  margin: 20px; /* Margen por defecto desktop */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: auto;
  max-height: 85vh;
  background: #fff;
  border-radius: 12px;
  position: relative;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-detalle-body {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0; /* CRUCIAL para scroll interno */
  padding: 0;
  overflow: hidden;
  flex: 1;
}

/* 1. HEADER FIJO */
.modal-header-fixed {
  padding: 25px 25px 10px 25px;
  flex-shrink: 0;
  background: #fff;
  border-bottom: 1px solid #eee;
}

.detalle-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  border: 1px solid #eee;
}
.dh-item span {
  display: block;
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  font-weight: 700;
}
.dh-item strong {
  display: block;
  font-size: 16px;
  color: #333;
  margin-top: 4px;
}

.items-title {
  font-size: 14px;
  color: #666;
  margin: 15px 0 10px 0;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* 2. ZONA SCROLLEABLE */
.modal-scrollable-table {
  flex: 1; /* Ocupa todo el espacio restante */
  overflow-y: auto; /* Habilita scroll vertical */
  padding: 0 25px;
  background-color: #fff;
  min-height: 0; /* Fix para Firefox/Flex */
  -webkit-overflow-scrolling: touch; /* Scroll suave en iOS */
}

.detalle-table {
  width: 100%;
  border-collapse: collapse;
}
.detalle-table th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
  text-align: left;
  font-size: 12px;
  color: #999;
  padding: 10px 0;
  border-bottom: 2px solid #eee;
}
.detalle-table td {
  padding: 12px 0;
  border-bottom: 1px solid #eee;
  font-size: 14px;
  vertical-align: middle;
}

.dt-prod {
  display: flex;
  align-items: center;
  gap: 12px;
}
.dt-img {
  width: 50px;
  height: 50px;
  border-radius: 6px;
  object-fit: contain;
  border: 1px solid #eee;
  background: #fff;
  padding: 2px;
}
.dt-info div {
  font-weight: 700;
  color: #333;
  margin-bottom: 2px;
}
.dt-info small {
  color: #888;
  font-size: 12px;
  display: block;
}

/* 3. FOOTER FIJO */
.modal-footer-fixed {
  padding: 15px 25px;
  flex-shrink: 0;
  background: #fff3cd;
  border-top: 1px solid #faeccc;
  font-size: 13px;
  color: #856404;
}

/* =========================================
   MEDIA QUERIES (TABLETS Y MOVILES)
   ========================================= */
@media (max-width: 900px) {
  .profile-layout {
    flex-direction: column;
  }
  .profile-sidebar {
    width: 100%;
    min-width: unset;
    padding: 16px 20px;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }
  .profile-menu-title {
    width: 100%;
    margin-bottom: 10px;
    padding-bottom: 10px;
    font-size: 16px;
  }
  .profile-logout-wrap {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    margin-left: auto;
  }
  .profile-content {
    padding: 16px;
  }

  /* Tabla Principal -> Tarjetas */
  .custom-table thead {
    display: none;
  }
  .custom-table,
  .custom-table tbody,
  .custom-table tr,
  .custom-table td {
    display: block;
    width: 100%;
  }
  .custom-table tr {
    background: #fff;
    margin-bottom: 15px;
    border-radius: 12px;
    border: 1px solid #eee;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    padding: 15px;
  }
  .custom-table td {
    padding: 8px 0;
    border-bottom: 1px solid #f9f9f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
  }
  .custom-table td:last-child {
    border-bottom: none;
    justify-content: flex-end;
    padding-top: 15px;
  }
  .custom-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #888;
    font-size: 12px;
    text-transform: uppercase;
    margin-right: 15px;
    text-align: left;
  }
  .btn-ver-pedido {
    width: 20%;
    border-radius: 6px;
    background-color: #f4f4f4;
    height: 40px;
  }

  /* MODAL EN MÓVIL (CORRECCIÓN DE SCROLL) */
  .modal {
    padding: 15px; /* Margen de seguridad para que no toque bordes */
    align-items: center; /* Centrar verticalmente */
  }

  .modal-detalle-panel {
    width: 100%;
    max-width: 100%;
    height: 85vh; /* Altura fija segura */
    position: relative; /* Ya no absolute bottom */
    bottom: auto;
    margin: 0;
    border-radius: 16px; /* Bordes redondeados completos */
    display: flex;
    flex-direction: column;
  }

  .modal-detalle-body {
    flex: 1; /* Forzar a ocupar espacio */
    overflow: hidden; /* Contener el scroll hijo */
  }

  .detalle-header {
    flex-wrap: wrap;
    gap: 10px;
  }
  .dh-item {
    width: 45%;
    margin-bottom: 5px;
  }

  /* Tabla Modal -> Lista limpia */
  .detalle-table thead {
    display: none;
  }
  .detalle-table tr {
    display: flex;
    flex-direction: column;
    padding: 15px 0;
    border-bottom: 1px solid #eee;
    position: relative;
  }
  .detalle-table td {
    border: none;
    padding: 2px 0;
    width: 100%;
    display: block;
  }

  .dt-prod {
    align-items: flex-start;
  }
  .dt-img {
    width: 60px;
    height: 60px;
  }

  .detalle-table td:nth-child(2),
  .detalle-table td:nth-child(3) {
    text-align: left;
    padding-left: 72px;
    color: #666;
    font-size: 13px;
  }

  .detalle-table td:nth-child(2)::before {
    content: "Cantidad: ";
    font-weight: 600;
  }
  .detalle-table td:nth-child(3)::before {
    content: "Subtotal: ";
    font-weight: 600;
  }
  .detalle-table td:nth-child(3) {
    color: #333;
    font-weight: 700;
    font-size: 15px;
    margin-top: 2px;
  }
}