:root {
  --bg: #f7f3f1; --surface: #ffffff; --surface-2: #f1ebe8; --ink: #231c20; --muted: #74686e; --line: #e6ddd9;
  --accent: #8f3160; --accent-ink: #ffffff; --accent-soft: #f6e3ec;
  --ok: #1d7a4f; --ok-soft: #dff3e8; --warn: #96560a; --warn-soft: #fbeed3; --danger: #b3261e; --danger-soft: #fbe4e2;
  --radius: 14px; --shadow: 0 1px 2px rgba(35, 28, 32, .06), 0 8px 24px rgba(35, 28, 32, .07);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151113; --surface: #1f1a1d; --surface-2: #2a2327; --ink: #f3ecef; --muted: #a7999f; --line: #372e33;
    --accent: #e58bb4; --accent-ink: #2a0f1c; --accent-soft: #3a2230;
    --ok: #6fd3a0; --ok-soft: #173326; --warn: #f1b45a; --warn-soft: #3a2a10; --danger: #ff8a80; --danger-soft: #3d1b19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
body.modal-open { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; letter-spacing: -.01em; text-wrap: balance; }
h2 { font-size: 17px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.splash { min-height: 100dvh; display: grid; place-items: center; color: var(--muted); }

/* ---------- estructura ---------- */
.shell { min-height: 100dvh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100dvh; padding: 20px 12px; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 16px; }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; color: var(--muted);
  text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link svg { flex: none; }
.sidebar .spacer { flex: 1; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px; border-top: 1px solid var(--line); margin-top: 8px; }
.me > div { min-width: 0; flex: 1; }
.me strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me small { color: var(--muted); }
.main { padding: 28px clamp(16px, 4vw, 40px) 48px; max-width: 1180px; width: 100%; }
.topbar, .tabbar { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

@media (max-width: 899px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20;
    padding: calc(10px + var(--safe-t)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); font-weight: 700;
  }
  .topbar img { width: 26px; height: 26px; border-radius: 7px; }
  .main { padding: 16px 16px calc(92px + var(--safe-b)); }
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
    padding: 6px 8px calc(6px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line);
  }
  .tabbar a {
    display: grid; justify-items: center; gap: 2px; padding: 6px 0; border-radius: 10px; color: var(--muted);
    text-decoration: none; font-size: 11px; font-weight: 600;
  }
  .tabbar a.active { color: var(--accent); }
  h1 { font-size: 20px; }
}

/* ---------- piezas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card > h3 { margin-bottom: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; white-space: nowrap;
  text-decoration: none; color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.btn.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.sm { min-height: 34px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
.btn.lg { min-height: 54px; font-size: 17px; padding: 0 22px; border-radius: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.field { display: grid; gap: 5px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; /* 16px evita el zoom automático de iOS */
}
textarea { min-height: 76px; resize: vertical; }
input[type='checkbox'] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); flex: none; }
input[type='color'] { padding: 3px; width: 54px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.money-input { position: relative; }
.money-input span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-left: 26px; font-variant-numeric: tabular-nums; }
.form { display: grid; gap: 14px; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-weight: 500; }
.notice { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 10px; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; font-size: 14px; }

.list { display: grid; }
.list > * { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; width: 100%; }
.list > *:first-child { border-top: 0; }
.list > button:hover { background: var(--surface-2); }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strike { text-decoration: line-through; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile small { color: var(--muted); font-weight: 600; }
.tile strong { display: block; font-size: 22px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile.hero { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tile.hero small { color: inherit; opacity: .8; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 16px; text-align: left; border-top: 1px solid var(--line); white-space: nowrap; }
thead th { border-top: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
td.right, th.right { text-align: right; font-variant-numeric: tabular-nums; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; color: var(--muted); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------- modal (hoja inferior en móvil) ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(20, 12, 16, .5); display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 20px; animation: fade .15s; }
.modal { min-width: 0; background: var(--surface); border-radius: 18px; width: min(520px, 100%); max-height: min(88dvh, 860px); display: flex; flex-direction: column; box-shadow: var(--shadow); animation: pop .18s; }
.modal.wide { width: min(1040px, 100%); height: min(88dvh, 860px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.modal-foot { padding: 12px 20px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px); } }
@media (max-width: 899px) {
  .modal-backdrop { padding: 0; place-items: end stretch; }
  .modal, .modal.wide { width: 100%; max-height: 94dvh; border-radius: 20px 20px 0 0; }
  .modal.wide { height: 94dvh; }
  .modal-foot > .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.toasts { position: fixed; z-index: 80; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); animation: pop .18s; }
.toast.err { background: var(--danger); color: #fff; }

/* ---------- acceso ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); display: grid; gap: 18px; }
.auth-card .logo { width: 64px; height: 64px; border-radius: 18px; }

/* ---------- venta ---------- */
.pos { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 1fr); gap: 20px; height: 100%; }
.pos > div { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.pos .catalog { overflow-y: auto; }
.svc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.svc { text-align: left; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; gap: 4px; position: relative; }
.svc:hover { border-color: var(--accent); }
.svc b { font-weight: 600; line-height: 1.25; }
.svc span { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.svc.in { border-color: var(--accent); background: var(--accent-soft); }
.svc i { position: absolute; top: 8px; right: 8px; font-style: normal; background: var(--accent); color: var(--accent-ink); min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.cart-line:first-child { border-top: 0; }
.cart-line select { min-height: 34px; padding: 4px 8px; font-size: 14px; width: auto; }
.qty { display: inline-flex; align-items: center; gap: 4px; }
.qty button { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; }
.qty b { min-width: 22px; text-align: center; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 0; }
.total-row.big { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.methods { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.methods .chip { border-radius: 11px; min-height: 44px; }
.methods .chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.picked { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 8px 8px 12px; border: 1px solid var(--line); border-radius: 11px; }
.suggest { border: 1px solid var(--line); border-radius: 11px; overflow: hidden; margin-top: 6px; }
@media (max-width: 899px) {
  .pos { display: block; height: auto; }
  .pos > div + div { margin-top: 18px; }
  .pos .catalog { overflow: visible; }
}

/* ---------- agenda ---------- */
.datebar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.datebar input { width: auto; }
.cal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100dvh - 190px); }
.cal-grid { display: grid; min-width: min-content; }
.cal-head { position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 8px; font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 150px; }
.cal-corner { position: sticky; left: 0; top: 0; z-index: 4; background: var(--surface); border-bottom: 1px solid var(--line); }
.cal-times { position: sticky; left: 0; z-index: 2; background: var(--surface); border-right: 1px solid var(--line); }
.cal-times div { height: 64px; font-size: 12px; color: var(--muted); text-align: right; padding: 0 8px; transform: translateY(-8px); font-variant-numeric: tabular-nums; }
.cal-times div:first-child { visibility: hidden; }
.cal-col { position: relative; border-left: 1px solid var(--line); min-width: 150px; cursor: pointer;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(color-mix(in srgb, var(--line) 45%, transparent) 1px, transparent 1px);
  background-size: 100% 64px, 100% 32px; }
.appt { display: flex; flex-direction: column; justify-content: flex-start; position: absolute; left: 4px; right: 4px; border-radius: 9px; padding: 4px 8px; overflow: hidden; border: 0; text-align: left; font-size: 13px; line-height: 1.25;
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-left: 4px solid var(--c); color: var(--ink); }
.appt b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appt small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appt.off { opacity: .45; }
.appt.off b { text-decoration: line-through; }
.appt.done { background: var(--ok-soft); border-left-color: var(--ok); }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 1; pointer-events: none; }
@media (max-width: 899px) { .cal { max-height: calc(100dvh - 250px - var(--safe-b)); } }

/* ---------- reportes / auditoría ---------- */
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 92px 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bar i { display: block; height: 14px; border-radius: 7px; background: var(--accent); min-width: 2px; }
.audit-detail { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font: 12.5px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word; margin: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
