:root {
  --forest: #1e5a35; --leaf: #3f8f3a; --sprout: #7cc46f; --gold: #b39a52;
  --bg: #f4f6f1; --surface: #ffffff; --surface-2: #eef3ec; --text: #17301f; --muted: #5d6f61;
  --line: #dde5da; --accent: var(--forest); --accent-2: var(--leaf); --on-accent: #ffffff;
  --ok-bg: #e5f2e1; --ok-fg: #1e5a35; --err-bg: #fbe9e7; --err-fg: #9b2c1f; --warn-bg: #fff4d9; --warn-fg: #7a5600;
  --shadow: 0 1px 2px rgba(20, 50, 30, .06), 0 4px 16px rgba(20, 50, 30, .05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1712; --surface: #15221a; --surface-2: #1b2b21; --text: #e3ece4; --muted: #9db1a2; --line: #26392d;
    --accent: #3f8f3a; --accent-2: #7cc46f; --ok-bg: #173523; --ok-fg: #a8dca0; --err-bg: #3a1a16; --err-fg: #f3b3a8;
    --warn-bg: #3a2e10; --warn-fg: #f1d48a; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1712; --surface: #15221a; --surface-2: #1b2b21; --text: #e3ece4; --muted: #9db1a2; --line: #26392d;
  --accent: #3f8f3a; --accent-2: #7cc46f; --ok-bg: #173523; --ok-fg: #a8dca0; --err-bg: #3a1a16; --err-fg: #f3b3a8;
  --warn-bg: #3a2e10; --warn-fg: #f1d48a; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent-2); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.top { display: flex; align-items: center; gap: 1rem; padding: .6rem 16px; background: var(--forest); color: #fff; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-size: 1.05rem; }
.brand b { color: var(--sprout); }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a { color: #d8ead6; text-decoration: none; padding: .35rem .7rem; border-radius: 8px; }
.nav a.on, .nav a:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.who { margin-left: auto; display: flex; align-items: center; gap: .75rem; font-size: .85rem; color: #d8ead6; }
.who form { margin: 0; }
.link { background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.theme { background: rgba(255, 255, 255, .12); border: 0; color: #fff; border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 1rem; }
.brand + .theme { margin-left: auto; }

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 16px; }
.hero { margin: .5rem 0 1.25rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tile { display: flex; flex-direction: column; gap: .35rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; color: var(--text); text-decoration: none; box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
a.tile:hover, a.tile:focus-visible { transform: translateY(-2px); border-color: var(--accent-2); outline: none; }
.tile h2 { margin: .25rem 0 0; font-size: 1.05rem; }
.tile p { margin: 0; color: var(--muted); font-size: .9rem; flex: 1; }
.tile .ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--accent-2); font-size: 1.2rem; }
.tile.soon { opacity: .6; }
.ext { color: var(--muted); font-size: .85em; }
.pill { align-self: flex-start; font-size: .72rem; padding: .15rem .55rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.in { background: var(--ok-bg); color: var(--ok-fg); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 9px; padding: .55rem .95rem; font: inherit; cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: .25rem .6rem; min-height: 30px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: wait; }

.form { display: flex; flex-direction: column; gap: .75rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
label.inline { max-width: 320px; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: .5rem .65rem; min-height: 40px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
input:invalid:not(:placeholder-shown) { border-color: var(--err-fg); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

.flash { padding: .7rem .9rem; border-radius: 9px; margin-bottom: 14px; background: var(--ok-bg); color: var(--ok-fg); }
.flash.err { background: var(--err-bg); color: var(--err-fg); }
.flash.warn { background: var(--warn-bg); color: var(--warn-fg); margin: 0; }
.flash.warn label { flex-direction: row; align-items: center; color: inherit; font-weight: 600; margin-top: .5rem; }
.flash.warn input { width: auto; min-height: 0; }

.login { max-width: 400px; margin: 6vh auto; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button, .tabs a { background: none; border: 0; border-bottom: 2px solid transparent; padding: .6rem .9rem; font: inherit; color: var(--muted); cursor: pointer; text-decoration: none; white-space: nowrap; }
.tabs .on { color: var(--text); border-bottom-color: var(--accent-2); font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filters label { flex: 1 1 130px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi span { display: block; color: var(--muted); font-size: .8rem; }
.kpi strong { display: block; font-size: 1.45rem; margin: .15rem 0; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: .78rem; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 { margin-bottom: 16px; }
.chartbox { position: relative; height: 260px; }

.ranking { display: flex; flex-direction: column; gap: .35rem; max-height: 300px; overflow: auto; }
.barrow { display: grid; grid-template-columns: 130px 1fr auto; gap: .6rem; align-items: center; background: none; border: 0; padding: .2rem 0; color: var(--text); font: inherit; font-size: .85rem; text-align: left; cursor: pointer; }
.barrow .track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.barrow .fill { display: block; height: 100%; background: var(--accent-2); border-radius: 99px; }
.barrow b { font-variant-numeric: tabular-nums; font-weight: 600; }

.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; font-variant-numeric: tabular-nums; }
th, td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
td.n, th.n { text-align: right; }
tfoot td, tfoot th { font-weight: 700; }
tr.voided td { text-decoration: line-through; color: var(--muted); }
td.na { color: var(--muted); }
.result { white-space: pre-wrap; background: var(--surface-2); border-radius: 9px; padding: .75rem; font-size: .8rem; max-height: 420px; overflow: auto; }
.result:empty { display: none; }
.token { display: block; padding: .6rem; background: var(--surface-2); border-radius: 8px; word-break: break-all; user-select: all; }
.created { border-color: var(--accent-2); }
.diff { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.diff pre { white-space: pre-wrap; word-break: break-word; font-size: .75rem; max-width: 380px; margin: .25rem 0; }

@media (max-width: 800px) {
  .grid2 { grid-template-columns: 1fr; }
  .who { margin-left: 0; width: 100%; justify-content: space-between; order: 3; }
  .top { gap: .5rem; }
  .theme { margin-left: auto; }
  .two { grid-template-columns: 1fr; }
  .barrow { grid-template-columns: 100px 1fr auto; }
  .diff { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
}
@media print { .top, .tabs, .filters, .foot, form { display: none !important; } }
.kpi strong span { display: inline; font-size: .8rem; color: var(--muted); }
@media (max-width: 800px) { .brand { order: 0; } .theme { order: 1; } .nav { order: 2; width: 100%; } .who { order: 3; } }
[hidden] { display: none !important; }
.goalhead { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: .75rem; }
.goalhead h2 { margin: 0 auto 0 0; align-self: center; }
.goalhead .manage { display: flex; gap: .5rem; align-items: flex-end; }
.inline-sm { flex-direction: column; max-width: 170px; }
.goal .kpis { margin-bottom: 0; }
.farol { display: inline-block; width: .8em; height: .8em; border-radius: 50%; margin-right: .35em; vertical-align: baseline; }
.farol.verde { background: #3f8f3a; } .farol.amarelo { background: #d6a300; } .farol.vermelho { background: #c0392b; } .farol.sem_ritmo, .farol.sem_meta { background: var(--line); }
table.items input, table.items select { min-height: 34px; padding: .3rem .45rem; }
table.items td { padding: .25rem; } table.items input { text-align: right; min-width: 90px; }
.card.soon { opacity: .7; border-style: dashed; }
.up { color: var(--leaf); } .down { color: var(--err-fg); }

/* Enviar, conta e caixa de entrada */
textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: .6rem .65rem; width: 100%; resize: vertical; min-height: 96px; }
textarea:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
label.check input { width: auto; min-height: 0; }
.who a { color: inherit; text-decoration: none; }
.who a:hover { text-decoration: underline; }
.enviar { max-width: 640px; margin: 0 auto; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.btn.big { min-height: 56px; font-size: 1.05rem; color: var(--text); }
.btn.primary.big { color: var(--on-accent); }
.btn.rec { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-fg); }
.previas { display: flex; flex-wrap: wrap; gap: .6rem; }
.previa { display: flex; flex-direction: column; gap: .3rem; align-items: flex-start; }
.previa img { width: 110px; height: 110px; object-fit: cover; border-radius: 9px; border: 1px solid var(--line); }
.previa audio, .anexos audio { max-width: 100%; }
.envios { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .7rem; }
.envios li { border-bottom: 1px solid var(--line); padding-bottom: .6rem; }
.entrada header { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.entrada .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.anexos { display: flex; flex-wrap: wrap; gap: .6rem; margin: .5rem 0; }
.anexos img { width: 160px; height: 160px; object-fit: cover; border-radius: 9px; border: 1px solid var(--line); }
.tratar { display: flex; gap: .5rem; flex-wrap: wrap; }
.tratar input { flex: 1; min-width: 180px; }
#audioStatus:empty, #previas:empty, #resultado:empty { display: none; }

/* Financeiro */
.neg { color: var(--err-fg); }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); }
.fbar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; min-width: 80px; }
.fbar i { display: block; height: 100%; border-radius: 4px; }
.fbar i.ent { background: var(--accent-2); }
.fbar i.sai { background: var(--err-fg); opacity: .75; }
.catl { display: grid; grid-template-columns: minmax(90px, 1.2fr) 2fr auto; gap: .6rem; align-items: center; font-size: .85rem; padding: .25rem 0; }
.catl span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#finResultado:empty { display: none; }
