/* ==========================================================================
   Sistema NFS-e — estilos globais (tema premium)
   Tokens, tipografia, componentes e responsividade
   ========================================================================== */

:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --border: #e1e8f3;
    --border-strong: #cfd9ea;
    --text: #122039;
    --muted: #62728f;
    --primary: #2563eb;
    --primary-600: #1d4ed8;
    --primary-700: #1e40af;
    --primary-50: #eaf1ff;
    --accent: #2563eb;
    --success: #0b7a52;
    --success-50: #e4f6ee;
    --danger: #c92a2a;
    --danger-50: #fdeded;
    --warning: #b25e09;
    --warning-50: #fff3df;
    --info: #1864ab;
    --info-50: #e7f1fb;
    --navy-1: #0f2447;
    --navy-2: #0f2447;
    --sidebar-text: #a9b9d9;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(20, 27, 46, .05), 0 1px 1px rgba(20, 27, 46, .03);
    --shadow-md: 0 4px 14px rgba(20, 27, 46, .07), 0 1px 3px rgba(20, 27, 46, .05);
    --shadow-lg: 0 14px 34px rgba(20, 27, 46, .12), 0 3px 8px rgba(20, 27, 46, .06);
    --ring: 0 0 0 4px rgba(37, 99, 235, .16);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv11", "ss01";
}

a { color: var(--primary); }

/* ---------- Layout ---------- */
.container { display: flex; min-height: 100vh; }

aside {
    width: 248px;
    background: var(--navy-1);
    color: var(--sidebar-text);
    padding: 20px 14px 16px;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: 1px 0 0 rgba(255, 255, 255, .04) inset;
}

.logo {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 2px 10px 20px;
    margin-bottom: 14px;
    font-size: 16.5px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.1px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.logo-mark {
    width: 34px; height: 34px;
    border-radius: 10px;
    background: var(--primary);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 800; color: #fff; letter-spacing: -.3px;
}
.logo small { display: block; font-size: 10.5px; font-weight: 500; color: var(--sidebar-text); letter-spacing: .2px; margin-top: 1px; }

.nav-titulo {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6c78a0;
    padding: 6px 12px 8px;
}

nav { display: flex; flex-direction: column; gap: 3px; }
nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background .18s, color .18s, transform .18s;
}
nav a svg { width: 18px; height: 18px; flex: 0 0 auto; opacity: .8; }
nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
nav a.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}
nav a.active svg { opacity: 1; }

.sidebar-footer {
    margin-top: auto;
    padding: 14px 12px 4px;
    border-top: 1px solid rgba(255, 255, 255, .07);
    font-size: 12px;
    color: var(--sidebar-text);
}
.sidebar-footer .empresa { color: #fff; font-weight: 600; font-size: 12.5px; line-height: 1.3; margin-bottom: 8px; }
.env-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px;
    font-size: 11px; font-weight: 700; letter-spacing: .2px;
}
.env-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px rgba(255, 255, 255, .12); }
.env-prod { background: rgba(32, 201, 151, .16); color: #63e6be; }
.env-homolog { background: rgba(255, 192, 26, .16); color: #ffd43b; }

main {
    margin-left: 248px;
    flex: 1;
    min-width: 0;
    padding: 28px 34px 48px;
    max-width: 1400px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 24px;
}
h1 { font-size: 23px; font-weight: 750; color: var(--text); letter-spacing: -.5px; line-height: 1.2; }
.page-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.user-info { font-size: 12.5px; color: var(--muted); }
.user-info p {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px;
    box-shadow: var(--shadow-sm);
}

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
}
.card h2 { font-size: 15.5px; font-weight: 700; color: var(--text); margin-bottom: 16px; letter-spacing: -.2px; }
.card h3 { font-size: 13.5px; font-weight: 700; color: var(--text); letter-spacing: -.1px; }
.card p { color: var(--muted); }

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-box {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-md);
    text-align: left;
    transition: transform .2s, box-shadow .2s;
}
.stat-box:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-icon {
    flex: 0 0 auto;
    width: 44px; height: 44px;
    border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; color: var(--primary);
    border: 1.5px solid var(--primary);
}
.stat-icon svg { width: 21px; height: 21px; stroke-width: 1.75; }
.stat-box h3 {
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 2px;
}
.stat-box .value { color: var(--text); font-size: 24px; font-weight: 750; letter-spacing: -.6px; line-height: 1.2; }

/* ---------- Formulários ---------- */
.form-group { margin-bottom: 16px; }

label {
    display: block;
    margin-bottom: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: #3a455f;
}

input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
input[type="password"], input[type="date"], input[type="file"], select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
input[type="password"], input[type="date"], select { height: 40px; }

input:hover, select:hover, textarea:hover { border-color: #b8c1d6; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: #a0a9bd; }
input:disabled, input[readonly], select:disabled, textarea:disabled { background: #f3f5fa; color: var(--muted); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--primary); vertical-align: middle; }
textarea { resize: vertical; min-height: 90px; height: auto; }
small { color: var(--muted); font-size: 11.5px; }

/* ---------- Botões ---------- */
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .18s, border-color .18s, box-shadow .18s, transform .18s;
}
button svg, .btn svg { width: 16px; height: 16px; }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: var(--ring); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-600); box-shadow: 0 4px 12px rgba(37, 99, 235, .3); }
.btn-secondary { background: #fff; color: var(--primary-700); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--primary-50); border-color: #b4c6ec; }
.btn-success { background: var(--success); color: #fff; box-shadow: var(--shadow-sm); }
.btn-success:hover { background: #096643; }
.btn-danger { background: var(--danger); color: #fff; box-shadow: var(--shadow-sm); }
.btn-danger:hover { background: #a81f1f; }
.btn-sm { height: 32px; padding: 0 13px; font-size: 12.5px; border-radius: 8px; }

.acoes-rapidas { display: flex; flex-wrap: wrap; gap: 12px; }

/* Botões de ícone (ações de tabela) */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    color: var(--muted);
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background .15s, color .15s, border-color .15s, transform .15s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--primary-50); color: var(--primary); border-color: #c5d0fb; transform: translateY(-1px); }
.icon-btn.danger:hover { background: var(--danger-50); color: var(--danger); border-color: #f3c3c3; }
.icon-btn.off { opacity: .4; cursor: not-allowed; pointer-events: none; box-shadow: none; }
.acoes { display: inline-flex; gap: 6px; }

/* ---------- Tabelas ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 10px; font-size: 13.5px; }
th {
    background: #f6f8fc;
    padding: 11px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--muted);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
th:first-child { border-left: 1px solid var(--border); border-top-left-radius: 10px; }
th:last-child { border-right: 1px solid var(--border); border-top-right-radius: 10px; }
td { padding: 13px 14px; border-bottom: 1px solid #edf0f6; vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #f7f9ff; }
tbody tr:last-child td { border-bottom: none; }

/* ---------- Badges de status ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 650;
    white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-50); color: var(--success); }
.badge-warning { background: var(--warning-50); color: var(--warning); }
.badge-danger { background: var(--danger-50); color: var(--danger); }
.badge-neutral { background: #eceff6; color: #46526d; }

/* ---------- Alertas ---------- */
.alert { padding: 13px 16px; margin-bottom: 16px; border-radius: 10px; border: 1px solid; font-size: 13px; }
.alert-success { background: var(--success-50); border-color: #b9e4d2; color: var(--success); }
.alert-error { background: var(--danger-50); border-color: #f3c3c3; color: var(--danger); }
.alert-warning { background: var(--warning-50); border-color: #f2d6a7; color: var(--warning); }
.alert-info { background: var(--info-50); border-color: #bcd6ee; color: var(--info); }

/* ---------- Lista de dados ---------- */
.dl { display: grid; grid-template-columns: 190px 1fr; gap: 10px 18px; font-size: 13.5px; }
.dl dt { color: var(--muted); font-weight: 600; }
.dl dd { color: var(--text); font-weight: 500; }

.vazio { text-align: center; padding: 34px 10px; color: var(--muted); }

.contacts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.contact-card { background: #f8f9fd; border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; }
.contact-card h3 { margin: 0 0 6px; color: var(--text); font-size: 14px; }
.contact-card p { margin: 3px 0; font-size: 12.5px; color: var(--muted); }

img, canvas, svg { max-width: 100%; }

/* ---------- Choices.js (selects com busca) ---------- */
.choices { font-size: 14px; margin-bottom: 0; }
.choices__inner {
    min-height: 40px !important;
    padding: 5px 12px !important;
    border: 1px solid var(--border-strong) !important;
    border-radius: 9px !important;
    background-color: #fff !important;
    display: flex;
    align-items: center;
}
.choices.is-focused .choices__inner, .choices.is-open .choices__inner { border-color: var(--primary) !important; box-shadow: var(--ring) !important; }
.choices__list--dropdown { border: 1px solid var(--border-strong) !important; border-radius: 10px !important; box-shadow: var(--shadow-lg); margin-top: 4px; }
.choices__list--dropdown .choices__item--selectable.is-highlighted { background: var(--primary-50) !important; color: var(--text); }
.choices__list--dropdown .choices__item { font-size: 13.5px; }
.choices__placeholder { opacity: .65; }

/* ==========================================================================
   Responsivo
   ========================================================================== */
@media (max-width: 992px) {
    aside { width: 212px; }
    main { margin-left: 212px; padding: 22px; }
}

@media (max-width: 768px) {
    .container { flex-direction: column; }

    aside {
        position: static;
        width: 100%;
        padding: 12px 12px 10px;
        overflow: visible;
        flex-direction: column;
    }
    .logo { padding: 2px 4px 12px; margin-bottom: 8px; }
    .nav-titulo, .sidebar-footer { display: none; }
    nav { flex-direction: row; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
    nav a { flex: 0 0 auto; white-space: nowrap; padding: 9px 13px; }

    main { margin-left: 0; padding: 16px 12px 36px; width: 100%; }
    header { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 16px; }
    h1 { font-size: 20px; }
    .card { padding: 16px; }
    .dashboard-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-box { padding: 14px; gap: 10px; }
    .stat-icon { width: 38px; height: 38px; }
    .dl { grid-template-columns: 1fr; gap: 2px 0; }
    .dl dt { margin-top: 8px; }

    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
    [style*="display: flex"], [style*="display:flex"] { flex-wrap: wrap; }

    input, select, textarea { font-size: 16px; }
    .btn, button { min-height: 42px; }
    .choices { width: 100%; }
    .acoes-rapidas .btn { flex: 1 1 150px; }

    /* Tabelas viram cards: cada linha é um cartão com rótulo + valor */
    table, tbody, tr, td { display: block; width: 100%; }
    table { border: none; }
    thead { display: none; }
    tbody tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-md);
        margin-bottom: 12px;
        padding: 6px 14px;
    }
    tbody tr:hover { background: var(--surface); }
    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 10px 0 !important;
        border: none !important;
        border-bottom: 1px solid #edf0f6 !important;
        text-align: right;
        word-break: break-word;
    }
    td:last-child { border-bottom: none !important; }
    td::before {
        content: attr(data-label);
        flex: 0 0 36%;
        text-align: left;
        font-size: 11px;
        font-weight: 700;
        color: var(--muted);
        text-transform: uppercase;
        letter-spacing: .5px;
    }
    td[data-label=""]::before { display: none; }
    td[data-label=""] { justify-content: flex-start; }
}

@media (max-width: 480px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .stat-box .value { font-size: 22px; }
}

/* Ajustes finos do Choices.js (lista compacta, texto truncado) */
.choices__list--single { padding: 0 !important; display: flex; align-items: center; }
.choices__list--single .choices__item, .choices__placeholder { padding: 0 !important; margin: 0 !important; line-height: 1.4 !important; }
.choices[data-type*="select-one"] .choices__button { margin: 0 6px 0 0 !important; padding: 0 !important; width: 14px !important; height: 14px !important; background-size: 10px 10px !important; }
.choices__input { padding: 6px 10px !important; background: transparent !important; }
.choices__list--dropdown .choices__item { padding: 8px 12px !important; min-height: auto !important; line-height: 1.35 !important; }
.choices__item--selectable { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.nowrap { white-space: nowrap; }
.tabela-wrap { width: 100%; overflow-x: auto; }
@media (max-width: 768px) { .tabela-wrap { overflow: visible; } }
@media (max-width: 768px) { td.cel-vazia { display: none !important; } }

/* ---------- Administração / multi-empresa ---------- */
.usuario-info { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: 12.5px; color: var(--sidebar-text); }
.usuario-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-link { height: auto; padding: 4px 6px; background: transparent; border: none; color: var(--sidebar-text); font-size: 12.5px; font-weight: 500; }
.btn-link:hover { color: #fff; }
.faixa-admin { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--primary-50); border: 1px solid #c5d5fb; color: var(--primary-700); border-radius: 10px; padding: 10px 14px; margin-bottom: 18px; font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 768px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.badge-info { background: var(--info-50); color: var(--info); }
.code-box { background: #0f2447; color: #d7e3ff; padding: 12px 14px; border-radius: 8px; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; word-break: break-all; }

.conta-link { color: var(--sidebar-text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conta-link:hover { color: #fff; }

/* ---------- Código de tributação municipal (consulta ao catálogo do município) ---------- */
.cod-mun-status { margin-top: 7px; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.cod-mun-status:empty { display: none; }
.cod-mun-status .msg { display: flex; gap: 8px; align-items: flex-start; }
.cod-mun-status .msg svg { flex: 0 0 auto; width: 16px; height: 16px; margin-top: 1px; }
.cod-mun-status .msg b { font-weight: 700; }
.cod-mun-status.ok { color: var(--success); }
.cod-mun-status.erro { color: var(--danger); }
.cod-mun-status.aviso { color: var(--warning); }
.cod-mun-status.info { color: var(--info); }
.cod-mun-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cod-mun-chip { height: 28px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: #fff; color: var(--primary-700); font-size: 12px; font-weight: 600; box-shadow: none; }
.cod-mun-chip:hover { background: var(--primary-50); border-color: #b4c6ec; }
.cod-mun-outros { margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.cod-mun-acoes { margin-top: 9px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.cod-mun-barra { flex: 1 1 160px; min-width: 120px; height: 6px; border-radius: 999px; background: #e4ebf7; overflow: hidden; }
.cod-mun-barra > i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .25s ease; }
.cod-mun-giro { animation: cod-mun-giro .9s linear infinite; }
@keyframes cod-mun-giro { to { transform: rotate(360deg); } }
.cod-mun-selo { display: inline-flex; align-items: center; gap: 5px; margin-top: 4px; font-size: 11.5px; line-height: 1.3; }
.cod-mun-selo.ok { color: var(--success); }
.cod-mun-selo.erro { color: var(--danger); }
.cod-mun-selo a { color: var(--primary-700); font-weight: 600; text-decoration: none; }
.cod-mun-selo a:hover { text-decoration: underline; }
