:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-soft: #64748b;
  --line: #e2e8f0;
  --brand: #0ea5e9;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --radius: 14px;
  --nav-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f1f5f9;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------- topbar / nav */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg); color: #fff;
}
.brand { font-weight: 700; letter-spacing: .3px; font-size: 1.1rem; }
.topbar .logout { margin-left: auto; color: #cbd5e1; text-decoration: none; font-size: 1.3rem; }

.content { padding: 16px; padding-bottom: calc(var(--nav-h) + 64px); max-width: 720px; margin: 0 auto; }

/* nav flutuante em pílula (estilo novo do kderno) */
.bottomnav {
  position: fixed; left: 12px; right: 12px; z-index: 100;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: 4px; padding: 6px 8px; max-width: 696px; margin: 0 auto;
  background: var(--bg); border-radius: 999px;
  box-shadow: 0 6px 20px rgba(15,23,42,.35);
}
.navitem {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; text-decoration: none; color: rgba(255,255,255,.6); font-size: .68rem; font-weight: 600;
  padding: 8px 4px; border-radius: 999px; transition: color .15s, background .15s, transform .15s;
}
.navitem i { font-size: 1.25rem; line-height: 1; }
.navitem.on { color: var(--brand); background: #fff; transform: scale(1.04); box-shadow: 0 2px 8px rgba(0,0,0,.15); }

.site-copyright {
  position: fixed; left: 0; right: 0; z-index: 99; text-align: center;
  bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  font-size: .58rem; color: var(--ink-soft); opacity: .8; pointer-events: none;
}
.site-copyright a { color: var(--ink-soft); font-weight: 600; text-decoration: none; pointer-events: auto; }

/* ---------------------------------------------------------- cards */
.month-label { font-size: 1.4rem; font-weight: 700; margin: 4px 0 14px; }
.page-title { font-size: 1.3rem; margin: 4px 0 16px; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card {
  background: var(--surface); border-radius: 12px; padding: 10px;
  box-shadow: 0 1px 3px rgba(15,23,42,.08); border: 1px solid var(--line);
  min-width: 0;
}
.card-label { font-size: .62rem; color: var(--ink-soft); margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-value { font-size: .92rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.receita-cap { font-size: .78rem; color: var(--ink-soft); margin: 10px 0 0; }
.receita-cap b { color: var(--ink); }
.receita-cap button { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: 0 0 0 6px; }
.card.good { background: var(--good-bg); border-color: #bbf7d0; }
.card.good .card-value { color: var(--good); }
.card.bad { background: var(--bad-bg); border-color: #fecaca; }
.card.bad .card-value { color: var(--bad); }
.card.warn { background: var(--warn-bg); border-color: #fde68a; }
.card.warn .card-value { color: var(--warn); }

/* ---------------------------------------------------------- panel / chart */
.panel {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-top: 16px;
}
.panel h2 { font-size: .95rem; margin: 0 0 14px; color: var(--ink-soft); font-weight: 600; }

.chart { display: flex; align-items: flex-end; gap: 5px; height: 130px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar { width: 100%; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar.pos { background: var(--good); }
.bar.neg { background: var(--bad); }
.bar-x { font-size: .6rem; color: var(--ink-soft); margin-top: 4px; }

/* ---------------------------------------------------------- month nav */
.monthnav { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.mn-mid { flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center; }
.mn-mid .month-label { margin: 0; }
.mn-btn {
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; text-decoration: none;
  color: var(--ink); font-size: 1.5rem;
}
.badge { background: var(--brand); color: #fff; font-size: .65rem; padding: 2px 8px; border-radius: 999px; }

/* ---------------------------------------------------------- grid/table */
.grid { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.grid th, .grid td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: .9rem; }
.grid th { background: #f8fafc; color: var(--ink-soft); font-size: .72rem; text-transform: uppercase; letter-spacing: .4px; }
.grid tr:last-child td { border-bottom: 0; }
.grid .r { text-align: right; }
.grid .muted-row td { color: var(--ink-soft); }
input.val {
  width: 92px; text-align: right; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit;
}
input.val.saving { opacity: .5; }
input.val.saved { border-color: var(--good); background: var(--good-bg); }
input.val.err { border-color: var(--bad); background: var(--bad-bg); }

.tag { font-size: .68rem; color: var(--ink-soft); background: #f1f5f9; padding: 2px 6px; border-radius: 6px; }
.chip {
  border: 0; padding: 5px 12px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  cursor: pointer;
}
.chip.paga { background: var(--good-bg); color: var(--good); }
.chip.aberta { background: var(--bad-bg); color: var(--bad); }

/* ---------------------------------------------------------- toolbar */
.toolbar { display: flex; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.link { color: var(--brand); text-decoration: none; font-size: .85rem; }
.month-select { padding: 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }

/* ---------------------------------------------------------- recebíveis */
.receb-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.receb-nome { font-weight: 700; }
.receb-vals { font-size: .85rem; color: var(--ink-soft); }
.progress { height: 10px; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--good); border-radius: 999px; transition: width .25s; }
.receb-sub { font-size: .8rem; color: var(--ink-soft); margin-top: 8px; }
.parcelas { list-style: none; padding: 0; margin: 12px 0 0; }
.parcelas li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: .88rem; }
.parcelas .p-val { margin-left: auto; }

/* ---------------------------------------------------------- remédios */
.med-list { display: flex; flex-direction: column; gap: 10px; }
.med { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.med.alert { border-color: #fecaca; background: var(--bad-bg); }
.med-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.med-nome { font-weight: 600; }
.med-dias { font-size: .75rem; color: var(--ink-soft); background: #f1f5f9; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.med-dias.alert { background: var(--bad); color: #fff; }
.med-meta { font-size: .82rem; color: var(--ink-soft); margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.med-meta.sub { font-size: .76rem; }

/* ---------------------------------------------------------- misc */
.empty { background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); padding: 20px; text-align: center; color: var(--ink-soft); margin: 14px 0; }
.empty a { color: var(--brand); }
.empty button, .toolbar button { margin-top: 10px; }
.muted { color: var(--ink-soft); }
button[type=submit] {
  background: var(--brand); color: #fff; border: 0; padding: 12px 18px; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer;
}

/* ---------------------------------------------------------- login */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-card { background: #fff; border-radius: 18px; padding: 28px 24px; width: 100%; max-width: 360px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-brand { margin: 0; text-align: center; font-size: 1.6rem; }
.login-sub { text-align: center; color: var(--ink-soft); margin: 4px 0 20px; font-size: .9rem; }
.login-card label { display: block; font-size: .82rem; color: var(--ink-soft); margin-bottom: 14px; }
.login-card input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; margin-top: 6px; }
.login-card button { width: 100%; background: var(--brand); color: #fff; border: 0; padding: 13px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; margin-top: 6px; }
.login-erro { background: var(--bad-bg); color: var(--bad); padding: 10px; border-radius: 8px; font-size: .85rem; margin-bottom: 16px; text-align: center; }

/* ---------------------------------------------------------- CRUD: botões + modais */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.section-head .page-title { margin: 0; }
.add-btn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--brand); color: #fff;
  border: 0; border-radius: 999px; padding: 9px 16px; font: inherit; font-weight: 600;
  font-size: .85rem; cursor: pointer; text-decoration: none;
}
.add-btn i { font-size: 1rem; }
.icon-btn { background: none; border: 0; color: var(--ink-soft); cursor: pointer; font-size: 1.05rem; padding: 6px; border-radius: 8px; }
.icon-btn:hover { background: #f1f5f9; }
.grid tr { cursor: default; }
.grid td.editcell { width: 40px; text-align: center; }

dialog.modal {
  border: 0; border-radius: 16px; padding: 0; width: min(92vw, 420px);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog.modal::backdrop { background: rgba(15,23,42,.5); }
.modal-body { padding: 20px; }
.modal-body h3 { margin: 0 0 16px; font-size: 1.1rem; }
.modal-body label { display: block; font-size: .78rem; color: var(--ink-soft); margin-bottom: 12px; }
.modal-body input, .modal-body select { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 10px; font: inherit; margin-top: 5px; background: #fff; }
.modal-body .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-body .check { display: flex; align-items: center; gap: 8px; flex-direction: row; }
.modal-body .check input { width: auto; margin: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions button { flex: 1; padding: 12px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; border: 0; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: #f1f5f9; color: var(--ink); }
.btn-danger { background: var(--bad-bg); color: var(--bad); }
.form-inline-del { margin-left: auto; }
