/* =========================================================================
   Panel de activos — hoja única, sin dependencias externas.
   Modo claro. Toda la paleta sale de las variables de :root.
   ========================================================================= */
:root {
  color-scheme: light;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --surface-3: #e7ecf3;
  --line: #dde3ec;
  --line-soft: #e9edf4;

  --text: #131926;
  --text-2: #3d4757;
  --muted: #6b7688;
  --faint: #97a1b2;

  --accent: #2f56cc;
  --accent-ink: #1e3a94;
  --accent-soft: #eaefff;
  --on-accent: #ffffff;

  --good: #0f7a52;
  --good-soft: #e6f5ee;
  --bad: #c0362b;
  --bad-soft: #fdeceb;
  --warn: #8a5d00;
  --warn-soft: #fdf3e0;

  --shadow-1: 0 1px 2px rgba(19, 25, 38, .06), 0 1px 3px rgba(19, 25, 38, .04);
  --shadow-2: 0 2px 4px rgba(19, 25, 38, .05), 0 8px 20px rgba(19, 25, 38, .06);

  --r-sm: 7px;
  --r: 12px;
  --r-lg: 16px;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; }

::selection { background: var(--accent-soft); }

/* ------------------------------------------------------------- estructura */
header.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  padding: 0 22px; height: 58px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
header.top .brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 650; letter-spacing: -.015em; white-space: nowrap;
}
header.top .brand i {
  width: 22px; height: 22px; border-radius: 6px; display: block;
  background: linear-gradient(135deg, var(--accent), #5b7ff0);
}
header.top nav {
  display: flex; gap: 2px; flex: 1;
  overflow-x: auto; scrollbar-width: none;
}
header.top nav::-webkit-scrollbar { display: none; }
header.top nav a {
  padding: 7px 13px; border-radius: var(--r-sm); color: var(--muted);
  font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .12s, color .12s;
}
header.top nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
header.top nav a.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
header.top .who { color: var(--faint); font-size: 13px; white-space: nowrap; }
header.top .who a { color: var(--muted); }

@media (max-width: 720px) {
  header.top {
    height: auto; flex-wrap: wrap; padding: 10px 16px 0; gap: 10px 14px;
  }
  header.top .brand { order: 1; }
  header.top .who { order: 2; margin-left: auto; }
  header.top nav {
    order: 3; flex-basis: 100%; padding-bottom: 8px;
    /* Se difumina el borde derecho para que se vea que hay más pestañas. */
    mask-image: linear-gradient(90deg, #000 88%, transparent);
  }
}

main { max-width: 1200px; margin: 0 auto; padding: 28px 22px 96px; }

h1 { font-size: 25px; margin: 0 0 3px; letter-spacing: -.025em; font-weight: 660; }
h2 {
  font-size: 13px; margin: 38px 0 13px; font-weight: 640;
  text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
h3 { font-size: 14px; margin: 0 0 10px; color: var(--muted); font-weight: 600; }
p.sub { color: var(--muted); margin: 0 0 22px; font-size: 14.5px; max-width: 68ch; }

.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spread {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 4px;
}

/* --------------------------------------------------------------- tarjetas */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(172px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 17px 18px; box-shadow: var(--shadow-1);
}
.card .k {
  color: var(--muted); font-size: 11.5px; font-weight: 620;
  text-transform: uppercase; letter-spacing: .06em;
}
.card .v {
  font-size: 29px; font-weight: 660; margin-top: 8px;
  letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1;
}
.card .v.sm { font-size: 22px; }
.card .v .unit { font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.card .d { font-size: 13px; margin-top: 7px; color: var(--muted); }
.card.hero {
  grid-column: span 2;
  background:
    radial-gradient(120% 140% at 100% 0%, #f7f9ff 0%, var(--surface) 55%);
  border-color: #d5ddec;
}
@media (max-width: 660px) { .card.hero { grid-column: span 1; } }

.up { color: var(--good); }
.down { color: var(--bad); }
.warn { color: var(--warn); }
.dim { color: var(--muted); }
.faint { color: var(--faint); }

.delta {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 620;
  font-variant-numeric: tabular-nums;
}
.delta.pos { background: var(--good-soft); color: var(--good); }
.delta.neg { background: var(--bad-soft); color: var(--bad); }
.delta.flat { background: var(--surface-2); color: var(--muted); }

/* ---------------------------------------------------------------- tablas */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-1);
}
.panel .pad { padding: 18px; }
.scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th {
  text-align: left; color: var(--muted); font-weight: 620; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 11px 13px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table td {
  padding: 12px 13px; border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table tr:last-child td { border-bottom: 0; }
table td.n, table th.n { text-align: right; font-variant-numeric: tabular-nums; }
table tbody tr { transition: background .1s; }
table tbody tr:hover { background: var(--surface-2); }
tfoot td {
  font-weight: 640; background: var(--surface-2);
  border-top: 1px solid var(--line); border-bottom: 0;
}

/* ------------------------------------------------------------------ chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 620; letter-spacing: .01em;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.chip::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .85;
}
.chip.plain::before { display: none; }
.chip.activo       { color: var(--good); background: var(--good-soft); border-color: #cfe8dd; }
.chip.construccion { color: var(--accent); background: var(--accent-soft); border-color: #d3ddfb; }
.chip.idea         { color: var(--warn); background: var(--warn-soft); border-color: #f0e2c4; }
.chip.pausado, .chip.vendido { color: var(--faint); }

.bar { height: 7px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.bar > span {
  display: block; height: 100%; border-radius: 5px;
  background: linear-gradient(90deg, var(--accent), #5b7ff0);
}
.bar.risk > span { background: linear-gradient(90deg, #d0483c, var(--bad)); }

/* --------------------------------------------------------- ORGANIGRAMA ---
   Árbol de arriba a abajo con conectores dibujados con bordes. En pantalla
   estrecha se convierte en una lista con carril lateral: un árbol horizontal
   en un móvil no se lee.                                                    */
.tree { padding: 26px 4px 8px; min-width: max-content; }
.tree ul {
  display: flex; justify-content: center; align-items: flex-start;
  list-style: none; margin: 0; padding: 34px 0 0; position: relative;
}
.tree li {
  position: relative; padding: 34px 12px 0; text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
/* Las dos mitades del conector horizontal que une a los hermanos. */
.tree li::before, .tree li::after {
  content: ""; position: absolute; top: 0; width: 50%; height: 34px;
  border-top: 2px solid var(--line);
}
.tree li::before { right: 50%; border-right: 2px solid var(--line); }
.tree li::after  { left: 50%; }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:only-child { padding-top: 34px; }
.tree li:first-child::before, .tree li:last-child::after { border: 0; }
.tree li:last-child::before { border-right: 2px solid var(--line); border-radius: 0 8px 0 0; }
.tree li:first-child::after { border-radius: 8px 0 0 0; }
/* Bajante desde el padre hacia la fila de hijos. */
.tree ul::before {
  content: ""; position: absolute; top: 0; left: 50%;
  width: 2px; height: 34px; background: var(--line);
}
.tree > .node-wrap { display: flex; flex-direction: column; align-items: center; }

.node {
  display: block; position: relative; text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-1);
  padding: 13px 15px; min-width: 178px; max-width: 232px;
  transition: box-shadow .15s, transform .15s, border-color .15s;
}
a.node:hover {
  text-decoration: none; box-shadow: var(--shadow-2);
  transform: translateY(-2px); border-color: #c8d3e6;
}
.node .nm {
  font-weight: 640; color: var(--text); letter-spacing: -.012em;
  font-size: 14.5px; display: flex; align-items: center; gap: 7px;
}
.node .meta { font-size: 12px; color: var(--faint); margin-top: 3px; }
.node .amount {
  font-size: 19px; font-weight: 660; margin-top: 9px;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.node .foot {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-soft);
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums;
}
/* Franja de color a la izquierda según el estado. */
.node::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--line);
}
.node.s-activo::before       { background: var(--good); }
.node.s-construccion::before { background: var(--accent); }
.node.s-idea::before         { background: #d9a441; }
.node.s-pausado::before, .node.s-vendido::before { background: var(--faint); }

.node.root {
  background: linear-gradient(135deg, var(--accent), #4468dd);
  border-color: transparent; color: var(--on-accent); min-width: 212px;
  box-shadow: 0 6px 18px rgba(47, 86, 204, .22);
}
.node.root::before { display: none; }
.node.root .nm { color: #fff; font-size: 16px; }
.node.root .meta, .node.root .foot { color: rgba(255, 255, 255, .78); border-color: rgba(255, 255, 255, .2); }
.node.root .amount { color: #fff; font-size: 23px; }

.node.group {
  background: var(--surface-2); border-style: dashed; box-shadow: none;
  min-width: 152px; padding: 10px 14px;
}
.node.group::before { display: none; }
.node.group .nm { font-size: 13px; color: var(--text-2); }
.node.group .amount { font-size: 15px; margin-top: 4px; }

/* Reparto con socios dentro del nodo. */
.split { display: flex; height: 5px; border-radius: 4px; overflow: hidden; margin-top: 9px; background: var(--surface-3); }
.split > i { display: block; height: 100%; background: var(--accent); }

.sparkbox { margin-top: 9px; height: 26px; }
.spark { width: 100%; height: 26px; display: block; }
.spark .ln { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.spark .ar { fill: rgba(47, 86, 204, .09); }
.spark .zr { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }

/* Móvil: el árbol pasa a lista con carril. */
@media (max-width: 780px) {
  .tree, .tree ul { display: block; min-width: 0; padding: 0; }
  .tree ul { padding-left: 20px; margin-top: 10px; border-left: 2px solid var(--line); }
  .tree ul::before { display: none; }
  .tree li {
    display: block; text-align: left; padding: 0 0 0 16px; margin-bottom: 10px;
  }
  .tree li::before, .tree li:last-child::before, .tree li:first-child::after {
    content: ""; display: block; position: absolute;
    left: -20px; top: 26px; width: 20px; height: 2px;
    background: var(--line); border: 0; border-radius: 0;
  }
  .tree li::after { display: none; }
  .node { max-width: none; min-width: 0; width: 100%; }
  .tree > .node-wrap { display: block; }
}

/* ------------------------------------------------------------- formularios */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 550; }
input, select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; font-size: 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:hover, select:hover, textarea:hover { border-color: #ccd5e4; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 86, 204, .13);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input.n { text-align: right; font-variant-numeric: tabular-nums; }
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
.field { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 660px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 17px; font: inherit; font-size: 14px; font-weight: 570;
  background: var(--accent); color: var(--on-accent); border: 1px solid transparent;
  border-radius: var(--r-sm); cursor: pointer;
  box-shadow: var(--shadow-1); transition: background .12s, box-shadow .12s;
}
button:hover, .btn:hover { background: var(--accent-ink); text-decoration: none; color: #fff; }
button:disabled { opacity: .6; cursor: default; }
button.ghost, .btn.ghost {
  background: var(--surface); color: var(--text-2); border-color: var(--line);
}
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); color: var(--text); }
button.tiny, .btn.tiny { padding: 5px 11px; font-size: 12.5px; box-shadow: none; }
button.danger {
  background: var(--surface); color: var(--bad); border-color: var(--line); box-shadow: none;
}
button.danger:hover { background: var(--bad-soft); color: var(--bad); }

details.add > summary {
  cursor: pointer; list-style: none; color: var(--muted); font-size: 14px;
  padding: 13px 2px; user-select: none; font-weight: 550;
  display: flex; align-items: center; gap: 8px;
}
details.add > summary::-webkit-details-marker { display: none; }
details.add > summary::before {
  content: "+"; display: inline-flex; align-items: center; justify-content: center;
  width: 19px; height: 19px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px;
}
details.add > summary:hover { color: var(--text); }
details.add[open] > summary { color: var(--text); }
details.add[open] > summary::before { content: "−"; }

.alert {
  padding: 12px 15px; border-radius: var(--r-sm); font-size: 14px; margin-bottom: 18px;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-1);
}
.alert.ok  { border-color: #cfe8dd; color: var(--good); background: var(--good-soft); }
.alert.err { border-color: #f3ccc8; color: var(--bad); background: var(--bad-soft); }
.alert.tip { border-color: #f0e2c4; color: var(--warn); background: var(--warn-soft); }
.alert a { color: inherit; text-decoration: underline; }

.empty { padding: 44px 22px; text-align: center; color: var(--faint); font-size: 14px; }

/* ---------------------------------------------------------------- gráficos */
.chart { width: 100%; height: 128px; display: block; }
.chart .area { fill: url(#gradArea); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .zero { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; }
/* OJO: no llamar `bar` a este rect. En Chrome las propiedades de geometría
   se pueden fijar desde CSS, y la regla `.bar { height: 7px }` de las barras
   de progreso le pisaba la altura al rect, dejando las columnas flotando. */
.chart .col { fill: var(--accent); }
.chart .col.neg { fill: var(--bad); }
.axis {
  display: flex; justify-content: space-between;
  color: var(--faint); font-size: 11px; margin-top: 8px;
}

/* -------------------------------------------------------------- pantallas */
.center { max-width: 392px; margin: 13vh auto; padding: 0 20px; }
.center .panel { padding: 30px; }
.center h1 { text-align: center; margin-bottom: 4px; }
.center p.sub { text-align: center; margin-bottom: 24px; }
.center .mark {
  width: 42px; height: 42px; border-radius: 11px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), #5b7ff0);
  box-shadow: 0 6px 16px rgba(47, 86, 204, .25);
}

.month-nav {
  display: flex; align-items: center; gap: 3px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 3px; box-shadow: var(--shadow-1);
}
.month-nav a {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 28px; border-radius: 5px; color: var(--muted); font-size: 15px;
}
.month-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.month-nav .now {
  font-weight: 620; min-width: 92px; text-align: center; font-size: 13.5px;
  text-transform: capitalize;
}

.sticky-save {
  position: sticky; bottom: 14px; margin-top: 26px; padding: 14px 18px;
  background: rgba(255, 255, 255, .95); backdrop-filter: saturate(180%) blur(10px);
  border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-2);
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
}
.mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------ texto del copiloto */
.prosa { line-height: 1.65; color: var(--text-2); }
.prosa h3 {
  font-size: 15.5px; color: var(--text); font-weight: 650; letter-spacing: -.01em;
  margin: 26px 0 10px; padding-bottom: 7px; border-bottom: 1px solid var(--line);
  text-transform: none;
}
.prosa h3:first-child { margin-top: 0; }
.prosa h4 { font-size: 14px; margin: 18px 0 6px; color: var(--text); font-weight: 620; }
.prosa p { margin: 0 0 11px; }
.prosa strong { color: var(--text); font-weight: 640; }
.prosa ul, .prosa ol { margin: 0 0 14px; padding-left: 22px; }
.prosa li { margin-bottom: 7px; }
.prosa li::marker { color: var(--faint); }
.prosa code {
  font-family: var(--mono); font-size: .88em;
  background: var(--surface-2); padding: 2px 6px; border-radius: 5px; color: var(--accent-ink);
}
.prosa table { margin: 6px 0 16px; }
.prosa .scroll { border: 1px solid var(--line); border-radius: var(--r-sm); }
.prosa td, .prosa th { font-size: 13px; }

/* Las tarjetas hermanas del árbol comparten altura: si cada una se ajusta a
   su contenido, la fila queda con los bordes inferiores a distinta altura. */
.tree ul { align-items: stretch; }
.tree li > .node { flex: 1; display: flex; flex-direction: column; }
.tree li > .node .foot { margin-top: auto; }

/* Desplegable dentro de una tabla: sin la burbuja del "+", que ahí sobra. */
details.add.inline > summary { padding: 0; font-size: 12.5px; color: var(--accent); }
details.add.inline > summary::before { display: none; }
details.add.inline > summary:hover { text-decoration: underline; }
details.add.inline[open] > summary { margin-bottom: 10px; }

/* En móvil "100 %" se partía en dos líneas dentro de su celda. */
table td.n, table th.n { white-space: nowrap; }

/* Un subelemento se lee como una pieza de su padre, no como un activo más. */
.node.child { min-width: 158px; background: var(--surface-2); }
.node.child .amount { font-size: 16px; }
.node.child .nm { font-size: 13.5px; }
