/* Invoices Manager v2 — tokens + layout. Tema escuro via [data-bs-theme="dark"] no <html>. */
:root {
  --surface-0: #f4f5f7;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --border: #e3e4e8;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --accent-soft: #e8f1fc;
  --sidebar-bg: #111827;
  --sidebar-text: #c9cdd6;
  --sidebar-active: #1f2a3d;
  --op-vivo: #2a78d6;   /* série 1 */
  --op-claro: #eb6834;  /* série 2 */
  --op-algar: #1baf7a;  /* série 3 */
  --good: #0a7d3e; --warning: #a15c00; --critical: #c42b2b;
  --grid: #ebebea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  --bs-body-bg: var(--surface-0);
  --bs-body-color: var(--text-primary);
  --bs-border-color: var(--border);
}
[data-bs-theme="dark"] {
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --border: #33332f;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #3987e5;
  --accent-soft: #1b2a3f;
  --sidebar-bg: #0c0c0b;
  --sidebar-text: #b5b4ab;
  --sidebar-active: #1e1e1c;
  --op-vivo: #3987e5;
  --op-claro: #d95926;
  --op-algar: #199e70;
  --good: #3fb872; --warning: #e0a33a; --critical: #ef6a6a;
  --grid: #2c2c29;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --bs-body-bg: var(--surface-0);
  --bs-body-color: var(--text-primary);
  --bs-border-color: var(--border);
}

html, body { height: 100%; }
body { background: var(--surface-0); color: var(--text-primary); font-size: 14px; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-muted) !important; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex: 0 0 240px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 1040;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.1rem 1rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand small { display: block; font-weight: 400; font-size: .72rem; color: var(--sidebar-text); letter-spacing: .08em; text-transform: uppercase; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; font-size: 1.1rem; }
.sidebar nav { flex: 1; overflow-y: auto; padding: .25rem .6rem; }
.nav-item { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 8px; color: var(--sidebar-text); text-decoration: none; margin-bottom: 2px; }
.nav-item i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; padding: 1rem .7rem .35rem; color: #6b7280; }
.sidebar-footer { padding: .75rem; border-top: 1px solid rgba(255, 255, 255, .07); }
.user-chip { display: flex; align-items: center; gap: .5rem; }
.user-chip img, .user-chip .avatar { width: 32px; height: 32px; border-radius: 50%; flex: 0 0 32px; }
.user-chip .avatar { background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; }
.user-meta { flex: 1; min-width: 0; line-height: 1.15; }
.user-meta strong { display: block; color: #fff; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--sidebar-text); font-size: .72rem; }
.btn-icon { background: transparent; border: 0; color: inherit; padding: .3rem .45rem; border-radius: 6px; line-height: 1; }
.btn-icon:hover { background: rgba(127, 127, 127, .18); }
.sidebar .btn-icon { color: var(--sidebar-text); }
.active-job { background: var(--sidebar-active); border-radius: 8px; padding: .5rem .6rem; margin-bottom: .6rem; font-size: .78rem; color: #fff; text-decoration: none; display: block; }
.active-job .spinner-grow { width: .55rem; height: .55rem; color: var(--op-algar); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.5rem .25rem; }
.page-title { font-size: 1.35rem; font-weight: 650; margin: 0; flex: 1; }
.topbar-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.content { padding: 1rem 1.5rem 3rem; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .4); }
  .topbar, .content { padding-left: 1rem; padding-right: 1rem; }
}

/* ---------- componentes ---------- */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); padding: .85rem 1rem; display: flex; align-items: center; gap: .5rem; }
.card-header h2 { font-size: .95rem; font-weight: 650; margin: 0; flex: 1; }
.card-header .hint { color: var(--text-muted); font-size: .8rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 1rem; }
.stat { padding: 1rem 1.1rem; }
.stat .label { color: var(--text-secondary); font-size: .8rem; display: flex; align-items: center; gap: .35rem; }
.stat .value { font-size: clamp(1.25rem, 1.6vw, 1.55rem); white-space: nowrap; font-weight: 650; margin-top: .2rem; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .delta { font-size: .78rem; color: var(--text-muted); }
.stat .delta .up { color: var(--critical); } .stat .delta .down { color: var(--good); }
a.stat { color: inherit; text-decoration: none; }
a.stat:hover { border-color: var(--accent); }

/* ---------- tabelas ---------- */
.table {
  --bs-table-bg: transparent; --bs-table-color: var(--text-primary); --bs-table-border-color: var(--border);
  --bs-table-hover-bg: transparent; margin: 0; border-collapse: separate; border-spacing: 0;
}
/* respiro nas células: 1ª/última coluna alinhadas com o padding do card-header */
.table > :not(caption) > * > * { padding: .5rem .8rem; border-bottom: 1px solid var(--border); box-shadow: none; }
.table-sm > :not(caption) > * > * { padding: .4rem .8rem; }
.table > :not(caption) > * > :first-child { padding-left: 1.1rem; }
.table > :not(caption) > * > :last-child { padding-right: 1.1rem; }
.table > thead th {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 650;
  white-space: nowrap; background: var(--surface-0); padding-top: .5rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1;
}
.table > tbody td { vertical-align: middle; }
.table > tbody > tr:last-child > td { border-bottom: 0; }
.table > tbody > tr { transition: background-color .12s; }
.table-hover > tbody > tr:hover > * { background: var(--accent-soft); }
tr.selected > td { background: var(--accent-soft) !important; }
tr.selected > td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.table td a:not(.btn) { text-decoration: none; font-weight: 550; }
.table td a:not(.btn):hover { text-decoration: underline; }
.table td.text-end, .table th.text-end { font-variant-numeric: tabular-nums; }
.table td .small, .table td small { line-height: 1.3; }
/* ícones de ação discretos, realçados ao passar o mouse na linha */
.table td .btn-icon { color: var(--text-muted); }
.table tr:hover .btn-icon { color: var(--accent); }
.table .form-check-input { margin: 0; cursor: pointer; }
.table .empty { padding: 3rem 1rem; }
.card > .table-responsive, .card > .table-wrap, .card > .card-body.p-0 { border-radius: 0 0 var(--radius) var(--radius); }
.table-wrap { overflow: auto; max-height: calc(100vh - 290px); }
.table-wrap::-webkit-scrollbar, .table-responsive::-webkit-scrollbar { width: 10px; height: 10px; }
.table-wrap::-webkit-scrollbar-thumb, .table-responsive::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--surface-1); }
.cell-trunc { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-fill { width: 100%; max-width: 0; } /* coluna que cede espaço e trunca o texto */
.col-fill .cell-trunc { max-width: 100%; }
.mark-box { margin-top: .75rem; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }

/* operadora: etiqueta com fundo suave na cor da série */
.op-badge { display: inline-flex; align-items: center; gap: .4rem; font-weight: 650; font-size: .74rem; letter-spacing: .02em;
  padding: .15rem .55rem; border-radius: 6px; white-space: nowrap;
  color: var(--op-color, var(--text-secondary)); background: color-mix(in srgb, var(--op-color, var(--text-muted)) 12%, transparent); }
.op-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--op-color, var(--text-muted)); }
.op-VIVO { --op-color: var(--op-vivo); } .op-CLARO { --op-color: var(--op-claro); } .op-ALGAR { --op-color: var(--op-algar); }
h2 .op-badge { font-size: .8rem; }

.status-pill { --pill: var(--text-secondary); display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .6rem; border-radius: 999px;
  font-size: .72rem; font-weight: 650; white-space: nowrap; color: var(--pill);
  background: color-mix(in srgb, var(--pill) 11%, transparent); border: 1px solid color-mix(in srgb, var(--pill) 28%, transparent); }
.status-queued { --pill: var(--text-secondary); }
.status-running { --pill: var(--accent); }
.status-succeeded { --pill: var(--good); }
.status-failed { --pill: var(--critical); }
.status-cancelled { --pill: var(--warning); }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filters .form-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); margin-bottom: .2rem; }
.form-control, .form-select { background-color: var(--surface-2); border-color: var(--border); }
.date-range .form-control { width: 8.6rem; flex: 0 0 auto; }
.chip-select { position: relative; }
.chip-select .dropdown-menu { max-height: 320px; overflow-y: auto; padding: .35rem; min-width: 12rem; }
.chip-select .dropdown-menu label { display: flex; gap: .5rem; padding: .25rem .5rem; border-radius: 6px; cursor: pointer; }
.chip-select .dropdown-menu label:hover { background: var(--accent-soft); }

.bulkbar { position: sticky; bottom: 1rem; z-index: 20; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
  background: var(--sidebar-bg); color: #fff; padding: .6rem .8rem; border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); margin-top: 1rem; }
.bulkbar .count { font-weight: 600; margin-right: auto; }

.console { background: #0d1117; color: #d1d5db; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem;
  border-radius: 10px; padding: .75rem; overflow: auto; max-height: 60vh; }
.console .line { white-space: pre-wrap; word-break: break-word; padding: 1px 0; }
.console .ts { color: #6b7280; margin-right: .5rem; }
.console .lvl-warn { color: #fbbf24; } .console .lvl-error { color: #f87171; }
.console .lvl-debug { color: #93c5fd; cursor: pointer; }
.shot-viewer { background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 16/9; display: grid; place-items: center; }
.shot-viewer img { width: 100%; height: 100%; object-fit: contain; }
.shot-strip { display: flex; gap: .4rem; overflow-x: auto; padding-top: .5rem; }
.shot-strip img { height: 54px; border-radius: 4px; cursor: pointer; opacity: .6; border: 2px solid transparent; }
.shot-strip img.active, .shot-strip img:hover { opacity: 1; border-color: var(--accent); }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2.5rem 1rem; text-align: center; color: var(--text-secondary); cursor: pointer; transition: .15s; background: var(--surface-1); }
.dropzone.drag, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone i { font-size: 2.2rem; color: var(--accent); }

.chart-box { position: relative; height: 300px; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty i { font-size: 2rem; display: block; margin-bottom: .5rem; }

.sheet-grid td[contenteditable="true"] { outline: none; min-width: 90px; }
.sheet-grid td[contenteditable="true"]:focus { box-shadow: inset 0 0 0 2px var(--accent); background: var(--surface-2); }
.sheet-grid td.dirty { background: rgba(234, 179, 8, .18) !important; }
.sheet-grid .rownum { color: var(--text-muted); font-size: .75rem; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background:
  radial-gradient(1200px 600px at 10% -10%, rgba(42, 120, 214, .18), transparent), var(--surface-0); }
.login-card { width: 100%; max-width: 380px; padding: 2rem; }
.btn-google { display: flex; align-items: center; justify-content: center; gap: .6rem; width: 100%; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-primary); font-weight: 600; padding: .6rem; }
.btn-google:hover { border-color: var(--accent); }
.hide-debug .lvl-debug { display: none; }

/* ---------- prévia dos campos IXC ---------- */
.ixc-fatura + .ixc-fatura { margin-top: 1.25rem; }
.ixc-fatura .nome { font-weight: 650; font-size: .85rem; margin-bottom: .4rem; }
.ixc-table-wrap { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.ixc-table { width: 100%; font-size: .82rem; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ixc-table th, .ixc-table td { padding: .3rem .75rem; border-bottom: 1px solid var(--grid); text-align: left; }
.ixc-table tbody tr:last-child > * { border-bottom: 0; }
/* linha vertical contínua separando nomes | P01 | P02 */
.ixc-table th + th, .ixc-table th + td, .ixc-table td + td { border-left: 2px solid var(--border); }
.ixc-table thead th { background: var(--surface-1); color: var(--text-secondary); border-bottom: 2px solid var(--accent); }
.ixc-table thead th.parte { padding: .6rem .75rem; }
.ixc-table thead th.parte .p { display: inline-block; background: var(--accent); color: #fff; font-size: .8rem; font-weight: 700; padding: .1rem .5rem; border-radius: 6px; margin-right: .5rem; }
.ixc-table thead th.parte .val { font-size: 1.15rem; font-weight: 700; color: var(--text-primary); }
/* faixa de grupo: Compra / Movimento de produtos / Contas a pagar */
.ixc-table tr.grp > * { background: var(--accent-soft); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: .5rem .75rem; }
.ixc-table tr.grp th { color: var(--accent); font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; box-shadow: inset 4px 0 0 var(--accent); }
.ixc-table tr.grp th i { margin-right: .45rem; font-size: .95rem; }
.ixc-table th.k { width: 28%; font-weight: 400; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text-secondary); }
.ixc-table td { font-weight: 600; cursor: default; }
.ixc-table td.vazio { color: var(--text-muted); font-weight: 400; font-style: italic; font-size: .76rem; }
.ixc-table td.o-ixc { color: var(--good); }
.ixc-table td.o-pendente.vazio { color: var(--warning); }
