/* =============================================================================
 * base.css — Reset, design tokens y componentes base (botones, inputs, modales,
 * toasts, drawers). Las variables de color las sobreescribe el JS desde settings.
 * ========================================================================== */

:root {
  /* Colores (valores por defecto; el panel los reemplaza en runtime) */
  --c-primary: #2563eb;
  --c-primary-dark: #1d4ed8;
  --c-accent: #f59e0b;
  --c-bg: #f4f5f7;
  --c-surface: #ffffff;
  --c-text: #1f2937;
  --c-muted: #6b7280;
  --c-danger: #dc2626;
  --c-success: #16a34a;
  --c-whatsapp: #25d366;
  --c-border: #e5e7eb;

  /* Escala y forma */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow: 0 4px 12px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --header-h: 116px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tap: 44px; /* área táctil mínima */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--c-primary) 45%, transparent); outline-offset: 2px; }

/* ---- Iconos --------------------------------------------------------------- */
.icon { display: inline-flex; width: 1.25em; height: 1.25em; flex: none; }
.icon svg { width: 100%; height: 100%; }

/* ---- Botones -------------------------------------------------------------- */
.btn {
  --btn-bg: var(--c-surface); --btn-fg: var(--c-text); --btn-bd: var(--c-border);
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: var(--tap); padding: .6em 1.1em;
  border: 1px solid var(--btn-bd); border-radius: var(--radius-sm);
  background: var(--btn-bg); color: var(--btn-fg);
  font-size: .95rem; font-weight: 600; line-height: 1;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease, opacity .15s;
  white-space: nowrap; user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .icon { width: 1.15em; height: 1.15em; }

.btn--primary { --btn-bg: var(--c-primary); --btn-fg: #fff; --btn-bd: transparent; box-shadow: var(--shadow-sm); }
.btn--primary:hover { --btn-bg: var(--c-primary-dark); }
.btn--accent { --btn-bg: var(--c-accent); --btn-fg: #111; --btn-bd: transparent; }
.btn--danger { --btn-bg: var(--c-danger); --btn-fg: #fff; --btn-bd: transparent; }
.btn--danger-ghost { --btn-fg: var(--c-danger); --btn-bd: color-mix(in srgb, var(--c-danger) 35%, transparent); }
.btn--whatsapp { --btn-bg: var(--c-whatsapp); --btn-fg: #fff; --btn-bd: transparent; box-shadow: var(--shadow-sm); }
.btn--whatsapp:hover { --btn-bg: #1db954; }
.btn--ghost { --btn-bg: transparent; }
.btn--ghost:hover { --btn-bg: color-mix(in srgb, var(--c-text) 6%, transparent); }
.btn--sm { min-height: 34px; padding: .4em .7em; font-size: .82rem; }
.btn--lg { min-height: 52px; font-size: 1.05rem; padding: .7em 1.4em; }
.btn--block { display: flex; width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); flex: none;
  border: none; background: transparent; color: inherit; border-radius: 50%;
  transition: background .15s, transform .08s;
}
.icon-btn:hover { background: color-mix(in srgb, currentColor 12%, transparent); }
.icon-btn:active { transform: scale(.92); }
.icon-btn .icon { width: 1.4em; height: 1.4em; }

/* ---- Formularios ---------------------------------------------------------- */
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap);
  padding: .6em .8em; font-size: 1rem; color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-primary) 18%, transparent); outline: none; }
textarea.input { min-height: 70px; resize: vertical; line-height: 1.45; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M6 8 0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .8em center; padding-right: 2.2em; }
.input--sm { min-height: 36px; font-size: .85rem; padding: .35em .6em; }

/* ---- Splash --------------------------------------------------------------- */
.splash {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
  background: var(--c-bg); transition: opacity .35s ease;
}
.splash--hide { opacity: 0; pointer-events: none; }
.splash__spinner { width: 46px; height: 46px; border: 4px solid var(--c-border); border-top-color: var(--c-primary); border-radius: 50%; animation: spin .8s linear infinite; }
.splash__text { color: var(--c-muted); font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toasts --------------------------------------------------------------- */
.toast-host {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 78px);
  transform: translateX(-50%); z-index: 9000;
  display: flex; flex-direction: column; gap: .5rem; align-items: center;
  width: max-content; max-width: 92vw; pointer-events: none;
}
.toast {
  padding: .75em 1.1em; border-radius: 999px; font-weight: 600; font-size: .9rem;
  color: #fff; background: #111827; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(12px); transition: opacity .25s, transform .25s;
}
.toast--show { opacity: 1; transform: translateY(0); }
.toast--success { background: var(--c-success); }
.toast--error { background: var(--c-danger); }
.toast--info { background: #334155; }

/* ---- Modales -------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 8000;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: rgba(17, 24, 39, .55); backdrop-filter: blur(2px);
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 440px; max-height: 92vh; overflow: auto;
  background: var(--c-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: pop .2s ease;
}
.modal--wide { max-width: 760px; }
.modal--sm { max-width: 380px; padding: 1.5rem; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal__head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; background: var(--c-surface); border-bottom: 1px solid var(--c-border); z-index: 1; }
.modal__head h3 { font-size: 1.1rem; }
.modal__body { padding: 1.25rem; }
.modal__msg { font-size: 1rem; margin-bottom: 1.25rem; }
.modal__actions { display: flex; gap: .75rem; justify-content: flex-end; }

/* ---- Drawers (off-canvas) ------------------------------------------------- */
.drawer-overlay { position: fixed; inset: 0; z-index: 6000; background: rgba(17, 24, 39, .5); opacity: 0; visibility: hidden; transition: opacity .25s, visibility .25s; }
.drawer-overlay--show { opacity: 1; visibility: visible; }
.drawer {
  position: fixed; top: 0; bottom: 0; z-index: 6100; width: min(86vw, 360px);
  background: var(--c-surface); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}
.drawer--left { left: 0; transform: translateX(-105%); }
.drawer--right { right: 0; transform: translateX(105%); width: min(90vw, 420px); }
.drawer--open { transform: translateX(0); }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.1rem; border-bottom: 1px solid var(--c-border); font-size: 1.05rem; }
.drawer__body { flex: 1; overflow: auto; padding: 1rem 1.1rem; }
.drawer__foot { display: flex; gap: .75rem; padding: 1rem 1.1rem; border-top: 1px solid var(--c-border); }
.drawer__foot .btn { flex: 1; }

/* ---- Utilidades ----------------------------------------------------------- */
.empty { color: var(--c-muted); text-align: center; padding: 2rem 1rem; }
[hidden] { display: none !important; }

/* Botón flotante de instalación PWA */
.install-btn {
  position: fixed; right: 1rem; bottom: calc(env(safe-area-inset-bottom) + 78px); z-index: 5500;
  border: none; border-radius: 999px; padding: .7em 1.1em;
  background: var(--c-primary); color: #fff; font-weight: 700; box-shadow: var(--shadow-lg);
  animation: pop .3s ease;
}
@media (min-width: 768px) { .install-btn { bottom: 1.5rem; } }
