:root {
    --navy-950: #14171c; --navy-900: #1c2027; --navy-800: #252a33; --navy-700: #323844;
    --blue-accent: #1f6f54; --blue-accent-dark: #175a44; --white: #ffffff;
    --gray-50: #f6f7f8; --gray-100: #ececee; --gray-200: #dcdfe3; --gray-300: #c5c9d0;
    --gray-400: #96a0ab; --text-900: #14171c; --text-500: #5b6470;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(20,23,28,0.06);
    --shadow-md: 0 10px 28px rgba(20,23,28,0.12);
    --shadow-lg: 0 20px 40px rgba(20,23,28,0.16);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--gray-50);
    color: var(--text-900);
    -webkit-font-smoothing: antialiased;
    display: flex;
    min-height: 100vh;
}

/* ── SIDEBAR ────────────────────────────────────────────── */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--navy-950) 0%, var(--navy-900) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 700;
    font-size: 17px;
    text-decoration: none;
    color: #fff;
}

.brand-mark {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--blue-accent);
    position: relative;
    flex-shrink: 0;
}
.brand-mark::before, .brand-mark::after {
    content: ""; position: absolute;
    background: rgba(255,255,255,0.9); border-radius: 1px;
}
.brand-mark::before { width: 13px; height: 2px; top: 10px; left: 9.5px; }
.brand-mark::after  { width: 9px;  height: 2px; top: 15px; left: 9.5px; }

.sidebar-brand small {
    display: block;
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: 10.5px;
    color: #8a94a3;
    letter-spacing: 0.3px;
    margin-top: 2px;
}

.nav { padding: 14px 10px; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 12px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 500;
    color: #b9c8e0;
    cursor: pointer;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
    text-decoration: none;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--blue-accent); color: #fff; font-weight: 600; }

.sidebar-footer {
    padding: 16px 20px;
    font-size: 10.5px;
    color: #5f7ba3;
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* ── MAIN ───────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    gap: 14px;
}
.topbar-title { font-size: 15px; font-weight: 700; color: var(--navy-950); }

.btn-enter {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--navy-900);
    color: #fff;
    border: none;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-enter svg { width: 14px; height: 14px; }

.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 20px 5px;
}

.card-wrap       { width: 100%; max-width: 680px; margin: 0 auto; }
.card-wrap-wide  { width: 100%; }

/* ── TYPOGRAPHY ─────────────────────────────────────────── */
.page-title {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 26px;
    font-weight: 700;
    color: var(--navy-950);
    margin: 0 0 6px;
    text-align: center;
}
.page-sub {
    font-size: 13.5px;
    color: var(--text-500);
    text-align: center;
    margin: 0 0 18px;
}

/* ── CARDS ──────────────────────────────────────────────── */
.query-card, .panel-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    padding: 16px;
    margin-bottom: 14px;
}
.panel-card { padding: 14px; }
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.panel-title  { font-size: 16px; font-weight: 700; color: var(--navy-950); }
.panel-count  { font-size: 12px; color: var(--gray-400); font-weight: 600; }

/* ── FORM ───────────────────────────────────────────────── */
.field-label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}
.field-label-row label { font-size: 13.5px; font-weight: 700; color: var(--navy-950); }
.char-count { font-size: 11.5px; font-family: 'JetBrains Mono', monospace; color: var(--text-500); }
.char-count strong { color: var(--blue-accent); }

.key-input, .form-input, .form-select {
    width: 100%;
    padding: 12px 14px;
    font-size: 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: 9px;
    background: var(--gray-50);
    color: var(--text-900);
    outline: none;
    transition: border-color .15s, background .15s, box-shadow .15s;
    font-family: 'Inter', sans-serif;
}
.key-input {
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.3px;
    padding: 14px 16px;
    font-size: 14.5px;
}
.key-input::placeholder { font-family: 'Inter', sans-serif; color: var(--gray-400); letter-spacing: normal; }
.key-input:focus, .form-input:focus, .form-select:focus {
    border-color: var(--blue-accent);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(31,111,84,0.12);
}
.key-input.invalid { border-color: #d5304a; box-shadow: 0 0 0 4px rgba(213,48,74,0.10); }

.hint { font-size: 12px; color: var(--text-500); margin-top: 8px; display: flex; align-items: center; gap: 6px; }
.hint.error { color: #d5304a; }
.hint svg { width: 13px; height: 13px; flex-shrink: 0; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--navy-950);
    margin-bottom: 6px;
}

/* ── BUTTONS ────────────────────────────────────────────── */
.actions { display: flex; gap: 12px; margin-top: 16px; }

.btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 13px 18px;
    border-radius: 9px;
    font-size: 14px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: transform .12s, box-shadow .12s, background .15s, opacity .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--blue-accent);
    color: #fff;
    box-shadow: 0 6px 18px rgba(31,111,84,0.32);
}
.btn-primary:hover  { background: var(--blue-accent-dark); }
.btn-primary:disabled {
    background: var(--gray-200);
    color: var(--gray-400);
    box-shadow: none;
    cursor: not-allowed;
}
.btn-secondary {
    background: var(--white);
    color: var(--navy-900);
    border: 1.5px solid var(--gray-200);
}
.btn-secondary:hover { border-color: var(--navy-700); background: var(--gray-50); }
.btn-sm { padding: 8px 14px; font-size: 12.5px; }

/* ── TYPE TOGGLE ─────────────────────────────────────────── */
.type-toggle { display: flex; gap: 8px; }
.type-toggle button {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: 1.5px solid var(--gray-200);
    background: var(--gray-50);
    color: var(--text-500);
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: all .15s;
}
.type-toggle button.active { background: var(--navy-950); color: #fff; border-color: var(--navy-950); }

/* ── DIVIDER ─────────────────────────────────────────────── */
.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0 12px;
    color: var(--gray-400);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--gray-200); }

/* ── STATUS BOX ──────────────────────────────────────────── */
.status-box {
    display: none;
    margin-top: 22px;
    padding: 16px 18px;
    border-radius: 10px;
    align-items: flex-start;
    gap: 12px;
}
.status-box.show    { display: flex; }
.status-box.loading { background: #eef4ff; border: 1px solid #cddffb; }
.status-box.success { background: #e5f7ee; border: 1px solid #bfe9d4; }
.status-box.error   { background: #fce9ec; border: 1px solid #f4c3cc; }
.status-icon { flex-shrink: 0; margin-top: 1px; }
.status-icon svg { width: 18px; height: 18px; }
.status-title { font-size: 13.5px; font-weight: 700; margin-bottom: 2px; }
.status-desc  { font-size: 12.5px; color: var(--text-500); }
.status-actions { margin-top: 10px; display: flex; gap: 8px; }
.status-actions .mini-btn {
    font-size: 12px; font-weight: 700; padding: 6px 12px;
    border-radius: 6px; border: none; cursor: pointer;
    background: #0f9d63; color: #fff;
}
.loading .status-title { color: var(--navy-900); }
.success .status-title { color: #0f9d63; }
.error   .status-title { color: #d5304a; }

.spinner {
    width: 18px; height: 18px;
    border: 2.5px solid #cddffb;
    border-top-color: var(--blue-accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── TABLES ──────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: left; padding: 9px 10px;
    font-size: 11px; font-weight: 700; color: var(--gray-400);
    text-transform: uppercase; letter-spacing: 0.4px;
    border-bottom: 1px solid var(--gray-200); background: var(--gray-50);
}
.data-table td {
    padding: 10px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--text-900);
    vertical-align: middle;
}
.data-table td.mono { font-size: 11px; white-space: nowrap; }
.data-table tr:hover td { background: var(--gray-50); }
.data-table .mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* ── BADGES ──────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
}
.badge-nfe          { background: #e5f0ff; color: #1a5fb4; }
.badge-cte          { background: #fff3e0; color: #c77700; }
.badge-mdfe         { background: #f0e5ff; color: #7c3aed; }
.badge-ok           { background: #e5f7ee; color: #0f9d63; }
.badge-pendente     { background: #fff8e1; color: #c79100; }
.badge-erro         { background: #fce9ec; color: #d5304a; }
.badge-compartilhado{ background: #e0f2fe; color: #0277bd; }

.table-actions { display: flex; gap: 6px; }
.table-actions button {
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid var(--gray-200);
    background: #fff;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-500);
    transition: all .15s;
}
.table-actions button:hover { border-color: var(--blue-accent); color: var(--blue-accent); }

/* ── STATS / MONITOR GRIDS ───────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.stat-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
}
.stat-label {
    font-size: 11.5px; font-weight: 600; color: var(--gray-400);
    text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px;
}
.stat-value {
    font-size: 28px; font-weight: 800; color: var(--navy-950);
    font-family: 'Source Serif 4', Georgia, serif;
}

.monitor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.monitor-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 14px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--blue-accent);
}
.monitor-card.warn    { border-left-color: #f59e0b; }
.monitor-card.danger  { border-left-color: #ef4444; }
.monitor-card.success { border-left-color: #0f9d63; }
.monitor-title  { font-size: 13px; font-weight: 700; color: var(--navy-950); margin-bottom: 4px; }
.monitor-desc   { font-size: 12px; color: var(--text-500); margin-bottom: 12px; }
.monitor-value  { font-size: 24px; font-weight: 800; color: var(--navy-950); }

/* ── TABS ────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 20px;
}
.tab {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all .15s;
    background: none;
    text-decoration: none;
    display: inline-block;
}
.tab:hover  { color: var(--navy-950); }
.tab.active { color: var(--blue-accent); border-bottom-color: var(--blue-accent); }

/* ── PAGINATION ──────────────────────────────────────────── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
}
.pagination a {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--gray-200);
    background: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-500);
    text-decoration: none;
    transition: all .15s;
}
.pagination a:hover  { border-color: var(--blue-accent); color: var(--blue-accent); }
.pagination a.active { background: var(--blue-accent); color: #fff; border-color: var(--blue-accent); }

/* ── EMPTY STATE ─────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--gray-400); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state h3  { font-size: 15px; font-weight: 700; color: var(--text-500); margin: 0 0 4px; }
.empty-state p   { font-size: 13px; margin: 0; }

/* ── TOAST ───────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.toast {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 14px 18px;
    box-shadow: var(--shadow-lg);
    display: flex; align-items: center; gap: 10px;
    font-size: 13px; font-weight: 600;
    animation: slideIn .3s ease;
    min-width: 280px;
    transition: opacity .3s, transform .3s;
}
.toast.success { border-left: 4px solid #0f9d63; }
.toast.error   { border-left: 4px solid #d5304a; }
.toast.info    { border-left: 4px solid var(--blue-accent); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 760px) {
    .sidebar { display: none; }
    .query-card, .panel-card { padding: 22px; }
    .stats-grid, .monitor-grid { grid-template-columns: 1fr; }
    .card-wrap-wide { padding: 0 4px; }
}

/* ── BANNER DE ERRO DE API ───────────────────────────────── */
.api-error-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-left: 4px solid #f59e0b;
    border-radius: 10px;
    padding: 14px 18px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 600;
    color: #7c5a00;
}
