/*
 * NestStock — Theme System (claro/escuro)
 * ------------------------------------------------------------------
 * Fonte única de verdade para cores e componentes visuais.
 * Inclua em cada página (ajuste o caminho conforme a pasta):
 *     <link rel="stylesheet" href="theme.css">        (raiz)
 *     <link rel="stylesheet" href="../theme.css">     (admin/ , user/)
 * E o script de tema logo em seguida:
 *     <script src="theme.js"></script>
 *
 * O tema é controlado pelo atributo data-theme no <html>:
 *     <html data-theme="dark">  |  <html data-theme="light">
 * O theme.js aplica o valor salvo em localStorage automaticamente.
 * ================================================================== */

/* ── TOKENS: TEMA ESCURO (padrão) ─────────────────────────────────── */
:root,
html[data-theme="dark"] {
    --bg-gradient:      linear-gradient(135deg, #020617 0%, #0f172a 100%);
    --surface:         rgba(15, 23, 42, 0.7);
    --surface-2:       rgba(15, 23, 42, 0.4);
    --surface-solid:   #0f172a;
    --border:          rgba(34, 211, 238, 0.12);
    --border-muted:    rgba(71, 85, 105, 0.35);
    --border-strong:   rgba(71, 85, 105, 0.6);

    --text:            #e2e8f0;   /* corpo */
    --text-strong:     #f1f5f9;   /* títulos */
    --text-muted:      #94a3b8;   /* secundário */
    --text-subtle:     #64748b;   /* terciário */
    --text-faint:      #475569;   /* placeholders */

    --input-bg:        rgba(15, 23, 42, 0.8);
    --input-border:    rgba(71, 85, 105, 0.6);
    --input-text:      #e2e8f0;

    --primary:         #22d3ee;
    --primary-strong:  #0891b2;
    --primary-rgb:     34, 211, 238;

    --glow:            0 0 24px rgba(34, 211, 238, 0.18);
    --shadow-card:     0 10px 30px rgba(0, 0, 0, 0.35);

    color-scheme: dark;
}

/* ── TOKENS: TEMA CLARO ───────────────────────────────────────────── */
html[data-theme="light"] {
    --bg-gradient:      linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    --surface:         rgba(255, 255, 255, 0.78);
    --surface-2:       rgba(241, 245, 249, 0.7);
    --surface-solid:   #ffffff;
    --border:          rgba(8, 145, 178, 0.18);
    --border-muted:    rgba(148, 163, 184, 0.4);
    --border-strong:   rgba(148, 163, 184, 0.7);

    --text:            #1e293b;
    --text-strong:     #0f172a;
    --text-muted:      #475569;
    --text-subtle:     #64748b;
    --text-faint:      #94a3b8;

    --input-bg:        #ffffff;
    --input-border:    rgba(148, 163, 184, 0.7);
    --input-text:      #0f172a;

    --primary:         #0891b2;
    --primary-strong:  #0e7490;
    --primary-rgb:     8, 145, 178;

    --glow:            0 0 24px rgba(8, 145, 178, 0.12);
    --shadow-card:     0 10px 30px rgba(15, 23, 42, 0.08);

    color-scheme: light;
}

/* ── BASE ─────────────────────────────────────────────────────────── */
/* !important para sobrepor os <style> inline legados das páginas. */
html[data-theme] body {
    background: var(--bg-gradient) !important;
    background-attachment: fixed;
    min-height: 100vh;
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Ubuntu', 'Cantarell', sans-serif;
    transition: background-color .25s ease, color .25s ease;
}
* { box-sizing: border-box; }
.gradient-bg { background: var(--bg-gradient); }

/* Placeholders de componentes não geram caixa própria (preserva sticky/layout). */
[data-component] { display: contents; }

/* Helpers de cor baseados nos tokens (para usar no HTML) */
.text-strong { color: var(--text-strong); }
.text-body   { color: var(--text); }
.text-muted  { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }

/* ── GLASSMORPHISM ────────────────────────────────────────────────── */
/* !important para vencer as definições inline de .glass das páginas. */
.glass,
.glass-effect {
    background: var(--surface) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-color: var(--border) !important;
}
.glow,
.glow-effect { box-shadow: var(--glow); }

/* ── BADGES ───────────────────────────────────────────────────────── */
.badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: rgba(var(--primary-rgb), 0.12);
    color: var(--primary);
    border: 1px solid rgba(var(--primary-rgb), 0.22);
}
.badge-green { background: rgba(16, 185, 129, 0.12); color: #10b981; border-color: rgba(16, 185, 129, 0.25); }
.badge-red   { background: rgba(239, 68, 68, 0.12);  color: #ef4444; border-color: rgba(239, 68, 68, 0.25); }
.badge-warn  { background: rgba(245, 158, 11, 0.12); color: #d97706; border-color: rgba(245, 158, 11, 0.25); }

/* ── BOTÕES ───────────────────────────────────────────────────────── */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #fff; border: none; border-radius: 0.5rem;
    padding: 0.55rem 1.25rem; cursor: pointer; font-weight: 600;
    transition: opacity .2s, transform .1s, box-shadow .2s;
}
.btn-primary:hover:not(:disabled) { opacity: .9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-secondary {
    background: var(--surface-2); color: var(--text-muted);
    border: 1px solid var(--border-muted); border-radius: 0.5rem;
    padding: 0.55rem 1.25rem; cursor: pointer; font-weight: 500;
    font-size: 0.9rem; transition: background .2s, color .2s, border-color .2s;
}
.btn-secondary:hover { border-color: var(--border-strong); color: var(--text-strong); }

/* Botão de marca WhatsApp */
.btn-wa {
    display: inline-flex; align-items: center; gap: 0.75rem;
    background: linear-gradient(135deg, #25d366, #128c7e);
    color: #fff; border: none; border-radius: 0.625rem;
    padding: 0.8rem 1.75rem; cursor: pointer; font-weight: 700;
    font-size: 1rem; transition: opacity .2s, transform .1s, box-shadow .2s;
    box-shadow: 0 0 28px rgba(37, 211, 102, 0.3);
}
.btn-wa:hover:not(:disabled) { opacity: .9; transform: translateY(-2px); box-shadow: 0 0 36px rgba(37, 211, 102, 0.4); }
.btn-wa:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

/* Variantes compactas de ação (usadas em tabelas/cards) */
.btn-danger {
    background: rgba(239, 68, 68, 0.15); color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3); border-radius: 0.4rem;
    padding: 0.3rem 0.75rem; cursor: pointer; font-size: 0.8rem;
    transition: background .2s; text-decoration: none; display: inline-block;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.28); }

.btn-edit {
    background: rgba(var(--primary-rgb), 0.1); color: var(--primary);
    border: 1px solid rgba(var(--primary-rgb), 0.25); border-radius: 0.4rem;
    padding: 0.3rem 0.75rem; cursor: pointer; font-size: 0.8rem;
    transition: background .2s; text-decoration: none; display: inline-block;
}
.btn-edit:hover { background: rgba(var(--primary-rgb), 0.22); }

.btn-msg {
    background: rgba(99, 102, 241, 0.1); color: #6366f1;
    border: 1px solid rgba(99, 102, 241, 0.25); border-radius: 0.4rem;
    padding: 0.3rem 0.75rem; cursor: pointer; font-size: 0.8rem;
    transition: background .2s; text-decoration: none; display: inline-block;
}
.btn-msg:hover { background: rgba(99, 102, 241, 0.22); }

.btn-wa-sm {
    background: rgba(37, 211, 102, 0.1); color: #16a34a;
    border: 1px solid rgba(37, 211, 102, 0.25); border-radius: 0.4rem;
    padding: 0.3rem 0.75rem; cursor: pointer; font-size: 0.8rem;
    transition: background .2s; text-decoration: none; display: inline-block;
}
.btn-wa-sm:hover { background: rgba(37, 211, 102, 0.22); }

/* ── INPUTS ───────────────────────────────────────────────────────── */
/* Estilo global de formulário (fonte única — theme-aware). */
input, select, textarea {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    width: 100%;
    outline: none;
    transition: border-color .2s, box-shadow .2s, background .2s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.15);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input[type="radio"], input[type="checkbox"] {
    width: auto; padding: 0; border: none; background: transparent;
    accent-color: var(--primary); cursor: pointer; flex-shrink: 0;
}
input[readonly] { opacity: 0.7; cursor: default; }
label { color: var(--text-muted); font-size: 0.82rem; display: block; margin-bottom: 0.25rem; }

.ns-field { display: flex; flex-direction: column; gap: 0.4rem; }
.ns-label {
    color: var(--text-muted); font-size: 0.82rem; font-weight: 500;
}
.ns-input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
    border-radius: 0.625rem;
    padding: 0.7rem 0.9rem;
    font-size: 0.95rem;
    outline: none;
    transition: border-color .2s, box-shadow .2s, background .2s;
}
.ns-input::placeholder { color: var(--text-faint); }
.ns-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}
.ns-input:disabled { opacity: .6; cursor: not-allowed; }

/* ── PAINÉIS INTERNOS ─────────────────────────────────────────────── */
.panel {
    background: var(--surface-2);
    border: 1px solid var(--border-muted);
    border-radius: 0.75rem;
}
code, .code {
    color: var(--primary);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
}

/* ── STEPS (lista numerada) ───────────────────────────────────────── */
.step-item { display: flex; align-items: flex-start; gap: 0.85rem; }
.step-num {
    width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
    background: rgba(var(--primary-rgb), 0.1);
    border: 1px solid rgba(var(--primary-rgb), 0.3);
    color: var(--primary); font-size: 0.72rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

/* ── SPINNER ──────────────────────────────────────────────────────── */
.spinner {
    width: 48px; height: 48px; border-radius: 50%;
    border: 4px solid rgba(var(--primary-rgb), 0.15);
    border-top-color: var(--primary);
    animation: ns-spin 0.9s linear infinite;
}
@keyframes ns-spin { to { transform: rotate(360deg); } }

/* ── TOGGLE DE TEMA (injetado pelo theme.js) ──────────────────────── */
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border-muted);
    color: var(--text-muted);
    cursor: pointer;
    transition: color .2s, border-color .2s, background .2s, transform .1s;
}
.theme-toggle:hover { color: var(--primary); border-color: var(--primary); transform: translateY(-1px); }
.theme-toggle svg { width: 18px; height: 18px; }
/* Mostra só o ícone correspondente ao tema ativo */
html[data-theme="dark"]  .theme-toggle .icon-sun  { display: block; }
html[data-theme="dark"]  .theme-toggle .icon-moon { display: none; }
html[data-theme="light"] .theme-toggle .icon-sun  { display: none; }
html[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* ── MODAL ────────────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: flex; align-items: center; justify-content: center;
}

/* ── CHIPS / SELEÇÃO ──────────────────────────────────────────────── */
.system-chip {
    display: inline-flex; align-items: center; gap: 0.4rem;
    background: var(--input-bg);
    border: 1px solid var(--border-strong);
    border-radius: 0.4rem; padding: 0.35rem 0.65rem;
    cursor: pointer; color: var(--text-muted); font-size: 0.8rem;
    transition: border-color .2s, color .2s, background .2s; user-select: none;
}
.system-chip.active {
    border-color: rgba(var(--primary-rgb), 0.5);
    color: var(--primary);
    background: rgba(var(--primary-rgb), 0.08);
}

.status-radio-label {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.7rem 0.85rem; border-radius: 0.5rem; cursor: pointer;
    border: 1px solid var(--border-muted);
    transition: border-color .2s, background .2s;
}
.status-radio-label:hover { border-color: var(--border-strong); }
.status-radio-label:has(input:checked) {
    border-color: rgba(var(--primary-rgb), 0.45);
    background: rgba(var(--primary-rgb), 0.06);
}

/* ── TABS ─────────────────────────────────────────────────────────── */
.tab-btn {
    font-size: 0.82rem; font-weight: 500; padding: 0.4rem 1rem;
    border-radius: 0.5rem; border: 1px solid transparent;
    color: var(--text-subtle); cursor: pointer; background: transparent;
    transition: color .2s, border-color .2s, background .2s;
}
.tab-btn:hover { color: var(--text-strong); }
.tab-btn.active {
    color: var(--primary);
    border-color: rgba(var(--primary-rgb), 0.3);
    background: rgba(var(--primary-rgb), 0.07);
}

/* ── PRODUCT CARD (seleção de produtos) ───────────────────────────── */
.product-card {
    cursor: pointer; border-radius: 0.5rem; padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-muted); background: var(--surface-2);
    transition: border-color .15s, background .15s;
}
.product-card:hover { border-color: var(--border-strong); }
.product-card.selected,
.product-card.selected-liga,
.product-card.sel-source { border-color: rgba(var(--primary-rgb), 0.55); background: rgba(var(--primary-rgb), 0.07); }
.product-card.selected-tiny { border-color: rgba(251, 146, 60, 0.55); background: rgba(251, 146, 60, 0.08); }
.product-card.sel-rec { border-color: rgba(139, 92, 246, 0.55); background: rgba(139, 92, 246, 0.08); }

.selected-banner { border-radius: 0.75rem; padding: 0.75rem 1rem; display: flex; align-items: center; gap: 0.75rem; }
.selected-banner.source { background: rgba(var(--primary-rgb), 0.06); border: 1px solid rgba(var(--primary-rgb), 0.2); }
.selected-banner.rec    { background: rgba(139, 92, 246, 0.06); border: 1px solid rgba(139, 92, 246, 0.2); }

/* ── NAV CARD (grade do admin) ────────────────────────────────────── */
.nav-card {
    display: block; background: var(--surface-2);
    border: 1px solid var(--border-muted); border-radius: 1rem; padding: 1.5rem;
    text-decoration: none; transition: border-color .2s, background .2s, transform .15s;
}
.nav-card:hover {
    border-color: rgba(var(--primary-rgb), 0.4);
    background: rgba(var(--primary-rgb), 0.05);
    transform: translateY(-2px);
}
.nav-card-icon {
    width: 2.5rem; height: 2.5rem; border-radius: 0.75rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; margin-bottom: 1rem;
}

/* ── STEP INDICATOR (wizards) ─────────────────────────────────────── */
.step-indicator { display: flex; align-items: center; gap: 0; }
.step-dot {
    width: 2rem; height: 2rem; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 700; transition: .2s;
    border: 2px solid var(--border-strong); color: var(--text-subtle); background: var(--surface-2);
}
.step-dot.active { border-color: var(--primary-strong); color: var(--primary); background: rgba(var(--primary-rgb), 0.1); }
.step-dot.done { border-color: #22c55e; color: #22c55e; background: rgba(34, 197, 94, 0.08); }
.step-line { flex: 1; height: 2px; background: var(--border-muted); margin: 0 0.25rem; }
.step-line.done { background: rgba(34, 197, 94, 0.4); }

.config-card { border: 1px solid var(--border-muted); border-radius: 0.75rem; background: var(--surface-2); }
.config-card-header { border-bottom: 1px solid var(--border-muted); padding: 0.75rem 1rem; display: flex; align-items: center; gap: 0.5rem; }
.result-row-ok  { border-color: rgba(34, 197, 94, 0.3) !important; background: rgba(34, 197, 94, 0.04) !important; }
.result-row-err { border-color: rgba(239, 68, 68, 0.3) !important; background: rgba(239, 68, 68, 0.04) !important; }

/* ── MISC ─────────────────────────────────────────────────────────── */
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.3); }
.id-chip {
    display: inline-block; font-size: 0.68rem; margin: 1px;
    background: var(--surface-2); border: 1px solid var(--border-muted);
    border-radius: 0.3rem; padding: 0.05rem 0.35rem; color: var(--text-muted);
}
.btn-swap {
    background: var(--surface-2); color: var(--text-muted);
    border: 1px solid var(--border-muted); border-radius: 0.4rem;
    padding: 0.3rem 0.9rem; cursor: pointer; font-size: 0.8rem;
    transition: color .2s, border-color .2s, background .2s;
}
.btn-swap:hover { color: var(--primary); border-color: rgba(var(--primary-rgb), 0.3); background: rgba(var(--primary-rgb), 0.06); }
th.sortable { cursor: default; user-select: none; }
th.sortable:hover { color: var(--text-strong); }
th.sort-asc::after  { content: ' ↑'; color: var(--primary); }
th.sort-desc::after { content: ' ↓'; color: var(--primary); }

/* ── SCROLLBAR ────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ── LINKS ────────────────────────────────────────────────────────── */
.ns-link { color: var(--text-muted); transition: color .2s; }
.ns-link:hover { color: var(--primary); }
.ns-link-danger { color: var(--text-subtle); transition: color .2s; }
.ns-link-danger:hover { color: #ef4444; }

/* ══════════════════════════════════════════════════════════════════
 *  CAMADA DE COMPATIBILIDADE — TEMA CLARO
 *  Remapeia as utilitárias Tailwind de tons neutros (slate/gray/white)
 *  usadas nas páginas legadas para que fiquem legíveis no tema claro.
 *  Só atua quando data-theme="light"; no escuro os valores originais
 *  do Tailwind permanecem intactos.
 * ══════════════════════════════════════════════════════════════════ */
/* Texto — do mais forte ao mais sutil */
html[data-theme="light"] .text-white,
html[data-theme="light"] .text-slate-100,
html[data-theme="light"] .text-gray-100 { color: var(--text-strong) !important; }
html[data-theme="light"] .text-slate-200,
html[data-theme="light"] .text-slate-300,
html[data-theme="light"] .text-gray-200,
html[data-theme="light"] .text-gray-300 { color: var(--text) !important; }
html[data-theme="light"] .text-slate-400,
html[data-theme="light"] .text-gray-400 { color: var(--text-muted) !important; }
html[data-theme="light"] .text-slate-500,
html[data-theme="light"] .text-slate-600,
html[data-theme="light"] .text-slate-700,
html[data-theme="light"] .text-gray-500,
html[data-theme="light"] .text-gray-600 { color: var(--text-subtle) !important; }
/* text-slate-900 já é escuro → mantém legível no claro */

/* Superfícies */
html[data-theme="light"] .bg-slate-800 { background-color: #f1f5f9 !important; }
html[data-theme="light"] .bg-slate-700,
html[data-theme="light"] .bg-slate-600 { background-color: #e2e8f0 !important; }
html[data-theme="light"] .bg-slate-800\/50 { background-color: rgba(241, 245, 249, 0.7) !important; }
html[data-theme="light"] .bg-slate-800\/40 { background-color: rgba(241, 245, 249, 0.6) !important; }
html[data-theme="light"] .bg-slate-800\/30 { background-color: rgba(241, 245, 249, 0.5) !important; }
html[data-theme="light"] .bg-slate-800\/20 { background-color: rgba(241, 245, 249, 0.4) !important; }
html[data-theme="light"] .bg-slate-700\/60,
html[data-theme="light"] .bg-slate-700\/50 { background-color: rgba(226, 232, 240, 0.7) !important; }
html[data-theme="light"] .bg-slate-900\/90 { background-color: rgba(248, 250, 252, 0.95) !important; }

/* Bordas */
html[data-theme="light"] .border-slate-600,
html[data-theme="light"] .border-slate-700,
html[data-theme="light"] .border-slate-800,
html[data-theme="light"] .border-slate-600\/50,
html[data-theme="light"] .border-slate-600\/40,
html[data-theme="light"] .border-slate-700\/50,
html[data-theme="light"] .border-slate-700\/40,
html[data-theme="light"] .border-slate-700\/30,
html[data-theme="light"] .border-slate-700\/20 { border-color: rgba(148, 163, 184, 0.45) !important; }
html[data-theme="light"] .divide-slate-700\/30 > :not([hidden]) ~ :not([hidden]),
html[data-theme="light"] .divide-slate-700\/20 > :not([hidden]) ~ :not([hidden]) { border-color: rgba(148, 163, 184, 0.4) !important; }

/* Placeholders */
html[data-theme="light"] .placeholder-gray-500::placeholder { color: #94a3b8 !important; }

/* ── UTIL ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.fade-in { animation: ns-fade-in .3s ease-in; }
@keyframes ns-fade-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
