:root {
  --brand: #0f766e;
  --brand-dark: color-mix(in srgb, var(--brand) 78%, black);
  --brand-soft: color-mix(in srgb, var(--brand) 12%, white);
  --bg: #f3f5f7;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --orange: #ea580c;
  --orange-soft: #ffedd5;
  --yellow: #ca8a04;
  --yellow-soft: #fef9c3;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --gray-soft: #f3f4f6;
  --wa: #25d366;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 14px rgba(0, 0, 0, .05);
  --nav-h: 66px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ico { display: inline-flex; width: 22px; height: 22px; }
.ico svg { width: 100%; height: 100%; }

/* ---------- Navegación ---------- */
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.nav-brand { display: none; }
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 11.5px; font-weight: 600;
}
.nav a.active { color: var(--brand); }
.nav a.active .ico { transform: translateY(-1px); }

#view {
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 90px);
  max-width: 1100px; margin: 0 auto;
}

@media (min-width: 900px) {
  .nav {
    inset: 0 auto 0 0; width: 236px; height: 100vh; padding: 20px 14px;
    display: flex; flex-direction: column; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); background: #fff;
  }
  .nav-brand {
    display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px;
    font-weight: 800; font-size: 17px;
  }
  .nav-brand img { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; }
  .nav a {
    flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 12px 14px; border-radius: 12px; font-size: 15px;
  }
  .nav a:hover { background: var(--gray-soft); }
  .nav a.active { background: var(--brand-soft); }
  #app #view { margin-left: 236px; padding: 28px 32px 80px; }
  @media (min-width: 1400px) { #app #view { margin-left: max(236px, calc((100vw - 1100px) / 2)); } }
}

/* ---------- Encabezados ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.page-head .sub::first-letter { text-transform: uppercase; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 15px; margin-bottom: 10px; }
.section-title { font-size: 13px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 24px 4px 10px; display: flex; justify-content: space-between; align-items: center; }

/* ---------- Tarjetas ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.list { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .list.grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

.item {
  display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; color: inherit;
}
.item:active { transform: scale(.99); }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-weight: 800; font-size: 16px;
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ---------- Resumen de inicio ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  border: 0; text-align: left; font: inherit; cursor: pointer; border-radius: var(--radius);
  padding: 14px; color: var(--text); box-shadow: var(--shadow); background: var(--card);
  border-bottom: 4px solid transparent; transition: transform .1s;
}
.stat:active { transform: scale(.98); }
.stat .n { font-size: 30px; font-weight: 800; line-height: 1; }
.stat .l { font-size: 13.5px; font-weight: 600; color: var(--muted); margin-top: 6px; }
.stat.red { border-color: var(--red); } .stat.red .n { color: var(--red); }
.stat.orange { border-color: var(--orange); } .stat.orange .n { color: var(--orange); }
.stat.yellow { border-color: var(--yellow); } .stat.yellow .n { color: var(--yellow); }
.stat.green { border-color: var(--green); } .stat.green .n { color: var(--green); }
.stat.selected { outline: 2px solid currentColor; outline-offset: -2px; }
.stat.red.selected { background: var(--red-soft); } .stat.orange.selected { background: var(--orange-soft); }
.stat.yellow.selected { background: var(--yellow-soft); } .stat.green.selected { background: var(--green-soft); }

.alert-card { position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 14px 14px 20px; overflow: hidden; }
.alert-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--c, var(--muted)); }
.alert-card.red { --c: var(--red); } .alert-card.orange { --c: var(--orange); }
.alert-card.yellow { --c: var(--yellow); } .alert-card.green { --c: var(--green); }
.alert-card .top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.alert-card .name { font-weight: 800; font-size: 17px; text-decoration: none; color: inherit; }
.alert-card .what { color: var(--muted); font-size: 14px; margin-top: 2px; }
.alert-card .when { font-weight: 700; margin-top: 8px; font-size: 14.5px; }
.alert-card .badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.alert-card .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

/* ---------- Insignias ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.yellow { background: var(--yellow-soft); color: #a16207; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.gray { background: var(--gray-soft); color: var(--muted); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.dot.red { background: var(--red); } .dot.orange { background: var(--orange); }
.dot.yellow { background: var(--yellow); } .dot.green { background: var(--green); } .dot.gray { background: #d1d5db; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 16px; border-radius: 12px; border: 0; cursor: pointer;
  font: inherit; font-weight: 700; font-size: 15px; text-decoration: none;
  background: var(--brand); color: #fff; transition: filter .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .ico { width: 20px; height: 20px; }
.btn.ghost { background: var(--gray-soft); color: var(--text); }
.btn.outline { background: #fff; color: var(--brand); box-shadow: inset 0 0 0 1.5px var(--brand); }
.btn.danger { background: var(--red); }
.btn.danger-ghost { background: var(--red-soft); color: var(--red); }
.btn.wa { background: var(--wa); color: #fff; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.row-btns { display: flex; gap: 10px; margin-top: 18px; }
.row-btns .btn { flex: 1; }
.icon-btn { border: 0; background: var(--gray-soft); width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 16px; display: grid; place-items: center; color: var(--text); flex: none; }
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 640px) { .actions-grid { grid-template-columns: repeat(3, 1fr); } }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 25;
  height: 58px; padding: 0 22px 0 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--brand); color: #fff; font: inherit; font-weight: 800; font-size: 16px;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 8px 24px color-mix(in srgb, var(--brand) 40%, transparent);
  text-decoration: none;
}
.fab .ico { width: 24px; height: 24px; }
@media (min-width: 900px) { .fab { bottom: 28px; right: 32px; } }

/* ---------- Formularios ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 5px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: #fff;
  border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 13px; min-height: 48px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type="color"] { padding: 4px; height: 48px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 4px 0 14px; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
.search { position: relative; display: block; margin-bottom: 14px; }
.search input { padding-left: 42px; background: #fff; }
.search .ico { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip { border: 0; background: #fff; box-shadow: var(--shadow); padding: 8px 14px; border-radius: 999px; font: inherit; font-size: 14px; font-weight: 700; color: var(--muted); white-space: nowrap; cursor: pointer; }
.chip.active { background: var(--brand); color: #fff; }
.vars { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.vars code { background: var(--brand-soft); color: var(--brand); padding: 2px 8px; border-radius: 6px; font-size: 12.5px; cursor: pointer; }

/* ---------- Hoja modal ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity .2s;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  width: 100%; max-height: 92vh; background: #fff; border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column; transform: translateY(30px); transition: transform .22s ease;
  padding-bottom: var(--safe-b);
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 10px; }
.sheet-head h3 { font-size: 19px; font-weight: 800; }
.sheet-body { padding: 6px 18px 20px; overflow-y: auto; }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { width: 540px; border-radius: 22px; max-height: 88vh; }
  .sheet.wide { width: 720px; }
}

/* ---------- Detalle ---------- */
.client-head { display: flex; gap: 14px; align-items: center; }
.client-head .avatar { width: 58px; height: 58px; font-size: 21px; }
.client-head h1 { font-size: 23px; font-weight: 800; }
.info-list { display: grid; gap: 8px; margin-top: 14px; font-size: 15px; }
.info-list div { display: flex; gap: 10px; align-items: flex-start; }
.info-list .ico { color: var(--muted); width: 19px; height: 19px; flex: none; margin-top: 1px; }
.quick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.quick .btn { min-width: 0; padding: 0 6px; gap: 6px; white-space: nowrap; }
.quick .btn .ico { flex: none; }
@media (max-width: 400px) {
  .quick .btn { font-size: 13px; gap: 4px; }
  .quick .btn .ico { width: 17px; height: 17px; }
}

.sale .head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.sale .name { font-weight: 800; font-size: 17px; }
.sale .rows { display: grid; gap: 8px; margin-top: 12px; }
.sale .r { display: flex; justify-content: space-between; gap: 10px; align-items: center; font-size: 14.5px; flex-wrap: wrap; }
.sale .r .k { color: var(--muted); }
.sale .r .v { font-weight: 700; text-align: right; }
.sale .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.history { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.history summary { cursor: pointer; font-weight: 700; color: var(--brand); font-size: 14px; }
.history ul { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.history li { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--gray-soft); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.menu-list { display: grid; gap: 8px; }
.menu-list .btn { justify-content: flex-start; }

/* ---------- Cotizaciones ---------- */
.q-item { background: var(--gray-soft); border-radius: 14px; padding: 12px; display: grid; gap: 8px; }
.q-item + .q-item { margin-top: 10px; }
.q-item .q-top { display: flex; gap: 8px; }
.q-item .q-top input { flex: 1; font-weight: 700; }
.q-item textarea { min-height: 52px; font-size: 14px; }
.q-item .q-nums { display: grid; grid-template-columns: 1fr 1.3fr 1.3fr; gap: 8px; align-items: end; }
.q-item .q-nums label span { font-size: 12px; font-weight: 700; color: var(--muted); display: block; margin-bottom: 4px; }
.q-item .amount { min-height: 48px; display: flex; align-items: center; justify-content: flex-end; font-weight: 800; }
.totals { display: grid; gap: 8px; font-size: 15px; }
.totals div { display: flex; justify-content: space-between; }
.totals .grand { font-size: 21px; font-weight: 800; color: var(--brand); border-top: 2px solid var(--line); padding-top: 10px; margin-top: 2px; }
.sticky-save {
  position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 10px); z-index: 5; margin-top: 16px;
  display: flex; gap: 10px; background: rgba(255, 255, 255, .95); backdrop-filter: blur(8px);
  padding: 10px; border-radius: 16px; box-shadow: 0 6px 22px rgba(0, 0, 0, .12);
}
.sticky-save .total-mini { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-left: 6px; }
.sticky-save .total-mini b { font-size: 19px; color: var(--brand); }
@media (min-width: 900px) { .sticky-save { bottom: 16px; } }
.pick-row { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: var(--gray-soft); cursor: pointer; border: 0; width: 100%; text-align: left; font: inherit; }
.pick-row + .pick-row { margin-top: 8px; }
.pick-row .grow { flex: 1; min-width: 0; }
.pick-row .price { font-weight: 800; color: var(--brand); }
.match-hint { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: var(--brand-soft); border-radius: 12px; padding: 10px 12px; margin: -4px 0 12px; font-size: 14px; }
.q-item .q-photo { display: flex; align-items: center; gap: 8px; }
.q-item .q-photo img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: #fff; }
.q-thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; }
.q-lines { display: grid; gap: 10px; }
.q-line { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.q-line:last-child { border-bottom: 0; padding-bottom: 0; }

/* ---------- Ajustes ---------- */
.settings-card h2 { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.settings-card > p { color: var(--muted); font-size: 14px; margin-bottom: 16px; }
.settings-card { margin-bottom: 16px; }
.logo-box { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.logo-box .preview { width: 84px; height: 84px; border-radius: 14px; background: var(--gray-soft); display: grid; place-items: center; overflow: hidden; flex: none; }
.logo-box img { width: 100%; height: 100%; object-fit: contain; }
.steps { margin: 0 0 14px; padding-left: 20px; color: var(--muted); font-size: 14px; display: grid; gap: 4px; }
.stage-preview { display: grid; gap: 6px; margin: 4px 0 14px; font-size: 14px; }
.stage-preview div { display: flex; align-items: center; gap: 8px; }

/* ---------- Cuenta regresiva del resumen ---------- */
.timer-card { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.timer-card .ico-big { width: 46px; height: 46px; border-radius: 14px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 22px; flex: none; }
.timer-card .grow { flex: 1; min-width: 0; }
.timer-card .count { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--brand); letter-spacing: .02em; }
.timer-card { align-items: flex-start; }
.timer-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
/* ---------- Estados vacíos y carga ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 46px; margin-bottom: 8px; }
.empty h3 { color: var(--text); font-size: 18px; margin-bottom: 4px; }
.loading { text-align: center; padding: 60px 0; color: var(--muted); }

/* ---------- Aviso flotante ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 90px); z-index: 80;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: all .25s;
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 14.5px;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, .2); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--red); }

/* ---------- PIN ---------- */
#login {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(160deg, var(--brand-soft), var(--bg) 55%);
}
.pin-wrap { width: 100%; max-width: 340px; text-align: center; }
.pin-logo { width: 84px; height: 84px; border-radius: 22px; margin: 0 auto 14px; object-fit: contain; background: #fff; box-shadow: var(--shadow); padding: 8px; }
.pin-wrap h1 { font-size: 22px; font-weight: 800; }
.pin-wrap .hint { color: var(--muted); margin-top: 6px; min-height: 22px; font-size: 15px; }
.pin-wrap .hint.error { color: var(--red); font-weight: 700; }
.pin-dots { display: flex; justify-content: center; gap: 18px; margin: 26px 0 30px; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--brand); transition: background .15s, transform .15s; }
.pin-dots span.on { background: var(--brand); transform: scale(1.1); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.pin-pad button {
  height: 70px; border-radius: 50%; border: 0; background: #fff; box-shadow: var(--shadow);
  font: inherit; font-size: 26px; font-weight: 700; color: var(--text); cursor: pointer; width: 70px; justify-self: center;
}
.pin-pad button:active { background: var(--brand-soft); transform: scale(.95); }
.pin-pad button.empty { visibility: hidden; }
.pin-pad button.del { background: transparent; box-shadow: none; font-size: 22px; }
