/* ==========================================================================
   INVICTUS · Base: reset, tipografía, componentes compartidos
   ========================================================================== */

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

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg, video { display: block; max-width: 100%; }
img { height: auto; }

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin: 0;
  text-wrap: balance;
}

p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
ul, ol { margin: 0; padding: 0; list-style: none; }
input, select, textarea, button { font-family: inherit; }
[hidden] { display: none !important; }

::selection { background: var(--accent); color: var(--text-inverse); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 99px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #2e2e38; }

/* ------------------------------------------------------------------ */
/* Utilidades                                                          */
/* ------------------------------------------------------------------ */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: clamp(1.1rem, 4vw, 2.5rem);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-cond);
  font-weight: 600;
  font-size: var(--fs-sm);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent-soft);
}
.eyebrow::before {
  content: '';
  width: 24px;
  height: 1px;
  background: currentColor;
  opacity: 0.7;
}

.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.accent { color: var(--accent-soft); }
.mono {
  font-family: var(--font-cond);
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}
.num { font-variant-numeric: tabular-nums; }
.hide-mobile { display: initial; }
.only-mobile { display: none; }
.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: fixed;
  top: 10px;
  left: 10px;
  z-index: 200;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: var(--r-sm);
  font-weight: 700;
  transform: translateY(-160%);
  transition: transform var(--dur) var(--ease);
}
.skip-link:focus { transform: translateY(0); }

/* ------------------------------------------------------------------ */
/* Marca                                                               */
/* ------------------------------------------------------------------ */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.24em;
  font-size: 0.95rem;
  text-transform: uppercase;
  color: var(--text);
}
.logo__img {
  display: block;
  height: 52px;
  width: auto;
}
.logo--sm .logo__img { height: 40px; }
.logo--lg .logo__img { height: 78px; }

/* ------------------------------------------------------------------ */
/* Botones                                                             */
/* ------------------------------------------------------------------ */
.btn {
  --btn-bg: transparent;
  --btn-fg: var(--text);
  --btn-border: var(--line-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.2rem;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-border);
  border-radius: var(--r-sm);
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: transform var(--dur) var(--ease), background var(--dur), border-color var(--dur), color var(--dur), box-shadow var(--dur);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn[disabled], .btn.is-loading { opacity: 0.55; pointer-events: none; }

.btn--primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--text-inverse);
  --btn-border: transparent;
  box-shadow: 0 10px 30px -14px rgba(231, 28, 34, 0.55);
}
.btn--primary:hover { --btn-bg: #c9151c; box-shadow: var(--shadow-accent); }

.btn--ghost:hover { background: rgba(255, 255, 255, 0.06); border-color: var(--line-strong); }
.btn--soft {
  --btn-bg: var(--surface-2);
  --btn-border: var(--line);
}
.btn--soft:hover { --btn-bg: var(--surface-3); }
.btn--danger {
  --btn-fg: #ffb3b3;
  --btn-border: rgba(255, 123, 114, 0.35);
  --btn-bg: rgba(255, 123, 114, 0.08);
}
.btn--danger:hover { background: rgba(255, 123, 114, 0.16); }

.btn--sm { padding: 0.42rem 0.8rem; font-size: 0.82rem; }
.btn--xs { padding: 0.3rem 0.6rem; font-size: 0.74rem; }
.btn--icon {
  width: 38px; height: 38px;
  padding: 0;
  border-radius: var(--r-sm);
  --btn-bg: var(--surface);
  --btn-border: var(--line);
}
.btn--block { width: 100%; }
.btn .ico { width: 16px; height: 16px; }

/* ------------------------------------------------------------------ */
/* Badges / chips                                                      */
/* ------------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.5rem;
  border-radius: var(--r-xs);
  font-family: var(--font-cond);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge--ok { background: var(--ok-wash); border-color: rgba(87, 207, 154, 0.3); color: var(--ok); }
.badge--warn { background: var(--warn-wash); border-color: rgba(240, 180, 90, 0.3); color: var(--warn); }
.badge--danger { background: var(--danger-wash); border-color: rgba(255, 123, 114, 0.3); color: var(--danger); }
.badge--info { background: var(--info-wash); border-color: rgba(127, 182, 255, 0.3); color: var(--info); }
.badge--accent { background: var(--accent-wash); border-color: rgba(231, 28, 34, 0.35); color: var(--accent-soft); }
.badge--violet { background: var(--violet-wash); border-color: rgba(169, 150, 255, 0.3); color: var(--violet); }
.badge--teal { background: var(--teal-wash); border-color: rgba(79, 209, 181, 0.3); color: var(--teal); }
.badge--dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.38rem 0.8rem;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.78rem;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip.is-active { background: var(--accent-wash); border-color: rgba(231, 28, 34, 0.45); color: var(--accent-soft); }

/* ------------------------------------------------------------------ */
/* Tarjetas                                                            */
/* ------------------------------------------------------------------ */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}
.card--flat { background: var(--surface); }
.card--pad-lg { padding: clamp(1.25rem, 2.5vw, 2rem); }
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.card__title { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
.card__sub { font-size: 0.8rem; color: var(--text-3); margin-top: 2px; }

/* ------------------------------------------------------------------ */
/* Formularios                                                         */
/* ------------------------------------------------------------------ */
.field { display: grid; gap: 0.4rem; }
.label {
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.input, .select, .textarea {
  width: 100%;
  padding: 0.72rem 0.9rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color var(--dur), background var(--dur), box-shadow var(--dur);
  appearance: none;
}
.input::placeholder, .textarea::placeholder { color: #6a655e; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: rgba(231, 28, 34, 0.65);
  box-shadow: 0 0 0 3px rgba(231, 28, 34, 0.14);
  background: var(--surface);
}
.textarea { min-height: 96px; resize: vertical; }
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23827d75' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.2rem;
  cursor: pointer;
}
.hint { font-size: 0.76rem; color: var(--text-3); }
.form-error {
  padding: 0.7rem 0.9rem;
  border-radius: var(--r-sm);
  background: var(--danger-wash);
  border: 1px solid rgba(255, 123, 114, 0.3);
  color: #ffb3b3;
  font-size: 0.82rem;
}

/* ------------------------------------------------------------------ */
/* Avatar                                                              */
/* ------------------------------------------------------------------ */
.avatar {
  --av-size: 36px;
  width: var(--av-size);
  height: var(--av-size);
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: calc(var(--av-size) * 0.34);
  letter-spacing: 0.02em;
  color: var(--accent-soft);
  background: radial-gradient(circle at 30% 25%, rgba(231, 28, 34, 0.28), rgba(231, 28, 34, 0.06) 60%), var(--surface-3);
  border: 1px solid rgba(231, 28, 34, 0.22);
  text-transform: uppercase;
}
.avatar--sm { --av-size: 30px; }
.avatar--lg { --av-size: 52px; }
.avatar--xl { --av-size: 72px; }

/* ------------------------------------------------------------------ */
/* Tablas                                                              */
/* ------------------------------------------------------------------ */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  min-width: 720px;
}
.table thead th {
  text-align: left;
  padding: 0.8rem 1rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}
.table tbody td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--dur); }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.table tbody tr[data-click] { cursor: pointer; }

.cell-main { display: flex; align-items: center; gap: 0.7rem; }
.cell-main__name { font-weight: 600; color: var(--text); }
.cell-main__meta { font-size: 0.74rem; color: var(--text-3); }

/* ------------------------------------------------------------------ */
/* Métricas / medidores                                                */
/* ------------------------------------------------------------------ */
.meter {
  height: 6px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
}
.meter--ok .meter__fill { background: linear-gradient(90deg, #2f9e73, var(--ok)); }
.meter--danger .meter__fill { background: linear-gradient(90deg, #b84545, var(--danger)); }

/* ------------------------------------------------------------------ */
/* Tabs                                                                */
/* ------------------------------------------------------------------ */
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  width: fit-content;
  max-width: 100%;
  overflow: auto;
}
.tab {
  padding: 0.45rem 0.95rem;
  border: 0;
  background: transparent;
  border-radius: var(--r-full);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-3);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur);
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-sm); }

/* ------------------------------------------------------------------ */
/* Modales y drawer                                                    */
/* ------------------------------------------------------------------ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(6px);
  animation: fade-in 200ms var(--ease);
}
.modal__panel {
  position: relative;
  width: min(100%, 560px);
  max-height: min(88vh, 780px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  padding: clamp(1.2rem, 3vw, 1.8rem);
  box-shadow: var(--shadow-lg);
  animation: pop-in 260ms var(--ease);
}
.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: var(--s-4);
}
.modal__title { font-size: 1.25rem; }
.modal__sub { font-size: 0.82rem; color: var(--text-3); margin-top: 2px; }
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: var(--s-5);
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: flex;
  justify-content: flex-end;
}
.drawer[hidden] { display: none; }
.drawer__backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  animation: fade-in 200ms var(--ease);
}
.drawer__panel {
  position: relative;
  width: min(100%, 560px);
  height: 100%;
  overflow-y: auto;
  background: var(--bg-soft);
  border-left: 1px solid var(--line-strong);
  padding: clamp(1.2rem, 3vw, 2rem);
  animation: slide-in 320ms var(--ease);
  box-shadow: var(--shadow-lg);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(12px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------------------------ */
/* Toast                                                               */
/* ------------------------------------------------------------------ */
.toast-stack {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 200;
  display: grid;
  gap: 0.5rem;
  width: min(92vw, 360px);
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.8rem 0.95rem;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
  font-size: 0.84rem;
  animation: pop-in 240ms var(--ease);
}
.toast--ok { border-left-color: var(--ok); }
.toast--error { border-left-color: var(--danger); }

/* ------------------------------------------------------------------ */
/* Estados                                                             */
/* ------------------------------------------------------------------ */
.empty {
  display: grid;
  place-items: center;
  gap: 0.5rem;
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-3);
  font-size: 0.86rem;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
}
.empty__icon { font-size: 1.6rem; opacity: 0.7; }

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent-soft);
  animation: spin 800ms linear infinite;
}
.spinner--lg { width: 30px; height: 30px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-screen {
  min-height: 60vh;
  display: grid;
  place-items: center;
  gap: 0.9rem;
  color: var(--text-3);
  font-size: 0.85rem;
}

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */
@media (max-width: 760px) {
  .hide-mobile { display: none !important; }
  .only-mobile { display: initial; }
  .card { padding: var(--s-4); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------------ */
/* Página legal                                                        */
/* ------------------------------------------------------------------ */
.legal-page { background: var(--bg); }
.legal__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1.1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
}
.legal {
  width: min(100% - 2.2rem, 760px);
  margin: clamp(2rem, 5vw, 4rem) auto 3rem;
}
.legal h1 {
  margin-top: 0.6rem;
  font-family: var(--font-head);
  font-size: clamp(2.2rem, 1.6rem + 3vw, 3.6rem);
  font-weight: 700;
  line-height: 0.95;
  text-transform: uppercase;
  letter-spacing: 0.012em;
}
.legal__lead { margin-top: 1rem; color: var(--text-2); font-size: 0.95rem; line-height: 1.65; }
.legal section { margin-top: 2rem; padding-top: 1.6rem; border-top: 1px solid var(--line); }
.legal h2 { font-family: var(--font-cond); font-size: 1.05rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-soft); }
.legal p, .legal li { margin-top: 0.7rem; color: var(--text-2); font-size: 0.9rem; line-height: 1.7; }
.legal ul { padding-left: 1.1rem; }
.legal li { margin-top: 0.35rem; }
.legal a { color: var(--accent-soft); text-decoration: underline; text-underline-offset: 2px; }
.legal code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82em; color: var(--text); background: var(--surface-2); padding: 0.1em 0.35em; border-radius: var(--r-xs); }
.legal__updated { margin-top: 2.2rem; color: var(--text-3); font-size: 0.76rem; }
.legal__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  justify-content: center;
  padding: 1.4rem;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
}
.legal__foot a { color: var(--text-3); }
.legal__foot a:hover { color: var(--text); }

/* ------------------------------------------------------------------ */
/* PWA: instalación y modo offline                                     */
/* ------------------------------------------------------------------ */
.install-help {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 1.2rem;
  background: rgba(4, 4, 6, 0.78);
  backdrop-filter: blur(6px);
}
.install-help__panel {
  position: relative;
  width: min(100%, 400px);
  padding: 1.6rem 1.4rem 1.3rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}
.install-help__panel h2 { margin-top: 0.5rem; font-family: var(--font-head); font-size: 1.8rem; font-weight: 700; line-height: 1; text-transform: uppercase; letter-spacing: 0.01em; }
.install-help__panel ol { margin: 1rem 0 1.2rem; padding-left: 1.2rem; display: grid; gap: 0.55rem; font-size: 0.85rem; color: var(--text-2); line-height: 1.5; }
.install-help__panel strong { color: var(--text); font-weight: 600; }
.install-help__close {
  position: absolute;
  top: 0.55rem; right: 0.6rem;
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.install-help__close:hover { color: var(--text); border-color: var(--line-strong); }

.offline-page { display: grid; place-items: center; min-height: 100svh; }
.offline { width: min(100% - 2.4rem, 560px); text-align: center; padding-block: 2rem; }
.offline .logo { display: inline-flex; margin-bottom: 1.6rem; }
.offline h1 { margin-top: 0.8rem; font-family: var(--font-head); font-size: clamp(2.2rem, 8vw, 3.4rem); font-weight: 700; line-height: 0.95; text-transform: uppercase; }
.offline p { margin-top: 1rem; color: var(--text-2); font-size: 0.92rem; line-height: 1.65; }
.offline__actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; margin-top: 1.6rem; }
.offline__note { font-size: 0.72rem; color: var(--text-3); }
