/* =============================================================
   BASE · reset, tipografía y componentes compartidos
   (usados tanto por el sitio público como por el panel)
   ============================================================= */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img, svg, video { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; padding: 0; }
table { border-collapse: collapse; width: 100%; }
:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--brand-accent); color: #fff; }

h1, h2, h3, h4 { font-family: var(--font-display); line-height: var(--lh-tight); letter-spacing: -.02em; font-weight: 700; }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); letter-spacing: -.01em; }
p { text-wrap: pretty; }
strong { font-weight: 650; }

.ico { flex: none; }
.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: var(--sp-5); }
.wrap-narrow { max-width: var(--wrap-narrow); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--sp-4); top: -60px; z-index: var(--z-modal);
  background: var(--brand-primary); color: #fff; padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-sm); transition: top var(--t-base);
}
.skip-link:focus { top: var(--sp-4); }

/* ------------------------------ Botones ------------------------------ */
.btn {
  --btn-bg: var(--brand-primary);
  --btn-fg: #fff;
  --btn-bd: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: .72em 1.25em;
  font-size: var(--fs-base); font-weight: 600; letter-spacing: -.01em;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-sm);
  cursor: pointer; white-space: nowrap; text-align: center;
  transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast), border-color var(--t-fast), opacity var(--t-fast);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--sh-2); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }

.btn-primary   { --btn-bg: var(--brand-primary); }
.btn-primary:hover { --btn-bg: var(--brand-primary-dark); }
.btn-accent    { --btn-bg: var(--brand-accent); }
.btn-accent:hover { --btn-bg: var(--brand-accent-dark); }
.btn-wa        { --btn-bg: var(--brand-whatsapp); --btn-fg: #06301A; }
.btn-ghost     { --btn-bg: transparent; --btn-fg: var(--ink-2); --btn-bd: var(--line-strong); }
.btn-ghost:hover { --btn-bg: var(--surface-2); --btn-fg: var(--ink); }
.btn-soft      { --btn-bg: var(--brand-primary-light); --btn-fg: var(--brand-primary); }
.btn-soft:hover { --btn-bg: var(--brand-accent-light); }
.btn-light     { --btn-bg: #fff; --btn-fg: var(--brand-primary); }
.btn-danger    { --btn-bg: var(--danger); }
.btn-danger-soft { --btn-bg: var(--danger-bg); --btn-fg: var(--danger); --btn-bd: var(--danger-line); }
.btn-link      { --btn-bg: transparent; --btn-fg: var(--brand-primary); padding: .3em .2em; text-decoration: underline; text-underline-offset: 3px; }
.btn-link:hover { box-shadow: none; transform: none; --btn-fg: var(--brand-accent-dark); }

.btn-lg { padding: .9em 1.6em; font-size: var(--fs-lg); border-radius: var(--r-md); }
.btn-sm { padding: .5em .85em; font-size: var(--fs-sm); border-radius: var(--r-xs); }
.btn-xs { padding: .35em .6em; font-size: var(--fs-xs); border-radius: var(--r-xs); gap: 4px; }
.btn-block { width: 100%; }
.btn-icon { padding: .55em; aspect-ratio: 1; }

/* ------------------------------ Badges ------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: .28em .62em; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 650; line-height: 1.35;
  background: var(--neutral-bg); color: var(--neutral-fg);
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; flex: none; }
.badge-plain::before { display: none; }
.badge-ok     { background: var(--ok-bg);     color: var(--ok);     border-color: var(--ok-line); }
.badge-warn   { background: var(--warn-bg);   color: var(--warn);   border-color: var(--warn-line); }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.badge-info   { background: var(--info-bg);   color: var(--info);   border-color: var(--info-line); }
.badge-brand  { background: var(--brand-primary-light); color: var(--brand-primary); border-color: #CFE3E7; }
.badge-accent { background: var(--brand-accent-light); color: var(--brand-accent-dark); border-color: #BDEBE4; }

/* --------------------------- Formularios ----------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .lbl {
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); letter-spacing: -.005em;
}
.lbl .req { color: var(--danger); }
.inp, .sel, .txt {
  width: 100%; padding: .62em .8em;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  font-size: var(--fs-base); line-height: 1.4;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.inp::placeholder, .txt::placeholder { color: var(--ink-4); }
.inp:hover, .sel:hover, .txt:hover { border-color: var(--ink-4); }
.inp:focus, .sel:focus, .txt:focus {
  outline: none; border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px var(--brand-accent-light);
}
.txt { min-height: 92px; resize: vertical; }
.sel {
  appearance: none; padding-right: 2.1em; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235E727A' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7em center;
}
.inp.is-error, .sel.is-error, .txt.is-error { border-color: var(--danger); background: #FFFBFB; }
.err-msg { font-size: var(--fs-xs); color: var(--danger); font-weight: 600; display: none; }
.field.has-error .err-msg { display: block; }
.hint { font-size: var(--fs-xs); color: var(--ink-3); }
.form-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .col-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.check {
  display: flex; align-items: flex-start; gap: var(--sp-3); cursor: pointer;
  padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.check:hover { border-color: var(--brand-accent); background: var(--surface-2); }
.check input { margin-top: 3px; accent-color: var(--brand-accent); width: 16px; height: 16px; flex: none; }
.check-txt { font-size: var(--fs-sm); color: var(--ink-2); }

/* ----------------------------- Cards --------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--sh-1);
}
.card-pad { padding: var(--sp-5); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line);
}
.card-head h3 { font-size: var(--fs-lg); }
.card-head .sub { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 500; }
.card-body { padding: var(--sp-5); }
.card-foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-md) var(--r-md); }

/* ----------------------------- Tablas -------------------------------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { font-size: var(--fs-sm); }
.tbl th {
  text-align: left; font-weight: 650; color: var(--ink-3); font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: .045em;
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--brand-primary); }
.tbl th .sort-i { opacity: .35; margin-left: 3px; }
.tbl th.is-sorted .sort-i { opacity: 1; color: var(--brand-accent-dark); }
.tbl td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr { transition: background var(--t-fast); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tr.clickable { cursor: pointer; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .actions { text-align: right; white-space: nowrap; }
.tbl tbody tr:last-child td { border-bottom: 0; }

/* Tablas → tarjetas en móvil */
@media (max-width: 760px) {
  .tbl.responsive thead { display: none; }
  .tbl.responsive, .tbl.responsive tbody, .tbl.responsive tr, .tbl.responsive td { display: block; width: 100%; }
  .tbl.responsive tr {
    border: 1px solid var(--line); border-radius: var(--r-sm);
    margin-bottom: var(--sp-3); padding: var(--sp-2); background: var(--surface);
  }
  .tbl.responsive td { border: 0; padding: 6px var(--sp-2); display: flex; gap: var(--sp-3); align-items: center; justify-content: space-between; }
  .tbl.responsive td::before {
    content: attr(data-label); font-size: var(--fs-2xs); font-weight: 700; color: var(--ink-4);
    text-transform: uppercase; letter-spacing: .05em; flex: none;
  }
  .tbl.responsive td.num, .tbl.responsive td.actions { text-align: right; }
  .tbl.responsive td.cell-main { border-bottom: 1px solid var(--line); padding-bottom: var(--sp-3); margin-bottom: 4px; }
  .tbl.responsive td.cell-main::before { display: none; }
}

/* --------------------------- Estados vacíos --------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--sp-9) var(--sp-5); color: var(--ink-3);
}
.empty-ico {
  width: 52px; height: 52px; border-radius: var(--r-md); display: grid; place-items: center;
  background: var(--surface-3); color: var(--ink-4); margin-bottom: var(--sp-4);
}
.empty h4 { font-size: var(--fs-lg); color: var(--ink); margin-bottom: 4px; }
.empty p { font-size: var(--fs-sm); max-width: 42ch; margin-bottom: var(--sp-4); }

/* ------------------------------ Skeleton ------------------------------ */
.sk { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%; animation: skl 1.3s ease infinite; border-radius: var(--r-xs); }
@keyframes skl { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.sk-line { height: 12px; margin-bottom: 10px; }
.sk-card { height: 96px; border-radius: var(--r-md); }

/* ------------------------------ Modales ------------------------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10, 30, 36, .5);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  z-index: var(--z-modal); display: grid; place-items: center; padding: var(--sp-4);
  animation: fadeIn .18s var(--ease);
  overflow-y: auto;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-4);
  width: min(560px, 100%); max-height: calc(100dvh - 2rem); display: flex; flex-direction: column;
  animation: pop .28s var(--ease-out); margin: auto;
}
.modal-lg { width: min(880px, 100%); }
.modal-xl { width: min(1080px, 100%); }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-5) var(--sp-4); border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 1.15rem; }
.modal-head .sub { font-size: var(--fs-sm); color: var(--ink-3); margin-top: 2px; }
.modal-x { color: var(--ink-3); padding: 4px; border-radius: var(--r-xs); transition: background var(--t-fast); }
.modal-x:hover { background: var(--surface-3); color: var(--ink); }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-foot {
  display: flex; gap: var(--sp-3); justify-content: flex-end; flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--line); background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}
@media (max-width: 560px) {
  .overlay { padding: 0; align-items: flex-end; }
  .modal { width: 100%; max-height: 94dvh; border-radius: var(--r-lg) var(--r-lg) 0 0; animation: slideUp .3s var(--ease-out); }
  .modal-foot { border-radius: 0; }
  .modal-foot .btn { flex: 1; }
}
@keyframes slideUp { from { transform: translateY(100%); } }

/* ------------------------------- Toasts ------------------------------- */
.toasts {
  position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-3); pointer-events: none; max-width: 360px;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3); pointer-events: auto;
  background: var(--ink); color: #fff; padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm); box-shadow: var(--sh-3); font-size: var(--fs-sm);
  animation: toastIn .3s var(--ease-out); border-left: 3px solid var(--brand-accent);
}
.toast.is-out { animation: toastOut .25s var(--ease) forwards; }
.toast-ok { border-left-color: #37D67A; }
.toast-err { border-left-color: #F26F63; }
.toast-warn { border-left-color: #F0B357; }
.toast b { display: block; font-weight: 650; }
.toast span { opacity: .8; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px); } }
@media (max-width: 560px) {
  .toasts { left: var(--sp-3); right: var(--sp-3); bottom: var(--sp-3); max-width: none; }
}

/* ------------------------------ Avatares ------------------------------ */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .01em; flex: none;
  background: var(--brand-primary-light); color: var(--brand-primary); user-select: none;
}
.avatar-lg { width: 52px; height: 52px; font-size: var(--fs-base); }
.avatar-sm { width: 28px; height: 28px; font-size: var(--fs-2xs); }

/* ------------------------------ Utilidades ---------------------------- */
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.col { display: flex; flex-direction: column; }
.wrapf { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--ink-3); }
.muted-2 { color: var(--ink-4); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.bold { font-weight: 650; }
.nums { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-ok { color: var(--ok); } .text-danger { color: var(--danger); } .text-warn { color: var(--warn); }
.mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); } .mt-6 { margin-top: var(--sp-6); }
.mb-3 { margin-bottom: var(--sp-3); } .mb-4 { margin-bottom: var(--sp-4); } .mb-5 { margin-bottom: var(--sp-5); }
.hide { display: none !important; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.divider { height: 1px; background: var(--line); border: 0; margin: var(--sp-5) 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: .35em .75em;
  border: 1px solid var(--line-strong); border-radius: var(--r-full);
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); background: var(--surface);
  cursor: pointer; transition: all var(--t-fast); white-space: nowrap;
}
.chip:hover { border-color: var(--brand-accent); color: var(--brand-primary); }
.chip.is-active { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.chips { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.scroll-x { overflow-x: auto; scrollbar-width: thin; }
.scroll-x::-webkit-scrollbar { height: 6px; }
.scroll-x::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

/* Etiquetas que se ocultan en pantallas angostas (botones de la topbar) */
@media (max-width: 620px) { .hide-sm { display: none; } }
