/* Panel de LocalVivo: base, estructura, ingreso, tablas, formularios y paneles.
   Misma dirección que el local: tinta + bermellón sobre papel tiza. */

:root {
  --side-w: 248px;
  --line: rgb(20 20 20 / 0.1);
  --line-strong: rgb(20 20 20 / 0.2);
  --surface: #fbf9f5;
  --surface-hi: #fff;
  --context: #8a857c;
  --text-page: clamp(2.4rem, 1.7rem + 2.2vw, 3.6rem);
  --space-1: 6px;
  --space-2: 12px;
  --space-3: 20px;
  --space-4: 32px;
  --space-5: 56px;
  --shadow-soft: 0 1px 2px rgb(0 0 0 / 0.06), 0 8px 24px -12px rgb(0 0 0 / 0.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); }
body {
  margin: 0; min-height: 100vh; font: var(--text-base)/1.45 var(--font-ui); color: var(--ink); background: var(--paper);
  -webkit-font-smoothing: antialiased; opacity: 0; transition: opacity 400ms ease;
}
body.ready { opacity: 1; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; letter-spacing: 0.01em; }
.num, .cell-num { font-variant-numeric: tabular-nums; text-align: right; }

/* Botones */
.btn-primary, .btn-ghost, .btn-danger, .btn-wa {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 20px;
  border-radius: var(--radius-pill); font-weight: 600; font-size: 0.9rem; text-decoration: none; white-space: nowrap;
  transition: background var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast), transform var(--duration-fast);
}
.btn-primary { border: 0; background: var(--night-700); color: var(--paper); }
.btn-primary:hover { background: var(--night-900); }
.btn-primary:active, .btn-ghost:active { transform: scale(0.97); }
.btn-primary span { display: inline-block; transition: transform var(--duration-normal) var(--ease-out-expo); }
.btn-primary:hover span { transform: translateX(3px); }
.btn-primary:disabled, .btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-ghost { border: 1px solid var(--line-strong); background: transparent; font-weight: 500; }
.btn-ghost:hover { border-color: var(--ink); background: rgb(20 20 20 / 0.03); }
.btn-ghost.danger, .mini.danger { color: var(--out); }
.btn-ghost.danger:hover { border-color: var(--out); background: rgb(196 64 42 / 0.06); }
.btn-danger { border: 0; background: var(--out); color: #fff; }
.btn-danger:hover { background: #a8331f; }
.btn-wa { border: 0; background: #1f9d55; color: #fff; }
.btn-wa:hover { background: #17824a; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 0.84rem; }
.btn-lg { min-height: 52px; padding: 0 26px; font-size: 1rem; }
.on-dark { color: var(--paper); border-color: rgb(245 242 236 / 0.25); }
.on-dark:hover { border-color: var(--accent); background: transparent; }
.mini {
  border: 1px solid var(--line-strong); background: transparent; border-radius: var(--radius-pill); padding: 5px 11px;
  font-size: 0.76rem; font-weight: 600; transition: border-color var(--duration-fast), background var(--duration-fast);
}
.mini:hover { border-color: var(--ink); }
.mini.solid { background: var(--out); border-color: var(--out); color: #fff; }
.mini:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 0; background: rgb(20 20 20 / 0.06); display: grid; place-items: center;
  font-size: 0.85rem; flex: none; transition: background var(--duration-fast);
}
.icon-btn:hover { background: rgb(20 20 20 / 0.14); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent-ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--ink); }

/* Marca */
.wordmark { margin: 0; font: 400 2rem/1 var(--font-display); letter-spacing: -0.01em; text-decoration: none; }
.wordmark em { color: var(--accent); }
.wordmark.small { font-size: 1.6rem; }
.kicker { margin: 0 0 8px; font-size: var(--text-sm); color: var(--accent-ink); font-weight: 600; letter-spacing: 0.02em; }

/* Ingreso */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(380px, 0.9fr); }
.login-art {
  position: relative; background: var(--night-900); color: var(--paper); padding: var(--space-5); display: flex; flex-direction: column;
  justify-content: space-between; overflow: hidden;
}
.login-art::after {
  content: ''; position: absolute; right: -12%; bottom: -18%; width: 70%; aspect-ratio: 1; border-radius: 50%;
  border: 1px solid rgb(255 90 54 / 0.35); box-shadow: 0 0 0 40px rgb(255 90 54 / 0.04), 0 0 0 80px rgb(255 90 54 / 0.03);
}
.login-art .wordmark { font-size: 2.4rem; }
.login-quote { margin: 0; max-width: 15ch; font: 400 clamp(2.6rem, 1.4rem + 3.4vw, 4.8rem)/0.98 var(--font-display); letter-spacing: -0.02em; }
.login-quote em { color: var(--accent); }
.login-facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; color: rgb(245 242 236 / 0.7); font-size: 0.92rem; position: relative; z-index: 1; }
.login-facts strong { color: var(--paper); font-weight: 600; }
.login-panel { display: flex; flex-direction: column; justify-content: center; padding: var(--space-5) clamp(24px, 6vw, 88px); }
.login-panel h1 { margin: 0 0 var(--space-4); font: 400 var(--text-page)/0.95 var(--font-display); letter-spacing: -0.02em; }
.login-panel h1 em { color: var(--accent-ink); }
.login-form { display: grid; gap: 16px; max-width: 420px; }
.login-form .form-errors { margin: 0; }
.login-form .btn-primary { justify-self: start; background: var(--accent); color: var(--night-900); }
.login-form .btn-primary:hover { background: var(--accent-strong); }
.login-status { margin: 0; min-height: 1.3em; font-size: 0.88rem; color: var(--ink-soft); }
.sending .login-status::before {
  content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%;
  background: var(--accent); animation: pulse 900ms ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(0.5); opacity: 0.5; } }
.login-note { margin: 0; font-size: 0.8rem; color: var(--ink-soft); max-width: 36ch; }
.login-sep { margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--line); max-width: 420px; }

/* Estructura del comercio */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; background: var(--night-900); }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--space-4);
  padding: 28px 16px 20px; background: var(--night-900); color: var(--paper);
}
.side .wordmark { padding: 0 12px; }
.side-nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.side-nav a {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; text-decoration: none;
  color: rgb(245 242 236 / 0.68); font-weight: 500; font-size: 0.92rem; transition: color var(--duration-fast), background var(--duration-fast);
}
.side-nav a:hover { color: var(--paper); background: rgb(245 242 236 / 0.06); }
.side-nav a[aria-current="page"] { color: var(--paper); background: var(--night-700); }
.side-nav a[aria-current="page"]::before {
  content: ''; position: absolute; left: -16px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.side-nav a[aria-current="page"] .nav-icon { color: var(--accent); }
.nav-icon svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { margin-top: auto; display: grid; gap: 10px; padding: 12px; border-top: 1px solid rgb(245 242 236 / 0.1); }
.side-user { font-size: 0.78rem; color: rgb(245 242 236 / 0.55); overflow: hidden; text-overflow: ellipsis; }
.side-foot .btn-ghost { justify-self: start; }

.work { min-width: 0; display: flex; flex-direction: column; background: var(--paper); }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: 14px clamp(20px, 3vw, 44px); background: rgb(245 242 236 / 0.88); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.shop { display: flex; align-items: center; gap: 12px; min-width: 0; }
.shop div { display: grid; line-height: 1.15; min-width: 0; }
.shop-name { font: 400 1.4rem var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shop span { font-size: 0.78rem; color: var(--ink-soft); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--accent);
  color: var(--night-900); font-weight: 600; font-size: 0.82rem; letter-spacing: 0.02em;
}
.top-links { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.view { padding: clamp(24px, 3.4vw, 48px) clamp(20px, 3vw, 44px) 80px; max-width: 1280px; width: 100%; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.page-title { margin: 0; font: 400 var(--text-page)/0.95 var(--font-display); letter-spacing: -0.02em; outline: none; }
.page-lead { margin: 10px 0 0; color: var(--ink-soft); max-width: 60ch; }
.page-actions { display: flex; gap: 8px; }
.fineprint { margin: var(--space-4) 0 0; font-size: 0.78rem; color: var(--ink-soft); max-width: 70ch; }
.empty { color: var(--ink-soft); font-size: 0.9rem; padding: 14px 0; }
.callout {
  margin: 0 0 var(--space-3); padding: 12px 16px; border-left: 3px solid var(--accent); background: var(--surface-hi);
  border-radius: 0 10px 10px 0; font-size: 0.88rem; color: var(--ink-soft);
}
.callout a { color: var(--accent-ink); font-weight: 600; }
.boot-fail { max-width: 520px; margin: 18vh auto; padding: 0 24px; }
.boot-fail h1 { font: 400 2.6rem/1 var(--font-display); margin: 0 0 12px; }
.loading { color: var(--ink-soft); }

/* Tablas */
.table-wrap { overflow-x: auto; background: var(--surface-hi); border-radius: var(--radius-panel); box-shadow: var(--shadow-soft); }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table thead th {
  position: sticky; top: 0; text-align: left; font-size: 0.72rem; font-weight: 600; color: var(--ink-soft); letter-spacing: 0.04em;
  text-transform: uppercase; padding: 14px 14px 10px; border-bottom: 1px solid var(--line); background: var(--surface-hi); white-space: nowrap;
}
.table thead th.cell-num { text-align: right; }

.table td, .table tbody th { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; text-align: left; font-weight: 400; }
.table tbody tr:last-child > * { border-bottom: 0; }
.table td.cell-num, .table th.cell-num { text-align: right; }
.table tbody tr { transition: background var(--duration-fast); }
.table tbody tr:hover { background: rgb(255 90 54 / 0.035); }
.table .sub { display: block; font-size: 0.78rem; color: var(--ink-soft); text-decoration: none; }
.table a.sub:hover { color: var(--accent-ink); }
.clickable { cursor: pointer; }
.row-link { border: 0; background: none; padding: 0; font-weight: 600; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.row-link:hover { text-decoration-color: var(--accent); }
.cell-date { color: var(--ink-soft); white-space: nowrap; font-size: 0.84rem; }
.cell-input, .cell-select {
  width: 96px; padding: 7px 9px; border-radius: 8px; border: 1px solid transparent; background: rgb(20 20 20 / 0.04);
  text-align: right; font-variant-numeric: tabular-nums; transition: border-color var(--duration-fast), background var(--duration-fast);
}
.cell-select { width: auto; text-align: left; }
.cell-input.wide { width: 220px; text-align: left; }
.cell-input:hover, .cell-select:hover { border-color: var(--line-strong); }
.cell-input:focus, .cell-select:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgb(255 90 54 / 0.18); }
.cell-input[aria-invalid="true"] { border-color: var(--out); background: rgb(196 64 42 / 0.06); }

/* Chips de estado */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius-pill); font-size: 0.76rem;
  font-weight: 600; white-space: nowrap; background: rgb(20 20 20 / 0.06); color: var(--ink);
}
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-pendiente_pago { color: #8a5a00; background: rgb(212 138 18 / 0.14); }
.st-pagado { color: var(--accent-ink); background: rgb(255 90 54 / 0.13); }
.st-preparando { color: #7a4b00; background: rgb(212 138 18 / 0.1); }
.st-listo { color: #1d5f8a; background: rgb(0 158 227 / 0.11); }
.st-entregado { color: var(--ok); background: rgb(47 143 91 / 0.12); }
.st-cancelado { color: var(--ink-soft); background: rgb(20 20 20 / 0.06); text-decoration: line-through; }
.t-activo { color: var(--ok); background: rgb(47 143 91 / 0.12); }
.t-prueba { color: #1d5f8a; background: rgb(0 158 227 / 0.11); }
.t-suspendido { color: var(--out); background: rgb(196 64 42 / 0.1); }

/* Formularios (completa .field de admin.css) */
.field-error { min-height: 0; font-size: 0.78rem; color: var(--out); font-weight: 500; }
.field-error:empty { display: none; }
.field-note { font-size: 0.76rem; color: var(--ink-soft); font-weight: 400; }
.field input[aria-invalid="true"] { border-color: var(--out); }
.form-ok { margin: 8px 0 0; font-size: 0.86rem; color: var(--ok); font-weight: 500; }
.form-card { background: var(--surface-hi); border-radius: var(--radius-panel); box-shadow: var(--shadow-soft); padding: clamp(18px, 2.4vw, 32px); display: grid; gap: 18px; }
.form-card fieldset { border: 0; margin: 0; padding: 0 0 18px; display: grid; gap: 14px; border-bottom: 1px solid var(--line); }
.form-card fieldset:last-of-type { border-bottom: 0; }
.form-card legend { font: 400 1.5rem var(--font-display); margin-bottom: 10px; padding: 0; }
.form-foot { display: flex; justify-content: flex-end; }
.row.three { grid-template-columns: repeat(3, 1fr); }
.form-card .row { align-items: start; }
.narrow input { max-width: 180px; }

/* Confirmación en línea */
.confirm { display: grid; gap: 10px; justify-items: start; }
.confirm-q { margin: 0; font-size: 0.88rem; font-weight: 500; color: var(--out); }
.confirm-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.confirm.busy { opacity: 0.6; pointer-events: none; }

/* Diálogos y panel lateral */
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(0.98); } }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
.modal-note { margin: 4px 20px 0; padding: 10px 12px; border-radius: 10px; background: rgb(255 90 54 / 0.08); font-size: 0.82rem; color: var(--ink-soft); }
.modal-note a { color: var(--accent-ink); font-weight: 600; }
.cover-preview { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 4px; box-shadow: 0 6px 18px -6px rgb(0 0 0 / 0.4); }
.drawer {
  margin: 0 0 0 auto; height: 100%; max-height: 100%; width: min(480px, 100%); padding: 0; border: 0; background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow-panel); display: none; flex-direction: column;
}
.drawer[open] { display: flex; animation: slide-in 420ms var(--ease-out-expo); }
.drawer::backdrop { background: rgb(0 0 0 / 0.42); backdrop-filter: blur(2px); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 26px 26px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0 0 10px; font: 400 2.2rem/1 var(--font-display); }
.drawer-body { flex: 1; overflow: auto; padding: 18px 26px; display: grid; gap: 22px; align-content: start; }
.drawer-body h3 { margin: 0 0 10px; font: 400 1.3rem var(--font-display); }
.drawer-foot { padding: 16px 26px 24px; border-top: 1px solid var(--line); display: grid; gap: 10px; background: var(--surface); }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.drawer-actions .btn-primary:first-child { flex: 1; }
.lines { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.lines td { padding: 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines td strong { display: block; font: 400 1.1rem/1.2 var(--font-display); }
.lines td span { font-size: 0.8rem; color: var(--ink-soft); }
.lines tfoot td { border: 0; padding: 4px 0; color: var(--ink-soft); }
.lines tfoot .grand td { padding-top: 10px; color: var(--ink); font-weight: 600; font-size: 1.05rem; }
.facts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.facts dt { font-size: 0.72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.facts dd { margin: 2px 0 0; font-size: 0.92rem; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; display: grid; gap: 14px; border-left: 1px solid var(--line-strong); }
.timeline li { position: relative; display: grid; gap: 2px; }
.timeline li::before {
  content: ''; position: absolute; left: -23px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--paper);
  border: 1.5px solid var(--ink-soft);
}
.timeline li.now::before { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px rgb(255 90 54 / 0.18); }
.timeline strong { font-size: 0.9rem; }
.timeline span { font-size: 0.8rem; color: var(--ink-soft); }

/* Aviso */
.toast {
  position: fixed; left: 50%; top: 20px; z-index: 50; transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  padding: 11px 18px; border-radius: var(--radius-pill); background: var(--night-900); color: var(--paper); font-size: 0.88rem; font-weight: 500;
  box-shadow: var(--shadow-panel); max-width: calc(100% - 32px); transition: opacity 260ms ease, transform 420ms var(--ease-out-expo);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-tone="error"] { background: var(--out); color: #fff; }
.toast::before { content: '✓  '; color: var(--accent); }
.toast[data-tone="error"]::before { content: '!  '; color: #fff; }

/* Diálogo de producto: que los campos se ajusten al ancho y no desborden */
.product-modal { width: min(720px, calc(100% - 24px)); overflow-x: hidden; }
.product-modal .new-grid > *, .product-modal .row > * { min-width: 0; }
.product-modal .field input, .product-modal .field textarea { width: 100%; min-width: 0; }
