/* ========================================================================
   ML MODULE — Shared modern UX stylesheet
   Inputs, modais, form sections, botões, cards e tabelas.
   Aplica regras com ESPECIFICIDADE de página (html body.ml-page) para
   sobrescrever estilos antigos sem !important.
   Links via <link rel="stylesheet" href="/css/ml-module.css"> e
   adicionamos `class="ml-page"` ao <body> (ou body inicia com ml-).
   ======================================================================== */

html body [class*="ml-"],
html body .ml-page,
html body {
    /* design tokens ML */
    --ml-ring: 0 0 0 3px rgba(99, 102, 241, 0.18);
    --ml-ring-success: 0 0 0 3px rgba(34, 197, 94, 0.2);
    --ml-ring-danger: 0 0 0 3px rgba(220, 38, 38, 0.18);
    --ml-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --ml-shadow-md: 0 4px 14px rgba(15, 23, 42, 0.06);
    --ml-shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.15);
    --ml-input-bg: var(--bg-primary, #fff);
    --ml-input-border: var(--border-color, #d1d5db);
    --ml-input-border-strong: var(--border, #cbd5e1);
}

/* ------------------ INPUT / SELECT / TEXTAREA ------------------ */
html body .modal .form-group input[type="text"],
html body .modal .form-group input[type="number"],
html body .modal .form-group input[type="email"],
html body .modal .form-group input[type="search"],
html body .modal .form-group input[type="url"],
html body .modal .form-group input[type="tel"],
html body .modal .form-group input[type="date"],
html body .modal .form-group input[type="datetime-local"],
html body .modal .form-group input[type="password"],
html body .modal .form-group select,
html body .modal .form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--ml-input-border);
    border-radius: 10px;
    background: var(--ml-input-bg);
    color: var(--text-primary, #1a1a2e);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    box-shadow: var(--ml-shadow-sm);
    line-height: 1.4;
}
html body .modal .form-group input:hover,
html body .modal .form-group select:hover,
html body .modal .form-group textarea:hover {
    border-color: var(--ml-input-border-strong);
}
html body .modal .form-group input:focus,
html body .modal .form-group select:focus,
html body .modal .form-group textarea:focus {
    border-color: var(--accent, #6366f1);
    box-shadow: var(--ml-ring);
    background: var(--bg-primary, #fff);
}
html body .modal .form-group input::placeholder,
html body .modal .form-group textarea::placeholder {
    color: var(--text-tertiary, #9ca3af);
    opacity: 1;
    font-weight: 400;
}
html body .modal .form-group input:disabled,
html body .modal .form-group select:disabled,
html body .modal .form-group textarea:disabled {
    background: var(--bg-secondary, #f3f4f6);
    color: var(--text-tertiary, #9ca3af);
    cursor: not-allowed;
}
html body .modal .form-group input[readonly] {
    background: var(--bg-secondary, #f8fafc);
    cursor: pointer;
}
html body .modal .form-group textarea { min-height: 110px; resize: vertical; }

/* Select com seta custom */
html body .modal .form-group select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 12px;
    padding-right: 38px;
}

/* Label moderno */
html body .modal .form-group label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1a1a2e);
    margin-bottom: 8px;
    letter-spacing: -0.1px;
}
html body .modal .form-group label .char-counter {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary, #6b7280);
    background: var(--bg-secondary, #f3f4f6);
    padding: 2px 8px;
    border-radius: 6px;
    font-variant-numeric: tabular-nums;
}

/* Grupo com "hint" abaixo */
html body .modal .form-hint {
    margin: 6px 0 0;
    font-size: 11px;
    color: var(--text-secondary, #6b7280);
    line-height: 1.5;
}

/* ------------------ MODAL ------------------ */
html body .modal-overlay {
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 24px;
}
html body .modal {
    background: var(--bg-primary, #fff);
    border-radius: 18px;
    padding: 24px 28px;
    width: 100%;
    max-width: 520px;
    box-shadow: var(--ml-shadow-lg);
    max-height: 92vh;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.05));
    scrollbar-width: thin;
    scrollbar-color: var(--border, #cbd5e1) transparent;
}
html body .modal::-webkit-scrollbar { width: 8px; }
html body .modal::-webkit-scrollbar-track { background: transparent; }
html body .modal::-webkit-scrollbar-thumb { background: var(--border, #cbd5e1); border-radius: 4px; }
html body .modal-large .modal { max-width: 780px; }
html body .modal > h3 {
    margin: 0 0 20px;
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary, #1a1a2e);
    display: flex;
    align-items: center;
    gap: 12px;
    letter-spacing: -0.3px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
html body .modal > h3 > i {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--bg-secondary, #f3f4f6);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
/* modal-actions: não sticky — rola junto com o conteúdo */
html body .modal .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

/* ------------------ FORM SECTION ------------------ */
html body .modal .form-section {
    background: var(--bg-secondary, #f8fafc);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    padding: 20px 22px;
    margin-bottom: 18px;
    box-shadow: var(--ml-shadow-sm);
}
html body .modal .form-section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 800;
    color: var(--text-primary, #1a1a2e);
    margin: 0 0 6px;
    letter-spacing: -0.2px;
}
html body .modal .form-section-title i {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(139, 92, 246, 0.12));
    color: var(--accent, #6366f1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
}
html body .modal .form-section-desc {
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
    margin: 0 0 14px;
    line-height: 1.6;
}

/* Inputs DENTRO de form-section: mantêm bg-primary para contraste */
html body .modal .form-section .form-group input[type="text"],
html body .modal .form-section .form-group input[type="number"],
html body .modal .form-section .form-group input[type="email"],
html body .modal .form-section .form-group input[type="search"],
html body .modal .form-section .form-group input[type="url"],
html body .modal .form-section .form-group select,
html body .modal .form-section .form-group textarea {
    background: var(--bg-primary, #fff);
}

/* ------------------ BOTÕES DO MODAL ------------------ */
html body .modal .btn {
    padding: 11px 22px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
    line-height: 1;
    letter-spacing: -0.1px;
}
html body .modal .btn:hover { transform: translateY(-1px); }
html body .modal .btn:active { transform: translateY(0); }
html body .modal .btn:focus-visible { box-shadow: var(--ml-ring); }
html body .modal .btn-primary {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
html body .modal .btn-primary:hover { box-shadow: 0 4px 14px rgba(99, 102, 241, 0.45); }
html body .modal .btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}
html body .modal .btn-success:hover { box-shadow: 0 4px 14px rgba(16, 185, 129, 0.45); }
html body .modal .btn-outline {
    background: transparent;
    color: var(--text-primary, #1a1a2e);
    border: 1.5px solid var(--border, #cbd5e1);
}
html body .modal .btn-outline:hover { background: var(--bg-secondary, #f3f4f6); }
html body .modal .btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

/* Toggle row moderno */
html body .modal .toggle-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-primary, #fff);
    border: 1.5px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
}
html body .modal .toggle-row:hover { border-color: var(--accent, #6366f1); }
html body .modal .toggle-row input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 40px;
    height: 22px;
    background: var(--border, #cbd5e1);
    border-radius: 22px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    margin-top: 2px;
    transition: background 0.2s ease;
}
html body .modal .toggle-row input[type="checkbox"]::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
html body .modal .toggle-row input[type="checkbox"]:checked {
    background: var(--accent, #6366f1);
}
html body .modal .toggle-row input[type="checkbox"]:checked::after {
    transform: translateX(18px);
}
html body .modal .toggle-row .toggle-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
html body .modal .toggle-row .toggle-text strong {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary, #1a1a2e);
}
html body .modal .toggle-row .toggle-text small {
    font-size: 11px;
    color: var(--text-secondary, #6b7280);
    line-height: 1.5;
}

/* ------------------ TOOLBAR / FILTROS ------------------ */
html body .toolbar {
    background: var(--bg-primary, #fff);
    border-radius: 14px;
    padding: 12px 16px;
    box-shadow: var(--ml-shadow-sm);
    border: 1px solid var(--border-color, #e5e7eb);
}
html body .toolbar input,
html body .toolbar select {
    background: var(--bg-secondary, #f8fafc);
    border: 1.5px solid transparent;
    border-radius: 9px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #1a1a2e);
    transition: all 0.15s ease;
}
html body .toolbar input:focus,
html body .toolbar select:focus {
    background: var(--bg-primary, #fff);
    border-color: var(--accent, #6366f1);
    box-shadow: var(--ml-ring);
    outline: none;
}

/* ------------------ STAT CARDS ------------------ */
html body .stats-row .stat-card,
html body .stats-grid .stat-card {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 16px;
    padding: 18px 20px;
    box-shadow: var(--ml-shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
html body .stats-row .stat-card:hover,
html body .stats-grid .stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--ml-shadow-md);
}
html body .stat-card .stat-icon {
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.22);
}

/* ------------------ TABELAS ------------------ */
html body .table-wrap,
html body table.ml-table {
    background: var(--bg-primary, #fff);
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--border-color, #e5e7eb);
    box-shadow: var(--ml-shadow-sm);
}
html body .table-wrap table th,
html body table.ml-table th {
    background: var(--bg-secondary, #f8fafc);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.4px;
    color: var(--text-secondary, #6b7280);
    font-weight: 700;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
html body .table-wrap table tr:hover td,
html body table.ml-table tr:hover td { background: var(--bg-secondary, #f8fafc); }
html body .table-wrap table td,
html body table.ml-table td { padding: 14px 16px; }

/* ------------------ VARIATIONS ROW (cores) ------------------ */
html body .variation-row {
    display: grid !important;
    grid-template-columns: 40px minmax(120px, 1.3fr) 90px 110px 80px auto !important;
    gap: 10px !important;
    align-items: center !important;
    background: var(--bg-primary, #fff) !important;
    border: 1.5px solid var(--border-color, #e5e7eb) !important;
    border-radius: 12px !important;
    padding: 10px 12px !important;
    box-shadow: var(--ml-shadow-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
html body .variation-row:hover {
    border-color: var(--accent, #6366f1) !important;
    box-shadow: var(--ml-shadow-md);
}
html body .variation-row input[type="text"],
html body .variation-row input[type="number"] {
    width: 100% !important;
    padding: 9px 11px !important;
    border-radius: 9px !important;
    border: 1.5px solid var(--border-color, #e5e7eb) !important;
    background: var(--bg-secondary, #f8fafc) !important;
    color: var(--text-primary, #1a1a2e) !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    transition: all 0.15s ease;
    min-width: 0;
    box-sizing: border-box;
    outline: none;
}
html body .variation-row input:focus {
    background: var(--bg-primary, #fff) !important;
    border-color: var(--accent, #6366f1) !important;
    box-shadow: var(--ml-ring) !important;
}
html body .variation-row .color-swatch {
    width: 34px !important;
    height: 34px !important;
    border-radius: 10px !important;
    border: 2px solid var(--border, #cbd5e1) !important;
    box-shadow: inset 0 0 0 2px #fff, 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.12s ease;
    cursor: pointer;
    flex-shrink: 0;
}
html body .variation-row .color-swatch:hover { transform: scale(1.08); }
/* Container da última coluna (imagem + botão X) */
html body .variation-row > div:last-child {
    display: flex !important;
    gap: 6px !important;
    align-items: center !important;
    justify-content: flex-end;
}
html body .variation-row .var-thumb,
html body .variation-row .var-thumb-btn {
    width: 36px !important;
    height: 36px !important;
    border-radius: 9px !important;
    flex-shrink: 0 !important;
}
html body .variation-row .var-thumb {
    object-fit: cover;
    cursor: pointer;
    border: 1.5px solid var(--border-color, #e5e7eb);
}
html body .variation-row .var-thumb-btn {
    border: 1.5px dashed var(--border, #cbd5e1) !important;
    background: var(--bg-secondary, #f8fafc) !important;
    color: var(--text-secondary, #6b7280) !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 13px;
    transition: all 0.15s ease;
}
html body .variation-row .var-thumb-btn:hover {
    border-color: var(--accent, #6366f1) !important;
    color: var(--accent, #6366f1) !important;
}
html body .variation-row .btn-del-var {
    width: 34px !important;
    height: 34px !important;
    border-radius: 50% !important;
    border: 1.5px solid rgba(220, 38, 38, 0.3) !important;
    background: var(--bg-primary, #fff) !important;
    color: #dc2626 !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 12px !important;
    padding: 0 !important;
    flex-shrink: 0;
    transition: all 0.12s ease;
}
html body .variation-row .btn-del-var:hover {
    background: #dc2626 !important;
    color: #fff !important;
    border-color: #dc2626 !important;
    transform: scale(1.06);
}

/* ------------------ PLAN CARDS ------------------ */
html body .plan-card {
    background: var(--bg-primary, #fff);
    box-shadow: var(--ml-shadow-sm);
    transition: all 0.15s ease;
}
html body .plan-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--ml-shadow-md);
}

/* ------------------ UPLOAD ZONE ------------------ */
html body .upload-zone {
    background: var(--bg-secondary, #f8fafc);
    border: 2px dashed var(--border, #cbd5e1);
    border-radius: 14px;
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s ease;
}
html body .upload-zone:hover,
html body .upload-zone.dragover {
    border-color: var(--accent, #6366f1);
    background: var(--bg-primary, #fff);
    box-shadow: var(--ml-ring);
}

/* ------------------ BADGE GLOBAL (keep solid colors per memory rule) ------------------ */
html body .badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: #fff;
    white-space: nowrap;
}

/* ------------------ DARK THEME tweaks ------------------ */
html.dark-theme body .modal-overlay,
.dark-theme html body .modal-overlay { background: rgba(0, 0, 0, 0.65); }
html.dark-theme body .modal .form-group input,
html.dark-theme body .modal .form-group select,
html.dark-theme body .modal .form-group textarea,
.dark-theme html body .modal .form-group input,
.dark-theme html body .modal .form-group select,
.dark-theme html body .modal .form-group textarea {
    background: var(--bg-input, #273549);
    border-color: var(--input-border, rgba(255, 255, 255, 0.15));
    color: var(--text-primary, #f1f5f9);
}
html.dark-theme body .modal .form-section,
.dark-theme html body .modal .form-section {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.08);
}
html.dark-theme body .toolbar,
html.dark-theme body .stat-card,
html.dark-theme body .table-wrap,
.dark-theme html body .toolbar,
.dark-theme html body .stat-card,
.dark-theme html body .table-wrap {
    background: var(--bg-card, #1e293b);
    border-color: rgba(255, 255, 255, 0.08);
}

/* ------------------ RESPONSIVIDADE ------------------ */
@media (max-width: 720px) {
    html body .modal { max-width: 100%; border-radius: 14px; }
    html body .modal > h3 { padding: 18px 20px 14px; font-size: 16px; }
    html body .modal > *:not(h3):not(.modal-actions) { padding-left: 20px; padding-right: 20px; }
    html body .modal > .modal-actions { padding: 12px 20px; }
    html body .modal .form-section { padding: 16px; }
    html body .variation-row {
        grid-template-columns: 34px minmax(80px, 1fr) 60px auto !important;
        gap: 6px !important;
        padding: 8px !important;
    }
    html body .variation-row input.var-sku,
    html body .variation-row input.var-price { display: none; }
}
