/* A interface da operação. Sem framework: tokens de cor em :root, modo escuro pelo sistema. */

:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --zebra: #fafbfc;
  --hover: #f1f5fd;
  --side-bg: #fbfbfc;
  --fg: #1b1f24;
  --muted: #667085;
  --line: #e5e7eb;
  --line-strong: #d0d5dd;
  --accent: #2563d9;
  --accent-fg: #ffffff;
  --accent-soft: #e9f0fd;
  --link: #2257c4;
  --pos: #0d7a43;
  --neg: #c2352a;
  --ok: #11663a;
  --ok-bg: #dff5e8;
  --warn: #8a5a00;
  --warn-bg: #fff3d1;
  --danger: #a8281e;
  --danger-bg: #fde4e1;
  --other: #4b3aa8;
  --other-bg: #ece8ff;
  --gray-bg: #eceef1;
  --new-bg: #fff8db;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 6%);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #171a1f;
    --surface-2: #1d2127;
    --zebra: #1a1d22;
    --hover: #1f2836;
    --side-bg: #13161a;
    --fg: #e6e8eb;
    --muted: #9aa3ae;
    --line: #2a2f36;
    --line-strong: #3a414b;
    --accent: #5b8fef;
    --accent-fg: #0b1220;
    --accent-soft: #1b2a45;
    --link: #8ab4ff;
    --pos: #6fd49a;
    --neg: #ff8f84;
    --ok: #7ad9a0;
    --ok-bg: #173826;
    --warn: #f3c35b;
    --warn-bg: #3a2f12;
    --danger: #ff9a8f;
    --danger-bg: #4a1f1b;
    --other: #b9adff;
    --other-bg: #2a2550;
    --gray-bg: #2a2e34;
    --new-bg: #3a3214;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
code { font-size: .9em; background: var(--gray-bg); padding: 0 .3em; border-radius: 4px; }
pre { overflow-x: auto; font-size: .8rem; background: var(--surface); padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 8px; margin: .5rem 0 0; }
.muted { color: var(--muted); }
small.muted, .small { font-size: .82rem; }
.svg-icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------ esqueleto: menu lateral e conteúdo */

.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: .9rem;
  padding: 1rem .75rem; background: var(--side-bg); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; padding: .1rem .5rem; color: var(--fg); font-weight: 700; font-size: 1rem; }
.brand:hover { text-decoration: none; }
.brand .logo { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); font-size: .8rem; }
.menu-btn { display: none; }

.switch { display: flex; gap: 2px; padding: 3px; background: var(--gray-bg); border-radius: 9px; }
.switch a, .switch span { flex: 1; text-align: center; padding: .3rem .4rem; border-radius: 7px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.switch a:hover { color: var(--fg); text-decoration: none; }
.switch .on { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); font-weight: 600; }

.side .menu { display: flex; flex-direction: column; gap: 1px; }
.side .menu h3 { margin: .9rem .6rem .3rem; font-size: .7rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.side .menu h3:first-child { margin-top: 0; }
.side .menu a { display: flex; align-items: center; gap: .6rem; padding: .42rem .6rem; border-radius: 7px; color: var(--fg); }
.side .menu a:hover { background: var(--gray-bg); text-decoration: none; }
.side .menu a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .user { margin-top: auto; display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem 0; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.side .user .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .user form { margin: 0; }

/* o entrar: uma página só, sem menu */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
body.login .card { width: min(22rem, 100%); padding: 1.5rem; }
body.login .brand { padding: 0; margin: 0 0 1.25rem; font-size: 1.15rem; }
body.login .btn { width: 100%; justify-content: center; }
body.login p:last-child { margin-bottom: 0; }

main { min-width: 0; padding: 1.4rem 1.75rem 3rem; }
.content { max-width: 1320px; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .6rem 1rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .side .switch { order: 3; flex-basis: 100%; }
  .side .menu { order: 4; flex-basis: 100%; }
  .side .user { order: 5; flex-basis: 100%; }
  .js .menu-btn { display: inline-flex; margin-left: auto; }
  .js .side:not(.open) .menu, .js .side:not(.open) .user { display: none; }
  main { padding: 1rem 1rem 2.5rem; }
}

/* ------------------------------------------------------------ cabeçalho da página */

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1.5rem; margin: 0 0 1.1rem; }
.page-head h1 { margin: 0; font-size: 1.5rem; font-weight: 650; letter-spacing: -.01em; }
.page-head .sub { margin: .2rem 0 0; color: var(--muted); }
.page-head .actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.back { display: inline-flex; align-items: center; gap: .3rem; margin: 0 0 .5rem; font-size: .9rem; }

.refresh { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .35rem .6rem; font-size: .85rem; }
.refresh .error { flex-basis: 100%; margin: 0; }
form.inline { display: inline; margin: 0; }

/* ------------------------------------------------------------ botões, campos, etiquetas */

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 2.25rem; padding: .4rem .9rem;
  font: inherit; font-weight: 550; line-height: 1.2; white-space: nowrap;
  color: var(--fg); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
  cursor: pointer; text-decoration: none;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { color: var(--accent-fg); background: var(--accent); border-color: var(--accent); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.07); }
button.small, .btn.small { min-height: 1.85rem; padding: .2rem .6rem; font-size: .85rem; }
button.change { color: var(--other); background: var(--other-bg); border-color: currentColor; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  min-height: 2.25rem; padding: .4rem .6rem;
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px;
}
input[type=checkbox], input[type=radio] { min-height: 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { display: block; width: 100%; }
select { max-width: 100%; }

.badge { display: inline-block; padding: .08rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 550; white-space: nowrap; background: var(--gray-bg); color: var(--fg); }
.badge.pending, .badge.today { background: var(--warn-bg); color: var(--warn); }
.badge.resolved, .badge.paid, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.change { background: var(--other-bg); color: var(--other); }
.badge.warn, .badge.late { background: var(--danger-bg); color: var(--danger); }
.badge.open { background: var(--accent-soft); color: var(--accent); }

.notice, .error {
  display: block; margin: 0 0 1rem; padding: .7rem 1rem;
  border: 1px solid transparent; border-radius: var(--radius);
}
.error, .notice.error { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.notice.ok { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.notice.warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.notice.info { background: var(--accent-soft); color: var(--fg); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.notice b, .error b { font-weight: 650; }
.notice a, .error a { color: inherit; text-decoration: underline; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.25rem; margin: 0 0 1rem; box-shadow: var(--shadow); }
.card > h2:first-child { margin-top: 0; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .25rem 1.25rem 1rem; margin: 1rem 0; }

/* ------------------------------------------------------------ números em destaque */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin: 0 0 1rem; }
.stat { min-width: 0; padding: .75rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat .label { display: block; color: var(--muted); font-size: .8rem; }
.stat .value { display: block; margin-top: .1rem; font-size: 1.2rem; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .value a { color: inherit; }
.stat .hint { display: block; color: var(--muted); font-size: .8rem; }
.stat.strong { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .stat { padding: .6rem .75rem; }
  .stat .value { font-size: 1.02rem; }
}

/* ------------------------------------------------------------ filtros */

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .75rem; }
.chip { display: inline-block; padding: .28rem .8rem; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--fg); font-size: .85rem; font-weight: 500; }
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: 0 0 1rem; }
.filters .grow { flex: 1 1 14rem; min-width: 0; }
.filters .range { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); }
.filters .check { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); white-space: nowrap; }
.filters .clear { font-size: .85rem; }
.js .nojs { display: none; }
.loading [data-live="results"] { opacity: .55; transition: opacity .15s; }

/* ------------------------------------------------------------ tabelas */

.table-wrap { overflow: clip; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin: 0 0 1rem; }
.table-wrap.wide { overflow: auto; max-height: calc(100vh - 2rem); }
@media (max-width: 1100px) { .table-wrap { overflow-x: auto; } }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: .5rem .75rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
thead { position: sticky; top: 0; z-index: 2; }
thead th { background: var(--surface-2); color: var(--muted); font-size: .78rem; font-weight: 600; white-space: nowrap; }
thead th a { color: inherit; }
thead th a:hover { color: var(--fg); }
tbody tr:nth-child(even) > td { background: var(--zebra); }
tbody tr:hover > td { background: var(--hover); }
tbody tr:last-child > td { border-bottom: 0; }
tfoot th, tfoot td { position: sticky; bottom: 0; background: var(--surface-2); color: var(--fg); font-weight: 650; border-top: 1px solid var(--line-strong); border-bottom: 0; }
td.empty { padding: 2rem; text-align: center; color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
td.notes { min-width: 16rem; max-width: 30rem; overflow-wrap: anywhere; }
.status { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
tr.adjust > td { background: var(--surface-2); color: var(--muted); font-style: italic; }
tbody tr.new > td { background: var(--new-bg); }
tbody tr.new > td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.row-actions { display: inline-flex; gap: .4rem; }

/* o balancete: a primeira coluna presa ao rolar para o lado */
.report th:first-child, .report td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 14rem; }
.report thead th:first-child { z-index: 3; background: var(--surface-2); }
/* sem listras: as linhas escondidas trocariam a ordem delas */
.report tbody tr > td { background: var(--surface); }
.report tbody tr:hover > td { background: var(--hover); }
/* o balancete em níveis: a seção com o total, as categorias e as filhas, recuadas */
.report tr.l0 > td { font-weight: 650; background: var(--surface-2); }
.report tr.l0 > td:first-child { text-transform: uppercase; font-size: .8rem; letter-spacing: .05em; }
.report tr.l1 > td:first-child { padding-left: 1.6rem; }
.report tr.l2 > td:first-child { padding-left: 3.4rem; }
.report tr.l2 > td { color: var(--muted); font-size: .92rem; }
.report tr.balance > td, .report tr.strong > td { font-weight: 650; background: var(--surface-2); }
.report tr.strong > td { border-top: 2px solid var(--line-strong); border-bottom: 2px solid var(--line-strong); }
.report tr.gap > td { font-style: italic; }
.report .tree { all: unset; cursor: pointer; display: inline-block; width: 1.1rem; margin-left: -1.3rem; margin-right: .2rem; text-align: center; color: var(--muted); }
.report tr.l0 .tree { margin-left: 0; }
.report .tree::before { content: '▸'; display: inline-block; transition: transform .15s; }
.report .tree[aria-expanded="true"]::before { transform: rotate(90deg); }
.report .tree:focus-visible { outline: 2px solid var(--accent); border-radius: 3px; }
html:not(.js) .report .tree { visibility: hidden; }

.pager { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: 0 0 1rem; color: var(--muted); }
.list-meta { margin: 0 0 .5rem; color: var(--muted); font-size: .88rem; }
.foot-note { color: var(--muted); font-size: .85rem; max-width: 60rem; }

/* ------------------------------------------------------------ formulários das operações */

.op-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(18rem, 24rem); gap: 1.25rem; align-items: start; }
.op-layout > .aside { position: sticky; top: 1rem; }
@media (max-width: 1100px) { .op-layout { grid-template-columns: minmax(0, 1fr); } .op-layout > .aside { position: static; } }

.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr)); gap: .9rem 1rem; }
.form .field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.form .field > span:first-child, .form .label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.form .field input, .form .field select { width: 100%; }
.form .field small { color: var(--muted); font-size: .78rem; }
.form .wide { grid-column: 1 / -1; }
.form .span2 { grid-column: span 2; }
@media (max-width: 640px) { .form .span2 { grid-column: 1 / -1; } }
.form fieldset { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .8rem 1rem; margin: 0; padding: .75rem 1rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); }
.form legend { padding: 0 .35rem; font-weight: 600; }
.form .choice { display: flex; align-items: center; gap: .45rem; padding: .35rem 0; }
.form .buttons { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: .25rem; }
.form .check { flex-direction: row; align-items: center; gap: .45rem; align-self: end; padding-bottom: .5rem; }
.form .field input[type=checkbox], .form .field input[type=radio] { width: auto; }
[hidden] { display: none !important; }

.money { position: relative; display: block; }
.money::before { content: "R$"; position: absolute; left: .65rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .9rem; pointer-events: none; }
.money input { padding-left: 2.1rem; text-align: right; font-variant-numeric: tabular-nums; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--gray-bg); border-radius: 9px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: .3rem .9rem; border-radius: 7px; color: var(--muted); font-weight: 550; }
.seg input:checked + span { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.combo { position: relative; display: block; }
.suggest { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); max-height: 18rem; overflow-y: auto; margin: 0; padding: .25rem; list-style: none; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / 14%); }
.suggest li { display: flex; justify-content: space-between; gap: .75rem; padding: .4rem .6rem; border-radius: 6px; cursor: pointer; }
.suggest li[aria-selected=true], .suggest li:hover { background: var(--accent-soft); }
.suggest li .doc { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.suggest li.info { cursor: default; color: var(--muted); background: none; }

.summary-card dl, .confirm dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .3rem 1rem; margin: .5rem 0 0; }
.summary-card dt, .confirm dt { color: var(--muted); }
.summary-card dd, .confirm dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }

.confirm { padding: 1rem 1.25rem; border: 1px solid var(--accent); border-radius: 12px; background: var(--accent-soft); }
.confirm h2 { margin: 0 0 .35rem; font-size: 1.05rem; }
.confirm .lead { margin: 0; }
.confirm details { margin: .75rem 0 0; }
.confirm summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
.confirm .buttons { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: 1rem; }
.confirm .stale-msg { display: none; margin: .75rem 0 0; color: var(--warn); font-weight: 550; }
.confirm.stale { border-color: var(--line-strong); background: var(--surface-2); }
.confirm.stale .stale-msg { display: block; }
.confirm.outcome-error { border-color: var(--danger); background: var(--danger-bg); }
.confirm.outcome-ok { border-color: var(--ok); background: var(--ok-bg); }
.confirm .error { margin: .75rem 0 0; }
.steps { margin: .25rem 0 0; padding-left: 1.2rem; color: var(--muted); }
.steps li { margin: .25rem 0; }

/* ------------------------------------------------------------ cadastros */

.rule { font-variant-numeric: tabular-nums; color: var(--muted); }
.title { font-size: 1.1rem; font-weight: 550; margin: .25rem 0; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; color: var(--muted); }
.adjusted { font-weight: 550; }
.history { margin: 0; padding-left: 1.1rem; }
.history li { margin-bottom: .5rem; }
.tallies { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .75rem; margin: 0 0 1rem; }
.tallies .stat a { display: block; font-size: .9rem; }
.decide .buttons { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0 0; }
.decide textarea { margin: .5rem 0 0; }

/* a lista das contas da recorrência, na simulação da alteração */
.confirm table.mini { width: 100%; margin: .75rem 0 .25rem; font-size: .88rem; border-collapse: collapse; }
.confirm table.mini th, .confirm table.mini td { padding: .2rem .4rem; background: transparent; position: static; border-bottom: 1px solid var(--line); }
.aside > section + section { margin-top: 1rem; }
.form fieldset > .wide { grid-column: 1 / -1; }
.confirm table.mini td:last-child { overflow-wrap: anywhere; }

/* conciliação */
table.recon ul.matched, table.recon ul.suggestions { list-style: none; margin: .25rem 0 0; padding: 0; }
table.recon ul.suggestions li { margin: 0 0 .3rem; }
table.recon ul.suggestions form.inline { margin-right: .35rem; }
table.recon tr.pending > td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: .75rem; }
p.sum { font-weight: 600; color: var(--warn); }
p.sum.ok { color: var(--ok); }
form.bulk button { white-space: normal; text-align: left; }

/* o seletor em links (o marketplace nas telas dos marketplaces) */
.seg a { display: block; padding: .3rem .9rem; border-radius: 7px; color: var(--muted); font-weight: 550; }
.seg a:hover { color: var(--fg); text-decoration: none; }
.seg a.on { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }

/* os pedidos dos marketplaces têm muitas colunas de valor: mais justas, para caber sem rolar */
table.orders th, table.orders td { padding-left: .5rem; padding-right: .5rem; }
table.orders th:first-child, table.orders td:first-child { padding-left: .75rem; }

/* o saldo dos marketplaces: a divisão de uma parte (a bandeira, na Amazon) recuada */
table.balance tr.sub td:first-child { padding-left: 1.75rem; }
table.balance tr.sub td { border-bottom-style: dashed; padding-top: .3rem; padding-bottom: .3rem; }
