/* Gastos de trabajo
   Paleta: papel de formulario autocopiativo + tinta índigo de bolígrafo. */

@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #EEF2F6;
  --surface: #FFFFFF;
  --ink: #1B2A4A;
  --blue: #2F5BD3;
  --muted: #5D6983;
  --rule: #D0D7E2;
  --stamp: #B92B45;
  --ok: #1B6E53;

  --font: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --step--1: 0.833rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.44rem;
  --radius: 6px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

h1, h2, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: var(--blue); text-underline-offset: 0.15em; }
code { font-size: 0.9em; background: var(--paper); padding: 0.1em 0.3em; border-radius: 3px; }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------- Cabecera ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  padding-top: calc(0.85rem + env(safe-area-inset-top, 0px));
  max-width: 68rem;
  margin: 0 auto;
}
.brand {
  font-weight: 800;
  font-stretch: 112%;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.topnav { display: flex; align-items: center; gap: 1.1rem; font-size: var(--step--1); }
.topnav form { margin: 0; }
.linklike {
  font: inherit;
  color: var(--blue);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}

.page { max-width: 68rem; margin: 0 auto; padding: 0.25rem 1rem 3rem; }
body.narrow .page { max-width: 32rem; }
body.narrow:not(:has(.topbar)) .page { padding-top: 12vh; }

/* ---------- Avisos ---------- */

.notice {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  border-left: 4px solid var(--ok);
  background: var(--surface);
  font-weight: 500;
}
.notice-error { border-left-color: var(--stamp); }

/* ---------- Estructura de la página del mes ---------- */

.layout { display: grid; gap: 1.5rem; }

@media (min-width: 56rem) {
  .layout { grid-template-columns: 23rem minmax(0, 1fr); gap: 2.5rem; align-items: start; }
  .side { position: sticky; top: 1rem; }
}

.monthnav {
  display: grid;
  grid-template-columns: 2.75rem 1fr 2.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.monthnav-title {
  text-align: center;
  font-size: var(--step-1);
  font-weight: 700;
}
.monthnav-btn {
  display: grid;
  place-items: center;
  height: 2.75rem;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--ink);
  text-decoration: none;
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
}
.monthnav-btn:hover { border-color: var(--ink); }
.monthnav-btn.is-disabled { opacity: 0.35; background: transparent; }

/* ---------- Resguardo con el total (el único gesto fuerte del diseño) ---------- */

.slip-wrap { filter: drop-shadow(0 6px 10px rgba(27, 42, 74, 0.22)); margin-bottom: 1.75rem; }

.slip-total {
  --tooth: 14px;
  background: var(--ink);
  color: #fff;
  padding: 1.25rem 1.25rem calc(1.4rem + var(--tooth) / 2);
  border-radius: var(--radius) var(--radius) 0 0;
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / var(--tooth) 100%;
          mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / var(--tooth) 100%;
}
.slip-label { font-size: var(--step--1); color: #B9C4DA; }
.slip-amount {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 0.5rem;
  margin: 0.1rem 0 0.35rem;
  line-height: 1;
}
.slip-amount .num {
  font-size: clamp(2.9rem, 13vw, 4rem);
  font-weight: 800;
  font-stretch: 70%;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.slip-amount .cur { font-size: var(--step-1); font-weight: 600; font-stretch: 85%; color: #B9C4DA; }
.slip-meta { font-size: var(--step--1); color: #D5DCEA; max-width: 34ch; }
.pdf-form { margin-top: 1rem; display: grid; gap: 0.7rem; }
.pdf-more { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.slip-sent { margin-top: 0.9rem; overflow-wrap: anywhere; }
.slip-total .check { color: #E6EBF5; }
.slip-total :focus-visible { outline-color: #fff; }

/* ---------- Paneles y formularios ---------- */

.panel, .slip-form {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.panel + .panel { margin-top: 1.25rem; }
.panel h1, .panel h2, .slip-form h1 { font-size: var(--step-1); font-weight: 700; margin-bottom: 0.4rem; }
.slip-form h1 { font-size: var(--step-2); font-weight: 800; font-stretch: 112%; letter-spacing: -0.015em; }
.lead, .hint { color: var(--muted); max-width: 52ch; }
.hint { font-size: var(--step--1); margin-bottom: 0.9rem; }
.hint-after { margin: 0.9rem 0 0; }
.check-list { display: grid; gap: 0.7rem; margin-top: 1.1rem; }
.print-frame { position: fixed; right: 0; bottom: 0; width: 0; height: 0; border: 0; }
.page-title { font-size: var(--step-2); font-weight: 800; margin-bottom: 1rem; }
.back { font-size: var(--step--1); margin-bottom: 1rem; }

label {
  display: block;
  font-size: var(--step--1);
  font-weight: 600;
  margin: 0.95rem 0 0.3rem;
}
.optional { font-weight: 400; color: var(--muted); margin-left: 0.25rem; }

input[type="text"], input[type="password"], input[type="date"], select, textarea {
  display: block;
  width: 100%;
  min-height: 2.9rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 1rem; /* evita el zoom automático de iOS */
  color: var(--ink);
  background: #FAFBFD;
  border: 1.5px solid #B5BFD0;
  border-radius: var(--radius);
  -webkit-appearance: none;
          appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 1.15rem) 55%, calc(100% - 0.8rem) 55%;
  background-size: 0.35rem 0.35rem;
  background-repeat: no-repeat;
  padding-right: 2.2rem;
}
textarea { min-height: 11rem; line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); background: #fff; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--stamp); }
input#amount { font-variant-numeric: tabular-nums; font-weight: 600; }
input[type="file"] { width: 100%; font: inherit; font-size: var(--step--1); color: var(--muted); }
input[type="file"]::file-selector-button {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid #B5BFD0;
  border-radius: var(--radius);
  padding: 0.5rem 0.8rem;
  margin-right: 0.7rem;
  cursor: pointer;
}

.field-error { color: var(--stamp); font-size: var(--step--1); font-weight: 500; margin-top: 0.3rem; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.row-2 > div { min-width: 0; }

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  font-weight: 500;
  cursor: pointer;
}
.check input { width: 1.15rem; height: 1.15rem; accent-color: var(--blue); flex: none; }

.current-receipt { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.7rem; }
.current-receipt img {
  display: block;
  width: 72px;
  height: 96px;
  object-fit: cover;
  border: 1px solid var(--rule);
  border-radius: 4px;
}

/* ---------- Botones ---------- */

.btn {
  display: inline-block;
  min-height: 2.9rem;
  padding: 0.6rem 1.2rem;
  margin-top: 1.2rem;
  font: inherit;
  font-weight: 700;
  text-align: center;
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-block { display: block; width: 100%; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #254BB5; }
.btn-paper { background: #fff; color: var(--ink); margin-top: 0; }
.btn-paper:hover { background: #E3E9F4; }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--ink); margin-top: 0; }
.btn-secondary:hover { background: var(--paper); }
.btn-ghost { background: transparent; color: #fff; border-color: #6F7FA3; margin-top: 0; text-decoration: none; padding-left: 0.5rem; padding-right: 0.5rem; }
.btn-ghost:hover { border-color: #fff; background: rgba(255, 255, 255, 0.08); }
.btn[disabled] { opacity: 0.6; cursor: progress; }
.btn-danger { background: transparent; color: var(--stamp); border-color: var(--stamp); margin-top: 0; }
.btn-danger:hover { background: var(--stamp); color: #fff; }
.danger-zone { margin-top: 1.5rem; text-align: right; }

/* ---------- Libro de gastos ---------- */

.ledger { min-width: 0; }
.empty { color: var(--muted); padding: 1rem 0; max-width: 40ch; }

.day + .day { margin-top: 1.6rem; }
.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--ink);
}
.day-head h2 { font-size: var(--step-0); font-weight: 700; }
.day-total { font-size: var(--step--1); color: var(--muted); font-variant-numeric: tabular-nums; }

.entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.15rem 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--rule);
}
.entry-desc { font-weight: 500; overflow-wrap: anywhere; }
.entry-cat { font-size: var(--step--1); color: var(--muted); }
.entry-amount {
  font-size: var(--step-1);
  font-weight: 700;
  font-stretch: 88%;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.entry-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 1.1rem;
  font-size: var(--step--1);
}
.entry-actions a { padding: 0.25rem 0; }
.no-receipt { color: var(--muted); padding: 0.25rem 0; }

@media (min-width: 40rem) {
  .entry { grid-template-columns: minmax(0, 1fr) 9.5rem 7rem; align-items: center; }
  .entry-main { grid-column: 1; grid-row: 1; }
  .entry-actions { grid-column: 2; grid-row: 1; justify-content: flex-end; }
  .entry-amount { grid-column: 3; grid-row: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .monthnav-btn { transition: background-color 0.12s ease, border-color 0.12s ease; }
}

@media print {
  .topbar, .side .panel, .pdf-form, .entry-actions { display: none; }
}
