/* =========================================================
  Merkaia - admin.css (Panel de Administración)
  Versión mejorada con nueva tabla de comisiones
  ========================================================= */

:root {
    --admin-bg: #f8f9fa;
    --admin-card-bg: #ffffff;
    --admin-border: #e9ecef;
    --admin-primary: #00a650;
    --admin-secondary: #6c757d;
    --admin-success: #28a745;
    --admin-danger: #dc3545;
    --admin-warning: #ffc107;
    --admin-info: #17a2b8;
}

body.page-admin {
    background-color: var(--admin-bg);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    color: #333;
}

.admin-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--admin-border);
}

.admin-header h1 {
    margin: 0;
    color: var(--admin-primary);
    font-size: 2.2em;
}

.admin-actions {
    display: flex;
    gap: 10px;
}

.admin-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--admin-primary);
    color: white;
}

.btn-primary:hover {
    background: #008a43;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--admin-secondary);
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-warning {
    background: var(--admin-warning);
    color: #000;
}

.btn-warning:hover {
    background: #e0a800;
}

.btn-info {
    background: var(--admin-info);
    color: white;
}

.btn-info:hover {
    background: #138496;
}

.btn-danger {
    background: var(--admin-danger);
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

/* Estadísticas */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--admin-card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    text-align: center;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-card h3 {
    margin: 0 0 15px 0;
    color: var(--admin-secondary);
    font-size: 1.1em;
    font-weight: 600;
}

.stat-card p {
    margin: 0;
    font-size: 2.5em;
    font-weight: bold;
    color: var(--admin-primary);
}

/* Pestañas */
.admin-tabs {
    display: flex;
    border-bottom: 2px solid var(--admin-border);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 12px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--admin-secondary);
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--admin-primary);
}

.tab-btn.active {
    color: var(--admin-primary);
    border-bottom-color: var(--admin-primary);
}

.tab-content {
    margin-bottom: 30px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

/* Secciones */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.search-box {
    display: flex;
    gap: 10px;
}

.search-box input {
    padding: 8px 12px;
    border: 1px solid var(--admin-border);
    border-radius: 4px;
    min-width: 250px;
}

.btn-small {
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

/* Tablas generales */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.data-table th {
    background: var(--admin-bg);
    padding: 15px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--admin-secondary);
    border-bottom: 2px solid var(--admin-border);
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--admin-border);
}

.data-table tr:hover {
    background-color: #f8f9fa;
}

/* =========================================================
   NUEVA TABLA DE COMISIONES - ESTILOS MEJORADOS
   ========================================================= */
.commission-table-container {
    overflow-x: auto;
    margin: 20px 0;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.commission-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 1200px;
    /* Para forcing scroll en móvil */
}

.commission-table th,
.commission-table td {
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid #edf2f7;
    vertical-align: middle;
}

.commission-table th {
    background-color: #f1f5f9;
    font-weight: 600;
    color: #1e293b;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.commission-table tr:hover td {
    background-color: #f8fafc;
}

/* Colores específicos para ciertas columnas */
.commission-table td:nth-child(10) {
    /* % comisión */
    text-align: center;
    font-weight: 500;
}

.commission-table td:nth-child(11),
/* Comisión $ */
.commission-table td:nth-child(12),
/* Costo Wompi */
.commission-table td:nth-child(13) {
    /* Envío */
    color: #dc2626;
    font-weight: 500;
}

.commission-table td:nth-child(15) {
    /* Total Pago */
    color: #16a34a;
    font-weight: bold;
}

/* Badges de estado dentro de la tabla */
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.status-delivered {
    background-color: #dcfce7;
    color: #166534;
}

.status-shipping {
    background-color: #fef9c3;
    color: #854d0e;
}

.status-processing {
    background-color: #e0f2fe;
    color: #0c4a6e;
}

.status-cancelled {
    background-color: #fee2e2;
    color: #991b1b;
}

/* Botón de pago dentro de tabla */
.payout-toggle-btn {
    background-color: #ef4444;
    color: white;
    border: none;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 500;
    transition: background 0.2s;
}

.payout-toggle-btn[data-estado="true"] {
    background-color: #22c55e;
}

/* Filtros y acciones */
.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filters input,
.filters select {
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: white;
    font-size: 0.85rem;
}

.table-actions-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    flex-wrap: wrap;
    gap: 15px;
    padding: 10px 0;
}

.selection-actions {
    display: flex;
    gap: 10px;
}

.table-summary {
    background: #f8fafc;
    padding: 8px 16px;
    border-radius: 30px;
    font-weight: 500;
    font-size: 0.9rem;
}

/* Modal de comisiones (pantalla completa) */
.modal-comisiones {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    overflow: auto;
}

.modal-comisiones-content {
    background-color: white;
    margin: 20px;
    padding: 20px;
    border-radius: 16px;
    width: calc(100% - 40px);
    height: calc(100% - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e2e8f0;
}

.modal-header h3 {
    margin: 0;
    color: var(--admin-primary);
}

.modal-close {
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #94a3b8;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #1e293b;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding-right: 8px;
}

/* Scroll personalizado */
.modal-body::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

/* =========================================================
   RESTO DE ESTILOS (sin cambios relevantes)
   ========================================================= */

/* Tarjetas de información */
.order-info-card,
.cart-info-card {
    background: var(--admin-bg);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

/* Items de pedido */
.order-item,
.cart-item,
.admin-order-card {
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.orders-container {
    margin-top: 20px;
}

.admin-order-card:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
    transition: all 0.2s ease;
}

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

.item-details {
    margin-bottom: 15px;
}

.item-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.status-select {
    padding: 8px;
    border: 1px solid var(--admin-border);
    border-radius: 4px;
}

.shipping-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shipping-fields input {
    padding: 8px;
    border: 1px solid var(--admin-border);
    border-radius: 4px;
}

/* Estados vacíos */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--admin-secondary);
}

/* Modal de administración */
.admin-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.admin-modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 25px;
    border-radius: 8px;
    width: 80%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.admin-modal-close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 20px;
    top: 15px;
}

.admin-modal-close:hover {
    color: black;
}

/* Detalles de usuario */
.user-detail-card {
    background: var(--admin-bg);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.user-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.user-stat {
    background: white;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.stat-number {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--admin-primary);
    margin: 10px 0 0;
}

.modal-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Comisiones resumen */
.commission-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.summary-card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.summary-card h3 {
    margin: 0 0 10px 0;
    color: #6c757d;
    font-size: 1rem;
}

.summary-card .value {
    font-size: 1.8rem;
    font-weight: bold;
    color: #4a6da7;
}

/* Configuración de comisiones */
.commission-config {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.commission-rates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.rate-card {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    border-left: 4px solid #4a6da7;
}

.rate-card h4 {
    margin: 0 0 10px 0;
    color: #343a40;
}

.rate-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #4a6da7;
}

.rate-slider {
    width: 100%;
    margin: 10px 0;
}

/* Tabla de usuarios */
.admin-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    margin-top: 20px;
}

.admin-table thead {
    background: linear-gradient(to right, #f8f9fa, #ffffff);
}

.admin-table th {
    padding: 16px;
    text-align: left;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #e9ecef;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.admin-table td {
    padding: 16px;
    vertical-align: middle;
    border-bottom: 1px solid #f1f3f5;
    color: #343a40;
    font-size: 0.95rem;
}

.admin-table tr:last-child td {
    border-bottom: none;
}

.admin-table tr:hover td {
    background-color: #f8f9fa;
}

.user-avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.user-avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6c757d, #495057);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.user-name {
    font-weight: 600;
    color: #212529;
}

.user-id-small {
    font-size: 0.75rem;
    color: #adb5bd;
    margin-top: 2px;
}

.user-badges {
    display: flex;
    gap: 5px;
    align-items: center;
}

.badge {
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-admin {
    background-color: #e3f2fd;
    color: #0d47a1;
    border: 1px solid #bbdefb;
}

.badge-user {
    background-color: #f3f3f3;
    color: #666;
    border: 1px solid #e0e0e0;
}

.badge-verified {
    background-color: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
    padding: 2px 6px;
    font-size: 0.8rem;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
    color: #6c757d;
}

.btn-icon:hover {
    background-color: #e9ecef;
    color: var(--admin-primary);
}

/* Conversaciones */
.conversacion-completa {
    max-height: 500px;
    overflow-y: auto;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-top: 15px;
}

.mensajes-contenedor {
    max-height: 250px;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.mensaje-admin {
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 8px;
}

.mensaje-usuario {
    background: linear-gradient(135deg, #e8f5e8, #d4edda);
    border-left: 4px solid var(--admin-primary);
    margin-left: 20px;
}

.mensaje-otro {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb);
    border-left: 4px solid var(--admin-info);
    margin-right: 20px;
}

/* Modal de confirmación de pago */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal-content {
    background-color: #fff;
    border-radius: 20px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    animation: modalFadeIn 0.2s ease-out;
}

.modal-close {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #aaa;
}

.modal-close:hover {
    color: #333;
}

/* Media Queries */
@media (max-width: 1024px) {
    .admin-container {
        padding: 15px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
}

@media (max-width: 768px) {
    .admin-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .admin-actions {
        flex-wrap: wrap;
        justify-content: center;
    }

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

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .search-box {
        width: 100%;
    }

    .search-box input {
        min-width: unset;
        flex: 1;
    }

    .commission-rates-grid {
        grid-template-columns: 1fr;
    }

    .filters {
        flex-direction: column;
    }

    .filters input,
    .filters select {
        width: 100%;
    }

    .modal-comisiones-content {
        margin: 10px;
        width: calc(100% - 20px);
        height: calc(100% - 20px);
        padding: 10px;
    }
}

@media (max-width: 480px) {
    .admin-container {
        padding: 10px;
    }

    .stat-card {
        padding: 20px;
    }

    .stat-card p {
        font-size: 2em;
    }

    .admin-modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 20px;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}