/* ============================================================================
   Sky Eleven Partners — Portal del socio
   Estilos: premium, sobrio, mobile-first, claro + oscuro (theme-aware).
   ============================================================================ */

/* ---- Paleta y variables (por defecto: OSCURO) ---- */
:root {
  --bg: #0B1220;
  --bg-elev: #0E1626;
  --surface: #131C31;
  --surface-2: #1A2440;
  --text: #E6EAF2;
  --text-muted: #9AA6BF;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  --primary: #2E6BFF;
  --primary-strong: #1E4FD6;
  --cyan: #22D3EE;
  --success: #22C55E;
  --warn: #F59E0B;
  --danger: #EF4444;

  --grad: linear-gradient(120deg, #2E6BFF 0%, #22D3EE 100%);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --radius-sm: 10px;
}

/* ---- Modo claro ---- */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #F7F8FB;
    --bg-elev: #FFFFFF;
    --surface: #FFFFFF;
    --surface-2: #F1F4FA;
    --text: #0B1220;
    --text-muted: #5A6577;
    --border: rgba(11, 18, 32, 0.10);
    --border-strong: rgba(11, 18, 32, 0.18);
    --shadow: 0 10px 30px rgba(11, 18, 32, 0.08);
  }
}
/* Override manual por si algún visor fuerza el tema */
:root[data-theme='dark'] {
  --bg: #0B1220; --bg-elev: #0E1626; --surface: #131C31; --surface-2: #1A2440;
  --text: #E6EAF2; --text-muted: #9AA6BF; --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14); --shadow: 0 10px 30px rgba(0,0,0,0.35);
}
:root[data-theme='light'] {
  --bg: #F7F8FB; --bg-elev: #FFFFFF; --surface: #FFFFFF; --surface-2: #F1F4FA;
  --text: #0B1220; --text-muted: #5A6577; --border: rgba(11,18,32,0.10);
  --border-strong: rgba(11,18,32,0.18); --shadow: 0 10px 30px rgba(11,18,32,0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--primary); }
button { font-family: inherit; }

/* Sin scroll horizontal jamás */
body { overflow-x: hidden; }

/* ---- Utilidades ---- */
.hidden { display: none !important; }
/* Ancho: todo el portal aprovecha la pantalla (hasta 1600px). En celular el tope
   no aplica (la pantalla es más chica) → queda full-width con su padding. */
.container { width: 100%; max-width: 1600px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--text-muted); }
.center { text-align: center; }

/* ---- Botones ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform .06s ease, filter .15s ease, background .15s ease;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.btn-primary { background: var(--grad); border: none; color: #fff; }
.btn-success { background: var(--success); border: none; color: #062012; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; }

/* ---- Wordmark de marca ---- */
.wordmark { display: inline-flex; flex-direction: column; line-height: 1; }
.wordmark .brand {
  font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.wordmark .sub {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.28em;
  text-transform: uppercase; color: var(--text-muted); margin-top: 3px;
}

/* ---- Logo marca / punto ---- */
.brand-dot {
  width: 34px; height: 34px; border-radius: 9px; background: var(--grad);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; flex: 0 0 auto;
}

/* ============================ LOGIN ============================ */
.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 440px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 32px 26px; text-align: center;
}
.login-hero-badge {
  width: 60px; height: 60px; border-radius: 16px; margin: 0 auto 18px;
  background: var(--grad); display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.6rem; font-weight: 800;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 6px; }
.login-card .sub-brand {
  font-size: 0.8rem; letter-spacing: 0.26em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 20px; font-weight: 600;
}
.login-card .pitch { color: var(--text-muted); margin-bottom: 24px; font-size: 0.98rem; }
.login-note {
  margin-top: 18px; font-size: 0.85rem; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.g-icon { width: 18px; height: 18px; }

/* ============================ APP SHELL ============================ */
.appbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.appbar-inner {
  max-width: 1600px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.appbar .who { margin-left: auto; text-align: right; line-height: 1.15; min-width: 0; }
.appbar .who .name { font-weight: 700; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar .who .mail { font-size: 0.75rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Cartel demo */
.demo-banner {
  background: linear-gradient(90deg, rgba(245,158,11,0.16), rgba(245,158,11,0.06));
  border-bottom: 1px solid rgba(245,158,11,0.35);
  color: var(--text); text-align: center; font-size: 0.85rem; font-weight: 600;
  padding: 7px 12px;
}
.demo-banner b { color: var(--warn); }

/* Navegación por pestañas (scroll horizontal en móvil) */
.tabs {
  position: sticky; top: 57px; z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tabs-inner { max-width: 1600px; margin: 0 auto; display: flex; gap: 4px; padding: 6px 10px; min-width: max-content; }
.tab {
  border: none; background: transparent; color: var(--text-muted);
  padding: 10px 14px; border-radius: 10px; font-weight: 600; font-size: 0.9rem;
  cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 8px;
}
.tab.active { background: var(--surface-2); color: var(--text); }
.tab:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
/* Iconitos del menú: los SVG heredan el color del texto; el logo va como imagen. */
.tab-ico { width: 17px; height: 17px; flex: 0 0 auto; fill: currentColor; }
.tab-ico-img { object-fit: contain; border-radius: 4px; }

/* Botón hamburguesa: SOLO en celular (en pantalla grande el menú ya está fijo) */
.btn-menu {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: 0 0 auto;
  background: transparent; border: 1px solid var(--border-strong);
  border-radius: 10px; color: var(--text); cursor: pointer; padding: 0;
}
.btn-menu svg { width: 20px; height: 20px; fill: currentColor; }
.btn-menu:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* ---- CELULAR: el menú es un CAJÓN que entra desde la izquierda ---- */
@media (max-width: 899px) {
  .tabs {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 264px; max-width: 82vw;
    background: var(--bg-elev);
    border-bottom: none; border-right: 1px solid var(--border);
    box-shadow: 6px 0 24px rgba(0,0,0,0.35);
    overflow-y: auto; overflow-x: hidden;
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 60;
  }
  body.menu-abierto .tabs { transform: translateX(0); }
  .tabs-inner {
    flex-direction: column; align-items: stretch;
    gap: 2px; padding: 16px 10px; min-width: 0; max-width: none; margin: 0;
  }
  .tab { width: 100%; text-align: left; justify-content: flex-start; padding: 12px 14px; font-size: 0.95rem; }
  /* Fondo oscuro: aparece con el cajón y se toca para cerrar */
  .menu-fondo {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 55; opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  body.menu-abierto .menu-fondo { opacity: 1; pointer-events: auto; }
  body.menu-abierto { overflow: hidden; }   /* que no scrollee el fondo */
}
/* En pantalla grande no existen ni el botón ni el fondo */
@media (min-width: 900px) {
  .btn-menu, .menu-fondo { display: none; }
}

/* ---- MENÚ LATERAL (pantallas grandes, estilo Master Sky) ----
   En celular NO aplica: ahí el menú es el cajón de arriba. */
@media (min-width: 900px) {
  .shell { display: flex; align-items: flex-start; gap: 0; }
  .tabs {
    position: sticky; top: 57px; align-self: flex-start;
    flex: 0 0 216px; width: 216px;
    height: calc(100vh - 57px);
    border-bottom: none; border-right: 1px solid var(--border);
    overflow-y: auto; overflow-x: hidden;
  }
  .tabs-inner {
    flex-direction: column; align-items: stretch;
    gap: 2px; padding: 14px 10px; min-width: 0; max-width: none; margin: 0;
  }
  .tab { width: 100%; text-align: left; justify-content: flex-start; padding: 11px 13px; }
  main { flex: 1 1 auto; min-width: 0; }
}

main { padding: 22px 0 60px; }
section.view { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view-title { font-size: 1.15rem; margin-bottom: 4px; }
.view-desc { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 18px; }

/* ---- Tarjetas KPI (dashboard) ---- */
.kpi-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 620px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--grad);
}
.kpi.kpi-warn::before { background: var(--warn); }
.kpi .kpi-label { font-size: 0.82rem; color: var(--text-muted); font-weight: 600; }
.kpi .kpi-value { font-size: 1.7rem; font-weight: 800; margin: 6px 0 4px; letter-spacing: -0.02em; }
.kpi .kpi-hint { font-size: 0.78rem; color: var(--text-muted); }

/* ---- Cards genéricas ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 6px; }
@media (min-width: 620px) { .card-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---- Marca card ---- */
.brand-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.brand-card-head h3 { font-size: 1.05rem; }
.brand-card-head .totclients { margin-left: auto; font-size: 0.78rem; color: var(--text-muted); }
.link-row {
  display: flex; gap: 8px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px; align-items: center; margin-bottom: 10px;
}
.link-row .link-text {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.82rem; color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.brand-metrics { display: flex; gap: 18px; margin-top: 4px; }
.brand-metrics .m .v { font-weight: 800; font-size: 1.05rem; }
.brand-metrics .m .k { font-size: 0.74rem; color: var(--text-muted); }
.brand-card.disabled { opacity: 0.55; }
.brand-actions { display: flex; gap: 8px; }
.brand-actions .btn { flex: 1; }

/* ---- Tablas ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; min-width: 520px; }
thead th {
  text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: 700; padding: 12px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { background: var(--surface); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Tablas en CELULAR: se apilan, NUNCA scroll lateral ----
   El scroll horizontal es una trampa: si el usuario no se da cuenta de que la
   tabla se corre, se pierde las últimas columnas — justo donde suele estar el
   dato que importa (ej: "cuánto le falta cobrar"). En pantalla chica cada fila
   pasa a ser una tarjeta con el rótulo al lado de cada valor.
   Se aplica SOLO a las tablas marcadas con .apilable (para no romper las demás),
   y cada <td> tiene que traer su data-label. */
@media (max-width: 640px) {
  .table-wrap.apilable { overflow-x: visible; border: none; box-shadow: none; border-radius: 0; }
  .table-wrap.apilable table { min-width: 0; width: 100%; display: block; }
  .table-wrap.apilable thead { display: none; }           /* los rótulos van por fila */
  .table-wrap.apilable tbody { display: block; }
  .table-wrap.apilable tbody tr {
    display: block; border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 10px; padding: 4px 0; background: var(--surface);
  }
  .table-wrap.apilable tbody tr:last-child { margin-bottom: 0; }
  .table-wrap.apilable tbody td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 14px;
    padding: 7px 13px; border-bottom: none; text-align: right;
  }
  /* El rótulo de la columna, a la izquierda de cada valor */
  .table-wrap.apilable tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto; text-align: left;
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-muted); font-weight: 700;
  }
  /* Si no tiene rótulo (columna de nombre), ocupa todo el ancho y hace de título */
  .table-wrap.apilable tbody td[data-label=""]::before { content: none; }
  .table-wrap.apilable tbody td[data-label=""] {
    justify-content: flex-start; text-align: left; font-weight: 800; font-size: 0.98rem;
    padding-top: 11px; padding-bottom: 9px; border-bottom: 1px solid var(--border);
    margin-bottom: 3px;
  }
  .table-wrap.apilable tbody td.num { text-align: right; }
  /* La fila que se despliega (gráfico + pestañas de una cuenta) NO se apila:
     es un panel entero, no una lista de valores. Va pegada a la tarjeta de
     arriba, sin borde propio ni rótulos. */
  .table-wrap.apilable tbody tr.fila-detalle {
    border: 1px solid var(--border); border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    margin-top: -11px; margin-bottom: 10px; padding: 0;
  }
  .table-wrap.apilable tbody tr.fila-detalle td {
    display: block; padding: 0; text-align: left;
  }
  .table-wrap.apilable tbody tr.fila-detalle td::before { content: none; }
}

/* ---- Chips / badges de estado ---- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 700; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.chip.ok { background: rgba(34,197,94,0.14); color: #34d17f; border-color: rgba(34,197,94,0.3); }
.chip.warn { background: rgba(245,158,11,0.14); color: var(--warn); border-color: rgba(245,158,11,0.3); }
.chip.info { background: rgba(46,107,255,0.14); color: #6f9bff; border-color: rgba(46,107,255,0.3); }
.chip.danger { background: rgba(239,68,68,0.14); color: #ff7a7a; border-color: rgba(239,68,68,0.3); }
.chip.hold { background: rgba(34,211,238,0.12); color: #45c9de; border-color: rgba(34,211,238,0.3); }

/* ---- Liquidaciones ---- */
.payout {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.payout-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.payout-head .period { font-weight: 800; font-size: 1.05rem; }
.payout-lines { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.payout-line { display: flex; justify-content: space-between; font-size: 0.88rem; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.payout-line:last-child { border-bottom: none; }
.payout-totals { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.payout-totals .row { display: flex; justify-content: space-between; font-size: 0.9rem; }
.payout-totals .row.net { font-weight: 800; font-size: 1.05rem; }
.payout-totals .row.debt { color: var(--warn); }

.invoice-box {
  margin-top: 14px; padding: 14px; border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface-2);
}
.invoice-box h4 { margin: 0 0 6px; font-size: 0.95rem; }
.invoice-box .expected { font-size: 1.35rem; font-weight: 800; margin: 8px 0; }
.invoice-box input[type=file] { display: block; width: 100%; margin: 10px 0; color: var(--text-muted); font-size: 0.85rem; }
.invoice-box input[type=file]::file-selector-button {
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 8px 12px; margin-right: 10px; cursor: pointer; font-weight: 600;
}

/* ---- Estado vacío ---- */
.empty { text-align: center; color: var(--text-muted); padding: 40px 16px; }
.empty .big { font-size: 2rem; margin-bottom: 8px; }

/* ============================ MODAL T&C ============================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(3, 7, 18, 0.72);
  display: flex; align-items: center; justify-content: center; padding: 18px;
  backdrop-filter: blur(4px);
}
.modal {
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.modal-head { padding: 20px 22px 12px; }
.modal-head h2 { font-size: 1.25rem; }
.modal-head p { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }
.modal-body { padding: 4px 22px; overflow-y: auto; font-size: 0.9rem; color: var(--text); }
.modal-body h4 { margin: 16px 0 4px; font-size: 0.95rem; }
.modal-body ul { margin: 6px 0; padding-left: 18px; color: var(--text-muted); }
.modal-body li { margin: 4px 0; }
.modal-foot { padding: 16px 22px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.modal-foot .btn { flex: 1; }

/* ============================ TOAST ============================ */
.toast-host {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: calc(100% - 32px); max-width: 420px; pointer-events: none;
}
.toast {
  pointer-events: auto; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 16px; font-size: 0.9rem; font-weight: 600; width: 100%;
  animation: toastIn .2s ease;
}
.toast.ok { border-left: 4px solid var(--success); }
.toast.err { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Spinner de carga ---- */
.loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 60px 16px; color: var(--text-muted); }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border-strong); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Simulador de ingresos (opcional) ---- */
.sim-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.sim-field { flex: 1; min-width: 140px; }
.sim-field label { display: block; font-size: 0.8rem; color: var(--text-muted); font-weight: 600; margin-bottom: 5px; }
.sim-field input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border-strong);
  color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 0.95rem; font-family: inherit;
}
.sim-field input:focus-visible { outline: 3px solid var(--cyan); outline-offset: 1px; }
.sim-result { margin-top: 16px; font-size: 1.4rem; font-weight: 800; }
.sim-result span { background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
