:root {
  --navy: #0f172a;
  --navy-2: #1e293b;
  --orange: #f97316;
  --orange-dark: #c2410c;
  --orange-soft: #ffedd5;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --ink: #0f172a;
  --muted: #64748b;
  --radius: 14px;
  --tabbar: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
.boot { text-align: center; color: var(--muted); padding: 40vh 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------- layout ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--navy); color: #fff;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 3px solid var(--orange);
}
.brand { font-weight: 700; font-size: 17px; }
.top .sub { font-size: 12px; color: #cbd5e1; }
.ghost {
  background: transparent; border: 1px solid #475569; color: #e2e8f0;
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer;
}
main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar) + 28px + env(safe-area-inset-bottom)); }
main.no-tabs { padding-bottom: 32px; }
.view > * + * { margin-top: 14px; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.tile { border-radius: 12px; padding: 12px; background: var(--card); border: 1px solid var(--line); text-align: center; }
.tile b { display: block; font-size: 20px; line-height: 1.2; }
.tile span { font-size: 12px; color: var(--muted); }
.tile.ok { background: var(--green-soft); border-color: transparent; }
.tile.ok b, .tile.ok span { color: var(--green); }
.tile.bad { background: var(--red-soft); border-color: transparent; }
.tile.bad b, .tile.bad span { color: var(--red); }
.tile.dark { background: var(--navy); border-color: var(--navy); }
.tile.dark b { color: #fff; }
.tile.dark span { color: #cbd5e1; }

.banner { border-radius: 12px; padding: 12px 14px; font-weight: 600; text-align: center; }
.banner.warn { background: var(--orange-soft); color: var(--orange-dark); }
.banner.ok { background: var(--green-soft); color: var(--green); }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 20px 20px; }
.login .logo {
  width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 14px; display: block;
}
.login h1 { text-align: center; margin: 0 0 4px; font-size: 24px; }
.login p.lead { text-align: center; margin: 0 0 22px; color: var(--muted); }
.hint { background: var(--orange-soft); color: var(--orange-dark); border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-top: 14px; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; background: #fff; border: 1px solid #cbd5e1; border-radius: 10px;
  padding: 11px 12px; font-size: 16px; /* 16px evita el zoom en iPhone */
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--orange); outline-offset: 0; border-color: var(--orange); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px 16px;
  background: var(--orange); color: #fff; font-weight: 700; cursor: pointer; text-align: center; margin-top: 14px;
}
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--navy); }
.btn.light { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.inline { display: inline-block; width: auto; margin: 0; padding: 8px 14px; font-size: 13px; }
.btn.tiny { display: inline-block; width: auto; margin: 0; padding: 6px 12px; font-size: 12.5px; border-radius: 999px; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.ok { background: var(--green-soft); color: var(--green); }
.err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

details.card > summary { cursor: pointer; font-weight: 700; color: var(--orange-dark); list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: 4px; }

/* ---------- big mark button ---------- */
.markwrap { display: flex; justify-content: center; padding: 8px 0; }
.markbtn {
  width: 168px; height: 168px; border-radius: 50%; border: 8px solid var(--orange);
  background: #fb923c; color: #fff; font-weight: 800; font-size: 18px; line-height: 1.15; cursor: pointer;
  box-shadow: 0 8px 24px rgba(249, 115, 22, .35);
}
.markbtn:active { transform: scale(.97); }
.markbtn:disabled { background: var(--green); border-color: #86efac; box-shadow: none; cursor: default; }
.markbtn small { display: block; font-size: 13px; font-weight: 600; opacity: .95; }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px 4px; text-align: center; }
.cal .dow { font-size: 11px; font-weight: 700; color: var(--muted); }
.cal .day { font-size: 13px; width: 32px; height: 32px; line-height: 32px; margin: 0 auto; border-radius: 50%; }
.cal .day.on { background: var(--green-soft); color: var(--green); font-weight: 700; }
.cal .day.today { background: var(--orange); color: #fff; font-weight: 700; }
.cal .day.on.today { background: var(--green-soft); color: var(--green); outline: 2px solid var(--orange); }
.legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }

/* ---------- lists ---------- */
.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item b { display: block; }
.dot { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; flex: none; }
.dot.ok { background: var(--green-soft); color: var(--green); }
.dot.bad { background: var(--red-soft); color: var(--red); }
.amount { font-weight: 700; color: var(--orange-dark); white-space: nowrap; }
.amount.in { color: var(--green); }
.empty { text-align: center; color: var(--muted); padding: 18px 0; }

.bar { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--orange); border-radius: 999px; }
.bar.in > i { background: var(--green); }

/* ---------- table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: right; font-size: 11.5px; color: var(--muted); font-weight: 700; padding: 8px 4px; background: var(--bg); }
td { text-align: right; padding: 10px 4px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; padding-left: 6px; }
td:first-child b { display: block; font-size: 13.5px; }
td:first-child span { font-size: 11.5px; color: var(--muted); }
tfoot td { font-weight: 800; border-bottom: 0; border-top: 2px solid var(--navy); }
@media (max-width: 420px) {
  table { font-size: 12px; }
  th { font-size: 10.5px; padding: 8px 2px; }
  td { padding: 9px 2px; }
  td:first-child b { font-size: 12.5px; }
  .card { padding: 12px; }
}
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="month"], .toolbar input[type="date"] { width: auto; flex: 1; min-width: 150px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--navy); display: grid; grid-template-columns: repeat(5, 1fr);
}
.tabbar button {
  background: transparent; border: 0; color: #94a3b8; font-size: 11.5px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tabbar svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--orange); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 22px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 50; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--red); }

/* ---------- print (cierre mensual a PDF) ---------- */
.print-only { display: none; }
@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  .printable, .printable * { visibility: visible; }
  .printable { position: absolute; left: 0; top: 0; width: 100%; border: 0; }
  .print-only { display: block; }
  .no-print { display: none !important; }
}
