:root {
    --bg: #0f172a;
    --bg-soft: #1e293b;
    --card: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --brand: #0078d4;      /* Azure blue */
    --brand-dark: #005a9e;
    --accent: #22c55e;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: #f1f5f9;
    line-height: 1.5;
}

.wrap { max-width: 1160px; margin: 0 auto; padding: 0 20px; }

/* ---- Top bar ---- */
.topbar {
    background: linear-gradient(135deg, var(--bg) 0%, #17305c 100%);
    color: #fff;
    padding: 18px 0;
    box-shadow: var(--shadow);
}
.topbar .wrap {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand .logo { font-size: 34px; line-height: 1; }
.brand h1 { font-size: 20px; margin: 0; font-weight: 650; }
.subtitle { margin: 2px 0 0; font-size: 13px; color: #cbd5e1; }

.controls { display: flex; align-items: center; gap: 10px; }
#rangeSelect {
    padding: 9px 12px; border-radius: 8px; border: 1px solid #33507f;
    background: #16264a; color: #fff; font-size: 14px; cursor: pointer;
}
.btn-refresh {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 18px; border: 0; border-radius: 8px;
    background: var(--brand); color: #fff; font-size: 14px; font-weight: 600;
    cursor: pointer; transition: background .15s, transform .05s;
}
.btn-refresh:hover { background: var(--brand-dark); }
.btn-refresh:active { transform: translateY(1px); }
.btn-refresh:disabled { opacity: .65; cursor: not-allowed; }
.btn-ghost {
    padding: 9px 12px; border: 1px solid #33507f; border-radius: 8px;
    background: #16264a; color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-ghost:hover { background: #1e3358; }
.tag {
    font-size: 11px; font-weight: 600; color: #0078d4; background: #e8f1fb;
    border-radius: 999px; padding: 2px 8px; margin-left: 6px; vertical-align: middle;
}
.btn-refresh .icon { display: inline-block; font-size: 16px; }
.btn-refresh.spinning .icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toast ---- */
.toast {
    display: none; margin: 18px 0 0; padding: 12px 16px; border-radius: 8px;
    font-size: 14px; border: 1px solid var(--line); background: #fff; box-shadow: var(--shadow);
}
.toast.show { display: block; }
.toast.ok { border-left: 4px solid var(--accent); }
.toast.err { border-left: 4px solid #ef4444; }
.toast.info { border-left: 4px solid var(--brand); }

/* ---- Warning banner (extracao com erro) ---- */
.warn {
    margin: 18px 0 0; padding: 12px 16px; border-radius: 8px; font-size: 13.5px;
    background: #fef2f2; color: #991b1b; border: 1px solid #fecaca;
    box-shadow: var(--shadow); word-break: break-word;
}
.warn[hidden] { display: none; }

/* ---- Barra do filtro de assinatura ---- */
.subfilter {
    margin: 18px 0 0; padding: 10px 14px; border-radius: 8px; font-size: 13.5px;
    background: #e8f1fb; color: #0f172a; border: 1px solid #bfdbfe;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.subfilter[hidden] { display: none; }
.chip-clear {
    border: 0; background: var(--brand); color: #fff; border-radius: 999px;
    padding: 4px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.chip-clear:hover { background: var(--brand-dark); }

/* ---- Cards ---- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 22px 0; }
.card {
    background: var(--card); border-radius: 12px; padding: 18px 20px;
    box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
}
.card-label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 26px; font-weight: 700; }
.card-value.small { font-size: 15px; font-weight: 600; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- Panels ---- */
.panel {
    background: var(--card); border-radius: 12px; padding: 20px 22px;
    box-shadow: var(--shadow); margin-bottom: 20px;
}
.panel h2 { font-size: 16px; margin: 0 0 14px; }
.chart-box { position: relative; height: 300px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ---- Table ---- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: #f8fafc; }
.table tr.clickable { cursor: pointer; }
.table tr.selected { background: #e8f1fb; }
.table tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--brand); font-weight: 600; }
.table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; color: var(--muted); }
.table th.sortable:hover { color: var(--brand); }
.table th.sortable.sorted { color: var(--brand); }
.table thead th { position: sticky; top: 0; background: var(--card); z-index: 1; }

/* Dica de coluna / drill-down */
.col-hint { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- Panel head + search ---- */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.search {
    padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
    font-size: 14px; min-width: 260px; max-width: 100%;
}
.search:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.table-scroll { overflow-x: auto; max-height: 520px; overflow-y: auto; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 2px 0; }

/* ---- Footer ---- */
.footer { color: var(--muted); font-size: 13px; padding: 24px 20px 40px; }

@media (max-width: 860px) {
    .cards { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
    .cards { grid-template-columns: 1fr; }
    .brand h1 { font-size: 17px; }
}
