@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

:root {
    --primary: #0f766e;
    --primary-dark: #115e59;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-hover: #eef2ff;
    --bg-input: #ffffff;
    --text: #0f172a;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
}
html.dark-theme {
    --primary: #818cf8;
    --primary-dark: #6366f1;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-tertiary: #334155;
    --bg-hover: rgba(129,140,248,.12);
    --bg-input: #1e293b;
    --text: #f1f5f9;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border: rgba(255,255,255,.12);
    --border-color: rgba(255,255,255,.12);
    --shadow: 0 1px 3px rgba(0,0,0,.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,.5);
}
html.dark-theme table th { background: #0f172a; }
html.dark-theme table tr:hover td { background: rgba(129,140,248,.08); }
html.dark-theme .sidebar { background: #1e293b; }
html.dark-theme .btn-secondary { background: #334155; color: #f1f5f9; }
* { box-sizing: border-box; font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
body { margin: 0; font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; font-weight: 400; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.01em; }
button, input, select, textarea { font-family: inherit; }
a { color: var(--primary); text-decoration: none; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; transition: .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #f1f5f9; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.input, select, textarea, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="search"] { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--bg-input); color: var(--text); box-sizing: border-box; font-family: inherit; }
.input:focus, select:focus, textarea:focus, input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }

/* Selects: garantir que options herdem o tema (Firefox/Chrome) */
select { appearance: none; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23475569' d='M5 6L0 0h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
select option { background: var(--bg-card); color: var(--text); }

/* Autocomplete (Chrome/Edge): forçar cores do tema, sem highlight amarelo */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px var(--bg-input) inset !important;
    -webkit-text-fill-color: var(--text) !important;
    caret-color: var(--text);
    transition: background-color 5000s ease-in-out 0s;
}
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.label { display: block; font-weight: 600; font-size: 12px; color: var(--text); margin-bottom: 6px; }
table { width: 100%; border-collapse: collapse; }
table th { text-align: left; padding: 10px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); background: var(--bg-tertiary); border-bottom: 1px solid var(--border); }
table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text); }
table tr:hover td { background: var(--bg-hover); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-blue { background: #dbeafe; color: #1e40af; }

/* Layout autenticado */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: 264px; background: var(--bg-card); border-right: 1px solid var(--border); padding: 20px 12px; flex-shrink: 0; height: 100vh; overflow: hidden; display: flex; flex-direction: column; position: sticky; top: 0; }
.sidebar-items::-webkit-scrollbar { width: 6px; }
.sidebar-items::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar-items::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.sidebar .brand { flex-shrink: 0; font-size: 18px; font-weight: 800; color: var(--primary); padding: 8px 12px 18px; margin-bottom: 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; }
.sidebar .brand img { display: block; max-height: 48px; max-width: 100%; object-fit: contain; }
.sidebar .nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; margin-bottom: 4px; border-radius: 8px; color: var(--text-muted); cursor: pointer; font-weight: 600; font-size: 13px; transition: .15s; text-decoration: none; }
.sidebar .nav-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.sidebar .nav-item.active { background: var(--bg-hover); color: var(--primary); }
.sidebar .nav-group { padding: 14px 14px 5px; font-size: 10.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 6px; }
.sidebar .nav-group:first-child { border-top: none; margin-top: 0; padding-top: 4px; }
.app-layout.sidebar-collapsed .sidebar .nav-group { text-align: center; padding-left: 0; padding-right: 0; }
.app-layout.sidebar-collapsed .sidebar .nav-group .nav-label { display: none; }
.app-layout.sidebar-collapsed .sidebar .nav-group::before { content: "•••"; color: var(--text-muted); }
/* Grupos recolhíveis (accordion por separador) */
.sidebar button.nav-group { -webkit-appearance: none; appearance: none; width: 100%; display: flex; align-items: center; gap: 8px; background: none; border: 0; border-top: 1px solid var(--border); cursor: pointer; font-family: inherit; text-align: left; }
.sidebar button.nav-group:first-child { border-top: 0; }
.sidebar .nav-group:hover { color: var(--text-primary); }
.sidebar .nav-group-caret { margin-left: auto; font-size: 10px; opacity: .65; transition: transform .18s; }
.sidebar .nav-group.collapsed .nav-group-caret { transform: rotate(-90deg); }
.nav-group-items.collapsed { display: none; }
.app-layout.sidebar-collapsed .sidebar .nav-group { justify-content: center; }
.app-layout.sidebar-collapsed .sidebar .nav-group-caret { display: none; }
.app-layout.sidebar-collapsed .nav-group-items.collapsed { display: block; }
html.dark-theme .sidebar .nav-item:hover { background: rgba(129,140,248,.14); color: #f1f5f9; }
html.dark-theme .sidebar .nav-item.active { background: rgba(129,140,248,.2); color: var(--primary); }
.sidebar .nav-item i { width: 16px; text-align: center; }
.nav-badge-novo { margin-left: auto; font-size: 9px; font-weight: 800; letter-spacing: .5px; color: #fff; background: linear-gradient(90deg,#f43f5e,#e11d48); padding: 2px 6px; border-radius: 10px; line-height: 1; box-shadow: 0 1px 3px rgba(225,29,72,.4); }
.nav-badge-teste { margin-left: auto; font-size: 9px; font-weight: 800; letter-spacing: .3px; text-transform: uppercase; color: #fff; background: linear-gradient(90deg,#f59e0b,#d97706); padding: 2px 6px; border-radius: 10px; line-height: 1; white-space: nowrap; box-shadow: 0 1px 3px rgba(217,119,6,.4); }
/* overflow-x explícito: com só `overflow-y: auto` o eixo X vira `auto` e um rótulo
   um pouco mais largo já cria barra de rolagem horizontal no menu. */
.sidebar-items { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.sidebar-footer { flex-shrink: 0; padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--border); background: inherit; }
/* Botão recolher menu (rail só com ícones) */
.sidebar-collapse-btn { flex-shrink: 0; display: flex; align-items: center; justify-content: flex-end; width: 100%; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0 8px 10px; font-size: 15px; }
.sidebar-collapse-btn:hover { color: var(--primary); }
@media (min-width: 1025px) {
    .app-layout.sidebar-collapsed .sidebar { width: 68px; padding-left: 8px; padding-right: 8px; }
    .app-layout.sidebar-collapsed .sidebar .brand { display: none; }
    .app-layout.sidebar-collapsed .nav-label { display: none; }
    .app-layout.sidebar-collapsed .nav-badge-novo,
    .app-layout.sidebar-collapsed .nav-badge-teste { display: none; }
    .app-layout.sidebar-collapsed .sidebar .nav-item { justify-content: center; gap: 0; padding: 11px 0; }
    .app-layout.sidebar-collapsed .sidebar .nav-item i { width: 100%; text-align: center; }
    .app-layout.sidebar-collapsed .sidebar-collapse-btn { justify-content: center; padding: 0 0 10px; }
    .app-layout.sidebar-collapsed .sidebar-collapse-btn i { transform: rotate(180deg); }
}
@media (max-width: 1024px) { .sidebar-collapse-btn { display: none; } }
.main { flex: 1; padding: 24px; overflow-x: auto; width: 100%; min-width: 0; max-width: none !important; }

/* Upload zones — padrão visual consistente (sobrescreve qualquer rule local) */
.upload-zone,
label.upload-zone {
    display: block !important;
    border: 2px dashed var(--border) !important;
    border-radius: 10px !important;
    padding: 24px 20px !important;
    text-align: center !important;
    cursor: pointer !important;
    transition: .15s !important;
    background: var(--bg-tertiary) !important;
    color: var(--text-muted) !important;
}
.upload-zone:hover { border-color: var(--primary) !important; background: var(--bg-hover) !important; color: var(--primary) !important; }
.upload-zone.has-file { border-color: var(--success) !important; background: rgba(5,150,105,.08) !important; color: var(--success) !important; }
.upload-zone input[type="file"] { display: none !important; }
.upload-zone i { font-size: 28px !important; color: var(--primary) !important; display: block !important; margin: 0 auto 8px !important; }
.upload-zone.has-file i { color: var(--success) !important; }

/* Inputs type=file soltos — esconder totalmente, usar label.upload-zone */
input[type="file"].input { display: none; }

/* Corrigir input com prefixo (ex: +55 WhatsApp) — não força width 100% em flex containers */
.flex-prefix { display: flex; align-items: stretch; gap: 0; }
.flex-prefix > *:first-child { border-radius: 8px 0 0 8px; border-right: 0; }
.flex-prefix > *:last-child { border-radius: 0 8px 8px 0; flex: 1; min-width: 0; }
.flex-prefix input.input { border-radius: 0 8px 8px 0; }
.input-prefix-tag { padding: 10px 12px; background: var(--bg-tertiary); border: 1px solid var(--border); font-weight: 600; color: var(--text-muted); white-space: nowrap; }

/* Override global — cards específicos por página usam variáveis do tema */
.conn-card, .cert-card { background: var(--bg-card) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }
.conn-card *, .cert-card * { color: inherit; }
.cert-card .badge { color: unset; } /* badges mantêm suas próprias cores */

/* Bank card — degradê fica em TODOS os temas */
.bank-card { color: #fff !important; }
html.dark-theme .bank-card { background: linear-gradient(135deg, #1e40af, #312e81) !important; }

/* Modais — override global, respeita tema */
.modal-box, .modal-body, .modal-head, .modal-foot { background: var(--bg-card) !important; color: var(--text) !important; }
.modal-head { border-bottom: 1px solid var(--border) !important; }
.modal-foot { border-top: 1px solid var(--border) !important; }
.modal-bg { background: rgba(0,0,0,.6) !important; }

/* Cards em geral sempre respeitam tema */
.card { background: var(--bg-card); color: var(--text); border-color: var(--border); }

/* Dark theme: override any inline #fff / #f8fafc / gray backgrounds de modais e caixas */
html.dark-theme [style*="background:#fff"],
html.dark-theme [style*="background: #fff"],
html.dark-theme [style*="background:#ffffff"],
html.dark-theme [style*="background-color:#fff"] {
    background: var(--bg-card) !important;
    color: var(--text) !important;
}
html.dark-theme [style*="background:#f8fafc"],
html.dark-theme [style*="background:#f1f5f9"],
html.dark-theme [style*="background:#eef2ff"] {
    background: var(--bg-tertiary) !important;
    color: var(--text) !important;
}
/* Borda inline forçada claro */
html.dark-theme [style*="border:1px solid #e2e8f0"],
html.dark-theme [style*="border:1px solid var(--border-color,#e2e8f0)"] {
    border-color: var(--border) !important;
}
/* Texto inline hardcoded em dark — adapta */
html.dark-theme [style*="color:#1e293b"],
html.dark-theme [style*="color:#0f172a"],
html.dark-theme [style*="color:#1a1a2e"] { color: var(--text) !important; }
html.dark-theme [style*="color:#64748b"],
html.dark-theme [style*="color:#94a3b8"] { color: var(--text-muted) !important; }

/* ============ RESPONSIVIDADE MOBILE ============ */

/* Hamburguer button — aparece só em mobile */
.mobile-menu-btn {
    display: none;
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    margin-right: 10px;
}

/* Overlay quando sidebar aberto em mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 90;
}
.sidebar-overlay.on { display: block; }

@media (max-width: 1024px) {
    /* Sidebar vira drawer */
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        z-index: 100;
        transition: left .25s;
        box-shadow: 4px 0 20px rgba(0,0,0,.15);
    }
    .sidebar.open { left: 0; }
    .main { padding: 16px; }
    .mobile-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
    .topbar h1 { font-size: 18px; }
}

@media (max-width: 768px) {
    body { font-size: 12px; }
    .main { padding: 10px; }
    .topbar { flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
    .topbar h1 { font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .user-menu { gap: 6px; }
    .user-menu a > div:not(.avatar) { display: none; }

    /* Grids 2+ colunas viram 1 em mobile */
    [style*="grid-template-columns:1fr 1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }

    .card { padding: 12px; }
    .card h3 { font-size: 13px; }
    .label { font-size: 11px; }
    .input, select, textarea, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"] { font-size: 12px; padding: 8px 10px; }

    /* Tabelas viram cards empilhados em mobile */
    .card > table,
    table.responsive-cards,
    .card table {
        display: block;
    }
    .card > table thead,
    table.responsive-cards thead,
    .card table thead { display: none; }
    .card > table tbody,
    table.responsive-cards tbody,
    .card table tbody { display: block; }
    .card > table tr,
    table.responsive-cards tr,
    .card table tr {
        display: block;
        margin-bottom: 10px;
        padding: 10px 12px;
        border: 1px solid var(--border);
        border-radius: 10px;
        background: var(--bg-card);
    }
    .card > table tr:hover td,
    table.responsive-cards tr:hover td,
    .card table tr:hover td { background: transparent; }
    .card > table td,
    table.responsive-cards td,
    .card table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        padding: 5px 0;
        border-bottom: 1px dashed var(--border);
        font-size: 11px;
        text-align: right;
        min-height: 24px;
    }
    .card > table td:last-child,
    table.responsive-cards td:last-child,
    .card table td:last-child { border-bottom: 0; }
    .card > table td::before,
    table.responsive-cards td::before,
    .card table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        text-align: left;
        flex-shrink: 0;
    }
    /* Se a td não tem data-label (checkbox/ações), ocupa linha inteira */
    .card > table td:not([data-label])::before,
    table.responsive-cards td:not([data-label])::before,
    .card table td:not([data-label])::before { content: none; }
    .card > table td:not([data-label]),
    table.responsive-cards td:not([data-label]),
    .card table td:not([data-label]) {
        justify-content: flex-end;
        gap: 6px;
    }
    .badge { font-size: 9px; padding: 2px 6px; }

    /* Modais 100% */
    .modal-box, .modal-bg > div { max-width: 100% !important; }
    .modal-bg, [style*="position:fixed;inset:0"] { padding: 8px !important; }

    /* Formulários */
    .form-row, .grid-2 { grid-template-columns: 1fr !important; }

    /* Botões menores */
    .btn { font-size: 11px; padding: 7px 10px; }

    /* Sidebar — mesmo drawer, fontes menores */
    .sidebar { width: 220px; padding: 14px 10px; }
    .sidebar .brand { font-size: 15px; padding-bottom: 14px; margin-bottom: 10px; }
    .sidebar .nav-item { font-size: 11px; padding: 9px 10px; gap: 10px; }

    h1 { font-size: 15px !important; }
    h2 { font-size: 13px !important; }
    h3 { font-size: 12px !important; }
    h4 { font-size: 11px !important; }
}

@media (max-width: 480px) {
    body { font-size: 11px; }
    .main { padding: 8px; }
    .user-menu .avatar { width: 30px; height: 30px; font-size: 13px; }
    .card { padding: 10px; }
    .card h3 { font-size: 12px; }
    table th, table td { padding: 5px 6px; font-size: 10px; }
    table th { font-size: 9px; }
    .badge { font-size: 8px; padding: 2px 5px; }
    .btn { font-size: 10px; padding: 6px 9px; }
    .input, select, textarea { font-size: 11px; padding: 7px 9px; }
    .sidebar { width: 200px; }
    .sidebar .nav-item { font-size: 10.5px; padding: 8px 9px; gap: 8px; }
    h1 { font-size: 13px !important; }
    h2 { font-size: 12px !important; }
    h3 { font-size: 11px !important; }
}

/* Password toggle — olho pra mostrar/esconder senha */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 40px; }
.pw-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1;
}
.pw-toggle:hover { color: var(--primary); background: var(--bg-hover); }

/* Inputs type=color padronizados */
input[type="color"] {
    padding: 2px;
    height: 40px;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
}
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.topbar h1 { margin: 0; font-size: 22px; }
.user-menu { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-menu .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
