/* ==========================================================================
   TUESTANTE ADMIN - ESTILOS GLOBALES Y LAYOUT DEL DASHBOARD (INDEX.CSS)
   ========================================================================== */

:root {
  /* --- PALETA CORPORATIVA OFICIAL --- */
  --primary: #005187;          /* Azul oscuro profundo / Corporativo */
  --primary-hover: #4d82bc;    /* Azul medio acero */
  --secondary: #4d82bc;        /* Azul medio acero */
  --secondary-hover: #005187;  /* Azul oscuro profundo */
  --accent: #84b6f4;           /* Azul claro vibrante */
  --bg-light: #c4dafa;         /* Azul pálido suave */
  --bg-primary: #fcffff;       /* Blanco con matiz cian ultra-suave */
  --bg-secondary: #f3f8fe;     /* Azul ultra-pálido */
  --text-main: #0f172a;        /* Slate oscuro / Slate-900 */
  --text-muted: #475569;       /* Slate medio / Slate-600 */
  --border-color: #cbd5e1;     /* Gris suave / Slate-300 */

  /* Tipografías y sombras */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', var(--font-sans);
  
  --shadow-sm: 0 1px 3px rgba(0, 81, 135, 0.04);
  --shadow-md: 0 4px 14px -1px rgba(0, 81, 135, 0.07), 0 2px 6px -1px rgba(0, 81, 135, 0.03);
  --shadow-lg: 0 10px 25px -3px rgba(0, 81, 135, 0.09), 0 4px 10px -2px rgba(0, 81, 135, 0.04);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

/* Reset y contención de layout estricta */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg-secondary);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   ESTRUCTURA PRINCIPAL DEL DASHBOARD (APP-LAYOUT)
   Adaptación dinámica exacta al ancho del drawer sin desbordar la pantalla
   ========================================================================== */
.app-layout {
  min-height: 100vh;
  min-height: 100dvh;
  margin-left: var(--drawer-current-width, 260px);
  width: calc(100% - var(--drawer-current-width, 260px));
  max-width: calc(100% - var(--drawer-current-width, 260px));
  min-width: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow-x: hidden;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              width 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background-color: var(--bg-secondary);
}

@media (max-width: 1023.98px) {
  .app-layout {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ==========================================================================
   CONTENEDOR PRINCIPAL DEL DASHBOARD
   ========================================================================== */
.app-main-content {
  flex: 1;
  padding: 22px 24px 32px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: hidden;
}

.dashboard-container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
  box-sizing: border-box;
}

/* ==========================================================================
   1. FILA SUPERIOR DE MÉTRICAS KPI (6 TARJETAS EN GRID RESPONSIVO)
   ========================================================================== */
.kpi-metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  min-width: 0;
}

.kpi-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
  text-decoration: none;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--secondary);
}

/* Iconos Cuadrados Redondeados con Colores Suaves */
.kpi-icon-wrapper {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.kpi-card:hover .kpi-icon-wrapper {
  transform: scale(1.05);
}

.kpi-icon-wrapper svg {
  width: 20px;
  height: 20px;
}

/* Esquemas de Colores de los Iconos */
.kpi-icon-blue {
  background-color: #e0f2fe;
  color: #0284c7;
}

.kpi-icon-orange {
  background-color: #ffedd5;
  color: #f97316;
}

.kpi-icon-purple {
  background-color: #f3e8ff;
  color: #9333ea;
}

.kpi-icon-amber {
  background-color: #fef3c7;
  color: #d97706;
}

.kpi-icon-cyan {
  background-color: #ccfbf1;
  color: #0d9488;
}

.kpi-icon-green {
  background-color: #dcfce7;
  color: #16a34a;
}

/* Información de la Tarjeta */
.kpi-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.kpi-title {
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.kpi-value {
  font-family: var(--font-heading);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.15;
  margin: 1px 0;
}

.kpi-trend {
  font-size: 0.715rem;
  font-weight: 600;
  color: #16a34a;
  display: flex;
  align-items: center;
  gap: 3px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-action-link {
  font-size: 0.735rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  line-height: 1.2;
  transition: color 0.15s ease, text-decoration 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-action-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* ==========================================================================
   2. SECCIÓN INFERIOR ADAPTADA (2 TARJETAS: DONUT Y TABLA)
   ========================================================================== */
.dashboard-bottom-grid {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
  width: 100%;
  min-width: 0;
}

/* --------------------------------------------------------------------------
   TARJETA A: PEDIDOS POR ESTADO (DONUT CHART)
   -------------------------------------------------------------------------- */
.donut-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  width: 100%;
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

/* Contenedor del Gráfico Donut */
.donut-chart-section {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 0;
  position: relative;
}

.donut-svg-container {
  width: 180px;
  height: 180px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.donut-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  overflow: visible;
}

.donut-segment {
  fill: none;
  stroke-width: 22;
  transition: stroke-width 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease, filter 0.2s ease;
  cursor: pointer;
}

.donut-segment:hover,
.donut-segment.is-hovered {
  stroke-width: 26;
  opacity: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}

.donut-center-info {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.donut-center-count {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
}

.donut-center-label {
  font-size: 0.775rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Leyenda de Estados */
.donut-legend-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 6px;
  border-top: 1px solid #f1f5f9;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.815rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.legend-item:hover,
.legend-item.is-highlighted {
  background-color: var(--bg-secondary);
  color: var(--text-main);
  transform: translateX(3px);
}

.legend-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-count {
  font-weight: 700;
  color: var(--text-main);
  font-size: 0.84rem;
  margin-left: 8px;
}

/* --------------------------------------------------------------------------
   TARJETA B: PEDIDOS RECIENTES (TABLA CON SCROLL LATERAL PROPIO)
   -------------------------------------------------------------------------- */
.recent-orders-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 480px;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  overflow: hidden;
}

.card-header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.card-header-link {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}

.card-header-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Contenedor con Scroll Lateral Propio de la Tabla */
.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin: 6px 0;
  border-radius: var(--radius-sm);
  /* Barra de scroll horizontal visualmente elegante */
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--bg-secondary);
}

.table-responsive::-webkit-scrollbar {
  height: 6px;
}

.table-responsive::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 9999px;
  margin: 0 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 9999px;
  border: 1.5px solid var(--bg-secondary);
}

.table-responsive::-webkit-scrollbar-thumb:hover {
  background: var(--primary-hover);
}

/* Tabla de Pedidos */
.orders-table {
  width: 100%;
  min-width: 540px; /* Asegura que las columnas de la tabla mantengan su legibilidad y activen el scroll lateral propio si el espacio es reducido */
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
  font-size: 0.865rem;
}

.orders-table thead th {
  padding: 12px 14px;
  font-size: 0.785rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  white-space: nowrap;
}

.orders-table tbody tr {
  transition: background-color 0.15s ease;
}

.orders-table tbody tr:hover {
  background-color: var(--bg-secondary);
}

.orders-table tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  color: var(--text-main);
}

/* Elementos de cada celda */
.order-code-text {
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.client-name-text {
  font-weight: 500;
  color: var(--text-main);
  white-space: nowrap;
}

.order-total-text {
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.order-date-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Badges de Estado Fieles al Diseño */
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.3;
}

/* En fabricación: Azul suave / Lavanda */
.badge-manufacturing {
  background-color: #e0e7ff;
  color: #4338ca;
}

/* Pago en revisión: Ámbar / Mostaza suave */
.badge-payment-review {
  background-color: #fef3c7;
  color: #b45309;
}

/* Esperando pago final: Violeta / Púrpura suave */
.badge-waiting-final {
  background-color: #f3e8ff;
  color: #7e22ce;
}

/* Enviado: Cian / Verde azulado suave */
.badge-shipped {
  background-color: #ccfbf1;
  color: #0f766e;
}

/* Pendiente de pago: Amarillo claro suave */
.badge-pending-payment {
  background-color: #fef9c3;
  color: #a16207;
}

/* Botón de Acciones (3 Puntos Verticales) */
.order-actions-col {
  text-align: right;
  width: 44px;
  position: relative;
}

.action-menu-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-menu-btn:hover {
  background-color: var(--bg-light);
  color: var(--primary);
}

.action-menu-btn svg {
  width: 18px;
  height: 18px;
}

/* Menú Desplegable Flotante de Acciones */
.action-popover {
  position: absolute;
  right: 14px;
  top: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 81, 135, 0.12);
  padding: 6px;
  min-width: 170px;
  z-index: 100;
  display: none;
  flex-direction: column;
  gap: 2px;
  text-align: left;
}

.action-popover.is-active {
  display: flex;
}

.action-popover-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-main);
  background: transparent;
  border: none;
  width: 100%;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.action-popover-item:hover {
  background-color: var(--bg-secondary);
  color: var(--primary);
}

.action-popover-item svg {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

/* Pie de la Tarjeta con Enlace con Flecha */
.card-footer-action {
  padding-top: 14px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
}

.footer-all-orders-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  transition: gap 0.2s ease, color 0.15s ease;
}

.footer-all-orders-link:hover {
  color: var(--primary-hover);
  gap: 10px;
}

.footer-all-orders-link svg {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.footer-all-orders-link:hover svg {
  transform: translateX(2px);
}

/* ==========================================================================
   MODAL DE DETALLE RÁPIDO DE PEDIDO
   ========================================================================== */
.quick-view-modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.quick-view-modal-backdrop.is-open {
  display: flex;
}

.quick-view-modal {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  animation: modalScaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.modal-close-btn:hover {
  background-color: var(--bg-secondary);
  color: var(--text-main);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.modal-row-label {
  color: var(--text-muted);
}

.modal-row-value {
  font-weight: 600;
  color: var(--text-main);
}

.modal-footer {
  padding: 14px 20px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ==========================================================================
   RESPONSIVE (ADAPTABILIDAD EN TODAS LAS RESOLUCIONES)
   ========================================================================== */
@media (max-width: 1400px) {
  .kpi-metrics-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1080px) {
  .dashboard-bottom-grid {
    grid-template-columns: 1fr;
  }

  .donut-card {
    max-width: 520px;
    margin: 0 auto;
    width: 100%;
  }
}

@media (max-width: 768px) {
  .app-main-content {
    padding: 16px 14px 28px;
  }

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

  .kpi-card {
    padding: 12px 10px;
    gap: 8px;
  }

  .kpi-icon-wrapper {
    width: 36px;
    height: 36px;
    border-radius: 8px;
  }

  .kpi-icon-wrapper svg {
    width: 18px;
    height: 18px;
  }

  .kpi-value {
    font-size: 1.3rem;
  }

  .recent-orders-card {
    padding: 16px 14px;
  }
}

@media (max-width: 480px) {
  .kpi-metrics-grid {
    grid-template-columns: 1fr;
  }
}
