/*
 * Catálogo WhatsApp Pro — Panel CSS
 * Clean rewrite. No conflicting rules. No !important wars.
 */

/* ================================================================
   BASE / RESET for panel scope
================================================================ */
#cwp-panel, #cwp-panel * {
    box-sizing: border-box;
}

/* ================================================================
   ALERTS
================================================================ */
.cwp-alert {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: .85rem;
    margin-bottom: 12px;
    display: none;
}
.cwp-alert--success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.cwp-alert--error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.cwp-alert--warn    { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.cwp-alert--info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ================================================================
   PANEL WRAPPER
================================================================ */
.cwp-panel-wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: #111;
}

/* ================================================================
   PANEL HEADER
================================================================ */
.cwp-panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e5e7eb;
    flex-wrap: wrap;
}
.cwp-panel-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}
.cwp-panel-logo img {
    width: 32px;
    height: 32px;
}
.cwp-panel-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: #111;
    margin: 0;
}
.cwp-panel-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
    flex-wrap: wrap;
}

/* ================================================================
   BUTTONS
================================================================ */
.cwp-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 6px;
    border: 1.5px solid transparent;
    font-size: .82rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    text-decoration: none;
    line-height: 1;
}
.cwp-btn--primary  { background: #25D366; color: #fff; border-color: #25D366; }
.cwp-btn--primary:hover { background: #1fa855; border-color: #1fa855; color: #fff; }
.cwp-btn--ghost    { background: #fff; color: #374151; border-color: #e5e7eb; }
.cwp-btn--ghost:hover { border-color: #9ca3af; }
.cwp-btn--danger   { color: #dc2626; border-color: #fca5a5; background: #fff; }
.cwp-btn--danger:hover { background: #fef2f2; }
.cwp-btn--sm { padding: 6px 12px; font-size: .78rem; }

/* Icon button (table actions) */
.cwp-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    color: #374151;
    transition: all .12s;
    padding: 0;
}
.cwp-btn-icon:hover              { border-color: #9ca3af; background: #f9fafb; }
.cwp-btn-icon--delete:hover      { border-color: #fca5a5; color: #dc2626; background: #fef2f2; }

/* ================================================================
   LOGIN SCREEN
================================================================ */
.cwp-login-screen {
    max-width: 380px;
    margin: 40px auto;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 32px;
    text-align: center;
}
.cwp-login-screen h2 { font-size: 1.2rem; margin: 0 0 8px; }
.cwp-login-screen p  { color: #6b7280; font-size: .85rem; margin: 0 0 20px; }
.cwp-input-wrap {
    position: relative;
    margin-bottom: 12px;
    text-align: left;
}
.cwp-input-toggle-pw {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: .8rem;
    padding: 0;
}

/* ================================================================
   FORM INPUTS
================================================================ */
.cwp-input, .cwp-select, .cwp-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #e5e7eb;
    border-radius: 6px;
    font-size: .875rem;
    background: #fff;
    color: #374151;
    transition: border-color .15s;
    font-family: inherit;
}
.cwp-input:focus, .cwp-select:focus, .cwp-textarea:focus {
    outline: none;
    border-color: #25D366;
    box-shadow: 0 0 0 3px rgba(37,211,102,.12);
}
.cwp-textarea { resize: vertical; min-height: 80px; }
.cwp-input--sm { padding: 6px 10px; font-size: .82rem; }

.cwp-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.cwp-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cwp-form-group label {
    font-size: .8rem;
    font-weight: 600;
    color: #374151;
}
.cwp-form-group--full { grid-column: 1 / -1; }
.cwp-form-group .cwp-note {
    font-size: .75rem;
    color: #9ca3af;
    margin: 2px 0 0;
}

/* ================================================================
   STATS BAR
================================================================ */
.cwp-stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.cwp-stat {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px 16px;
    text-align: center;
}
.cwp-stat__value {
    display: block;
    font-size: 1.8rem;
    font-weight: 800;
    color: #111;
    line-height: 1;
    margin-bottom: 4px;
}
.cwp-stat__value--warn   { color: #b5770d; }
.cwp-stat__value--danger { color: #dc2626; }
.cwp-stat__label { font-size: .75rem; color: #6b7280; font-weight: 500; }

/* ================================================================
   TABLE FILTERS
================================================================ */
.cwp-table-filters {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.cwp-filter-search {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1.5px solid #e5e7eb;
    border-radius: 20px;
    padding: 6px 12px;
    flex: 1;
    min-width: 160px;
    background: #fff;
}
.cwp-filter-search svg { color: #9ca3af; flex-shrink: 0; }
.cwp-filter-search input { border: none; outline: none; font-size: .82rem; width: 100%; background: transparent; }

/* ================================================================
   PRODUCTS TABLE
================================================================ */
.cwp-table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid #e5e7eb; }
.cwp-table { width: 100%; border-collapse: collapse; background: #fff; min-width: 500px; }
.cwp-table th {
    padding: 10px 12px;
    text-align: left;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #6b7280;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}
.cwp-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
    font-size: .85rem;
}
.cwp-table tr:last-child td { border-bottom: none; }
.cwp-table tr:hover td { background: #fafafa; }
.cwp-table-img {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}
.cwp-table-img-placeholder {
    width: 44px;
    height: 44px;
    background: #f3f4f6;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}
.cwp-product-name-cell { font-weight: 600; max-width: 200px; }
.cwp-id-badge {
    display: inline-block;
    background: #f3f4f6;
    color: #374151;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: .75rem;
    font-family: monospace;
}
.cwp-table-actions { display: flex; gap: 4px; }
.cwp-stock-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
}
.cwp-stock-badge--in  { background: #dcfce7; color: #166534; }
.cwp-stock-badge--low { background: #fef9c3; color: #854d0e; }
.cwp-stock-badge--out { background: #fee2e2; color: #991b1b; }

/* ================================================================
   MODAL OVERLAY & MODAL
================================================================ */
.cwp-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.5);
    z-index: 999999;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px;
    overflow-y: auto;
}
.cwp-modal {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 720px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    margin: auto;
    position: relative;
}
.cwp-modal--sm { max-width: 420px; }

.cwp-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid #f3f4f6;
    flex-shrink: 0;
}
.cwp-modal__title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
    color: #111;
}
.cwp-modal__close {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1.5px solid #e5e7eb;
    background: #fff;
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: 700;
    color: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}
.cwp-modal__close:hover { background: #f3f4f6; }

/* ================================================================
   MODAL TABS — desktop
================================================================ */
.cwp-modal-tabs {
    display: flex;
    border-bottom: 2px solid #f3f4f6;
    padding: 0 22px;
    gap: 4px;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.cwp-modal-tabs::-webkit-scrollbar { display: none; }

.cwp-mtab {
    padding: 12px 14px;
    border: none;
    background: none;
    font-size: .82rem;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color .12s, border-color .12s;
}
.cwp-mtab:hover  { color: #374151; }
.cwp-mtab.active { color: #25D366; border-bottom-color: #25D366; }

/* ================================================================
   MODAL BODY & PANELS
   Panel visibility is controlled 100% by jQuery .show() / .hide()
   No CSS display rules for cwp-mpanel so there's NOTHING to conflict with
================================================================ */
.cwp-modal__body {
    padding: 20px 22px;
    overflow-y: auto;
    flex: 1;
    max-height: 65vh;
}

/* cwp-mpanel: NO display rule here. jQuery controls visibility. */
.cwp-mpanel {
    width: 100%;
}

.cwp-modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid #f3f4f6;
    flex-shrink: 0;
}
.cwp-modal__footer .cwp-spinner {
    width: 16px; height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: #25D366;
    border-radius: 50%;
    animation: cwpSpin .6s linear infinite;
    display: none;
    margin-left: 6px;
}
@keyframes cwpSpin { to { transform: rotate(360deg); } }

/* ================================================================
   MODAL FORM — checkboxes for payment methods
================================================================ */
.cwp-modal-pago-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.cwp-modal-pago-check {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border: 1.5px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    font-size: .82rem;
    transition: border-color .12s;
}
.cwp-modal-pago-check:hover { border-color: #25D366; }
.cwp-modal-pago-check input { accent-color: #25D366; }
.cwp-checkboxes { display: flex; flex-direction: column; gap: 8px; }
.cwp-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .85rem;
    cursor: pointer;
}
.cwp-checkbox-label input[type="checkbox"] { accent-color: #25D366; }
.cwp-select { cursor: pointer; }

/* Add term row */
.cwp-add-term-row {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}
.cwp-add-term-row input {
    flex: 1;
}

/* ================================================================
   IMAGE UPLOAD
================================================================ */
.cwp-images-section { display: flex; flex-direction: column; gap: 20px; }
.cwp-img-section h4 { font-size: .875rem; font-weight: 700; color: #374151; margin: 0 0 10px; }
.cwp-portada-wrap {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    flex-wrap: wrap;
}
.cwp-portada-preview {
    width: 100px;
    height: 100px;
    border-radius: 8px;
    background: #f3f4f6;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid #e5e7eb;
}
.cwp-img-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 4px;
    color: #9ca3af;
    font-size: .65rem;
}
.cwp-img-upload-area { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cwp-drop-zone {
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    padding: 24px 16px;
    text-align: center;
    background: #f9fafb;
    cursor: pointer;
    transition: border-color .12s;
}
.cwp-drop-zone:hover, .cwp-drop-zone.drag-over { border-color: #25D366; background: #f0fdf4; }
.cwp-drop-zone p  { margin: 6px 0 10px; font-size: .82rem; color: #6b7280; }
.cwp-drop-zone .cwp-note { font-size: .72rem; color: #9ca3af; margin: 8px 0 0; }
.cwp-gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 12px;
}
.cwp-gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    background: #f3f4f6;
}
.cwp-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.cwp-gallery-item__delete {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0,0,0,.6);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.cwp-upload-progress { margin-top: 10px; }
.cwp-progress-bar { background: #f3f4f6; border-radius: 4px; height: 6px; overflow: hidden; }
.cwp-progress-fill { background: #25D366; height: 100%; width: 0%; transition: width .2s; }
#cwp-progress-text { font-size: .72rem; color: #6b7280; margin-top: 4px; display: block; }

/* ================================================================
   STOCK MODAL
================================================================ */
.cwp-stock-product-info {
    background: #f9fafb;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: .85rem;
    color: #374151;
}

/* ================================================================
   MOBILE — 768px and below
================================================================ */
@media (max-width: 768px) {

    /* Stats: 2x2 grid */
    .cwp-stats-bar { grid-template-columns: repeat(2, 1fr); }

    /* Form grid: 1 column */
    .cwp-form-grid { grid-template-columns: 1fr; }

    /* Payment methods: 2 columns */
    .cwp-modal-pago-grid { grid-template-columns: repeat(2, 1fr); }

    /* Gallery: 3 columns */
    .cwp-gallery-grid { grid-template-columns: repeat(3, 1fr); }

    /* Modal: full screen bottom sheet */
    .cwp-modal-overlay {
        padding: 0;
        align-items: flex-end;
        overflow: hidden;
    }
    .cwp-modal {
        border-radius: 16px 16px 0 0;
        max-width: 100vw;
        width: 100vw;
        height: 94vh;
        max-height: 94vh;
        margin: 0;
    }
    .cwp-modal__body {
        max-height: none;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
    }

    /* Tabs: hide on mobile, show all panels as sections */
    .cwp-modal-tabs {
        display: none;
    }

    /*
     * MOBILE PANELS: ALL visible, stacked vertically.
     * jQuery hides them on desktop via .hide() — but on mobile
     * we override with display:block to show everything.
     * This is the ONLY display rule for cwp-mpanel.
     */
    .cwp-mpanel {
        display: block !important;
        margin-bottom: 24px;
    }

    /* Section header label before each panel on mobile */
    .cwp-mpanel::before {
        content: attr(data-label);
        display: block;
        font-size: .7rem;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: .08em;
        color: #9ca3af;
        padding-bottom: 8px;
        border-bottom: 1px solid #f3f4f6;
        margin-bottom: 12px;
    }

    /* Table: smaller cells */
    .cwp-table th,
    .cwp-table td { padding: 8px; font-size: .78rem; }
    .cwp-table-img, .cwp-table-img-placeholder { width: 36px; height: 36px; }
    .cwp-product-name-cell { max-width: 100px; font-size: .78rem; }

    /* Panel actions */
    .cwp-panel-actions { margin-left: 0; width: 100%; }
    .cwp-panel-header { flex-direction: column; align-items: flex-start; }
}

/* Settings modal section titles */
.cwp-settings-section-title {
    font-size: .75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #9ca3af;
    margin: 0 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #f3f4f6;
}
