:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e9eaee;
  --text: #14161a;
  --text-dim: #80838c;
  --accent: #2f6fed;
  --accent-dim: #eaf1ff;
  --ok: #16a34a;
  --ok-bg: #e9f9ef;
  --bad: #e0393f;
  --bad-bg: #fdeaea;
  --dot: #c7c9d1;
  --radius: 18px;
  --radius-sm: 12px;
}

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

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

/* iOS hace zoom al enfocar cualquier input < 16px — todos a 16px como mínimo */
input, select, textarea { font-size: 16px; }

#app { max-width: 520px; margin: 0 auto; }

/* ============================== LOGIN ============================== */
#login-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px;
}
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card h1 {
  font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 24px; font-weight: 600; letter-spacing: -0.021em; color: #1d1d1f; margin: 0 0 6px;
}
.login-card .brand-sep { color: #86868b; font-weight: 400; margin: 0 2px; }
.login-sub { font-size: 13.5px; line-height: 1.45; color: var(--text-dim); margin: 0 0 22px; }
.login-card .pin-input { letter-spacing: normal; text-indent: 0; text-align: center; font-size: 17px; font-weight: 600; }
.login-card .pin-input::placeholder { letter-spacing: normal; text-indent: 0; }
.login-card .pin-submit { margin-top: 12px; }

/* ============================== PIN (hoja de acceso admin) ============================== */
.sheet-sub { margin: -10px 0 18px; font-size: 13px; line-height: 1.45; color: var(--text-dim); }
.pin-input {
  width: 100%; font: inherit; font-size: 26px; font-weight: 700;
  letter-spacing: .55em; text-indent: .55em; text-align: center;
  padding: 16px 0; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--bg); color: var(--text);
  caret-color: var(--accent); transition: border-color .12s ease, background .12s ease;
}
.pin-input::placeholder { color: var(--dot); letter-spacing: .35em; text-indent: .35em; }
.pin-input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.gate-pin-error { color: var(--bad); font-size: 12.5px; font-weight: 600; min-height: 18px; margin-top: 8px; text-align: center; }
.pin-submit {
  width: 100%; margin-top: 6px; padding: 15px; border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font: inherit; font-weight: 700; font-size: 15.5px;
}
.pin-submit:disabled { opacity: .4; }
.pin-cancel {
  width: 100%; margin-top: 4px; padding: 12px; border: none; background: none;
  color: var(--text-dim); font: inherit; font-weight: 600; font-size: 14px;
}

/* ============================== APP SHELL ============================== */
header.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 14px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
header.topbar h1 {
  margin: 0;
  font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.021em;
  color: #1d1d1f;
}
header.topbar h1 .brand-sep { color: #86868b; font-weight: 400; margin: 0 2px; }
header.topbar .sub { font-size: 12px; font-weight: 400; color: #86868b; margin-top: 2px; text-transform: capitalize; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.role-pill {
  border: none; background: var(--accent-dim); color: var(--accent);
  font: inherit; font-weight: 700; font-size: 12.5px; padding: 8px 12px; border-radius: 999px;
}
.role-pill.admin-active { background: var(--text); color: white; }
.icon-btn {
  border: none; background: var(--bg); color: var(--text-dim);
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 17px; height: 17px; }

main { padding: 6px 20px 100px; }
.view { display: none; }
.view.active { display: block; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

input[type=date] { font: inherit; border: none; background: transparent; color: var(--text-dim); font-weight: 600; }

/* ============================== ABRIR DÍA / BLOQUEO ============================== */
.open-day-card { background: #fff7e6; border: 1.5px solid #f4d792; border-radius: var(--radius); padding: 18px; margin: 12px 0 18px; }
.open-day-title { font-weight: 800; font-size: 15px; margin-bottom: 4px; }
.open-day-card p { font-size: 12.5px; color: var(--text-dim); margin: 0 0 14px; line-height: 1.4; }
.open-day-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.open-day-row .acc-badge { width: 32px; height: 32px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.open-day-row .name { flex: 1; font-weight: 700; font-size: 13.5px; }
.open-day-row input { width: 110px; font: inherit; font-weight: 700; font-size: 16px; text-align: right; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); }

.blocked-card { text-align: center; padding: 50px 24px; }
.blocked-icon { font-size: 40px; margin-bottom: 10px; }
.blocked-title { font-weight: 800; font-size: 17px; margin-bottom: 8px; }
.blocked-card p { color: var(--text-dim); font-size: 13.5px; margin: 0 0 22px; line-height: 1.4; }
.blocked-card .save-btn { max-width: 220px; margin: 0 auto; }

/* ============================== CONFIRM / EDIT ============================== */
.confirm-summary { background: var(--bg); border-radius: var(--radius-sm); padding: 16px; font-size: 14.5px; line-height: 1.7; margin-bottom: 4px; }
.confirm-summary b { font-weight: 800; }
.confirm-summary .row { display: flex; justify-content: space-between; }

.kind-seg { margin-bottom: 12px; }
.kind-seg button { font-size: 12px; padding: 10px 6px; }

.mov-edit-btn { background: none; border: none; color: var(--text-dim); padding: 0; margin-left: 8px; }
.mov-edit-btn svg { width: 13px; height: 13px; }

.opening-edit-link { background: none; border: none; color: var(--accent); font: inherit; font-size: 11.5px; font-weight: 700; padding: 0; }

/* ============================== SALDOS ============================== */
.totals-card { background: var(--text); color: white; border-radius: var(--radius); padding: 22px; margin: 10px 0 18px; }
.totals-card .label { font-size: 12.5px; opacity: .65; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.totals-card .value { font-size: 34px; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em; }
.totals-card .chips { display: flex; gap: 8px; margin-top: 14px; }
.chip { font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: rgba(255,255,255,.12); }
.chip.ok { color: #7CE2A0; }
.chip.warn { color: #ffb4b4; }
.chip.pending { color: #cfd2da; }

.acc-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 10px; }
.acc-card .row1 { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.acc-card .id-row { display: flex; align-items: center; gap: 10px; }
.acc-badge { width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.acc-card .name { font-weight: 700; font-size: 14.5px; }
.acc-card .teorico { font-size: 21px; font-weight: 800; letter-spacing: -0.01em; margin-top: 1px; }
.acc-card .flow { font-size: 12px; color: var(--text-dim); margin-top: 1px; }
.acc-card .flow .up { color: var(--ok); }
.acc-card .flow .down { color: var(--bad); }
.acc-card .opening-line { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.edit-pencil { border: none; background: none; color: var(--text-dim); padding: 4px; flex-shrink: 0; }
.edit-pencil svg { width: 15px; height: 15px; }

.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; margin-top: 4px; }
.status-dot.cuadrado { background: var(--ok); }
.status-dot.descuadrado { background: var(--bad); }
.status-dot.pendiente { background: var(--dot); }

.count-row { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: var(--radius-sm); padding: 8px 10px; }
.count-row label { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.count-row input { flex: 1; border: none; background: transparent; font: inherit; font-weight: 700; font-size: 16px; color: var(--text); text-align: right; }
.count-row input:focus { outline: none; }
.count-row .count-ro { flex: 1; text-align: right; font-weight: 700; font-size: 16px; color: var(--text-dim); }
.count-row .diff { font-size: 12px; font-weight: 700; white-space: nowrap; }
.count-row .diff.ok { color: var(--ok); }
.count-row .diff.bad { color: var(--bad); }

.add-account-btn { width: 100%; padding: 14px; border: 1.5px dashed var(--border); background: none; border-radius: var(--radius); color: var(--text-dim); font: inherit; font-weight: 600; font-size: 13.5px; margin-top: 4px; }

/* ============================== REGISTRO ============================== */
.entry-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 10px 0 20px; position: relative; }

.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.acc-chip {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px 9px 9px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font: inherit; font-weight: 700; font-size: 13px; color: var(--text);
}
.acc-chip .dot { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.acc-chip.active { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }

.seg { display: flex; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); margin-bottom: 14px; }
.seg button { flex: 1; padding: 12px 8px; border: none; background: var(--bg); color: var(--text-dim); font: inherit; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.seg button svg { width: 15px; height: 15px; }
.seg button.active.entra { background: var(--ok-bg); color: var(--ok); }
.seg button.active.sale { background: var(--bad-bg); color: var(--bad); }

.amount-row { position: relative; margin-bottom: 14px; }
.amount-row input {
  width: 100%; font: inherit; font-size: 40px; font-weight: 800;
  border: none; background: var(--bg); border-radius: var(--radius-sm);
  color: var(--text); text-align: center; padding: 18px 0;
}
.amount-row input:focus { outline: 2px solid var(--accent); }
.time-pill {
  position: absolute; top: 8px; right: 8px;
  border: none; background: var(--surface); color: var(--text-dim);
  font: inherit; font-weight: 700; font-size: 11.5px;
  padding: 5px 10px; border-radius: 999px;
}

.save-btn { width: 100%; padding: 15px; background: var(--accent); color: white; border: none; border-radius: var(--radius-sm); font: inherit; font-weight: 700; font-size: 15.5px; }

.saved-flash {
  position: absolute; inset: 0; border-radius: var(--radius);
  background: var(--ok); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px;
  opacity: 0; pointer-events: none; transition: opacity .12s ease;
}
.saved-flash.show { opacity: 1; }

.section-label { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); margin: 18px 0 8px; }
.list-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 16px; }

.mov-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.mov-row:last-child { border-bottom: none; }
.mov-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 16px; }
.mov-main { flex: 1; min-width: 0; }
.mov-main .t1 { font-weight: 700; font-size: 14px; }
.mov-main .t2 { font-size: 12px; color: var(--text-dim); margin-top: 1px; }
.mov-amt { font-weight: 800; font-size: 14.5px; white-space: nowrap; text-align: right; }
.mov-amt .dir { display: block; font-size: 10.5px; font-weight: 700; margin-top: 1px; }
.mov-amt .dir.entra { color: var(--ok); }
.mov-amt .dir.sale { color: var(--bad); }
.mov-amt.anulado { opacity: .35; text-decoration: line-through; font-weight: 600; }
.mov-undo { background: none; border: none; color: var(--text-dim); font-size: 11px; padding: 0; margin-top: 3px; }

.empty-hint { text-align: center; color: var(--text-dim); font-size: 13.5px; padding: 30px 0; }

/* ============================== SHEETS ============================== */
.sheet-overlay { position: fixed; inset: 0; background: rgba(15, 16, 20, .4); display: none; align-items: flex-end; justify-content: center; z-index: 30; }
.sheet-overlay.open { display: flex; }
.sheet { width: 100%; max-width: 520px; background: var(--surface); border-radius: 24px 24px 0 0; padding: 10px 20px calc(24px + env(safe-area-inset-bottom)); animation: sheet-up .18s ease; max-height: 85dvh; overflow-y: auto; }
.sheet.tall { max-height: 80dvh; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 999px; margin: 6px auto 16px; }
.sheet h3 { margin: 0 0 18px; font-size: 17px; font-weight: 800; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--text-dim); margin-bottom: 6px; }
.field input[type=text], .field input[type=number], .field select {
  width: 100%; font: inherit; font-weight: 600; font-size: 16px;
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.color-swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; }
.color-swatch.active { border-color: var(--text); }

.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-actions button { flex: 1; padding: 14px; border-radius: var(--radius-sm); font: inherit; font-weight: 700; font-size: 14.5px; border: none; }
.sheet-actions .cancel { background: var(--bg); color: var(--text-dim); }
.sheet-actions .save { background: var(--accent); color: white; }

/* ============================== AUDIT ============================== */
.audit-item { font-size: 13px; padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 10px; }
.audit-item:last-child { border-bottom: none; }
.audit-item .txt { color: var(--text); }
.audit-item .at { color: var(--text-dim); font-size: 11.5px; white-space: nowrap; }
.audit-item.anulacion .txt { color: var(--bad); }
.audit-item.cierre .txt { color: var(--accent); font-weight: 600; }

/* ============================== NAV ============================== */
nav.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; max-width: 520px; margin: 0 auto;
  background: rgba(255,255,255,.92); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); display: none;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); z-index: 10;
}
nav.bottom-nav.show { display: flex; }
nav.bottom-nav button { flex: 1; background: none; border: none; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 2px; color: var(--text-dim); font: inherit; font-size: 11px; font-weight: 600; border-radius: 12px; }
nav.bottom-nav button.active { color: var(--accent); }
nav.bottom-nav svg { width: 22px; height: 22px; }
