:root {
  --celeste: #2f9bd6;
  --celeste-osc: #1f7db1;
  --celeste-claro: #e8f4fb;
  --tinta: #1a2733;
  --gris: #6b7a86;
  --linea: #dfe6ec;
  --bg: #f4f7fa;
  --ok: #17924a;
  --error: #d64545;
  --radio: 14px;
  --sombra: 0 6px 24px rgba(20, 50, 80, 0.10);
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--tinta);
  overscroll-behavior: none;
}

.pantalla { display: none; min-height: 100dvh; }
.pantalla.activa { display: block; }

/* ---------- Login ---------- */
#pantalla-login { display: none; place-items: center; min-height: 100dvh; padding: 24px; }
#pantalla-login.activa { display: grid; }
.login-card {
  background: #fff; border-radius: 20px; box-shadow: var(--sombra);
  padding: 32px 26px; width: 100%; max-width: 360px; text-align: center;
}
.login-logo { width: 120px; height: auto; margin-bottom: 8px; }
.login-card h1 { margin: 4px 0 0; font-size: 1.5rem; }
.login-card .sub { margin: 2px 0 22px; color: var(--gris); font-size: .95rem; }
#pin-input {
  width: 100%; padding: 15px; font-size: 1.3rem; text-align: center; letter-spacing: 4px;
  border: 2px solid var(--linea); border-radius: 12px; margin-bottom: 14px;
}
#pin-input:focus { outline: none; border-color: var(--celeste); }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 12px; padding: 14px 18px; font-size: 1rem; font-weight: 600;
  cursor: pointer; width: 100%; }
.btn-primary { background: var(--celeste); color: #fff; }
.btn-primary:active { background: var(--celeste-osc); }
.btn-ghost { background: #fff; color: var(--celeste-osc); border: 1.5px solid var(--linea); }
.btn-sm { width: auto; padding: 9px 16px; font-size: .9rem; }
.icon-btn { background: none; border: none; font-size: 1.5rem; color: var(--tinta); cursor: pointer; padding: 4px 10px; line-height: 1; }
.link-btn { background: none; border: none; color: var(--celeste-osc); font-size: .9rem; cursor: pointer; padding: 6px 0; }
.error { color: var(--error); font-size: .9rem; min-height: 1.2em; margin: 8px 0 0; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  background: #fff; padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--linea);
}
.topbar-logo { width: 30px; height: 30px; object-fit: contain; }
.topbar-title { font-weight: 700; flex: 1; }
.topbar .icon-btn { margin: -4px 0; }

.contenido { padding: 18px 16px 60px; max-width: 640px; margin: 0 auto; }

/* ---------- Home ---------- */
.btn-grande {
  width: 100%; border: none; border-radius: 18px; cursor: pointer;
  background: linear-gradient(135deg, var(--celeste), var(--celeste-osc));
  color: #fff; padding: 26px 20px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: var(--sombra); margin-bottom: 12px;
}
.btn-grande .mic { font-size: 2.4rem; }
.btn-grande .txt { font-size: 1.2rem; font-weight: 700; }
.btn-grande .hint { font-size: .85rem; opacity: .9; font-weight: 400; }
.seccion { font-size: 1rem; color: var(--gris); margin: 26px 0 10px; }

.lista { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: #fff; border: 1px solid var(--linea); border-radius: 12px; padding: 13px 15px;
  display: flex; align-items: center; justify-content: space-between; cursor: pointer;
}
.item:active { background: var(--celeste-claro); }
.item .info { min-width: 0; }
.item .info b { display: block; font-size: 1rem; }
.item .info small { color: var(--gris); }
.item .monto { font-weight: 700; color: var(--celeste-osc); white-space: nowrap; margin-left: 10px; }
.vacio { color: var(--gris); text-align: center; padding: 20px; font-size: .9rem; }

/* ---------- Editor ---------- */
.transcript { background: var(--celeste-claro); border-radius: 10px; padding: 10px 12px; font-size: .85rem; color: var(--celeste-osc); margin-bottom: 14px; }
.campos { display: flex; gap: 10px; }
.campos label { flex: 1; }
label { display: block; font-size: .78rem; color: var(--gris); font-weight: 600; margin-bottom: 12px; }
input, textarea, select {
  width: 100%; margin-top: 4px; padding: 11px 12px; font-size: 1rem; color: var(--tinta);
  border: 1.5px solid var(--linea); border-radius: 10px; background: #fff; font-family: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--celeste); }
.grupo { border: 1px solid var(--linea); border-radius: 14px; padding: 12px 14px 2px; margin: 4px 0 14px; }
.grupo legend { font-weight: 700; color: var(--tinta); padding: 0 6px; font-size: .95rem; }

.obra { border: 1px solid var(--linea); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; background: #fff; }
.obra-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.obra-head input { margin: 0; font-weight: 700; }
.obra-head .quitar { flex: none; width: auto; }
.tarea { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.tarea .detalle { flex: 1; margin: 0; }
.tarea .imp { width: 108px; margin: 0; }
.tarea .quitar, .obra-head .quitar { background: none; border: none; color: var(--error); font-size: 1.3rem; cursor: pointer; padding: 0 4px; }
.add-tarea { background: none; border: none; color: var(--celeste-osc); font-size: .88rem; cursor: pointer; padding: 4px 0; font-weight: 600; }

.total-row { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 2px; font-weight: 700; font-size: 1.1rem; }
.total-input { display: flex; align-items: center; gap: 4px; border: 2px solid var(--celeste); border-radius: 10px; padding: 4px 10px; }
.total-input span { color: var(--gris); }
.total-input input { width: 140px; border: none; margin: 0; padding: 6px 0; font-size: 1.15rem; font-weight: 700; text-align: right; }
.total-input input:focus { outline: none; }
.notas-label { margin-top: 12px; }
.acciones-editor { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(15, 35, 55, .55);
  display: none; place-items: center; padding: 24px; backdrop-filter: blur(2px); }
.overlay.activa { display: grid; }
.grab-box { background: #fff; border-radius: 20px; padding: 30px 26px; text-align: center; width: 100%; max-width: 340px; }
.grab-tiempo { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.grab-msg { color: var(--gris); margin: 8px 0 20px; }
.grab-acciones { display: flex; gap: 10px; }
.onda { display: flex; gap: 5px; justify-content: center; align-items: flex-end; height: 44px; margin-bottom: 6px; }
.onda span { width: 6px; background: var(--celeste); border-radius: 3px; animation: onda 1s infinite ease-in-out; }
.onda span:nth-child(1){ animation-delay: 0s } .onda span:nth-child(2){ animation-delay: .15s }
.onda span:nth-child(3){ animation-delay: .3s } .onda span:nth-child(4){ animation-delay: .45s }
.onda span:nth-child(5){ animation-delay: .6s }
@keyframes onda { 0%,100%{ height: 10px } 50%{ height: 40px } }
.spinner { width: 44px; height: 44px; border: 4px solid var(--celeste-claro); border-top-color: var(--celeste); border-radius: 50%; margin: 0 auto 6px; animation: giro .8s linear infinite; }
@keyframes giro { to { transform: rotate(360deg) } }

/* ---------- Preview ---------- */
.overlay-preview { background: #33414d; place-items: start stretch; padding: 0; flex-direction: column; }
.overlay-preview.activa { display: flex; }
.preview-topbar { display: flex; align-items: center; gap: 10px; background: #fff; padding: 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top)); position: sticky; top: 0; }
.preview-topbar span { flex: 1; font-weight: 700; }
.preview-topbar .icon-btn { color: var(--tinta); }
.preview-scroll { flex: 1; overflow: auto; padding: 16px; display: flex; justify-content: center; align-items: flex-start; }
.hoja-wrap { position: relative; margin: 0 auto; }
.preview-scroll .hoja { transform-origin: top left; box-shadow: 0 4px 20px rgba(0,0,0,.4); }

/* ---------- HOJA A4 · estilo "Minimalista claro" (pantalla y PDF) ---------- */
.hoja {
  width: 794px; min-height: 1123px; background: #fff; color: #1a2530;
  padding: 46px 48px 40px; align-self: flex-start;
  font-family: "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; display: flex; flex-direction: column;
}
.hoja * { box-sizing: border-box; }
.hoja .money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hoja .eyebrow { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: #94a1ab; }

.h-logo { display: block; margin: 0 auto; height: 132px; }
.h-contacto { text-align: center; font-size: 13px; color: #7c8892; margin-top: 12px; line-height: 1.6; }
.h-contacto b { color: #37474f; font-weight: 600; }
.h-rule { height: 1px; background: #e6ebef; margin: 22px 0; }

.h-meta { display: flex; justify-content: space-between; align-items: flex-end; }
.h-meta .t-lbl { color: var(--celeste-osc); }
.h-meta h2 { font-size: 26px; font-weight: 600; margin: 4px 0 0; letter-spacing: -.02em; color: #1a2530; }
.h-meta .fecha { text-align: right; font-size: 12px; color: #94a1ab; letter-spacing: .04em; text-transform: uppercase; }
.h-meta .fecha b { display: block; color: #1a2530; font-size: 16px; font-weight: 600; margin-top: 3px; letter-spacing: 0; text-transform: none; }

.h-cli { background: #f5f8fa; border-radius: 14px; padding: 16px 20px; margin: 18px 0 4px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 13px 22px; }
.h-cli .v { font-size: 15px; font-weight: 600; color: #26333f; margin-top: 3px; }

.h-body { flex: 1; }

.tk { width: 100%; border-collapse: collapse; margin-top: 16px; }
.tk thead th { padding: 4px 4px 10px; border-bottom: 1.5px solid #d7dee4; font-weight: 600; }
.tk thead th.d { text-align: left; }
.tk thead th.i { text-align: right; width: 210px; border-left: 1px solid #e6ebef; padding-left: 16px; }
.tk .obra-h td { padding: 18px 4px 4px; border: none; }
.tk .obra-h td.i { border-left: 1px solid #e6ebef; }
.tk .obra-h .oh { display: flex; align-items: center; gap: 12px; }
.tk .obra-h .oh span { color: var(--celeste-osc); font-weight: 700; font-size: 13px; letter-spacing: .02em; }
.tk .obra-h .oh .ln { flex: 1; height: 1px; background: #e6ebef; }
.tk td.d { padding: 11px 4px; font-size: 14px; color: #33424e; border-bottom: 1px solid #eef2f5; }
.tk td.i { padding: 11px 4px 11px 16px; font-size: 14px; text-align: right; color: #1a2530; font-weight: 600;
  border-bottom: 1px solid #eef2f5; border-left: 1px solid #e6ebef; width: 210px; }

.h-total { margin-top: 26px; background: #eaf5fc; border-radius: 16px; padding: 20px 24px;
  display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.h-total .tl { color: var(--celeste-osc); font-weight: 600; font-size: 15px; }
.h-total .tv { font-size: 28px; font-weight: 700; color: #123f5c; letter-spacing: -.01em; }
.h-notas { margin-top: 16px; font-size: 13px; color: #5f6b75; white-space: pre-wrap; line-height: 1.5; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--tinta); color: #fff; padding: 12px 20px; border-radius: 30px; font-size: .9rem;
  opacity: 0; transition: .25s; z-index: 40; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--error); }

@media (max-width: 480px) {
  .campos { flex-direction: column; gap: 0; }
}
