/* Cuentas del Corral — estilos (iOS primero) */
:root {
  --bg: #EEF1EF;
  --surface: #FFFFFF;
  --surface-2: #F7F9F8;
  --ink: #15201C;
  --ink-2: #3F4D47;
  --muted: #6C7973;
  --line: #D9DFDC;
  --fill: #E4E9E6;
  --accent: #2B5F75;
  --accent-ink: #FFFFFF;
  --accent-soft: #E0ECF1;
  --pos: #22774A;
  --pos-soft: #E1F1E7;
  --neg: #B83A2C;
  --neg-soft: #FAE6E2;
  --warn: #9A5F0B;
  --warn-soft: #FBEFD9;
  --tag: #F4C430;
  --tag-edge: #D5A612;
  --tag-ink: #332700;
  --backdrop: rgba(10, 20, 16, .38);
  --serie-1: #2a78d6;
  --serie-2: #eb6834;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  color-scheme: light;
}
/* Modo noche: automático (según el teléfono) o elegido en Ajustes → Apariencia */
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="dia"]) {
    --bg: #0E1214;
    --surface: #182023;
    --surface-2: #151C1F;
    --ink: #E9EEF0;
    --ink-2: #C3CDD1;
    --muted: #8F9CA2;
    --line: #2B3539;
    --fill: #243034;
    --accent: #79B8D1;
    --accent-ink: #0B1A20;
    --accent-soft: #1C3440;
    --pos: #62C487;
    --pos-soft: #16301F;
    --neg: #F18677;
    --neg-soft: #3A1D19;
    --warn: #E6B452;
    --warn-soft: #362A12;
    --tag: #E7B925;
    --tag-edge: #B38D12;
    --tag-ink: #2A2000;
    --backdrop: rgba(0, 0, 0, .55);
    --serie-1: #3987e5;
    --serie-2: #d95926;
    color-scheme: dark;
  }
}
:root[data-tema="noche"] {
  --bg: #0E1214;
  --surface: #182023;
  --surface-2: #151C1F;
  --ink: #E9EEF0;
  --ink-2: #C3CDD1;
  --muted: #8F9CA2;
  --line: #2B3539;
  --fill: #243034;
  --accent: #79B8D1;
  --accent-ink: #0B1A20;
  --accent-soft: #1C3440;
  --pos: #62C487;
  --pos-soft: #16301F;
  --neg: #F18677;
  --neg-soft: #3A1D19;
  --warn: #E6B452;
  --warn-soft: #362A12;
  --tag: #E7B925;
  --tag-edge: #B38D12;
  --tag-ink: #2A2000;
  --backdrop: rgba(0, 0, 0, .55);
  --serie-1: #3987e5;
  --serie-2: #d95926;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.35 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .dots, .dots { stroke-width: 2.4; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; opacity: 0; }

/* ---------- Estructura ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
main.sin-scroll { overflow: hidden; }
.view {
  max-width: 680px;
  margin: 0 auto;
  padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
  padding-bottom: 32px;
  padding-left: var(--gutter);
  padding-right: var(--gutter-r);
}
.view.push { animation: push-in .32s cubic-bezier(.2, .8, .2, 1); }
@keyframes push-in { from { transform: translateX(28%); opacity: .4; } to { transform: none; opacity: 1; } }

.nav { display: flex; align-items: center; justify-content: space-between; min-height: 44px; gap: 8px; }
.large-title {
  font: 700 34px/1.1 var(--font-round);
  letter-spacing: -.01em;
  margin: 2px 0 16px;
  text-wrap: balance;
}
.icon-btn {
  width: 44px; height: 44px; margin-right: -8px;
  display: grid; place-items: center;
  color: var(--accent); border-radius: 22px;
}
.icon-btn.accent svg { width: 26px; height: 26px; stroke-width: 2.2; }
.icon-btn:active, .link:active, .back:active { opacity: .45; }
.link { color: var(--accent); min-height: 44px; padding: 0 8px; font-size: 17px; }
.link.strong { font-weight: 600; }
.back { display: flex; align-items: center; gap: 2px; color: var(--accent); min-height: 44px; margin-left: -10px; padding-right: 8px; font-size: 17px; }
.back svg { width: 26px; height: 26px; stroke-width: 2.2; }

/* ---------- Barra de pestañas ---------- */
.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface-2);
  border-top: .5px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: 52px; color: var(--muted); font-size: 10.5px; font-weight: 500;
}
.tabbar button svg { width: 26px; height: 26px; }
.tabbar button[aria-selected="true"] { color: var(--accent); }
.tabbar button[aria-selected="true"] svg { stroke-width: 2.1; }

/* ---------- Listas agrupadas (estilo iOS) ---------- */
.group { background: var(--surface); border-radius: 12px; overflow: hidden; }
.group + .group, .group + .hint + .group { margin-top: 14px; }
.section-h {
  font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin: 26px 16px 7px;
}
.section-h:first-child { margin-top: 4px; }
.section-h .r { float: right; text-transform: none; letter-spacing: 0; }
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 48px; padding: 11px 16px;
  text-align: left; position: relative;
}
.field[hidden] + .field::before { display: none; }
.row + .row::before, .chart-wrap + .row::before, .empty-mini + .row::before, .row + .row-btn::before, .row-btn + .row-btn::before, .field + .field::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line);
}
button.row:active, a.row:active { background: var(--fill); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 500; overflow-wrap: anywhere; }
.row-title small { font-weight: 400; color: var(--muted); font-size: 15px; margin-left: 4px; }
.row-sub { font-size: 14.5px; color: var(--muted); overflow-wrap: anywhere; }
.row-end { display: flex; align-items: center; gap: 6px; color: var(--muted); text-align: right; flex: none; }
.row-end .chev { width: 16px; height: 16px; stroke-width: 2.4; opacity: .55; }
.row-val { font-weight: 500; color: var(--ink); white-space: nowrap; }
.row-val-sub { display: block; font-size: 13px; color: var(--muted); font-weight: 400; }
.row.total .row-title, .row.total .row-val { font-weight: 700; }
.kv { justify-content: space-between; }
.kv .k { color: var(--ink-2); }
.kv .k small { display: block; color: var(--muted); font-size: 13.5px; }

.row-btn {
  display: flex; align-items: center; justify-content: center; position: relative;
  width: 100%; min-height: 48px; padding: 10px 16px; color: var(--accent); font-size: 17px; cursor: pointer;
}
.row-btn:active { background: var(--fill); }
.row-btn.danger { color: var(--neg); }
.row-btn.armed { background: var(--neg); color: #fff; font-weight: 600; }
.row-btn[disabled] { opacity: .4; }
.row-btn.con-ico { gap: 8px; }
.row-btn.con-ico svg { width: 21px; height: 21px; }

/* Recibo de venta */
.recibo-img { display: block; width: 100%; max-width: 440px; height: auto; margin: 0 auto 12px; border-radius: 16px; background: #EEF1EF; }
.btn.ancho { display: flex; width: 100%; margin: 4px 0 0; min-height: 50px; font-size: 17px; }
.btn.ancho svg { width: 21px; height: 21px; stroke-width: 2; }

.pos { color: var(--pos) !important; }
.neg { color: var(--neg) !important; }
.warn { color: var(--warn) !important; }

/* ---------- Arete (etiqueta amarilla de la oreja) ---------- */
.tag {
  position: relative; flex: none;
  display: inline-flex; align-items: flex-end; justify-content: center;
  min-width: 52px; height: 40px; padding: 0 8px 6px;
  background: var(--tag); color: var(--tag-ink);
  font: 700 15px/1 var(--font-round); letter-spacing: .01em;
  border-radius: 13px 13px 9px 9px;
  box-shadow: inset 0 -2.5px 0 var(--tag-edge);
}
.tag::before {
  content: ""; position: absolute; top: 5px; left: 50%; width: 7px; height: 7px; margin-left: -3.5px;
  border-radius: 50%; background: var(--surface); box-shadow: inset 0 1px 1.5px rgba(0,0,0,.35);
}
.tag.lg { min-width: 84px; height: 64px; font-size: 24px; padding-bottom: 10px; border-radius: 20px 20px 13px 13px; box-shadow: inset 0 -3.5px 0 var(--tag-edge); }
.tag.lg::before { top: 8px; width: 10px; height: 10px; margin-left: -5px; background: var(--bg); }
.tag.off { filter: saturate(.2); opacity: .75; }

/* ---------- Resumen ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: var(--surface); border-radius: 14px; padding: 13px 14px 14px;
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
  text-align: left;
}
button.tile:active { background: var(--fill); }
.tile-k { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile-v { font: 700 clamp(21px, 6.4vw, 26px)/1.15 var(--font-round); letter-spacing: -.01em; overflow-wrap: anywhere; margin-top: 2px; }
.tile-v small { font: 500 15px var(--font); color: var(--muted); letter-spacing: 0; }
.money { white-space: nowrap; }
.tile-v .money small { font: 600 .56em var(--font-round); color: inherit; opacity: .7; margin-right: .18em; vertical-align: .32em; }
.tile-s { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.tile-s b { font-weight: 600; }

.install-hint {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: var(--accent-soft); color: var(--ink); border-radius: 12px; padding: 10px 6px 10px 14px; margin-bottom: 16px; font-size: 15px;
}
.install-hint .link { flex: none; font-weight: 600; }

.alert-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.alert-ico svg { width: 19px; height: 19px; stroke-width: 2; }
.alert-ico.vac { background: var(--warn-soft); color: var(--warn); }
.alert-ico.vac.late { background: var(--neg-soft); color: var(--neg); }
.alert-ico.peso { background: var(--accent-soft); color: var(--accent); }
.alert-ico.ok { background: var(--pos-soft); color: var(--pos); }

.bars { padding: 6px 16px 14px; display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; align-items: baseline; font-size: 15px; }
.bar-row .v { font-weight: 600; }
.bar-row .v small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.bar-track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); min-width: 4px; }

/* ---------- Segmentado y chips ---------- */
.seg {
  display: flex; background: var(--fill); border-radius: 10px; padding: 2px; gap: 2px; margin-bottom: 14px;
}
.seg button {
  flex: 1; min-height: 34px; border-radius: 8px; font-size: 14.5px; font-weight: 500; color: var(--ink-2); padding: 4px 6px;
}
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] {
  background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.seg-wrap { flex-wrap: wrap; }
.seg-wrap button { flex: 1 1 40%; min-height: 38px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 2px 14px; }
.chips button {
  min-height: 34px; padding: 6px 12px; border-radius: 17px; background: var(--surface); color: var(--accent);
  font-size: 14.5px; font-weight: 500; border: .5px solid var(--line);
}
.chips button:active { background: var(--accent-soft); }

/* ---------- Ficha ---------- */
.det-head { display: flex; align-items: center; gap: 16px; margin: 6px 0 18px; }
.det-title { font: 700 24px/1.15 var(--font-round); }
.det-peso { display: inline-flex; align-items: center; gap: 6px; font: inherit; color: inherit; padding: 2px 0; margin-right: 2px; }
.det-peso svg { width: 19px; height: 19px; color: var(--accent); stroke-width: 2; }
.det-peso:active { opacity: .6; }
.det-sexo { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; padding: 6px 8px 6px 16px; margin: -6px 0 12px; }
.det-sexo .seg { margin: 0; flex: 0 1 220px; }
.det-sexo + .peso-edit { margin-top: 0; }
.peso-edit { margin: -6px 0 16px; }
.peso-edit #dp-valor { font: 700 22px var(--font-round); }
.dp-pie { display: flex; align-items: center; gap: 4px; padding: 6px 10px 10px 16px; border-top: .5px solid var(--line); }
.dp-pista { flex: 1; color: var(--muted); font-size: 13.5px; line-height: 1.3; }
.dp-pista.neg { color: var(--neg); }
.btn.dp-ok { margin: 0; min-height: 38px; padding: 0 16px; font-size: 16px; }
.det-sub { color: var(--muted); font-size: 15px; margin-top: 3px; }
.pill {
  display: inline-block; font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 10px; vertical-align: 3px; margin-left: 6px;
  font-family: var(--font); letter-spacing: .01em;
}
.pill.activo { background: var(--pos-soft); color: var(--pos); }
.pill.vendido { background: var(--accent-soft); color: var(--accent); }
.pill.muerto { background: var(--neg-soft); color: var(--neg); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 6px; }
.quick button {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: var(--surface); border-radius: 12px; padding: 12px 4px 10px; color: var(--accent); font-size: 13.5px; font-weight: 600;
}
.quick button:active { background: var(--fill); }
.quick svg { width: 25px; height: 25px; }

.mini-del {
  width: 40px; height: 40px; margin: -8px -10px -8px 0; display: grid; place-items: center; color: var(--muted); border-radius: 20px; flex: none;
}
.mini-del svg { width: 18px; height: 18px; }
.mini-del.armed { width: auto; padding: 0 12px; background: var(--neg); color: #fff; font-size: 14px; font-weight: 600; }

.chart-wrap { position: relative; padding: 12px 10px 6px 4px; touch-action: pan-y; }
.chart-wrap svg.chart { width: 100%; height: auto; display: block; stroke: none; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis-t { fill: var(--muted); font: 11.5px var(--font); }
.chart .line { stroke: var(--accent); stroke-width: 2.25; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: .1; }
.chart .pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .pt.last { r: 5.5; }
.chart .lbl { fill: var(--ink); font: 600 12.5px var(--font); }
.chart .meta { stroke: var(--ink-2); stroke-width: 1.25; stroke-dasharray: 5 4; opacity: .55; }
.chart .meta-t { fill: var(--ink-2); font: 600 11.5px var(--font); }
.chart .proy { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 5; fill: none; opacity: .75; }
.chart .pt-proy { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .proy-t { fill: var(--accent); font-weight: 600; }
.chart .bar-e { fill: var(--serie-1); }
.chart .bar-s { fill: var(--serie-2); }
.chart .hl { fill: var(--fill); }
.chart-tip b { font-weight: 700; }
.chart-tip { line-height: 1.4; }
.leyenda { display: flex; align-items: center; gap: 16px; padding: 12px 16px 0; font-size: 13.5px; color: var(--ink-2); flex-wrap: wrap; }
.leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.leyenda .ley-u { margin-left: auto; color: var(--muted); font-size: 12.5px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.sw.e { background: var(--serie-1); }
.sw.s { background: var(--serie-2); }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats3 > div { background: var(--surface); border-radius: 12px; padding: 10px 11px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.stats3 .k { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stats3 .v { font: 700 17px/1.2 var(--font-round); overflow-wrap: anywhere; }
.stats3 .v .money small { font: 600 .62em var(--font-round); opacity: .7; margin-right: .15em; }
.chips.anios { margin: 0 2px 12px; }
.chips.anios button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.desglose { background: var(--surface-2); position: relative; }
.desglose::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
.desglose .row { padding-left: 30px; min-height: 42px; padding-block: 8px; }
.desglose .row + .row::before { left: 30px; }
.desglose .kv .k { font-size: 15.5px; }
.desglose + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
.row .chev.abajo { transform: rotate(90deg); }
.tags-fila { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px 4px; }
.tag.mini { min-width: 42px; height: 30px; font-size: 12.5px; padding: 0 6px 4px; border-radius: 10px 10px 7px 7px; box-shadow: inset 0 -2px 0 var(--tag-edge); cursor: pointer; }
.tag.mini::before { top: 4px; width: 5px; height: 5px; margin-left: -2.5px; }
.tags-fila + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
.chart .guide { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; top: 4px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 600; padding: 5px 9px; border-radius: 8px; white-space: nowrap; pointer-events: none;
}
.empty-mini { color: var(--muted); font-size: 15px; padding: 14px 16px; margin: 0; }

.notes { padding: 12px 16px; white-space: pre-wrap; color: var(--ink-2); font-size: 16px; }

/* ---------- Vacío ---------- */
.empty {
  background: var(--surface); border-radius: 14px; padding: 26px 20px; text-align: center; color: var(--muted); font-size: 15.5px;
}
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; font-family: var(--font-round); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 20px; margin-top: 14px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 16.5px;
}
.btn:active { opacity: .8; }

.avatar { width: 34px; height: 34px; border-radius: 17px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent); font: 700 15px var(--font-round); }
.cat-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent); }
.cat-ico svg { width: 20px; height: 20px; }

/* ---------- Hojas (sheets) ---------- */
.backdrop { position: fixed; inset: 0; background: var(--backdrop); opacity: 0; pointer-events: none; transition: opacity .28s; z-index: 40; }
.backdrop.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  max-width: 680px; margin: 0 auto;
  background: var(--bg); border-radius: 14px 14px 0 0;
  display: flex; flex-direction: column;
  transform: translateY(104%); transition: transform .34s cubic-bezier(.2, .85, .25, 1), visibility 0s linear .34s;
  visibility: hidden;
  box-shadow: 0 -6px 30px rgba(0,0,0,.15);
}
.sheet.on { transform: none; visibility: visible; transition: transform .34s cubic-bezier(.2, .85, .25, 1), visibility 0s; }
.sheet-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 6px 8px; border-bottom: .5px solid var(--line); background: var(--surface-2); border-radius: 14px 14px 0 0;
}
.sheet-head::before {
  content: ""; position: absolute; top: 5px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: var(--line);
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-head .link:first-child { justify-self: start; }
.sheet-head .link:last-child { justify-self: end; }
.sheet-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 18px var(--gutter-r) calc(40px + env(safe-area-inset-bottom, 0px)) var(--gutter);
}

.form .field {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; position: relative;
  min-height: 50px; padding: 4px 16px;
}
.form .field > span:first-child { color: var(--ink); flex: none; max-width: 55%; }
.form input, .form select {
  flex: 1; min-width: 0; border: 0; background: transparent; text-align: right; font-size: 17px; padding: 10px 0; outline: none;
}
.form input::placeholder, .form textarea::placeholder { color: var(--muted); opacity: .8; }
.form input[type="date"] { -webkit-appearance: none; appearance: none; min-height: 36px; color: var(--accent); display: flex; justify-content: flex-end; }
.form input[type="date"]::-webkit-date-and-time-value { text-align: right; }
.form select { -webkit-appearance: none; appearance: none; color: var(--accent); direction: rtl; text-overflow: ellipsis; }
.form select option { direction: ltr; }
.form textarea { width: 100%; border: 0; background: transparent; padding: 12px 16px; font-size: 17px; resize: vertical; outline: none; display: block; }
.with-unit { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; justify-content: flex-end; }
.with-unit em { font-style: normal; color: var(--muted); }
.unit { display: inline-flex; flex: none; gap: 2px; padding: 2px; border-radius: 9px; background: var(--fill); }
.unit button { min-width: 40px; height: 32px; border-radius: 7px; font-size: 15px; font-weight: 600; color: var(--muted); }
.unit button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.14); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 34px; border-radius: 9px; background: var(--fill); color: var(--ink); font-size: 22px; line-height: 1; }
.stepper button:active { background: var(--line); }
.stepper output { min-width: 34px; text-align: center; font-weight: 600; font-size: 18px; }

.hint { color: var(--muted); font-size: 14px; margin: 8px 16px 0; line-height: 1.4; }
.hint:empty, .sheet-err:empty { display: none; }
.sheet-err { color: var(--neg); font-size: 15px; font-weight: 500; margin: 12px 16px 0; }
.actions-list { margin-top: 26px; }
.calc { margin-top: 14px; }

/* ---------- Estado de sincronización y avisos ---------- */
.sync-pill {
  display: inline-flex; align-items: center; gap: 7px; min-height: 30px; padding: 4px 11px 4px 9px; border-radius: 15px;
  background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 500; max-width: 75%; text-align: left;
}
.sync-pill::before { content: ""; width: 8px; height: 8px; border-radius: 4px; background: var(--muted); flex: none; }
.sync-pill.ok::before { background: var(--pos); }
.sync-pill.pend::before, .sync-pill.local::before { background: var(--warn); }
.sync-pill.error::before { background: var(--neg); }
.sync-pill.sync::before { background: var(--accent); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 300;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; font-weight: 500;
  max-width: calc(100% - 32px); transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }


/* ---------- Inicio de sesión y bloqueo ---------- */
:root {
  --auth-bg-1: #3C7E97;
  --auth-bg-2: #2B5F75;
  --auth-bg-3: #173946;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="dia"]) { --auth-bg-1: #24566A; --auth-bg-2: #183D4B; --auth-bg-3: #0A1C23; }
}
:root[data-tema="noche"] { --auth-bg-1: #24566A; --auth-bg-2: #183D4B; --auth-bg-3: #0A1C23; }
.auth {
  position: fixed; inset: 0; z-index: 200;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 24px) var(--gutter-r) calc(env(safe-area-inset-bottom, 0px) + 28px) var(--gutter);
  background:
    radial-gradient(90% 55% at 50% 8%, var(--auth-bg-1) 0%, transparent 70%),
    linear-gradient(180deg, var(--auth-bg-2) 0%, var(--auth-bg-3) 100%);
  background-color: var(--auth-bg-2);
  color: #fff;
  transition: opacity .35s ease, transform .35s ease;
}
.auth.saliendo { opacity: 0; transform: scale(1.04); pointer-events: none; }
.auth-top { text-align: center; margin: max(3vh, 8px) 0 24px; }
.auth-tag {
  width: 96px; height: 112px; display: block; margin: 0 auto 16px;
  stroke: none; fill: initial;
  transform-origin: 50% 13.5%;
  animation: columpio 2.6s cubic-bezier(.3, .6, .35, 1) both;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, .28));
}
@keyframes columpio {
  0% { transform: rotate(-16deg); }
  22% { transform: rotate(10deg); }
  44% { transform: rotate(-5.5deg); }
  66% { transform: rotate(2.5deg); }
  84% { transform: rotate(-1deg); }
  100% { transform: rotate(0); }
}
.auth-title { margin: 0; font: 700 30px/1.1 var(--font-round); letter-spacing: -.01em; text-wrap: balance; }
.auth-sub { margin: 7px 0 0; color: rgba(255, 255, 255, .72); font-size: 15.5px; }

.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface); color: var(--ink);
  border-radius: 24px; padding: 22px 20px 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .28), 0 2px 6px rgba(0, 0, 0, .1);
  animation: subir .5s .15s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes subir { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.au-vista { display: flex; flex-direction: column; }
.au-h { margin: 0 0 4px; font: 700 22px/1.2 var(--font-round); text-align: center; }
.au-hint { margin: 0 0 6px; color: var(--muted); font-size: 14.5px; text-align: center; line-height: 1.4; }
.au-field { display: block; margin-top: 12px; }
.au-field > span:first-child {
  display: block; margin: 0 4px 6px; font-size: 12.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.au-field input {
  width: 100%; height: 50px; padding: 0 14px; border-radius: 13px;
  border: 1.5px solid transparent; background: var(--fill); color: var(--ink);
  font-size: 17px; outline: none; transition: border-color .15s, background .15s;
}
.au-field input::placeholder { color: var(--muted); opacity: .75; }
.au-field input:focus { border-color: var(--accent); background: var(--surface); }
.au-pass { position: relative; display: block; }
.au-pass input { padding-right: 50px; }
.au-ojo {
  position: absolute; right: 3px; top: 3px; width: 44px; height: 44px;
  display: grid; place-items: center; color: var(--muted); border-radius: 11px;
}
.au-ojo svg { width: 21px; height: 21px; }
.au-ojo[aria-pressed="true"] { color: var(--accent); }
.au-err { margin: 12px 4px 0; color: var(--neg); font-size: 14.5px; font-weight: 500; text-align: center; }
.au-err:empty { display: none; }
.au-btn {
  margin-top: 18px; min-height: 52px; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-size: 17px; font-weight: 600;
  transition: opacity .15s, transform .1s;
}
.au-btn:active { transform: scale(.985); opacity: .85; }
.au-btn[disabled], .bio-btn[disabled] { opacity: .55; }
.au-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 18px; margin-top: 12px; }
.au-links button { min-height: 40px; padding: 0 4px; color: var(--accent); font-size: 15px; font-weight: 500; }

.bio-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 54px; border-radius: 14px; background: var(--ink); color: var(--surface);
  font-size: 17px; font-weight: 500;
}
.bio-btn b { font-weight: 700; }
.bio-btn:active { opacity: .85; }
.bio-btn .faceid { width: 26px; height: 26px; stroke-width: 1.7; }
.au-sep { display: flex; align-items: center; gap: 12px; margin: 18px 0 2px; color: var(--muted); font-size: 13.5px; }
.au-sep::before, .au-sep::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.au-centro { align-items: center; text-align: center; }
.au-centro > form { width: 100%; display: flex; flex-direction: column; }
.au-hola { margin: 2px 0 16px; font: 700 23px/1.2 var(--font-round); }
.bio-grande {
  width: 92px; height: 92px; border-radius: 28px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  transition: transform .15s;
}
.bio-grande:active { transform: scale(.94); }
.bio-grande .faceid { width: 52px; height: 52px; stroke-width: 1.5; }
.bio-grande.quieto { margin: 4px 0 14px; }
.bio-grande.leyendo .faceid { animation: leyendo 1.1s ease-in-out infinite; }
@keyframes leyendo { 50% { opacity: .35; } }
.au-bio-lbl { margin: 12px 0 0; color: var(--muted); font-size: 15px; }
.au-ofrecer .au-btn, #au-ofrecer .au-btn { width: 100%; }

@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}


/* ---------- Foto del cerdo ---------- */
.foto-wrap { position: relative; margin: 0 0 16px; }
.foto-box {
  display: block; width: 100%; aspect-ratio: 4 / 3; border-radius: 16px; overflow: hidden;
  background: var(--fill);
}
.foto-box img { width: 100%; height: 100%; object-fit: cover; display: block; }
.foto-vacia {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--muted); font-size: 14px; font-weight: 500;
}
.foto-vacia svg { width: 22px; height: 22px; stroke-width: 1.8; opacity: .8; }
.foto-vacia svg.cerdo-ph { width: 44px; height: 44px; stroke-width: 1.3; opacity: .45; margin-bottom: 2px; }
.foto-quitar {
  position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center;
}
.foto-quitar svg { width: 16px; height: 16px; stroke-width: 2.4; }

/* ---------- Mostrar a comprador ---------- */
.mostrar-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mostrar-tile { background: var(--surface); border-radius: 16px; overflow: hidden; text-align: left; }
.mostrar-tile:active { background: var(--fill); }
.mostrar-tile .mt-foto {
  width: 100%; aspect-ratio: 1 / 1; background: var(--fill); display: flex; align-items: center; justify-content: center;
}
.mostrar-tile .mt-foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mostrar-tile .mt-foto svg { width: 34px; height: 34px; color: var(--muted); opacity: .45; stroke-width: 1.3; }
.mostrar-tile .mt-cod { display: block; padding: 10px 12px 12px; font: 700 17px var(--font-round); }

.mostrar-card { text-align: center; padding-top: 6px; }
.mostrar-card .mc-foto {
  width: 100%; max-width: 320px; aspect-ratio: 1 / 1; margin: 0 auto 18px; border-radius: 24px; overflow: hidden;
  background: var(--fill); display: flex; align-items: center; justify-content: center;
}
.mostrar-card .mc-foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mostrar-card .mc-foto svg { width: 64px; height: 64px; color: var(--muted); opacity: .4; stroke-width: 1.2; }
.mostrar-card .mc-cod { margin-bottom: 18px; }
.mostrar-stats { display: flex; gap: 10px; justify-content: center; }
.mostrar-stat { background: var(--surface); border-radius: 14px; padding: 14px 24px; min-width: 120px; }
.mostrar-stat .ms-k { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }
.mostrar-stat .ms-v { font: 700 22px var(--font-round); }
