:root {
    --bg: #f6f8ec;
    --surface: #fbfdf4;
    --surface-strong: #ffffff;
    --ink: #12241f;
    --muted: #50635c;
    --line: #d6dec5;
    --brand: #0f8752;
    --brand-dark: #07663d;
    --warning: #c66b1c;
    --danger: #b32020;
    --radius: 16px;
    --shadow: 0 22px 46px rgba(18, 36, 31, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 20% 10%, #dbead4, transparent 42%),
        radial-gradient(circle at 87% 0%, #f7e3c2, transparent 36%), var(--bg);
    color: var(--ink);
    font-family: "Space Grotesk", "IBM Plex Sans", "Trebuchet MS", sans-serif;
    line-height: 1.5;
    position: relative;
}

.bg-orb {
    position: fixed;
    width: 340px;
    height: 340px;
    border-radius: 999px;
    filter: blur(70px);
    opacity: 0.24;
    pointer-events: none;
    z-index: 0;
}

.bg-orb-a {
    background: #9bc8a8;
    top: 12%;
    left: -90px;
}

.bg-orb-b {
    background: #efcb99;
    bottom: 10%;
    right: -80px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 14px 22px;
    background: rgba(246, 248, 236, 0.88);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(18, 36, 31, 0.08);
}

.brand {
    text-decoration: none;
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.brand strong {
    display: block;
    letter-spacing: 0.2px;
}

.brand small {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
    letter-spacing: 0.28px;
    text-transform: uppercase;
}

.brand-chip {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(130deg, var(--brand), var(--brand-dark));
    color: #f5ffe4;
    font-weight: 700;
}

.topbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.menu-links {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.menu-link {
    text-decoration: none;
    color: #345048;
    font-size: 0.88rem;
    border-radius: 999px;
    padding: 7px 10px;
    border: 1px solid transparent;
}

.menu-link:hover {
    border-color: var(--line);
    background: #fff;
}

.menu-link.active {
    border-color: #9ccfae;
    background: #e8f5e9;
    color: #0b6c40;
}

.user-badge {
    padding: 6px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.88rem;
    color: var(--muted);
    background: var(--surface);
}

.container {
    position: relative;
    z-index: 2;
    max-width: 1180px;
    margin: 26px auto 36px;
    padding: 0 18px;
}

.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.72);
    box-shadow: var(--shadow);
    padding: 22px;
}

.panel h1,
.panel h2 {
    margin: 0;
}

.panel p {
    color: var(--muted);
    margin: 8px 0 0;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.panel-actions {
    display: inline-flex;
    gap: 8px;
    align-items: center;
}

.auth-panel {
    max-width: 430px;
    margin: 48px auto;
}

.stack {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

label {
    display: grid;
    gap: 6px;
    font-size: 0.92rem;
    color: var(--muted);
}

input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
    outline: none;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(15, 135, 82, 0.14);
}

select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
    outline: none;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(15, 135, 82, 0.14);
}

.error {
    margin: 0;
    font-size: 0.9rem;
    color: var(--danger);
}

.notice {
    margin: 0 0 14px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    font-size: 0.9rem;
}

.notice.warning {
    border-color: #f2d1ab;
    background: #fff4e4;
    color: #8f4d10;
}

.notice a {
    color: inherit;
    font-weight: 600;
    margin-left: 6px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 10px;
    border: 1px solid transparent;
    padding: 9px 12px;
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--ink);
    cursor: pointer;
    transition:
        transform 0.16s ease,
        box-shadow 0.16s ease,
        background 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn.primary {
    background: linear-gradient(130deg, var(--brand), var(--brand-dark));
    color: #efffeb;
    box-shadow: 0 10px 18px rgba(7, 102, 61, 0.26);
}

.btn.ghost {
    border-color: var(--line);
    background: var(--surface-strong);
}

.btn.danger {
    border-color: #efc0c0;
    background: #fff1f1;
    color: #8f1c1c;
}

.btn.danger:hover {
    background: #ffe6e6;
}

.btn.small {
    padding: 6px 10px;
    font-size: 0.82rem;
    border-color: var(--line);
    background: var(--surface-strong);
}

.inline-form {
    margin: 0;
}

.glosa-code {
    position: relative;
    display: inline-block;
    cursor: help;
    border-bottom: 1px dashed #8fa398;
    line-height: 1.2;
}

.glosa-code::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%);
    min-width: 220px;
    max-width: 380px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(12, 36, 26, 0.2);
    background: rgba(14, 28, 23, 0.96);
    color: #f4fff8;
    font-size: 0.78rem;
    line-height: 1.3;
    white-space: normal;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 35;
}

.glosa-code::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: calc(100% + 4px);
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: rgba(14, 28, 23, 0.96) transparent transparent transparent;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 35;
}

.glosa-code:hover::after,
.glosa-code:hover::before,
.glosa-code:focus-visible::after,
.glosa-code:focus-visible::before {
    opacity: 1;
    visibility: visible;
}

.grid-2 {
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.card {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.86);
    padding: 16px;
}

.card h2 {
    margin: 0;
}

.card .meta {
    margin: 8px 0 14px;
    font-size: 0.88rem;
}

.kpi-grid {
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.filters-form {
    margin-top: 18px;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    align-items: end;
}

.filters-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.charts-grid {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.chart-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    padding: 14px;
}

.chart-card h3 {
    margin: 0;
    font-size: 0.95rem;
}

.chart-card-wide {
    grid-column: 1 / -1;
}

.area-chart {
    margin-top: 12px;
}

.area-chart-svg {
    width: 100%;
    height: 250px;
    display: block;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: linear-gradient(
        180deg,
        rgba(232, 242, 223, 0.85) 0%,
        rgba(255, 255, 255, 0.96) 78%
    );
}

.area-chart-svg line {
    stroke: #d5dec8;
    stroke-width: 1;
    stroke-dasharray: 4 6;
}

.area-fill {
    opacity: 0.16;
}

.area-fill.valor_cobrado {
    fill: #0f8752;
}

.area-fill.valor_recebido {
    fill: #2f8ed7;
}

.area-fill.valor_glosado {
    fill: #d84d3f;
}

.area-line {
    fill: none;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.area-line.valor_cobrado {
    stroke: #0f8752;
}

.area-line.valor_recebido {
    stroke: #2f8ed7;
}

.area-line.valor_glosado {
    stroke: #d84d3f;
}

.area-legend {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.area-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.9);
    font-size: 0.8rem;
    color: #2d443d;
}

.area-dot {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    display: inline-block;
}

.area-dot.valor_cobrado {
    background: #0f8752;
}

.area-dot.valor_recebido {
    background: #2f8ed7;
}

.area-dot.valor_glosado {
    background: #d84d3f;
}

.area-axis {
    margin-top: 9px;
    display: grid;
    gap: 6px;
    font-size: 0.76rem;
    color: var(--muted);
}

.area-axis span {
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar-list {
    margin-top: 12px;
    display: grid;
    gap: 10px;
}

.bar-row,
.status-row {
    display: grid;
    gap: 6px;
}

.bar-meta {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.82rem;
}

.bar-meta strong {
    font-size: 0.84rem;
}

.bar-track {
    height: 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #eef4dc;
    overflow: hidden;
}

.bar-track > span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(130deg, var(--brand), var(--brand-dark));
}

.status-bars {
    margin-top: 12px;
    display: grid;
    gap: 10px;
}

.status-track > span {
    display: block;
    height: 100%;
    border-radius: 999px;
    padding: 0;
    border-width: 0;
}

.kpi {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    padding: 12px;
}

.kpi small {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.kpi strong {
    display: block;
    margin-top: 4px;
    font-size: 1.05rem;
}

.table-wrap {
    margin-top: 16px;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
}

.table-wrap.compact {
    margin-top: 10px;
    overflow: visible;
    position: relative;
}

.table-wrap.compact table {
    min-width: 0;
}

.table-wrap.compact .glosa-code::after {
    left: 0;
    transform: none;
    min-width: 200px;
    max-width: min(420px, 82vw);
}

.table-wrap.compact .glosa-code::before {
    left: 14px;
    transform: none;
}

.actions-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
    background: #fff;
}

th,
td {
    text-align: left;
    border-bottom: 1px solid var(--line);
    padding: 11px 10px;
    font-size: 0.88rem;
    vertical-align: top;
}

th {
    background: #eff4dc;
    font-size: 0.79rem;
    text-transform: uppercase;
    letter-spacing: 0.34px;
    color: #3b4d46;
}

td small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

.status {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.77rem;
    font-weight: 600;
    border: 1px solid;
}

.status.pago {
    color: #0b6c40;
    background: #e5f8ea;
    border-color: #b7e7c7;
}

.status.glosa_parcial {
    color: #8f4d10;
    background: #fff4e4;
    border-color: #f2d1ab;
}

.status.glosa_total {
    color: #931f1f;
    background: #ffe8e8;
    border-color: #f3b7b7;
}

.status.processing {
    color: #8f4d10;
    background: #fff4e4;
    border-color: #f2d1ab;
}

.empty {
    margin-top: 18px;
}

.details-box {
    margin-top: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    overflow: hidden;
}

.details-box summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    font-size: 0.9rem;
    color: #253933;
    border-bottom: 1px solid var(--line);
}

.details-box summary::-webkit-details-marker {
    display: none;
}

.details-box[open] summary {
    background: #f5fae6;
}

.mt-16 {
    margin-top: 16px;
}

.log-box {
    margin: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 420px;
    overflow: auto;
    font-size: 0.84rem;
    line-height: 1.4;
}

.error-report-list {
    margin-top: 16px;
    display: grid;
    gap: 10px;
}

.error-entry {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.92);
    padding: 10px 12px;
}

.error-entry.erro {
    border-color: #efc0c0;
    background: #fff3f3;
}

.error-entry.aviso {
    border-color: #f2d1ab;
    background: #fff9ef;
}

.error-entry-title {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #1b302a;
}

.error-entry-meta {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--muted);
}

.error-entry-meta span {
    padding: 2px 7px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
}

.error-entry-lines {
    margin: 7px 0 0;
    font-size: 0.82rem;
    color: #2d443d;
}

.envio-mismatch-list {
    margin-top: 14px;
    display: grid;
    gap: 10px;
}

.envio-mismatch-body {
    padding: 10px 12px 12px;
    border-top: 1px solid var(--line);
}

.envio-mismatch-body p {
    margin: 0 0 8px;
    font-size: 0.84rem;
    color: #2d443d;
}

@media (max-width: 980px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filters-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 700px) {
    .topbar {
        padding: 12px 14px;
    }

    .topbar-actions .user-badge {
        display: none;
    }

    .menu-links {
        display: none;
    }

    .container {
        padding: 0 10px;
    }

    .panel {
        padding: 14px;
    }

    .panel-head {
        flex-direction: column;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .filters-form {
        grid-template-columns: 1fr;
    }

    .filters-actions {
        display: grid;
    }
}
