:root {
  --bg: #faf8f6;
  --surface: #ffffff;
  --surface-2: #f3efeb;
  --ink: #1f1b24;
  --muted: #6b6572;
  --line: #e8e3de;
  --accent: #a3295f;
  --accent-ink: #ffffff;
  --danger: #c0262d;
  --ok: #17803d;
  --shadow: 0 1px 2px rgba(31, 27, 36, .06), 0 8px 24px rgba(31, 27, 36, .08);
  --radius: 14px;
  --hour-h: 64px;
  --gutter: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151217;
    --surface: #1e1a22;
    --surface-2: #28232d;
    --ink: #f3eff5;
    --muted: #a49dab;
    --line: #2e2833;
    --accent: #e0709f;
    --accent-ink: #1a0f15;
    --danger: #ff7b81;
    --ok: #55d184;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { min-height: 100%; display: flex; flex-direction: column; }
.boot { margin: auto; color: var(--muted); }

/* ───── botones ───── */
.btn {
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600;
}
.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.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid transparent; background: transparent;
  display: inline-grid; place-items: center; font-size: 22px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ───── formularios ───── */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, .field > .lbl { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 10px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 2px; }
.error { color: var(--danger); font-size: 14px; margin: 4px 0 10px; min-height: 0; }
.error:empty { display: none; }

/* ───── pantallas de acceso ───── */
.auth { margin: auto; width: min(420px, 100%); padding: 28px 22px calc(28px + var(--safe-b)); }
.auth .logo {
  width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 32px; margin-bottom: 18px;
}
.auth h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.01em; }
.auth p { margin: 0 0 22px; color: var(--muted); }
.auth .btn { width: 100%; }

/* ───── barra superior ───── */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: calc(8px + var(--safe-t)) 10px 8px;
}
.topline { display: flex; align-items: center; gap: 4px; }
.title {
  flex: 1; min-width: 0; text-align: center; border: 0; background: transparent; padding: 4px 6px; border-radius: 10px;
  font-weight: 700; font-size: 17px; line-height: 1.2;
}
.title small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.title:hover { background: var(--surface-2); }
.today-btn { font-size: 14px; font-weight: 700; color: var(--accent); width: auto; padding: 0 10px; }
.subline { display: flex; align-items: center; gap: 10px; margin-top: 6px; overflow-x: auto; scrollbar-width: none; }
.subline::-webkit-scrollbar { display: none; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; flex: none; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.chips { display: flex; gap: 6px; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--accent)); flex: none; }

.offline {
  background: #7a4b00; color: #fff; text-align: center; font-size: 14px; padding: 6px 10px;
}

/* ───── vista día ───── */
main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 0 0 calc(96px + var(--safe-b)); }
.day { position: relative; padding: 12px 10px 0 6px; }
.grid { position: relative; margin-left: var(--gutter); cursor: cell; }
.hline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); pointer-events: none; }
.hline.half { border-top-style: dashed; opacity: .55; }
.hlabel {
  position: absolute; left: calc(-1 * var(--gutter)); width: calc(var(--gutter) - 8px); text-align: right;
  font-size: 12px; color: var(--muted); transform: translateY(-50%); pointer-events: none;
}
.appt {
  position: absolute; border: 0; border-left: 4px solid var(--c); border-radius: 8px; padding: 3px 7px; text-align: left;
  background: color-mix(in srgb, var(--c) 16%, var(--surface)); overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; gap: 1px; line-height: 1.2; font-size: 13px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 18%, transparent);
}
.appt:hover { filter: brightness(.97); z-index: 3; }
.appt .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .s, .appt .n { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.appt.st-confirmada { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ok) 60%, transparent); }
.appt.st-realizada { opacity: .72; }
.appt.st-realizada .t::before { content: "✓ "; color: var(--ok); }
.appt.st-cancelada, .appt.st-no_vino { opacity: .5; background: repeating-linear-gradient(135deg, var(--surface-2), var(--surface-2) 6px, var(--surface) 6px, var(--surface) 12px); }
.appt.st-cancelada .t { text-decoration: line-through; }
.appt.st-no_vino .t::before { content: "✗ "; color: var(--danger); }
.nowline { position: absolute; left: -6px; right: 0; border-top: 2px solid var(--danger); pointer-events: none; z-index: 4; }
.nowline::before { content: ""; position: absolute; left: -2px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.empty-hint {
  position: absolute; left: 0; right: 0; top: 18px; text-align: center; color: var(--muted); font-size: 14px; pointer-events: none;
}

/* ───── vista semana ───── */
.week { display: grid; gap: 10px; padding: 12px 10px 0; }
@media (min-width: 820px) { .week { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; } }
.daycard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; min-height: 80px; }
.daycard.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dayhead { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-2); border: 0; text-align: left; width: 100%; }
.dayhead b { font-size: 15px; }
.dayhead span { color: var(--muted); font-size: 13px; }
.dayhead .count { margin-left: auto; font-weight: 700; color: var(--ink); }
.dayitems { padding: 6px; display: grid; gap: 6px; flex: 1; align-content: start; }
.witem {
  display: block; width: 100%; text-align: left; border: 0; border-left: 4px solid var(--c); border-radius: 8px; padding: 6px 8px;
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); font-size: 13px; line-height: 1.25;
}
.witem b { display: block; }
.witem small { color: var(--muted); }
.witem.st-cancelada, .witem.st-no_vino { opacity: .5; text-decoration: line-through; }
.witem.st-realizada { opacity: .72; }
.free { color: var(--muted); font-size: 13px; padding: 4px 6px; }
.addday { border: 0; border-top: 1px solid var(--line); background: transparent; padding: 8px; color: var(--accent); font-weight: 700; font-size: 14px; }

/* ───── FAB ───── */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + var(--safe-b)); z-index: 30; width: 60px; height: 60px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-ink); font-size: 32px; line-height: 1; box-shadow: var(--shadow);
}
.fab:hover { filter: brightness(1.06); }

/* ───── hojas / diálogos ───── */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 10, 20, .5); display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 94dvh; background: var(--surface); border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column; box-shadow: var(--shadow); animation: up .2s ease-out;
}
@media (min-width: 640px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 20px; max-height: 90dvh; }
}
.sheet header { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px 18px; border-bottom: 1px solid var(--line); }
.sheet header h2 { margin: 0; font-size: 18px; flex: 1; }
.sheet .body { padding: 16px 18px 8px; overflow-y: auto; flex: 1; }
.sheet footer { display: flex; gap: 10px; padding: 12px 18px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); flex-wrap: wrap; }
.sheet footer .grow { flex: 1; }
.menu-list { display: grid; gap: 4px; }
.menu-list .btn { text-align: left; justify-content: flex-start; border-color: transparent; background: transparent; }
.menu-list .btn:hover { background: var(--surface-2); }
.me { padding: 4px 4px 12px; color: var(--muted); font-size: 14px; }
.me b { color: var(--ink); font-size: 16px; }
.msg { margin: 0 0 8px; line-height: 1.5; white-space: pre-line; }
.conf-list { margin: 8px 0 0; padding-left: 18px; }

.act-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.act-item:last-child { border-bottom: 0; }
.act-item b { font-weight: 700; }
.act-item small { display: block; color: var(--muted); margin-top: 2px; }

.svc-row { display: grid; grid-template-columns: 1fr 84px 44px; gap: 8px; margin-bottom: 8px; align-items: center; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.user-row .nm { flex: 1; min-width: 120px; font-weight: 600; }
.user-row .nm small { display: block; font-weight: 400; color: var(--muted); }
.user-row.off { opacity: .55; }

/* ───── avisos ───── */
#toasts {
  position: fixed; left: 0; right: 0; bottom: calc(92px + var(--safe-b)); z-index: 70; display: grid; gap: 8px; justify-items: center; padding: 0 12px; pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 520px; width: fit-content; background: var(--ink); color: var(--bg); border-radius: 12px;
  padding: 10px 14px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; font-size: 14px; animation: up .2s ease-out;
}
.toast button { border: 0; background: transparent; color: inherit; font-weight: 800; text-decoration: underline; padding: 4px; }
.toast.err { background: var(--danger); color: #fff; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes up { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

@media print {
  .topbar .icon-btn, .fab, #toasts, .subline, .addday { display: none !important; }
  body { background: #fff; color: #000; }
}

/* ───── aviso dentro del formulario ───── */
.banner {
  background: color-mix(in srgb, #d97706 18%, var(--surface)); border: 1px solid #d97706; border-radius: 12px;
  padding: 10px 12px; margin-bottom: 14px; font-size: 14px;
}
