:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --border: #e3e5e9;
    --text: #17181c;
    --muted: #6b6f76;
    --primary: #17181c;
    --primary-dark: #000000;
    --accent: #2f6fed;
    --accent-light: #eaf0fe;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --erro: #b91c1c;
    --erro-bg: #fee2e2;
    --warn-bg: #fef3c7;
    --warn: #92610a;
    --shadow: 0 1px 2px rgba(16, 17, 20, 0.04), 0 1px 3px rgba(16, 17, 20, 0.06);
    --sidebar-bg: #17181c;
    --sidebar-text: #b7b9c2;
    --sidebar-text-active: #ffffff;
    --sidebar-border: #2a2b31;
    --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: "Segoe UI", -apple-system, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- App shell (sidebar + content) ---- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0.9rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.4rem 0.5rem 1.5rem;
    color: #fff;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
}
.brand-name {
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
}
.side-nav a {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.65rem;
    border-radius: 7px;
    color: var(--sidebar-text);
    font-size: 0.88rem;
    font-weight: 500;
}
.side-nav a:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--sidebar-text-active);
    text-decoration: none;
}
.side-nav a.active {
    background: var(--accent);
    color: #fff;
}
.side-nav a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.logout-form { margin: 0.5rem 0 0; padding-top: 0.75rem; border-top: 1px solid var(--sidebar-border); }
.logout-form .link-button {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
    padding: 0.55rem 0.65rem;
    border-radius: 7px;
    font-family: inherit;
}
.logout-form .link-button:hover { background: rgba(255, 255, 255, 0.06); color: var(--sidebar-text-active); }
.logout-form svg { width: 18px; height: 18px; flex-shrink: 0; }

.main-col {
    flex: 1;
    min-width: 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 2rem 3rem;
}

h1 { font-size: 1.5rem; margin: 0 0 0.5rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 1.75rem 0 0.75rem; font-weight: 600; }
h3 { font-size: 0.92rem; margin: 1.25rem 0 0.5rem; font-weight: 600; }
.muted { color: var(--muted); }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}
.page-header .actions { display: flex; gap: 0.5rem; }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.35rem 1.5rem;
    margin-top: 1.25rem;
    box-shadow: var(--shadow);
}

.table-scroll {
    overflow-x: auto;
    margin-top: 0.75rem;
}
.table-scroll table { margin-top: 0; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    margin-top: 0.75rem;
    box-shadow: var(--shadow);
}
th, td {
    text-align: left;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}
th { background: #fafafb; font-weight: 600; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbff; }
table.kv th { width: 220px; background: #fafafb; }
.mono { font-family: "SFMono-Regular", Consolas, Menlo, monospace; font-size: 0.83rem; }

.row-actions { display: flex; gap: 0.5rem; align-items: center; }
.row-actions form { margin: 0; }

.cards { display: flex; gap: 1rem; margin: 1rem 0; flex-wrap: wrap; }
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.1rem 1.5rem;
    display: flex;
    flex-direction: column;
    min-width: 170px;
    box-shadow: var(--shadow);
}
.card-number { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; }
.card-label { color: var(--muted); font-size: 0.83rem; margin-top: 0.2rem; }

.badge {
    display: inline-block;
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 500;
    background: #eceef1;
    color: #3b3d44;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-nenhum_documento { background: #eceef1; color: #3b3d44; }
.badge-rejeicao { background: var(--warn-bg); color: var(--warn); }
.badge-erro { background: var(--erro-bg); color: var(--erro); }

.flash {
    padding: 0.65rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    font-size: 0.88rem;
}
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-erro { background: var(--erro-bg); color: var(--erro); }

form.form-card, form.form-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.1rem;
    margin-top: 0.75rem;
    box-shadow: var(--shadow);
}
form.form-card { flex-direction: column; align-items: stretch; max-width: 420px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 0.75rem;
}
.checkbox-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    margin-top: 0.75rem;
}
.checkbox-grid label { flex-direction: row; align-items: center; gap: 0.4rem; color: var(--text); }
.form-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }

.integracao-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 0.75rem;
}
.mini-card {
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.mini-card-header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.mini-card .form-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.6rem; }
.mini-card-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.mini-card-actions form { margin: 0; }

label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.83rem;
    color: var(--muted);
    font-weight: 500;
}
label:has(input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
}

input, select, button {
    font: inherit;
}
input[type="text"], input[type="password"], input[type="file"], select {
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus, input[type="password"]:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

button, .button {
    padding: 0.55rem 1.05rem;
    border-radius: 7px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.88rem;
    display: inline-block;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
button:hover, .button:hover { background: #1d4fc7; border-color: #1d4fc7; text-decoration: none; }
button.secondary, .button.secondary { background: #fff; color: var(--text); border-color: var(--border); }
button.secondary:hover { background: #f5f6f8; border-color: var(--border); }
button.danger, .button.danger { background: #fff; color: var(--erro); border-color: var(--erro); }
button.danger:hover { background: var(--erro-bg); border-color: var(--erro); }

.login-box {
    max-width: 380px;
    margin: 4rem auto;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 2.25rem;
    text-align: center;
    box-shadow: 0 8px 28px rgba(16, 17, 20, 0.09);
}
.login-box h1 {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    justify-content: center;
    width: 100%;
}
.login-box h1::before {
    content: "N";
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
}
.login-box form { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 1.4rem; text-align: left; }

.xml-preview {
    background: #101114;
    color: #cfd6e6;
    padding: 1.1rem;
    border-radius: 10px;
    overflow-x: auto;
    font-size: 0.8rem;
    max-height: 600px;
}

.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        align-items: center;
        padding: 0.6rem 1rem;
        overflow-x: auto;
    }
    .brand { padding: 0 1rem 0 0; }
    .brand-name { display: none; }
    .side-nav { flex-direction: row; }
    .side-nav a span:last-child { display: none; }
    .logout-form { margin: 0 0 0 auto; padding-top: 0; border-top: none; }
    .logout-form .link-button span:last-child { display: none; }
    .container { padding: 1.25rem; }
}
