/* ============================================================
   Financeiro Cafeína — design tokens
   ============================================================ */
:root {
  --bg: #f5f1ec;
  --surface: #ffffff;
  --surface-2: #faf7f3;
  --ink: #231b16;
  --ink-2: #5c5048;
  --ink-3: #8c7f75;
  --line: #e9e1d8;
  --line-2: #f1ebe4;
  --brand: #6b8710;
  --brand-2: #55700b;
  --brand-ink: #ffffff;
  --brand-soft: #eef4d3;
  --side: #1c1612;
  --side-ink: #d9cdc2;
  --side-mute: #8d7f73;
  --pos: #1d8a5a;
  --pos-soft: #e3f4ec;
  --neg: #c2413a;
  --neg-soft: #fbe7e4;
  --warn: #a8691a;
  --warn-soft: #fbf0da;
  --shadow: 0 1px 2px rgba(35, 27, 22, .05), 0 4px 14px rgba(35, 27, 22, .04);
  --shadow-lg: 0 20px 50px rgba(35, 27, 22, .22);
  --radius: 14px;
  --radius-sm: 10px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #14100e;
  --surface: #1d1713;
  --surface-2: #231c18;
  --ink: #f2eae2;
  --ink-2: #c6b9ad;
  --ink-3: #8f8379;
  --line: #342b26;
  --line-2: #2a221e;
  --brand: #a7c523;
  --brand-2: #bcd84a;
  --brand-ink: #172002;
  --brand-soft: #29310f;
  --side: #0f0b09;
  --side-ink: #d9cdc2;
  --pos: #46c28d;
  --pos-soft: #16322580;
  --neg: #f0786e;
  --neg-soft: #3b1f1d80;
  --warn: #e3a342;
  --warn-soft: #3a2d1580;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.hide { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }

/* ============================================================ layout */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; min-height: 100vh;
  padding: 22px 14px 16px; z-index: 40;
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 4px 10px 18px; }
.brand img { width: 168px; max-width: 100%; height: auto; display: block; }
.brand small { color: var(--side-mute); font-size: 12px; padding-left: 2px; letter-spacing: .04em; }
.brand .logo { width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(145deg, #8fb015, #55700b); display: grid; place-items: center; color: #fff; box-shadow: 0 6px 16px rgba(143, 176, 21, .35); }
.brand b { display: block; font-size: 17px; letter-spacing: .01em; color: #fff; }
.brand small { color: var(--side-mute); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--side-mute); padding: 16px 12px 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--side-ink); font-weight: 500; transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .06); }
.nav a.active { background: rgba(143, 176, 21, .2); color: #fff; }
.nav a.active svg { color: #b5d33f; }
.side .foot { margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }
.userbox { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(143, 176, 21, .22); color: #c2dd55; display: grid; place-items: center; font-weight: 700; flex: none; }
.userbox .nm { font-weight: 600; color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbox .em { font-size: 12px; color: var(--side-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; color: inherit; flex: none;
}
.iconbtn:hover { background: rgba(127, 110, 98, .14); }
.side .iconbtn { color: var(--side-mute); }
.side .iconbtn:hover { color: #fff; background: rgba(255, 255, 255, .08); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line-2);
}
.topbar h1 { font-size: 20px; letter-spacing: -.01em; }
.topbar .sub { color: var(--ink-3); font-size: 13px; }
.menu-btn { display: none; }
.page { padding: 24px 28px 60px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .grow h2 { font-size: 18px; }

/* ============================================================ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--ink-3) 40%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 4px 12px color-mix(in srgb, var(--brand) 30%, transparent); }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(127, 110, 98, .12); }
.btn.danger { color: var(--neg); }
.btn.danger.solid { background: var(--neg); color: #fff; border-color: var(--neg); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.input, .select, textarea.input {
  height: 38px; width: 100%; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 70px; }
.input:focus, .select:focus, textarea.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238c7f75' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
label.fld { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field { min-width: 0; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 11px; top: 10px; color: var(--ink-3); width: 17px; height: 17px; }
.input-icon .input { padding-left: 36px; }
.help { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-weight: 600; font-size: 13px;
  color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(35, 27, 22, .12); }
.seg button.on.rec { color: var(--pos); }
.seg button.on.desp { color: var(--neg); }

.monthnav { display: inline-flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.monthnav button { border: 0; background: transparent; width: 36px; height: 38px; cursor: pointer; display: grid; place-items: center; color: var(--ink-2); }
.monthnav button:hover { color: var(--brand); }
.monthnav .lbl { min-width: 150px; text-align: center; font-weight: 700; text-transform: capitalize; }

/* ============================================================ cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .hd { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; }
.card .hd h3 { font-size: 14px; font-weight: 700; }
.card .hd .sub { color: var(--ink-3); font-size: 12px; }
.card .bd { padding: 16px 18px 18px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.mb { margin-bottom: 16px; }

.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi .lb { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-weight: 600; font-size: 13px; }
.kpi .ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; }
.kpi .ic.rec { background: var(--pos-soft); color: var(--pos); }
.kpi .ic.desp { background: var(--neg-soft); color: var(--neg); }
.kpi .ic.res { background: var(--brand-soft); color: var(--brand); }
.kpi .ic.cash { background: var(--warn-soft); color: var(--warn); }
.kpi .v { font-size: 26px; font-weight: 750; letter-spacing: -.02em; margin: 10px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .s { color: var(--ink-3); font-size: 12.5px; display: flex; gap: 6px; flex-wrap: wrap; }
.bar { height: 6px; border-radius: 99px; background: var(--line-2); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--brand); }
.bar.pos > i { background: var(--pos); } .bar.neg > i { background: var(--neg); }

.alert {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius);
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); color: var(--ink); margin-bottom: 16px;
}
.alert svg { color: var(--warn); }
.alert.neg { background: var(--neg-soft); border-color: color-mix(in srgb, var(--neg) 30%, transparent); }
.alert.neg svg { color: var(--neg); }

/* ============================================================ table */
.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3);
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; font-weight: 700;
}
table.t th.sortable { cursor: pointer; user-select: none; }
table.t th.sortable:hover { color: var(--ink); }
table.t td { padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t tr.sel { background: var(--brand-soft); }
table.t tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); }
table.t .name { font-weight: 600; }
table.t td.desc { min-width: 220px; }
table.t td.nowrap, table.t th { white-space: nowrap; }
table.t .sm { font-size: 12px; color: var(--ink-3); }
table.t td.act { white-space: nowrap; text-align: right; width: 1%; padding-left: 4px; padding-right: 8px; }
table.t td.act .iconbtn { width: 30px; height: 30px; }
table.t .sm svg.i { width: 12px; height: 12px; vertical-align: -2px; }
table.t tr.group td { background: var(--surface-2); font-weight: 700; text-transform: uppercase; font-size: 11.5px; letter-spacing: .05em; color: var(--ink-2); }
table.t tr.total td { font-weight: 800; border-top: 2px solid var(--line); background: var(--surface-2); }
.chk { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.pos { background: var(--pos-soft); color: var(--pos); }
.pill.neg { background: var(--neg-soft); color: var(--neg); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.mute { background: var(--line-2); color: var(--ink-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); }

.filters { padding: 14px 16px; margin-bottom: 14px; }
.filters .frow { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 10px; align-items: end; }
.c2 { grid-column: span 2; } .c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c6 { grid-column: span 6; }
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.summary .s { padding: 12px 16px; }
.summary .s .l { color: var(--ink-3); font-size: 12px; font-weight: 600; }
.summary .s .n { font-size: 19px; font-weight: 750; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.bulkbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--ink); color: var(--bg); border-radius: 12px; margin-bottom: 12px; }
.bulkbar .btn { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 30%, transparent); }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; color: var(--ink-3); font-size: 13px; }

.list .it { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.list .it:last-child { border: 0; }
.datebadge { width: 44px; text-align: center; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); padding: 4px 0; flex: none; }
.datebadge b { display: block; font-size: 16px; line-height: 1.1; }
.datebadge small { font-size: 10.5px; text-transform: uppercase; color: var(--ink-3); letter-spacing: .05em; }
.datebadge.late { background: var(--neg-soft); border-color: transparent; color: var(--neg); }
.datebadge.late small { color: var(--neg); }
.rank { display: grid; gap: 12px; }
.rank .rk .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; gap: 10px; }
.rank .rk .top span:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend { display: grid; gap: 8px; margin-top: 12px; }
.legend .lg { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .lg .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chartbox { position: relative; height: 300px; }
.chartbox.sm { height: 220px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font-weight: 600; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.empty { text-align: center; padding: 48px 20px; color: var(--ink-3); }
.empty svg { width: 36px; height: 36px; opacity: .5; margin-bottom: 8px; }
.skel { background: linear-gradient(90deg, var(--line-2), var(--surface-2), var(--line-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 10px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ============================================================ modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(20, 14, 10, .55); backdrop-filter: blur(3px); z-index: 100; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 600px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .18s; border: 1px solid var(--line); }
.modal.sm { max-width: 440px; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.modal .mh { display: flex; align-items: center; padding: 18px 22px 10px; gap: 10px; }
.modal .mh h3 { font-size: 17px; flex: 1; }
.modal .mb2 { padding: 8px 22px 18px; overflow-y: auto; }
.modal .mf { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line-2); background: var(--surface-2); border-radius: 0 0 18px 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); animation: pop .2s; max-width: 360px; display: flex; gap: 10px; align-items: center; }
.toast.err { background: var(--neg); color: #fff; }

/* ============================================================ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(900px 500px at 15% 10%, color-mix(in srgb, var(--brand) 18%, transparent), transparent),
  radial-gradient(700px 400px at 90% 90%, color-mix(in srgb, var(--brand) 12%, transparent), transparent), var(--bg); }
.login .card { width: 100%; max-width: 400px; padding: 32px; }
.login .login-logo { background: #1c1612; border-radius: 14px; padding: 20px 24px; margin: -8px -8px 22px; display: grid; place-items: center; }
.login .login-logo img { width: 190px; max-width: 100%; display: block; }
.login h1 { font-size: 22px; letter-spacing: -.01em; }
.login p { color: var(--ink-3); margin: 4px 0 22px; }
.login .field + .field { margin-top: 14px; }
.login .btn { width: 100%; margin-top: 20px; height: 44px; }
.err-msg { background: var(--neg-soft); color: var(--neg); padding: 10px 12px; border-radius: 10px; margin-top: 14px; font-weight: 500; }

/* ============================================================ responsive */
@media (max-width: 1180px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main { grid-template-columns: minmax(0, 1fr); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters .frow { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .c2, .c3, .c4 { grid-column: span 3; } .c6 { grid-column: span 6; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; width: 270px; height: 100vh; min-height: 0; overflow-y: auto; transform: translateX(-100%); transition: transform .22s; }
  .side.open { transform: none; box-shadow: var(--shadow-lg); }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 39; }
  .menu-btn { display: inline-grid; }
  .topbar, .page { padding-left: 16px; padding-right: 16px; }
  .g3, .g2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .page-head > .grow { flex: 1 1 100%; }
  .monthnav { flex: 1; } .monthnav .lbl { min-width: 0; flex: 1; }
  .card .hd { flex-wrap: wrap; }
  .filters .frow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .c2, .c3, .c4, .c6 { grid-column: span 2; }
  .kpi { padding: 12px 14px; } .kpi .v { font-size: 19px; margin: 8px 0 2px; } .kpi .lb { font-size: 12px; gap: 6px; } .kpi .ic { width: 26px; height: 26px; } .kpi .s { font-size: 11.5px; }
  .topbar .sub { display: none; }
  .hide-sm { display: none; }
}

/* ============================================================ print */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .side, .topbar, .no-print, .scrim, .toasts { display: none !important; }
  .app { display: block; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .print-only { display: block; margin-bottom: 14px; }
  table.t th { background: #f3f3f3 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .chartbox { height: 240px; }
}


/* ============================================================
   Celular / tablet: experiência de app
   ============================================================ */
.tabbar, .only-m { display: none; }
table.t.stick th:first-child, table.t.stick td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
table.t.stick thead th:first-child { background: var(--surface-2); }
table.t.stick tr.group td:first-child, table.t.stick tr.total td:first-child { background: var(--surface-2); }
.mlist { display: grid; }
.mcard { padding: 14px 16px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.mcard:last-child { border-bottom: 0; }
.mcard:active { background: var(--surface-2); }
.mc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.mc-title { font-weight: 650; line-height: 1.3; min-width: 0; overflow-wrap: anywhere; }
.mc-amt { font-weight: 800; white-space: nowrap; font-size: 15px; }
.mc-sub { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--ink-3); font-size: 12.5px; margin-top: 5px; }
.mc-bot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 10px; }

@keyframes sheet { from { transform: translateY(100%); } }

@media (max-width: 900px) {
  :root { --tab-h: 64px; }
  html { -webkit-tap-highlight-color: transparent; }
  .only-m { display: inline-flex; }
  .hide-m { display: none !important; }
  .menu-btn, #newTx { display: none !important; }
  .topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
  .topbar h1 { font-size: 18px; }
  .page { padding: 16px 14px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom)); }
  .toasts { right: 12px; left: 12px; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  /* barra de abas fixa */
  .tabbar {
    display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: center;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgba(35, 27, 22, .06);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); min-height: var(--tab-h);
  }
  .tabbar a, .tabbar button.tab {
    display: flex; flex-direction: column; align-items: center; gap: 3px; border: 0; background: transparent;
    font-size: 11px; font-weight: 650; color: var(--ink-3); padding: 6px 2px; border-radius: 12px; cursor: pointer; text-decoration: none;
  }
  .tabbar svg.i { width: 22px; height: 22px; }
  .tabbar .active { color: var(--brand); }
  .tabbar .fab {
    width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink);
    display: grid; place-items: center; justify-self: center; margin-top: -26px; cursor: pointer;
    box-shadow: 0 8px 20px color-mix(in srgb, var(--brand) 45%, transparent), 0 0 0 6px var(--bg);
  }
  .tabbar .fab svg.i { width: 26px; height: 26px; stroke-width: 2.2; }
  .tabbar .fab:active { transform: scale(.94); }

  /* menu "Mais" como gaveta */
  .side { padding-top: calc(22px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

  /* controles com alvo de toque confortável (16px evita zoom no iPhone) */
  .input, .select, textarea.input { height: 44px; font-size: 16px; }
  textarea.input { height: auto; }
  .btn { height: 42px; } .btn.sm { height: 36px; }
  .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; } .seg::-webkit-scrollbar { display: none; }
  .page-head { gap: 8px; }
  .page-head > .seg { flex: 1 1 100%; }
  .page-head > .seg button { flex: 1; }

  /* filtros recolhíveis */
  .filters { display: none; }
  .filters.open { display: block; }
  .filters .frow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters .c2, .filters .c3, .filters .c4 { grid-column: span 1; }
  .filters .c6, .filters .c4.row { grid-column: span 2; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .summary .s { padding: 10px 12px; } .summary .s .n { font-size: 16px; }
  .chartbox { height: 240px; }
  .pager { flex-direction: column; gap: 8px; }
}

@media (max-width: 560px) {
  /* formulários e confirmações viram painel que sobe de baixo */
  .overlay { align-items: end; padding: 0; }
  .modal, .modal.sm { max-width: none; width: 100%; border-radius: 22px 22px 0 0; max-height: 94vh; animation: sheet .24s ease-out; border-bottom: 0; }
  .modal .mh { padding: 18px 18px 8px; }
  .modal .mb2 { padding: 6px 18px 16px; }
  .modal .mf { padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); border-radius: 0; }
  .modal .mf .btn { flex: 1; }
  .modal .mf #fDel { flex: 0 0 auto; }
  .login .card { padding: 24px; }
  .form-grid .seg { width: 100%; } .form-grid .seg button { flex: 1; }
}
