:root {
  --bg: #0b0b0d;
  --bg-elevated: #17171b;
  --card: #1e1e23;
  --border: #2c2c33;
  --silver: #c9cdd6;
  --silver-bright: #eef0f4;
  --text: #f2f3f5;
  --text-dim: #9a9ca3;
  --accent: #cfd4de;
  --green: #34d17c;
  --yellow: #f0b93d;
  --red: #ef4b4b;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--silver-bright);
  outline-offset: 2px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

h1, h2, h3, .title, .btn, .name-chip span.n, .stat-box .num, .nav-btn {
  font-family: "Poppins", "Inter", -apple-system, sans-serif;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button, input, select {
  font-family: inherit;
}

a { color: inherit; }

.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  background: linear-gradient(180deg, var(--bg) 60%, rgba(11,11,13,0.85));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar img.logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
}

.topbar .title {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.3px;
  flex: 1;
  margin: 0;
}

.topbar .subtitle {
  font-size: 12px;
  color: var(--text-dim);
}

.icon-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Main content ---------- */
.screen {
  flex: 1;
  padding: 16px 16px calc(96px + var(--safe-bottom));
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.screen.no-nav {
  padding-bottom: calc(24px + var(--safe-bottom));
}

/* ---------- Login screen ---------- */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px calc(32px + var(--safe-bottom));
  text-align: center;
  gap: 20px;
}

.login-wrap img.logo-big {
  width: 96px;
  height: 96px;
  border-radius: 22px;
  object-fit: cover;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}

.login-wrap h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: 0.5px;
}

.login-wrap p.tag {
  margin: -8px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}

.name-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.name-chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.name-chip:active { background: var(--bg-elevated); }

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(145deg, #3a3b42, #17171b);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--silver-bright);
}

.name-chip span.n {
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

.pin-pad {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.pin-dots {
  display: flex;
  gap: 14px;
}

.pin-dots .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--silver);
  background: transparent;
}

.pin-dots .dot.filled {
  background: var(--silver-bright);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

.keypad button {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  border-radius: 16px;
  padding: 16px 0;
}

.keypad button:active { background: var(--bg-elevated); }

.keypad button.ghost {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
}

.error-msg {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: underline;
  padding: 6px;
}

.link-btn.active-link {
  color: var(--yellow);
  font-weight: 700;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + var(--safe-bottom));
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
  font-size: 11px;
  font-weight: 600;
}

.nav-btn .ic { font-size: 20px; }

.nav-btn.active { color: var(--silver-bright); }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card h2, .card h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.card .muted {
  color: var(--text-dim);
  font-size: 12.5px;
}

.steps-list {
  margin: 10px 0 0;
  padding-left: 20px;
}

.steps-list li {
  margin-bottom: 4px;
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

button.accordion-header {
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  color: inherit;
  font: inherit;
  padding: 0;
  min-height: 44px;
}

.accordion-header-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.accordion-header-title h3 {
  margin: 0;
}

.accordion-chevron {
  font-size: 14px;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.accordion-chevron.collapsed {
  transform: rotate(-90deg);
}

.accordion-body {
  overflow: hidden;
  max-height: 4000px;
  opacity: 1;
  visibility: visible;
  transition: max-height 0.3s ease, opacity 0.25s ease, margin-top 0.3s ease, visibility 0s linear 0s;
  margin-top: 14px;
}

.accordion-body.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  visibility: hidden;
  transition: max-height 0.3s ease, opacity 0.25s ease, margin-top 0.3s ease, visibility 0s linear 0.3s;
}

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  margin: 22px 0 10px;
}

.section-title:first-child { margin-top: 0; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
}

.stat-box .num {
  font-size: 20px;
  font-weight: 700;
  color: var(--silver-bright);
}

.stat-box .lbl {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ---------- Forms ---------- */
.field {
  margin-bottom: 14px;
  min-width: 0;
}

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input, .field select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 16px;
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--silver);
}

.field input:focus-visible, .field select:focus-visible {
  outline: 2px solid var(--silver-bright);
  outline-offset: 1px;
}

.field input::placeholder, .field textarea::placeholder {
  color: var(--text-dim);
  opacity: 1;
}

.field input:disabled, .field select:disabled, .field textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: none;
  font-size: 15.5px;
  font-weight: 700;
  background: linear-gradient(145deg, var(--silver-bright), var(--silver) 60%, #9498a3);
  color: #0b0b0d;
}

.btn:active { filter: brightness(0.95); }

.btn.secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn.danger {
  background: var(--red);
  color: #fff;
}

.btn.block-sm {
  padding: 10px;
  font-size: 13.5px;
  width: auto;
}

.btn:disabled, .btn.secondary:disabled {
  opacity: 0.6;
  filter: none;
  cursor: not-allowed;
}

.spinner-sm {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  opacity: 0.85;
  display: inline-block;
  vertical-align: middle;
  margin-right: 7px;
  animation: spin 0.7s linear infinite;
}

/* ---------- Log list ---------- */
.log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.log-item:last-child { border-bottom: none; }

.log-item .ex-name {
  font-weight: 600;
  font-size: 14.5px;
}

.log-item .ex-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.log-item .ex-date {
  font-size: 11.5px;
  color: var(--text-dim);
  text-align: right;
}

.log-item .ex-notes {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 3px;
}

.day-group {
  margin-bottom: 18px;
}

.day-group:last-child {
  margin-bottom: 0;
}

.day-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.day-group-date {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--silver-bright);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.day-group-label {
  font-size: 11px;
  font-weight: 700;
  background: rgba(207, 212, 222, 0.12);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 20px;
}

.pr-badge {
  display: inline-block;
  background: rgba(240, 185, 61, 0.15);
  color: var(--yellow);
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  margin-left: 6px;
}

.trend-up { color: var(--green); font-size: 12px; }
.trend-down { color: var(--red); font-size: 12px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}

.badge.ok { background: rgba(52,209,124,0.15); color: var(--green); }
.badge.soon { background: rgba(240,185,61,0.15); color: var(--yellow); }
.badge.overdue { background: rgba(239,75,75,0.15); color: var(--red); }

/* ---------- Client rows (admin) ---------- */
.client-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.client-row:last-child { border-bottom: none; }

.client-row .info { flex: 1; min-width: 0; }

.client-row .info .name {
  font-weight: 600;
  font-size: 14.5px;
}

.client-row .info .due {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

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

.error-state {
  text-align: center;
  color: var(--text);
  font-size: 13.5px;
  padding: 24px 10px 10px;
}

.error-state .btn {
  margin-top: 12px;
}

.offline-banner {
  background: var(--yellow);
  color: #0b0b0d;
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
  padding: 10px 14px;
  padding-top: calc(10px + var(--safe-top));
}

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(84px + var(--safe-bottom));
  z-index: 20;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--silver-bright), var(--silver));
  color: #0b0b0d;
  border: none;
  font-size: 26px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 30;
  display: flex;
  align-items: flex-end;
}

.modal-sheet {
  background: var(--bg-elevated);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 18px 18px calc(24px + var(--safe-bottom));
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-bottom: none;
}

.modal-sheet .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-sheet .modal-head h3 { margin: 0; font-size: 16px; }

.toast {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--silver-bright);
  color: #0b0b0d;
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 600;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.toast.toast-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-right: 8px;
}

.toast-action-btn {
  background: #0b0b0d;
  color: var(--silver-bright);
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
}

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--silver-bright);
  animation: spin 0.7s linear infinite;
  margin: 24px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.tabs-inline {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.tabs-inline button {
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.tabs-inline button.active {
  background: var(--silver-bright);
  color: #0b0b0d;
  border-color: var(--silver-bright);
}

/* ---------- Polish: transitions & micro-interactions ---------- */
.btn, .name-chip, .keypad button, .nav-btn, .icon-btn, .tabs-inline button, .client-row button {
  transition: transform 0.12s ease, filter 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.btn:active, .name-chip:active, .keypad button:active, .icon-btn:active {
  transform: scale(0.96);
}

.nav-btn { position: relative; }

.nav-btn.active::after {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 3px;
  border-radius: 3px;
  background: var(--silver-bright);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

#tab-progreso:not(.hidden),
#tab-registrar:not(.hidden),
#tab-pago:not(.hidden),
#admin-tab-pagos:not(.hidden),
#admin-tab-clientes:not(.hidden),
#admin-tab-progreso:not(.hidden) {
  animation: fadeIn 0.28s ease;
}

.login-wrap .name-grid, .login-wrap .pin-pad {
  animation: fadeIn 0.3s ease;
}

/* ---------- Skeleton loaders ---------- */
.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.skeleton-list::before, .skeleton-list::after, .skeleton-list {
  content: "";
}

.skeleton-row {
  height: 46px;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--bg-elevated) 25%, #232329 37%, var(--bg-elevated) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ---------- 4-stat grid (admin pagos) ---------- */
.stat-row-4 {
  grid-template-columns: repeat(2, 1fr);
}

/* ---------- Textarea ---------- */
.field textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 15px;
  resize: vertical;
  font-family: inherit;
}

.field textarea:focus {
  outline: none;
  border-color: var(--silver);
}

/* ---------- Chart ---------- */
#chart-container svg {
  width: 100%;
  height: auto;
  display: block;
}

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

.mini-chart-block {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.mini-chart-block:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.mini-chart-title {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text);
  margin-bottom: 6px;
}

/* ---------- Small action buttons (whatsapp / copy link) ---------- */
.mini-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 10px;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mini-btn.whatsapp { color: var(--green); border-color: rgba(52,209,124,0.35); }

.row-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.quick-link {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  cursor: pointer;
}

.quick-link .ql-title {
  font-weight: 700;
  font-size: 14.5px;
  margin-bottom: 4px;
}

.quick-link:active { background: var(--bg-elevated); }

.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  cursor: pointer;
}

.checklist-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--silver-bright);
  flex-shrink: 0;
}

.checklist-item span {
  font-size: 13.5px;
  color: var(--text);
}

.checklist-item span.checked-text {
  color: var(--text-dim);
  text-decoration: line-through;
}

.plan-card {
  background: linear-gradient(160deg, #1e1e23, #0f0f12);
}

.plan-card .plan-name {
  font-family: "Poppins", sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--silver-bright);
  margin: 2px 0 10px;
}

.plan-feature {
  font-size: 13px;
  color: var(--text-dim);
  margin: 4px 0;
}

.plan-feature.locked {
  color: var(--text-dim);
  font-style: italic;
}

.announcement-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.announcement-item:last-child { border-bottom: none; }

.announcement-item .a-title {
  font-weight: 700;
  font-size: 14px;
}

.announcement-item .a-date {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.announcement-item .a-msg {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
  white-space: pre-line;
}

.streak-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--yellow);
  background: rgba(240,185,61,0.12);
  padding: 4px 10px;
  border-radius: 20px;
  margin-left: 8px;
}

.badge-new {
  display: inline-block;
  background: rgba(240, 185, 61, 0.18);
  color: var(--yellow);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  vertical-align: middle;
}

.status-detail {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.field-error {
  color: var(--red);
  font-size: 12.5px;
  margin-top: 6px;
}
