:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #e6e8eb;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #16a34a;
  --accent-strong: #15803d;
  --ok: #16a34a;
  --err: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --tabbar-h: 60px;
}

* { box-sizing: border-box; }

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

/* ===== Shell ===== */
.viewport {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
}
.view.hidden { display: none; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  z-index: 10;
}
.tabitem {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.7rem;
}
.tabitem .ico { font-size: 1.15rem; line-height: 1; }
.tabitem.active { color: var(--accent-strong); font-weight: 600; }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent-strong);
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(21, 128, 61, .35);
  cursor: pointer;
  z-index: 11;
}

/* ===== Dashboard ===== */
.dash-header { margin-bottom: 18px; }
.dash-hello { font-size: 1.35rem; font-weight: 700; margin: 0; }
.dash-sub { color: var(--muted); font-size: 0.9rem; margin: 2px 0 0; }

.mes-sel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.mes-sel button {
  background: none; border: none; color: var(--accent-strong);
  font-size: 1.2rem; cursor: pointer; padding: 4px 10px;
}
.mes-sel .mes-label { font-weight: 600; }

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.metric .m-label { color: var(--muted); font-size: 0.8rem; }
.metric .m-value { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }
.metric .m-value.pos { color: var(--ok); }
.metric .m-value.neg { color: var(--err); }

.card {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2 { font-size: 1rem; margin: 0 0 14px; }
.card .empty { color: var(--muted); font-size: 0.9rem; }

/* barras gasto por categoría */
.bar-row { margin-bottom: 12px; }
.bar-top { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 5px; }
.bar-top .b-amount { color: var(--muted); }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.bar-note {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--surface-2);
  font-size: 0.85rem; color: var(--muted);
}
.bar-note strong { color: var(--err); }
.bar-note.ok { color: var(--ok); }

/* cuentas */
.acct-group { margin-bottom: 14px; }
.acct-group:last-child { margin-bottom: 0; }
.acct-group .g-head {
  display: flex; justify-content: space-between;
  font-size: 0.8rem; color: var(--muted); margin-bottom: 8px;
  border-bottom: 1px solid var(--surface-2); padding-bottom: 6px;
}
.acct-row { display: flex; justify-content: space-between; font-size: 0.92rem; padding: 5px 0; }
.acct-row .a-saldo.neg { color: var(--err); }
.acct-row .a-saldo.pos { color: var(--text); }
.g-total { font-weight: 700; }
.g-total.neg { color: var(--err); }

/* movimientos */
.mov-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--surface-2);
}
.mov-row:last-child { border-bottom: none; }
.mov-left .m-desc { font-size: 0.95rem; }
.mov-left .m-meta { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.mov-amount { font-weight: 600; white-space: nowrap; }
.mov-amount.gasto { color: var(--err); }
.mov-amount.ingreso { color: var(--ok); }
.mov-amount.transferencia { color: var(--muted); }

.stub { text-align: center; color: var(--muted); padding: 60px 0; }
.stub .s-title { font-size: 1.2rem; color: var(--text); margin-bottom: 6px; }

/* ===== Movimientos: lista ===== */
.mov-list { margin-top: 4px; }
.day-head {
  font-size: 0.72rem; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); margin: 18px 0 6px; font-weight: 600;
}
.mov-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: none; cursor: pointer; text-align: left;
  padding: 11px 2px; border-bottom: 1px solid var(--surface-2);
  font: inherit; color: var(--text);
}
.mov-item:last-child { border-bottom: none; }
.mi-ico {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--surface-2); font-size: 1.05rem;
}
.mi-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mi-desc { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mi-meta { font-size: 0.78rem; color: var(--muted); }
.mi-amount { flex: 0 0 auto; font-weight: 600; white-space: nowrap; }
.mi-amount.gasto { color: var(--err); }
.mi-amount.ingreso { color: var(--ok); }
.mi-amount.transferencia { color: var(--muted); }

/* ===== Movimientos: detalle ===== */
.det-top { margin-bottom: 8px; }
.det-back { background: none; border: none; color: var(--accent-strong); font-size: 0.95rem; cursor: pointer; padding: 6px 0; }
.det-head { text-align: center; padding: 8px 0 20px; }
.det-ico {
  width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--surface-2); font-size: 1.6rem;
}
.det-desc { font-size: 1.05rem; font-weight: 600; }
.det-amount { font-size: 2rem; font-weight: 700; margin-top: 6px; }
.det-amount.gasto { color: var(--err); }
.det-amount.ingreso { color: var(--ok); }
.det-amount.transferencia { color: var(--text); }
.det-tag { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }

.det-fields { padding: 4px 16px; }
.det-row { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--surface-2); font-size: 0.92rem; }
.det-row:last-child { border-bottom: none; }
.d-label { color: var(--muted); }
.d-value { font-weight: 600; text-align: right; }
.det-nota { margin-top: 6px; font-size: 0.92rem; }

.det-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.det-actions .submit { margin-top: 0; }
.submit.danger { background: transparent; border: 1px solid var(--err); color: var(--err); }

/* ===== Cargador (vista Agregar) ===== */
.agregar h1 { font-size: 1.35rem; margin: 8px 0 18px; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 20px;
}
.tab {
  padding: 12px 4px;
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius);
  font-size: 0.92rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.tab.active {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
  font-weight: 600;
}

.field { margin-bottom: 16px; }
.field.hidden { display: none; }

label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}
label .opt { color: var(--muted); font-weight: 400; }

input, select, textarea {
  width: 100%;
  padding: 13px 12px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  -webkit-appearance: none;
  appearance: none;
}
textarea { resize: vertical; font-family: inherit; line-height: 1.4; }
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'><path d='M4 6l4 4 4-4z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.quick {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--surface-2);
}
.quick label { margin-bottom: 8px; }
.quick .submit { margin-top: 10px; }
.submit.secondary {
  background: transparent;
  border: 1px solid var(--accent-strong);
  color: var(--accent-strong);
}
.hint { display: block; margin-top: 6px; color: var(--muted); font-size: 0.8rem; }

.submit {
  width: 100%;
  margin-top: 8px;
  padding: 16px;
  background: var(--accent-strong);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}
.submit:disabled { opacity: .55; cursor: default; }

.result { margin-top: 18px; font-size: 0.95rem; }
.result.ok, .result.err { padding: 14px; border-radius: var(--radius); }
.result.ok { background: #ecfdf5; border: 1px solid var(--ok); color: #065f46; }
.result.err { background: #fef2f2; border: 1px solid var(--err); color: #991b1b; }
.result code { font-family: ui-monospace, monospace; }
