:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #ece8de;
  --ink: #1b1e22;
  --ink-2: #5d6168;
  --line: #ddd8cc;
  --accent: #1f5f4a;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe4;
  --danger: #b3261e;
  --aguarda: #a15c00;
  --aguarda-soft: #fbecd2;
  --pendente: #1d4f91;
  --pendente-soft: #dde8f7;
  --recebida: #2b6b3f;
  --recebida-soft: #dcefe1;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16191d;
    --surface: #1f2328;
    --surface-2: #2a2f35;
    --ink: #eef0f2;
    --ink-2: #a3a9b1;
    --line: #343a41;
    --accent: #5fbf9a;
    --accent-ink: #0e1a15;
    --accent-soft: #1d3a30;
    --danger: #f2827a;
    --aguarda: #f0b35a;
    --aguarda-soft: #3a2c16;
    --pendente: #8db6f0;
    --pendente-soft: #1b2b44;
    --recebida: #7fcf98;
    --recebida-soft: #1a3324;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
body.no-tabbar #app { padding-bottom: calc(env(safe-area-inset-bottom) + 24px); }

/* ---------- cabeçalhos */
.top { display: flex; align-items: center; gap: 8px; min-height: 44px; margin: 4px 0 16px; }
.top h1 { font-size: 26px; line-height: 1.15; margin: 0; flex: 1; letter-spacing: -0.01em; }
.top .back { width: 44px; height: 44px; margin-left: -10px; display: grid; place-items: center; border: 0; background: none; border-radius: 50%; }
.top .back svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.eyebrow { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); margin: 0 0 2px; font-weight: 600; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); margin: 28px 4px 10px; font-weight: 650; }

/* ---------- cartões e listas */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.hero { background: var(--accent); color: var(--accent-ink); border-radius: 20px; padding: 20px; }
.hero .label { opacity: 0.85; font-size: 15px; }
.hero .big { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin: 4px 0 14px; }
.hero .row { display: flex; gap: 12px; }
.hero .row > div { flex: 1; background: rgb(255 255 255 / 0.12); border-radius: 12px; padding: 10px 12px; }
.hero .row small { display: block; opacity: 0.85; font-size: 13px; }
.hero .row b { font-size: 19px; }

.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; text-decoration: none; min-height: 60px; border: 0; background: none; width: 100%; text-align: left; }
.item + .item { border-top: 1px solid var(--line); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { color: var(--ink-2); font-size: 14px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .side { text-align: right; flex-shrink: 0; }
.item .side .amount { font-weight: 650; }
.item .chev { width: 18px; height: 18px; fill: none; stroke: var(--ink-2); stroke-width: 2; flex-shrink: 0; }
.item.selected { background: var(--accent-soft); }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex-shrink: 0; display: grid; place-items: center; }
.item.selected .check { background: var(--accent); border-color: var(--accent); }
.item.selected .check::after { content: ""; width: 10px; height: 6px; border: 2.5px solid var(--accent-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }

.company-card { display: block; text-decoration: none; }
.company-card + .company-card { margin-top: 10px; }
.company-card .head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.company-card .head .name { font-weight: 650; font-size: 18px; flex: 1; }
.company-card .head .meta { color: var(--ink-2); font-size: 14px; }
.company-card .figures { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.figure { border-radius: 10px; padding: 8px 10px; }
.figure small { display: block; font-size: 12.5px; font-weight: 600; }
.figure b { font-size: 18px; }
.figure.pendente { background: var(--pendente-soft); color: var(--pendente); }
.figure.aguarda { background: var(--aguarda-soft); color: var(--aguarda); }

.badge { display: inline-block; font-size: 12.5px; font-weight: 650; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.aguarda { background: var(--aguarda-soft); color: var(--aguarda); }
.badge.pendente { background: var(--pendente-soft); color: var(--pendente); }
.badge.recebida { background: var(--recebida-soft); color: var(--recebida); }
.flag { display: inline-block; font-size: 11px; font-weight: 700; color: var(--ink-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; vertical-align: 2px; }

.empty { text-align: center; color: var(--ink-2); padding: 32px 16px; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }

.banner { display: flex; align-items: center; gap: 12px; background: var(--aguarda-soft); color: var(--aguarda); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-weight: 600; }
.banner span { flex: 1; }
.banner button { border: 0; background: var(--aguarda); color: var(--surface); border-radius: 10px; padding: 8px 12px; font-weight: 650; }

/* ---------- filtros */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 12px; padding: 2px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; text-decoration: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: 15px; font-weight: 550; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.search { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 17px; }
.totals { display: flex; justify-content: space-between; color: var(--ink-2); font-size: 14px; margin: 0 4px 8px; }

/* ---------- formulários */
form .field { margin-bottom: 16px; }
label, .label { display: block; font-weight: 600; font-size: 15px; margin: 0 0 6px 2px; }
.hint { color: var(--ink-2); font-size: 14px; margin: 6px 2px 0; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=tel], select, textarea {
  width: 100%; min-height: 52px; border: 1.5px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 12px 14px; font-size: 18px; appearance: none; -webkit-appearance: none;
}
input[type=date] { display: block; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 20px; padding-right: 40px; }
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.amount-input { position: relative; }
.amount-input input { font-size: 28px; font-weight: 650; padding-right: 44px; min-height: 64px; }
.amount-input::after { content: "€"; position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 24px; color: var(--ink-2); }
.calc { display: flex; justify-content: space-between; align-items: baseline; background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 12px 14px; margin-top: 8px; font-weight: 600; }
.calc b { font-size: 22px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { border: 0; background: none; min-height: 46px; border-radius: 9px; font-weight: 600; font-size: 16px; color: var(--ink-2); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.methods { display: flex; flex-wrap: wrap; gap: 8px; }
.methods button { border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 14px; font-weight: 550; min-height: 46px; }
.methods button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.subpanel { border-left: 3px solid var(--accent-soft); padding-left: 14px; margin-top: 14px; }

.picker { position: relative; }
.picker .results { margin-top: 6px; }
.picker .chosen { display: flex; align-items: center; gap: 10px; border: 1.5px solid var(--accent); background: var(--accent-soft); border-radius: 12px; padding: 10px 10px 10px 14px; min-height: 52px; }
.picker .chosen .main { flex: 1; min-width: 0; }
.picker .chosen b { display: block; }
.picker .chosen small { color: var(--ink-2); }
.picker .chosen button { border: 0; background: none; color: var(--accent); font-weight: 650; padding: 8px; }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 56px; border: 0; border-radius: 14px; font-weight: 650; font-size: 18px; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: none; color: var(--danger); }
.btn:disabled { opacity: 0.55; }
.btn + .btn { margin-top: 10px; }
.btn-inline { text-decoration: none; border: 0; background: none; color: var(--accent); font-weight: 650; padding: 8px 4px; font-size: 16px; }
.actions { margin-top: 24px; }
.sticky-actions { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 12px 16px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.sticky-actions > * { max-width: 608px; margin: 0 auto; }
.error { color: var(--danger); font-weight: 600; margin: 8px 2px; }

/* ---------- login */
.login { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 18px; }
.login h1 { font-size: 30px; margin: 0 0 4px; }
.login p { color: var(--ink-2); margin: 0 0 28px; }

/* ---------- barra inferior */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); display: flex; justify-content: space-around; align-items: center;
}
#tabbar[hidden] { display: none; }
#tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--ink-2); font-size: 11.5px; font-weight: 600; padding: 6px 0; }
#tabbar a svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
#tabbar a svg circle { fill: currentColor; stroke: none; }
#tabbar a.active { color: var(--accent); }
#tabbar .tab-add { flex: 0 0 auto; width: 58px; height: 58px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); justify-content: center; margin-top: -18px; box-shadow: 0 6px 18px rgb(0 0 0 / 0.18); }
#tabbar .tab-add svg { width: 30px; height: 30px; stroke-width: 2.6; }

/* ---------- toast */
#toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translate(-50%, -20px); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: 0.25s; max-width: calc(100% - 32px); z-index: 20; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.muted { color: var(--ink-2); }
.spacer { height: 12px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv span:first-child { color: var(--ink-2); }
