/* NexoFina · sistema de diseño
   Reglas: contraste AA, objetivos táctiles ≥ 44 px, foco visible, respeta "reducir movimiento",
   una sola familia tipográfica del sistema (carga instantánea, sin fuentes externas).
   Todo es claro por defecto; el modo oscuro solo entra de noche (según el sistema) o si la persona lo elige. */

:root {
  color-scheme: dark;
  --bg: #0a0d0b;
  --bg-2: #0e1210;
  --surface: #131815;
  --surface-2: #1a211d;
  --surface-3: #242d27;
  --line: rgba(255, 255, 255, 0.075);
  --line-2: rgba(255, 255, 255, 0.15);
  --text: #f1f4ee;
  --text-2: #a9b3aa;
  --text-3: #7f8a81;
  --lime: #d4f25a;
  --lime-2: #c3e345;
  --lime-ink: #161c05;
  --lime-soft: rgba(212, 242, 90, 0.12);
  --accent: #d4f25a;
  --primary-bg: #d4f25a;
  --primary-hover: #c3e345;
  --primary-ink: #161c05;
  --ok: #7ddfa6;
  --ok-soft: rgba(125, 223, 166, 0.13);
  --warn: #f2d266;
  --warn-soft: rgba(242, 210, 102, 0.13);
  --danger: #ff7d6e;
  --danger-soft: rgba(255, 125, 110, 0.13);
  /* Series de gráficas (validadas para daltonismo sobre superficie oscura) */
  --series-1: #7fa41c;
  --series-2: #4d8be6;
  --series-3: #d9609f;
  --series-muted: #7f8a81;
  --chart-line: #eef2e6;
  --chart-area: rgba(212, 242, 90, 0.22);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 9px;
  --font: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1ec;
  --bg-2: #f4f6f1;
  --surface: #ffffff;
  --surface-2: #f1f4ee;
  --surface-3: #e4e8df;
  --line: rgba(18, 28, 16, 0.09);
  --line-2: rgba(18, 28, 16, 0.19);
  --text: #121812;
  --text-2: #465046;
  --text-3: #667066;
  --lime-soft: rgba(150, 190, 20, 0.16);
  --accent: #4a7300;
  --primary-bg: #141a12;
  --primary-hover: #262f21;
  --primary-ink: #dcf772;
  --ok: #0f7a4d;
  --ok-soft: rgba(15, 122, 77, 0.1);
  --warn: #855f00;
  --warn-soft: rgba(133, 95, 0, 0.1);
  --danger: #c2372b;
  --danger-soft: rgba(194, 55, 43, 0.09);
  --series-1: #5f8f00;
  --series-2: #1b7fd0;
  --series-3: #b5459f;
  --series-muted: #8a938a;
  --chart-line: #161b12;
  --chart-area: rgba(160, 205, 30, 0.3);
  --shadow: 0 18px 44px rgba(18, 28, 16, 0.14);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body::before { /* brillo de fondo suave, fijo */
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 520px at 18% -12%, rgba(212, 242, 90, 0.09), transparent 60%),
    radial-gradient(760px 480px at 100% 0%, rgba(77, 139, 230, 0.08), transparent 60%);
  pointer-events: none;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.55rem, 2.6vw, 2rem); font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; }
h2 { font-size: 1.02rem; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 0.95rem; font-weight: 600; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 0.82rem; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

.icon { flex: none; display: block; }

/* ------------------------------ Botones ------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary-bg); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.lime { background: var(--lime); color: var(--lime-ink); }
.btn.lime:hover { background: var(--lime-2); }
.btn.ghost { background: transparent; border-color: var(--line-2); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.soft { background: var(--surface-2); color: var(--text); }
.btn.soft:hover { background: var(--surface-3); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { min-height: 36px; padding: 0 14px; font-size: 0.84rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.busy { cursor: progress; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-2);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-2); }
.icon-btn.sm { width: 36px; height: 36px; }
.icon-btn.plain { background: transparent; border-color: transparent; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* ------------------------------ Superficies ------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  min-width: 0;
}
.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card-head > .grow { flex: 1; min-width: 0; }
.card-head p { color: var(--text-3); font-size: 0.8rem; margin-top: 1px; }
.card-ic { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); flex: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.accent { background: var(--lime-soft); color: var(--accent); }
.chip.lime { background: var(--lime); color: var(--lime-ink); }

/* Selector segmentado y filtros en pastilla */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 0; border-radius: 999px; background: transparent;
  color: var(--text-2); font-weight: 600; font-size: 0.84rem; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--lime); color: var(--lime-ink); }
.seg.quiet button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.form > .seg, .field > .seg, .card > .seg { justify-self: start; }

/* Pestañas subrayadas (dentro de una página) */
.subtabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.subtabs button { min-height: 42px; padding: 0 2px; border: 0; background: none; color: var(--text-3); font-weight: 600; font-size: 0.9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.subtabs button:hover { color: var(--text); }
.subtabs button[aria-pressed="true"] { color: var(--text); border-bottom-color: var(--text); }

/* ------------------------------ Formularios ------------------------------ */
.field { display: grid; gap: 6px; min-width: 0; }
.field label { font-size: 0.8rem; font-weight: 600; color: var(--text-2); }
.hint { color: var(--text-3); font-size: 0.78rem; }
.input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--bg-2);
  color: var(--text);
  font-size: 16px; /* evita el zoom automático de iOS al enfocar */
}
textarea.input { padding: 10px 14px; min-height: 76px; resize: vertical; }
.input::placeholder { color: var(--text-3); }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
select.input { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input.big { min-height: 60px; font-size: 1.6rem; font-weight: 600; letter-spacing: -0.02em; }
.form { display: grid; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--series-1); flex: none; }
.form-error { padding: 10px 14px; border-radius: var(--r-md); background: var(--danger-soft); color: var(--danger); font-weight: 600; font-size: 0.88rem; }

/* Interruptor */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 0.85rem; color: var(--text-2); }
.switch input { position: absolute; opacity: 0; width: 46px; height: 28px; margin: 0; cursor: pointer; }
.switch i { width: 46px; height: 28px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line-2); position: relative; transition: background 0.15s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text-2); transition: transform 0.15s, background 0.15s; }
.switch input:checked + i { background: var(--lime); border-color: transparent; }
.switch input:checked + i::after { transform: translateX(18px); background: var(--lime-ink); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------ Diálogos ------------------------------ */
.dlg {
  width: min(520px, calc(100vw - 24px));
  max-height: min(88dvh, 860px);
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.dlg[open] { display: flex; flex-direction: column; }
.dlg.wide { width: min(760px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(4, 8, 5, 0.66); backdrop-filter: blur(3px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 12px 22px; }
.dlg-title { font-size: 1.1rem; }
.dlg-body { padding: 4px 22px 20px; overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 0; }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; padding: 14px 22px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.dlg-foot:empty { display: none; }
@media (max-width: 640px) {
  .dlg, .dlg.wide { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; border-width: 1px 0 0; max-height: 92dvh; }
  .dlg-foot .btn { flex: 1; }
  .row, .row3 { grid-template-columns: 1fr; }
  .row.keep { grid-template-columns: 1fr 1fr; }
}

/* ------------------------------- Avisos ------------------------------- */
.toasts { position: fixed; inset: auto auto calc(92px + env(safe-area-inset-bottom)) 50%; transform: translateX(-50%); z-index: 2147483647; display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); margin: 0; padding: 0; border: 0; background: transparent; color: inherit; overflow: visible; pointer-events: none; }
.toasts:empty { display: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--r-md); background: var(--surface-3); border: 1px solid var(--line-2); box-shadow: var(--shadow); font-weight: 600; font-size: 0.9rem; animation: rise 0.2s ease-out; }
.toast.ok .icon { color: var(--ok); }
.toast.error .icon { color: var(--danger); }
.toast.warn .icon { color: var(--warn); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.empty { display: grid; gap: 8px; justify-items: center; text-align: center; padding: 36px 16px; color: var(--text-2); }
.empty strong { color: var(--text); font-size: 1rem; }

/* ------------------------------- Tablas ------------------------------- */
.table-wrap { overflow-x: auto; position: relative; } /* el texto .sr-only de las tablas es absoluto; sin esto escapa del scroll y ensancha toda la página */
table.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th { text-align: left; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; font-variant-numeric: tabular-nums; }

/* Marca */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.08rem; letter-spacing: -0.02em; color: var(--text); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; overflow: hidden; flex: none; }
.brand-mark img, .brand-mark .logo { display: block; width: 100%; height: 100%; }
.brand b, .wordmark b { color: var(--accent); font-weight: 800; }
.brand small { display: block; font-weight: 500; font-size: 0.72rem; letter-spacing: 0; color: var(--text-3); }

.spinner { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

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