/* =========================================================================
   admin.css - Estilos unificados para la SPA de Administración MBA
   ========================================================================= */

:root {
    --primary-color: #000;
    --secondary-color: #fff;
    --accent-color: #FFD700;
    --text-color: #333;
    --light-grey: #f4f4f4;
    --mid-grey: #e0e0e0;
    --dark-grey: #555;
    --header-height: 80px;
    --error-color: #dc3545;
    --success-color: #28a745;
    --info-color: #007bff;
    --warning-color: #ffc107;
    --sales-color: #6a0dad;
    --sidebar-width: 250px;
    --sidebar-bg: #222;
    --sidebar-text: #eee;
    --sidebar-hover: #333;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--light-grey);
    overflow-x: hidden;
    padding-top: var(--header-height);
    display: flex;
    min-height: calc(100vh - var(--header-height));
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

ul {
    list-style: none;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: 'Montserrat', sans-serif;
    color: var(--primary-color);
    line-height: 1.2;
    margin-bottom: 0.8em;
}

/* ================== Header ================== */
.main-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height);
    background-color: var(--primary-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
}

.main-header .logo {
    height: 50px;
    display: flex;
    align-items: center;
    overflow: hidden;
    gap: 12px;
}

.main-header .logo .logo-text {
    font-family: 'Dancing Script', cursive;
    font-size: 2.8em;
    font-weight: 700;
    letter-spacing: -3px;
    line-height: 1;
    background: linear-gradient(to right, var(--secondary-color), var(--light-grey), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 2px 2px 5px rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
}

.main-header .logo .logo-text:hover {
    transform: scale(1.05) translateY(-2px);
}

.main-header .logo .admin-badge {
    background: var(--accent-color);
    color: #000;
    font-size: 0.65em;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    font-family: 'Montserrat', sans-serif;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.admin-greeting {
    color: rgba(255, 255, 255, 0.8);
    font-family: 'Poppins', sans-serif;
    font-size: 1.1em;
}

.admin-greeting strong {
    color: #fff;
}

.store-links {
    display: flex;
    gap: 8px;
}

.store-link-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 5px 12px;
    border-radius: 5px;
    font-size: 0.8em;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.2s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 5px;
}

.store-link-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--accent-color);
}

.logout-btn {
    background-color: var(--error-color);
    color: var(--secondary-color);
    padding: 8px 15px;
    border: none;
    border-radius: 5px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85em;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.logout-btn:hover {
    background-color: #c82333;
}

/* ================== Layout Principal (SPA) ================== */
.admin-page-wrapper {
    display: flex;
    width: 100%;
    flex-grow: 1;
}

/* Sidebar Navigation */
.sidebar-nav {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    flex-shrink: 0;
    padding-top: 20px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav ul li a {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    color: var(--sidebar-text);
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-nav ul li a:hover {
    background-color: var(--sidebar-hover);
    color: var(--accent-color);
}

.sidebar-nav ul li a i {
    font-size: 1.2em;
    margin-right: 15px;
    width: 25px;
    text-align: center;
}

.sidebar-nav ul li a.active-link {
    background-color: var(--sidebar-hover);
    color: var(--accent-color);
    border-left: 5px solid var(--accent-color);
    padding-left: 15px;
}

/* Main Content Area */
.main-content-area {
    flex-grow: 1;
    padding: 30px;
    background-color: #f0f2f5;
    position: relative;
    max-width: calc(100% - var(--sidebar-width));
    /* Evita desbordamiento horizontal */
}

/* Vistas de la SPA */
.admin-view {
    display: none;
    width: 100%;
    animation: fadeIn 0.4s ease;
}

.admin-view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.main-content-area h1 {
    font-size: 2.2em;
    margin-bottom: 25px;
}

.container-card {
    background-color: var(--secondary-color);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    padding: 25px;
    margin-bottom: 25px;
}

/* ================== Dashboard ================== */
.summary-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background-color: var(--secondary-color);
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    text-align: left;
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-card .icon {
    font-size: 3em;
    color: var(--info-color);
    flex-shrink: 0;
}

.stat-card .details h4 {
    font-size: 1.8em;
    margin-bottom: 5px;
    color: var(--primary-color);
}

.stat-card .details p {
    font-size: 0.9em;
    color: var(--dark-grey);
    margin-bottom: 0;
}

.stat-card.total-visits .icon {
    color: #f39c12;
}

.stat-card.whatsapp-messages .icon {
    color: #25d366;
}

.stat-card.top-products .icon {
    color: #2980b9;
}

.stat-card.top-consulted .icon {
    color: #8e44ad;
}

/* Grid de tablas pequeñas en Dashboard */
.product-overview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.product-overview-section {
    background-color: var(--secondary-color);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.product-overview-section h2 {
    font-size: 1.4em;
    margin-bottom: 15px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--light-grey);
    padding-bottom: 10px;
}

.product-overview-table {
    width: 100%;
    border-collapse: collapse;
}

.product-overview-table th,
.product-overview-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid var(--light-grey);
    font-size: 0.9em;
    vertical-align: middle;
}

.product-overview-table th {
    background-color: #fafafa;
    color: var(--dark-grey);
}

.product-overview-table img {
    max-width: 40px;
    height: 40px;
    object-fit: contain;
}

/* ================== Tablas y Filtros (Productos / Stock) ================== */
.product-list-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 20px;
}

.header-title-row {
    display: flex;
    align-items: center;
    gap: 20px;
}

.product-count-badge {
    background: var(--accent-color);
    color: #000;
    font-size: 0.8em;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 700;
    vertical-align: middle;
}

.btn-new-product {
    background: var(--primary-color);
    color: #fff;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9em;
}

.btn-new-product:hover {
    background: #333;
    transform: translateY(-2px);
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--secondary-color);
    border: 1.5px solid var(--mid-grey);
    border-radius: 10px;
    padding: 10px 15px;
    width: 100%;
    max-width: 400px;
}

.search-bar:focus-within {
    border-color: var(--primary-color);
}

.search-bar input {
    border: none;
    outline: none;
    width: 100%;
    font-family: 'Poppins', sans-serif;
}

/* Filtros rápidos (Botones) */
.category-filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.filter-btn {
    padding: 8px 18px;
    border: 1.5px solid var(--mid-grey);
    border-radius: 25px;
    background: var(--secondary-color);
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn.active,
.filter-btn:hover {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* Filtros Stock (Selects/Checkbox) */
.filter-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    align-items: center;
    background: var(--secondary-color);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
}

.filter-controls .form-group {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-controls .form-group.checkbox-group {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.filter-controls select,
.filter-controls input[type="text"] {
    padding: 8px 12px;
    border: 1px solid var(--mid-grey);
    border-radius: 6px;
}

/* Tabla Principal */
.table-wrapper {
    background: var(--secondary-color);
    border-radius: 12px;
    overflow-x: auto;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
}

.main-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

.main-table th {
    background: #1a1a1a;
    color: #fff;
    padding: 15px;
    text-align: left;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.85em;
    text-transform: uppercase;
}

.main-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--light-grey);
    vertical-align: middle;
    font-size: 0.9em;
}

.main-table tr:hover {
    background: #fafafa;
}

.img-cell img {
    width: 50px;
    height: 50px;
    object-fit: contain;
    border-radius: 5px;
    border: 1px solid var(--mid-grey);
}

.product-name {
    font-weight: 600;
    color: var(--primary-color);
}

.product-sku {
    font-size: 0.8em;
    color: var(--dark-grey);
}

.price-cell {
    font-weight: 700;
    font-size: 1.05em;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75em;
    font-weight: 700;
}

.status-badge.active {
    background: #d4edda;
    color: #155724;
}

.status-badge.inactive {
    background: #f8d7da;
    color: #721c24;
}

.status-badge.oferta {
    background: #fff3cd;
    color: #856404;
    margin-top: 5px;
}

.stock-status-low {
    color: var(--error-color);
    font-weight: 700;
}

.stock-status-ok {
    color: var(--success-color);
    font-weight: 700;
}

.actions-cell button {
    padding: 6px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    margin-right: 5px;
    transition: all 0.2s;
}

.edit-btn {
    background: var(--accent-color);
    color: #000;
}

.edit-btn:hover {
    background: #e6c100;
}

.delete-btn {
    background: #f8d7da;
    color: var(--error-color);
}

.delete-btn:hover {
    background: var(--error-color);
    color: #fff;
}

/* Estados (Empty/Loading) */
.empty-state,
.loading-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--dark-grey);
    background: var(--secondary-color);
    border-radius: 12px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--mid-grey);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ================== Formulario de Producto ================== */
.form-container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--secondary-color);
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.btn-back {
    background: transparent;
    border: none;
    color: var(--dark-grey);
    cursor: pointer;
    font-weight: 600;
    margin-bottom: 20px;
}

.btn-back:hover {
    color: var(--primary-color);
}

.form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--light-grey);
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.form-header h2 {
    margin: 0;
}

.form-mode-badge {
    background: var(--primary-color);
    color: #fff;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
}

.form-mode-badge.editing {
    background: var(--warning-color);
    color: #000;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px 20px;
}

.form-group-full {
    grid-column: 1 / -1;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.85em;
    color: var(--dark-grey);
    margin-bottom: 5px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1.5px solid var(--mid-grey);
    border-radius: 8px;
    font-family: inherit;
    background: #fafafa;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--primary-color);
    background: #fff;
    outline: none;
}

.image-upload-area {
    border: 2px dashed var(--mid-grey);
    padding: 20px;
    text-align: center;
    border-radius: 10px;
    cursor: pointer;
    background: #fafafa;
}

.image-upload-area:hover {
    border-color: var(--primary-color);
}

.image-upload-area input[type="file"] {
    display: none;
}

.image-preview {
    max-width: 150px;
    height: 100px;
    object-fit: contain;
    display: none;
    margin: 10px auto 0;
}

.switch-group {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #fafafa;
    border: 1px solid var(--light-grey);
    border-radius: 8px;
    margin-bottom: 15px;
}

.switch-label {
    flex: 1;
    font-weight: 600;
    font-size: 0.9em;
    margin: 0;
}

.switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #ccc;
    border-radius: 24px;
    transition: .3s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: .3s;
}

input:checked+.slider {
    background: var(--success-color);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* Accordion sections form */
.form-section-toggle {
    width: 100%;
    background: var(--light-grey);
    border: none;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.form-section-toggle .arrow {
    transition: transform 0.2s;
}

.form-section-toggle.open .arrow {
    transform: rotate(90deg);
}

.form-section-content {
    display: none;
    padding: 10px;
}

.form-section-content.open {
    display: block;
}

.form-actions {
    display: flex;
    gap: 15px;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--light-grey);
}

.btn-save {
    flex: 2;
    background: var(--primary-color);
    color: #fff;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}

.btn-save:hover {
    background: #333;
}

.btn-cancel {
    flex: 1;
    background: var(--light-grey);
    padding: 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

/* Cambiar Contraseña Form */
.change-password-section {
    max-width: 500px;
    margin: 0 auto;
}

/* ================== Utils ================== */
.message {
    padding: 12px 18px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 600;
    text-align: center;
    display: none;
}

.message.success {
    background-color: #d4edda;
    color: #155724;
}

.message.error {
    background-color: #f8d7da;
    color: #721c24;
}

.message.info {
    background-color: #cce5ff;
    color: #004085;
}

/* ================== Responsive ================== */
@media (max-width: 900px) {
    .admin-page-wrapper {
        flex-direction: column;
    }

    .sidebar-nav {
        width: 100%;
        height: auto;
        position: relative;
        top: 0;
    }

    .sidebar-nav ul {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .sidebar-nav ul li a {
        padding: 10px;
        flex-direction: column;
        font-size: 0.85em;
    }

    .sidebar-nav ul li a i {
        margin: 0 0 5px 0;
    }

    .sidebar-nav ul li a.active-link {
        border-left: none;
        border-bottom: 3px solid var(--accent-color);
    }

    .main-content-area {
        padding: 15px;
        max-width: 100%;
    }

    .product-overview-grid {
        grid-template-columns: 1fr;
    }

    .form-grid-2 {
        grid-template-columns: 1fr;
    }

    .main-header {
        padding: 0 15px;
    }

    .main-header .logo .logo-text {
        font-size: 2em;
    }

    .admin-greeting,
    .store-links {
        display: none;
    }
}