:root {
  --bg: #0b1220;
  --bg-2: #0f172a;
  --card: #131c2e;
  --card-2: #1a2438;
  --line: #24314a;
  --text: #e6edf7;
  --muted: #8b9ab3;
  --accent: #0ea5e9;
  --accent-2: #38bdf8;
  --accent-ink: #04121c;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --wa: #25d366;
  --radius: 18px;
  --radius-sm: 12px;
  --tabbar-h: 68px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 500px at 50% -200px, #0c2a43 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent-2); }
svg { display: block; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.container { max-width: 640px; margin: 0 auto; padding: 16px; outline: none; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(11, 18, 32, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 1.2rem; letter-spacing: .3px; }
.brand b { color: var(--accent); }
.brand-logo { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.icon-btn { background: var(--card); border: 1px solid var(--line); border-radius: 12px; width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(15, 23, 42, .95); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 600; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active span { background: rgba(14, 165, 233, .15); }
.tabbar span { padding: 4px 18px; border-radius: 999px; }

/* ---------- Tipografía y secciones ---------- */
h1 { font-size: 1.55rem; margin: 6px 0 4px; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.lead { color: var(--muted); margin: 0 0 18px; }
.step { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: inline-grid; place-items: center; font-size: .85rem; font-weight: 800; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

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

/* ---------- Servicios ---------- */
.services { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.option {
  position: relative; text-align: left; cursor: pointer;
  background: var(--card-2); border: 2px solid transparent; border-radius: var(--radius-sm);
  padding: 14px 12px; min-height: 104px; display: flex; flex-direction: column; gap: 6px;
  transition: border-color .15s, background .15s, transform .1s;
}
.option:active { transform: scale(.98); }
.option .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: rgba(14, 165, 233, .12); color: var(--accent); }
.option .name { font-weight: 700; font-size: .95rem; }
.option .price { color: var(--accent-2); font-weight: 800; }
.option[aria-pressed="true"] { border-color: var(--accent); background: rgba(14, 165, 233, .1); }
.option[aria-pressed="true"]::after {
  content: ""; position: absolute; top: 10px; right: 10px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%2304121c' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' d='M5 12l5 5 9-10'/%3E%3C/svg%3E") center/14px no-repeat;
}

/* ---------- Días y horas ---------- */
.days { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.days::-webkit-scrollbar { display: none; }
.day {
  flex: 0 0 auto; scroll-snap-align: start; min-width: 66px; padding: 10px 8px; cursor: pointer;
  border-radius: var(--radius-sm); border: 2px solid transparent; background: var(--card-2);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.day .dw { font-size: .75rem; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.day .dn { font-size: 1.35rem; font-weight: 800; }
.day .dm { font-size: .72rem; color: var(--muted); }
.day[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.day[aria-pressed="true"] .dw, .day[aria-pressed="true"] .dm { color: var(--accent-ink); }

.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.slot {
  min-height: 56px; border-radius: var(--radius-sm); background: var(--card-2); border: 2px solid transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-weight: 800; font-size: 1.05rem;
}
.slot small { font-size: .7rem; font-weight: 600; color: var(--muted); }
.slot[aria-pressed="true"] { border-color: var(--accent); background: rgba(14, 165, 233, .15); }
.slot[aria-pressed="true"] small { color: var(--accent-2); }
.slot:disabled { opacity: .38; cursor: not-allowed; text-decoration: line-through; }
.slot:disabled small { text-decoration: none; }
.legend { display: flex; gap: 14px; margin-top: 10px; font-size: .78rem; color: var(--muted); flex-wrap: wrap; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.input {
  width: 100%; height: 52px; padding: 0 14px; border-radius: var(--radius-sm);
  background: var(--bg-2); border: 1.5px solid var(--line); font-size: 1rem;
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(14, 165, 233, .25); }
.input.upper { text-transform: uppercase; letter-spacing: 1px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  height: 56px; border-radius: var(--radius-sm); border: 2px solid transparent; background: var(--card-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700;
}
.seg button[aria-pressed="true"] { border-color: var(--accent); background: rgba(14, 165, 233, .12); color: var(--accent-2); }

/* ---------- Botones ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  min-height: 56px; padding: 0 18px; border-radius: 16px; border: 0; cursor: pointer;
  font-size: 1.05rem; font-weight: 800; text-decoration: none; transition: transform .1s, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 24px -10px rgba(14, 165, 233, .7); }
.btn-primary:disabled { background: #22324a; color: var(--muted); box-shadow: none; cursor: not-allowed; }
.btn-wa { background: var(--wa); color: #052e16; }
.btn-ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn-sm { min-height: 44px; font-size: .92rem; border-radius: 12px; }
.btn + .btn { margin-top: 10px; }

.sticky-cta { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 5; }
.summary-bar { display: flex; justify-content: space-between; align-items: center; font-size: .9rem; color: var(--muted); margin-bottom: 8px; padding: 0 4px; }
.summary-bar b { color: var(--text); font-size: 1.1rem; }
.error { color: #fca5a5; background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .35); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: .9rem; }

/* ---------- Confirmación ---------- */
.confirm { text-align: center; padding: 24px 16px; }
.check { width: 76px; height: 76px; border-radius: 50%; background: rgba(34, 197, 94, .15); color: var(--ok); display: grid; place-items: center; margin: 4px auto 14px; }
.code { display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.7rem; font-weight: 800; letter-spacing: 2px; color: var(--accent); background: rgba(14, 165, 233, .1); border: 1px dashed var(--accent); padding: 8px 18px; border-radius: 14px; margin: 8px 0 4px; }
.rows { text-align: left; margin: 18px 0; }
.rows div { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.rows div:last-child { border: 0; }
.rows span { color: var(--muted); }
.rows b { text-align: right; }

/* ---------- Dueño: PIN ---------- */
.pin-wrap { max-width: 340px; margin: 24px auto; text-align: center; }
.lock { width: 64px; height: 64px; border-radius: 20px; background: rgba(14, 165, 233, .12); color: var(--accent); display: grid; place-items: center; margin: 0 auto 12px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); }
.pin-dots i.on { background: var(--accent); border-color: var(--accent); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button { height: 64px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); font-size: 1.5rem; font-weight: 700; cursor: pointer; display: grid; place-items: center; }
.keypad button:active { background: var(--card-2); }

/* ---------- Dueño: Agenda ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 10px; }
.stat .ico { color: var(--accent); margin-bottom: 6px; }
.stat .v { font-size: 1.3rem; font-weight: 800; line-height: 1.1; word-break: break-word; }
.stat .l { font-size: .72rem; color: var(--muted); margin-top: 2px; }
a.stat { text-decoration: none; color: inherit; }
a.stat.alert .v { color: var(--warn); }

.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.daynav .label { flex: 1; text-align: center; font-weight: 700; text-transform: capitalize; }

.turn { padding: 14px; }
.turn-head { display: flex; gap: 12px; align-items: flex-start; }
.hour { flex: none; width: 64px; text-align: center; background: var(--card-2); border-radius: 12px; padding: 8px 0; }
.hour b { display: block; font-size: 1.2rem; }
.hour small { color: var(--muted); font-size: .7rem; }
.turn-info { flex: 1; min-width: 0; }
.turn-info .who { font-weight: 800; font-size: 1.05rem; }
.turn-info .meta { color: var(--muted); font-size: .85rem; display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; }
.plate { font-family: ui-monospace, Menlo, monospace; background: #e6edf7; color: #0b1220; border-radius: 6px; padding: 1px 6px; font-weight: 800; font-size: .8rem; letter-spacing: 1px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; font-weight: 800; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st-pendiente { color: #fbbf24; background: rgba(245, 158, 11, .12); }
.st-en_proceso { color: var(--accent-2); background: rgba(14, 165, 233, .14); }
.st-terminado { color: #4ade80; background: rgba(34, 197, 94, .12); }
.st-no_vino { color: #f87171; background: rgba(239, 68, 68, .12); }
.turn.is-no_vino { opacity: .6; }
.turn.is-terminado .who { text-decoration: none; }

.status-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.status-row button {
  min-height: 48px; border-radius: 12px; background: var(--card-2); border: 2px solid transparent; cursor: pointer;
  font-size: .72rem; font-weight: 700; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 4px 2px;
}
.status-row button[aria-pressed="true"].s-pendiente { border-color: #f59e0b; color: #fbbf24; background: rgba(245, 158, 11, .12); }
.status-row button[aria-pressed="true"].s-en_proceso { border-color: var(--accent); color: var(--accent-2); background: rgba(14, 165, 233, .14); }
.status-row button[aria-pressed="true"].s-terminado { border-color: var(--ok); color: #4ade80; background: rgba(34, 197, 94, .12); }
.status-row button[aria-pressed="true"].s-no_vino { border-color: var(--danger); color: #f87171; background: rgba(239, 68, 68, .12); }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .ico { color: var(--line); margin: 0 auto 10px; width: 48px; }

/* ---------- Clientes ---------- */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.search { position: relative; }
.search .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 44px; }
.chip {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  min-height: 52px; padding: 0 14px; border-radius: 14px; cursor: pointer;
  background: var(--card); border: 2px solid var(--line); font-weight: 700; text-align: left;
}
.chip .count { background: var(--card-2); border-radius: 999px; padding: 2px 10px; font-size: .85rem; }
.chip[aria-pressed="true"] { border-color: var(--warn); background: rgba(245, 158, 11, .1); color: #fbbf24; }
.chip[aria-pressed="true"] .count { background: var(--warn); color: #1c1203; }
.chip .left { display: flex; align-items: center; gap: 10px; }

.client-head { display: flex; align-items: center; gap: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 14px; background: rgba(14, 165, 233, .14); color: var(--accent-2); display: grid; place-items: center; font-weight: 800; flex: none; }
.client-head .who { font-weight: 800; }
.client-head .phone { color: var(--muted); font-size: .88rem; text-decoration: none; }
.client-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.client-grid div { background: var(--card-2); border-radius: 12px; padding: 8px 10px; }
.client-grid span { display: block; font-size: .7rem; color: var(--muted); }
.client-grid b { font-size: .92rem; }
.late { color: #fbbf24; }
.client-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 12px; }
.client-actions .btn + .btn { margin-top: 0; }
.client-actions .call { width: 52px; padding: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px);
  background: #e6edf7; color: #0b1220; padding: 12px 18px; border-radius: 14px; font-weight: 700; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.skeleton { height: 96px; border-radius: var(--radius); background: linear-gradient(90deg, var(--card) 0%, var(--card-2) 50%, var(--card) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; margin-bottom: 12px; }
@keyframes sk { to { background-position: -200% 0; } }

@media (min-width: 560px) {
  .services { grid-template-columns: repeat(4, 1fr); }
  .slots { grid-template-columns: repeat(5, 1fr); }
  .stat .v { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
