:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1e2128;
    --text: #f0f1f3;
    --text-muted: #9aa0ab;
    --border: #30343c;
    --primary: #3b82f6;
    --primary-text: #ffffff;
    --green: #4ade80;
    --green-bg: #14321f;
    --amber: #fbbf24;
    --amber-bg: #3a2e0f;
    --red: #f87171;
    --red-bg: #3a1414;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  padding-bottom: 76px;
  min-height: 100vh;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 8px;
}

header.topbar {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  z-index: 10;
}
header.topbar h1 {
  font-size: 18px;
  margin: 0;
}
header.topbar .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

nav.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
nav.bottomnav a {
  flex: 1;
  text-align: center;
  padding: 10px 4px 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 12px;
}
nav.bottomnav a .icon { display: block; font-size: 20px; margin-bottom: 2px; }
nav.bottomnav a.active { color: var(--primary); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
}
.filters select, .filters input {
  flex: none;
}

select, input[type="text"], input[type="date"], input[type="number"], textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  width: 100%;
}
textarea { resize: vertical; min-height: 60px; }

label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin: 12px 0 4px;
}
label:first-child { margin-top: 0; }

.field-row { display: flex; gap: 10px; }
.field-row > div { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: var(--primary-text);
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 16px;
}
.btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.danger { background: var(--red); }

.fab {
  position: fixed;
  right: 18px;
  bottom: 84px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 28px;
  border: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  z-index: 15;
  cursor: pointer;
}

.lanc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.lanc-item .left { min-width: 0; }
.lanc-item .desc { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lanc-item .meta { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.lanc-item .valor { font-weight: 700; white-space: nowrap; margin-left: 10px; }
.lanc-item .valor.negativo { color: var(--green); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge.pago { background: var(--green-bg); color: var(--green); }
.badge.pendente { background: var(--amber-bg); color: var(--amber); }

.day-group {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 18px 0 6px;
}
.day-group:first-child { margin-top: 0; }

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.kpi-grid .card { margin-bottom: 0; }
.kpi-label { font-size: 12px; color: var(--text-muted); }
.kpi-value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.kpi-value.small { font-size: 16px; }

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px;
  font-size: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  z-index: 30;
}
.modal-backdrop[hidden] { display: none; }
.modal-sheet {
  background: var(--surface);
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom, 0));
}
.modal-sheet h2 { margin: 0 0 12px; font-size: 17px; }
.modal-sheet .close { float: right; background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; }

.disclaimer {
  background: var(--amber-bg);
  color: var(--amber);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.tabs { display: flex; gap: 6px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tabs button {
  background: none; border: none; padding: 10px 4px; font-size: 14px; color: var(--text-muted);
  border-bottom: 2px solid transparent; cursor: pointer;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table th, table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table th { color: var(--text-muted); font-weight: 600; font-size: 12px; }

.section-title { font-size: 15px; font-weight: 700; margin: 20px 0 8px; }
.section-title:first-child { margin-top: 0; }

a { color: var(--primary); }

.progress-track {
  background: var(--border);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
}
.progress-fill.over { background: var(--red); }
