:root {
  /* Marca Petlov: rojo + negro */
  --teal: #e5401e;     /* rojo Petlov (nombre conservado para no romper refs) */
  --teal-d: #b83214;   /* rojo oscuro */
  --ink: #1d1d1d;
  --muted: #8a8a8a;
  --bg: #f5f3f2;
  --card: #ffffff;
  --line: #e6e2e0;
  --danger: #c0392b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.wrap { max-width: 460px; margin: 0 auto; padding: 16px 14px 48px; }

.top { display: flex; align-items: center; gap: 12px; margin: 10px 2px 18px; }
.brand {
  width: 54px; height: 54px; flex: none; padding: 5px;
  display: grid; place-items: center; font-size: 26px;
  background: #fff; border: 1px solid var(--line); border-radius: 15px;
  box-shadow: 0 2px 6px rgba(20, 30, 40, .06);
}
.brand img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
h1 { font-size: 23px; margin: 0; line-height: 1.1; letter-spacing: -0.2px; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 2px 10px rgba(20, 30, 40, .05);
}

h2 {
  font-size: 15px; margin: 0 0 14px; display: flex; align-items: baseline; gap: 6px;
  padding-left: 11px; position: relative;
}
h2::before {
  content: ''; position: absolute; left: 0; top: 1px; bottom: 1px;
  width: 4px; border-radius: 3px; background: var(--teal);
}
h2 small, span small { font-weight: 400; color: var(--muted); font-size: 12px; }

.field-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.field-line + .field-line { border-top: 1px solid var(--line); }
.field-line > span { font-size: 14px; color: var(--ink); }
.field-line.col { flex-direction: column; align-items: stretch; gap: 6px; }
.field-line input[type="text"], .field-line input[type="date"], textarea {
  font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; background: #fbfdfd; width: 58%;
}
.field-line.col input, .field-line.col textarea { width: 100%; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal); }

/* navegación de fecha ( ‹ fecha › ) */
.date-field { gap: 10px; }
.date-nav { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.date-nav input[type="date"] { flex: 1; min-width: 0; width: auto; }
.nav-btn {
  width: 36px; height: 38px; flex: none; cursor: pointer;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  color: var(--teal-d); font-size: 20px; font-weight: 700; line-height: 1;
}
.nav-btn:hover { background: #fdeee9; }
.nav-btn:active { background: #f9ddd4; }
.save-row { display: flex; justify-content: flex-end; min-height: 16px; margin-top: 6px; }
.save-status { font-size: 12px; color: var(--muted); }

/* filas con stepper */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row .lbl { font-size: 15px; }
.stepper { display: flex; align-items: center; gap: 8px; flex: none; }
.stepper button {
  width: 38px; height: 38px; flex: none;
  border: 1px solid var(--line); background: #fdeee9; color: var(--teal-d);
  font-size: 22px; line-height: 1; border-radius: 10px; cursor: pointer;
}
.stepper button:active { background: #f9ddd4; }
.stepper input {
  width: 52px; text-align: center; font: inherit; font-size: 17px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 4px; background: #fff;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* filas personalizadas (agregadas por el usuario) */
.row.custom .lbl-input {
  flex: 1; min-width: 0; font: inherit; font-size: 15px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fbfaf9;
}
/* caja de monto en pesos (sección Efectivo): sin stepper, con $ */
.amount {
  display: flex; align-items: center; gap: 2px; flex: none;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 0 10px;
}
.amount:focus-within { outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal); }
.amount .cur { color: var(--muted); font-weight: 600; font-size: 15px; }
.amount .cnt {
  width: 92px; text-align: right; font: inherit; font-size: 16px; font-weight: 600;
  border: none; background: transparent; padding: 9px 0; -moz-appearance: textfield;
}
.amount .cnt:focus { outline: none; }
.amount .cnt::-webkit-outer-spin-button,
.amount .cnt::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.row.custom .rm {
  width: 32px; height: 32px; flex: none; cursor: pointer;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
  color: var(--danger); font-size: 18px; line-height: 1;
}
.row.custom .rm:active { background: #fdeee9; }

.add-row {
  margin-top: 8px; width: 100%;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--teal-d);
  background: #fff; border: 1px dashed var(--teal); border-radius: 11px;
  padding: 10px; cursor: pointer;
}
.add-row:active { background: #fdeee9; }

/* Diferencia (sobrante / faltante) */
.diferencia { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.dif-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dif-lbl { font-size: 15px; font-weight: 600; }
.dif-ctrls { display: flex; align-items: center; gap: 8px; }
.dif-sign {
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; line-height: 1;
}
.dif-sign.pos { background: #e7f6ec; color: #1f8a4c; border-color: #bfe6cd; }
.dif-sign.neg { background: #fde7e1; color: var(--danger); border-color: #f3c9bd; }
.dif-sign:active { filter: brightness(.96); }
.dif-motivo {
  margin-top: 8px; width: 100%; font: inherit; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fbfaf9;
}

.subtotal {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; padding-top: 10px; border-top: 2px solid var(--line);
  font-size: 14px; color: var(--muted);
}
.subtotal b { font-size: 18px; color: var(--teal-d); }
/* Subtotal (solo visible cuando hay diferencia): más discreto que el Total */
.subtotal.sub { margin-top: 12px; padding-top: 8px; border-top-width: 1px; }
.subtotal.sub b { font-size: 15px; color: var(--ink); font-weight: 600; }

.note {
  background: #fff7e6; border: 1px solid #f3e2b8; color: #7a5b16;
  border-radius: 12px; padding: 10px 12px; font-size: 13px; margin: 4px 2px 16px;
}

.actions { display: flex; flex-direction: column; gap: 10px; }
.btn {
  font: inherit; font-size: 16px; font-weight: 600;
  border: none; border-radius: 14px; padding: 14px; cursor: pointer;
}
.btn.primary { background: var(--teal); color: #fff; }
.btn.primary:active { background: var(--teal-d); }
.btn.ghost { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn.ghost.danger { color: var(--danger); }

.preview { margin-top: 20px; }
.preview-hint { font-size: 12px; color: var(--muted); margin: 0 2px 8px; }
.preview img {
  width: 100%; border-radius: 14px; border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(20, 48, 45, .1);
}
