:root {
  --paper: #FAF9FC;
  --surface: #FFFFFF;
  --ink: #241B2F;
  --ink-soft: #756E82;
  --primary: #6C2BD9;
  --primary-dark: #4B1D99;
  --dark-card: #241B2F;
  --accent: #2FE0C9;
  --danger: #C0325A;
  --success: #16915F;
  --warn: #B5730B;
  --warn-bg: #FBF1DF;
  --line: #E4DEF0;
  --radius: 14px;
  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
}
* { box-sizing: border-box; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}
#app { max-width: 480px; margin: 0 auto; min-height: 100vh; padding: 24px 20px 60px; }

/* ---------- Computador: más ancho ---------- */
@media (min-width: 700px) {
  #app { max-width: 840px; }
}

.screen { display: none; }
.screen.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

h2 { font-family: var(--font-display); color: var(--primary-dark); font-size: 1.35rem; margin: 0 0 4px; }
.muted { color: var(--ink-soft); }
.mt { margin-top: 22px; }

/* ---------- Cargando ---------- */
.center-box { text-align: center; padding: 60px 10px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; margin: 0 auto 14px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.big-icon { font-size: 2.6rem; margin-bottom: 6px; }

/* ---------- Marca ---------- */
.brandmark { text-align: center; padding: 20px 0 18px; }
.brand-logo { height: 60px; margin-bottom: 12px; }
.brandmark .sub { color: var(--ink-soft); font-size: .95rem; margin: 0; }
.header-logo { height: 28px; display: block; margin-bottom: 8px; }

/* ---------- Formularios ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .82rem; color: var(--ink-soft); font-weight: 600; }
input, select {
  font-family: inherit; font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,43,217,.12); }
input[type="date"] { min-height: 46px; }

/* ---------- Botones ---------- */
.btn { font-family: inherit; font-size: 1rem; font-weight: 600; cursor: pointer; border-radius: 12px; padding: 12px 16px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); transition: transform .12s, background .15s, border-color .15s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(108,43,217,.06); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: .85rem; border-radius: 10px; }
.btn.danger { color: var(--danger); border-color: rgba(192,50,90,.35); }
.btn.danger:hover { background: rgba(192,50,90,.06); }

.back-btn { background: none; border: none; color: var(--primary); font-size: .95rem; font-weight: 600; cursor: pointer; padding: 4px 0; margin-bottom: 8px; }

.error-msg { color: var(--danger); font-size: .88rem; margin: 4px 0 0; min-height: 1em; }
.section-hint { color: var(--ink-soft); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin: 20px 0 10px; }
.hint-text { color: var(--ink-soft); font-size: .82rem; margin: 8px 0 0; }
.setup-note { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 12px; font-size: .82rem; margin-top: 18px; }

/* ---------- Encabezado de panel ---------- */
.panel-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.eyebrow { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); background: #063F3A; padding: 2px 8px; border-radius: 6px; }
.biz-name-tag { display: inline-block; margin-left: 6px; font-size: .78rem; color: var(--ink-soft); font-weight: 600; }
.generic-mark {
  width: 64px; height: 64px; border-radius: 16px; background: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 1.8rem;
  margin: 0 auto;
}
.logo-upload-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; background: var(--surface);
  border: 1px solid var(--line); cursor: pointer; font-size: .75rem;
  margin-left: -14px; margin-bottom: 6px; position: relative; top: 8px;
}
.wa-support-link {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  color: #1D8A5C; font-weight: 600; font-size: .85rem; text-decoration: none;
  margin-top: 18px; padding: 10px; border-radius: 10px; background: #E9F8F0;
}
.wa-support-btn {
  display: inline-flex; align-items: center; gap: 5px; color: #1D8A5C;
  font-weight: 700; font-size: .75rem; text-decoration: none; background: #E9F8F0;
  border: 1px solid #BFE9D3; padding: 5px 10px; border-radius: 999px;
}
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 42px; width: 100%; }
.pw-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1.05rem;
  padding: 6px 8px; color: var(--ink-soft); line-height: 1;
}
.panel-header h2 { margin-top: 6px; }

/* ---------- Pestañas ---------- */
.tabs { display: none; flex-direction: column; flex-wrap: nowrap; overflow-x: visible;
  position: fixed; z-index: 999; width: 220px; max-width: calc(100vw - 40px);
  max-height: calc(100vh - 90px); overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; box-shadow: 0 10px 28px rgba(36,27,47,.2);
}
.tabs.open { display: flex; }
.hamburger-btn {
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  width: 34px; height: 34px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 9px; padding: 0 8px; cursor: pointer; flex: 0 0 auto;
}
.hamburger-btn span { display: block; width: 16px; height: 2px; background: var(--ink); border-radius: 2px; }

/* ---------- Accesos rápidos (los 3-4 que más se usan, fuera del menú) ---------- */
.quick-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 18px; }
.quick-tab { flex: 0 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: .85rem; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.quick-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab { flex: 0 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; font-size: .85rem; font-weight: 600; color: var(--ink-soft); cursor: pointer; text-align: left; width: 100%; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn .2s ease; }

.period-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.period-btn { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 0; font-size: .85rem; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.period-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.report-controls { display: flex; gap: 8px; margin-bottom: 12px; }

/* ---------- Formulario de proceso ---------- */
.entry-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

/* ---------- Ledger ---------- */
.ledger { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.ledger-empty { color: var(--ink-soft); text-align: center; padding: 22px 0; font-size: .9rem; }
.ledger-row { display: flex; justify-content: space-between; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; gap: 10px; }
.lr-name { display: block; font-weight: 600; font-size: .95rem; }
.lr-dim { font-weight: 400; color: var(--ink-soft); }
.lr-sub { display: block; font-size: .78rem; color: var(--ink-soft); margin-top: 2px; }
.lr-right { display: flex; align-items: center; gap: 10px; }
.lr-value { font-weight: 700; white-space: nowrap; }
.lr-del { background: none; border: none; color: var(--ink-soft); font-size: .95rem; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.lr-del:hover { color: var(--danger); background: rgba(192,50,90,.08); }

/* ---------- Tarjeta resumen mecánico ---------- */
.summary-card { background: var(--dark-card); color: #fff; border-radius: var(--radius); padding: 16px 18px; margin-top: 14px; }
.summary-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.summary-row.muted { color: #C9C1D6; font-size: .9rem; }
.summary-row.total { border-top: 1px solid rgba(255,255,255,.12); margin-top: 6px; padding-top: 12px; }
.summary-row.total strong { color: var(--accent); font-size: 1.3rem; }

/* ---------- Usuarios ---------- */
.users-list { display: flex; flex-direction: column; gap: 12px; }
.user-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.user-card.pending { border-color: #EBD9AE; }
.uc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.uc-head strong { font-size: 1rem; }
.uc-info { font-size: .82rem; color: var(--ink-soft); line-height: 1.6; margin: 8px 0 12px; }
.uc-actions { display: flex; gap: 8px; align-items: center; }
.uc-actions .uc-role { flex: 1; }
.badge { font-size: .72rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.role-mecanico { background: #E6F1FB; color: #185FA5; }
.badge.role-administrador { background: #EEEDFE; color: #534AB7; }
.badge.role-propietario { background: #E1F5EE; color: #0F6E56; }

/* ---------- Recordatorio de cambio de aceite (aviso emergente) ---------- */
.reminder-overlay {
  position: fixed; inset: 0; background: rgba(36, 27, 47, .45);
  display: flex; align-items: center; justify-content: center; z-index: 10000;
  padding: 20px; animation: fadeIn .2s ease;
}
.reminder-card {
  background: var(--surface); border-radius: 18px; max-width: 440px; width: 100%;
  box-shadow: 0 24px 60px rgba(0,0,0,.3); overflow: hidden;
}
.reminder-head {
  background: var(--primary); color: #fff; padding: 18px 20px;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: 1.02rem;
}
.reminder-close { background: none; border: none; color: #fff; font-size: 1.2rem; cursor: pointer; }
.reminder-body { padding: 10px 20px 20px; max-height: 60vh; overflow-y: auto; }
.reminder-item {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 0; border-bottom: 1px dashed var(--line); font-size: .95rem;
}
.reminder-item:last-child { border-bottom: none; }
.reminder-item strong { font-size: 1.02rem; }
.reminder-tag {
  display: inline-block; align-self: flex-start;
  background: #F3F0F9; color: var(--primary); font-weight: 700; font-size: .78rem;
  padding: 3px 10px; border-radius: 999px; margin: 2px 0;
}
.reminder-tag.credit { background: #FFF1D6; color: #8A5A00; }
.reminder-section-title {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-soft); font-weight: 700; margin: 14px 0 4px;
}
.reminder-section-title:first-child { margin-top: 6px; }
.reminder-date { font-size: .8rem; color: var(--ink-soft); }

/* ---------- Aviso flotante (toast) ---------- */
#app-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: .88rem; font-weight: 600; max-width: 88vw; text-align: center;
  z-index: 9999; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#app-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#app-toast.error { background: var(--danger); }

/* ---------- Botón en modo "confirmar" (reemplaza confirm()) ---------- */
.confirm-armed { background: var(--danger) !important; color: #fff !important; border-color: var(--danger) !important; }

/* ---------- Buscador con lupa ---------- */
.search-box { position: relative; margin-bottom: 10px; }
.search-box .search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: .9rem; pointer-events: none;
}
.search-box input {
  width: 100%; padding: 11px 14px 11px 38px;
  border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: .92rem; background: var(--surface);
}

/* ---------- Método de pago ---------- */
.paymethod-group { display: flex; gap: 8px; }
.paymethod-btn {
  flex: 1; font-family: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  border-radius: 10px; padding: 11px 8px; transition: all .15s;
}
.paymethod-btn.selected { background: var(--primary); border-color: var(--primary); color: #fff; }
.mixto-split { display: flex; gap: 8px; }
.mixto-split input { flex: 1; }

/* ---------- Proceso pendiente de precio ---------- */
.lr-pending-tag { display: inline-block; background: var(--warn-bg); color: var(--warn); font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.price-inline { display: none; flex-direction: column; gap: 8px; background: #F6F3FB; border: 1px dashed var(--line); border-radius: 12px; padding: 12px; margin-top: 8px; }
.price-inline.open { display: flex; }
.price-inline input { margin: 0; }
.price-inline .paymethod-group { margin-top: 2px; }
.pm-tag { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-top: 4px; display: inline-block; }
.pm-tag.efectivo { background: #E1F5EE; color: #0F6E56; }
.pm-tag.transferencia { background: #E6F1FB; color: #185FA5; }
.pm-tag.mixto { background: #FBF1DF; color: #8A5A00; }
.due-badge { display: inline-block; font-weight: 800; font-size: .78rem; padding: 5px 12px; border-radius: 999px; letter-spacing: .02em; }
.due-badge-red { background: var(--danger); color: #fff; }
.due-badge-yellow { background: #F2A70C; color: #4A3200; }
.due-badge-paid { background: var(--success); color: #fff; }
.lr-photo-btn { background: none; border: none; font-size: 1.1rem; cursor: pointer; padding: 0 2px; }

/* ---------- Métricas de efectivo / transferencia ---------- */
.pay-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0 6px; }
.pay-split .metric { background: #F3F0F9; }

/* ---------- Métricas ---------- */
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.metric { background: #F3F0F9; border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.metric.wide { margin-bottom: 6px; }
.metric.hi { background: #E1F5EE; }
.metric.hi .metric-label, .metric.hi .metric-value { color: #0F6E56; }
.metric.warn { background: #FBE9E9; }
.metric.warn .metric-label, .metric.warn .metric-value { color: #B3261E; }
.metric-label { font-size: .78rem; color: var(--ink-soft); }
.metric-value { font-size: 1.35rem; font-weight: 700; }

/* ---------- Ranking (top) ---------- */
.rank-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.rank-row.top { background: var(--surface); border: 2px solid var(--accent); border-radius: 12px; margin-bottom: 8px; }
.rank-num { width: 26px; height: 26px; flex: 0 0 auto; border-radius: 50%; background: #EDE9F6; color: var(--ink-soft); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .82rem; }
.rank-row.top .rank-num { background: #D6F5EC; color: #0F6E56; }
.rank-info { flex: 1; display: flex; flex-direction: column; }
.rank-name { font-weight: 600; font-size: .95rem; }
.rank-sub { font-size: .76rem; color: var(--ink-soft); }
.rank-val { text-align: right; display: flex; flex-direction: column; }
.rank-val strong { font-size: 1rem; color: var(--primary-dark); }
.rank-row.top .rank-val strong { color: #0F6E56; }
.rank-tag { font-size: .72rem; color: var(--ink-soft); }
