/* Tablero del equipo. Colores, tipografías, radio y logos salen de /app/static/marca.css (marca/marca.yaml →
   `python -m growth_os marca aplicar`): aquí no hay colores de marca escritos a mano. */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.45 var(--f-text);
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
body::before { /* grano sutil de la marca (forma.textura) */
  content: ''; position: fixed; inset: 0; pointer-events: none; opacity: var(--grain-op, 0); z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.tnum { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── estructura (como el tablero original: riel lateral + contenido) ── */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; position: relative; z-index: 1; }
.layout.collapsed { grid-template-columns: 68px 1fr; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 8px; padding: 18px 12px;
  border-right: 1px solid var(--line); background: var(--surface);
}
.sb-logo { display: flex; align-items: center; gap: 8px; padding: 4px 8px 16px; min-height: 44px; }
.sb-logo .logo { height: 26px; aspect-ratio: var(--logo-ratio); background: var(--logo) left center / contain no-repeat; }
.sb-logo .iso { display: none; width: 30px; aspect-ratio: var(--isotipo-ratio); background: var(--isotipo) center / contain no-repeat; }
.sb-logo .os { font: 600 11px var(--f-label); letter-spacing: .14em; color: var(--muted); }
.collapsed .sb-logo .logo, .collapsed .sb-logo .os, .collapsed .nav-label, .collapsed .collapse-label, .collapsed .user-txt { display: none; }
.collapsed .sb-logo .iso { display: block; }
.sb-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border: 0; background: none; border-radius: var(--r);
  color: var(--text-2); cursor: pointer; text-align: left; position: relative;
}
.nav-item:hover { background: var(--hl); color: var(--text-strong); }
.nav-item.active { background: var(--accent-soft); color: var(--text-strong); }
.nav-item.active::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent); }
.nav-item svg { flex: none; }
.sb-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.collapse-btn, .user-card {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: none; border-radius: var(--r);
  color: var(--muted); cursor: pointer;
}
.collapse-btn:hover, .user-card:hover { background: var(--hl); color: var(--text); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--text-strong); font: 600 12px var(--f-label);
}
.user-txt { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.user-txt b { font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.user-txt small { color: var(--faint); font-size: 11px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar .spacer { flex: 1; }
.content { padding: 22px 28px 96px; max-width: 1480px; width: 100%; }
.page-h { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-h h1 {
  margin: 0; font: 400 30px/1.1 var(--f-display); text-transform: var(--display-case); letter-spacing: -.01em; color: var(--text-strong);
}
.page-h .sub { color: var(--muted); margin-top: 6px; }
.eyebrow { font: 600 11px var(--f-label); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

/* ── controles ── */
.seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 12px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line-soft); }
.seg button:hover { background: var(--hl); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.sel, .inp {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 7px 10px; color: var(--text);
}
.sel { padding-right: 28px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--r); padding: 7px 12px; cursor: pointer; color: var(--text);
}
.btn:hover { border-color: var(--line-strong); }
.btn.primary { background: var(--btn-bg); color: var(--btn-ink); border-color: transparent; }
.btn.primary:hover { background: var(--btn-hover); }
.btn.icon { padding: 7px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line); color: var(--text-2); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.chip.mute { color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

.banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; margin-bottom: 16px; border-radius: var(--r);
  border: 1px solid var(--warn); background: var(--warn-bg); color: var(--text);
}
.banner.err { border-color: var(--bad); background: var(--bad-bg); }
.banner b { color: var(--text-strong); font-weight: 600; }

/* ── tarjetas ── */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 14px; }
/* 6 tarjetas: 6 en una fila, 3 + 3 o 2 + 2 + 2, nunca una sola abajo */
.kpis.n6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 1280px) { .kpis.n6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.cols-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.cols-eq { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: calc(var(--r) * 1.6); padding: 16px 18px;
  min-width: 0; position: relative;
}
.card h3 { margin: 0 0 12px; font: 600 11px var(--f-label); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.card h3 .r { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; font-family: var(--f-text); }
.kpi { display: flex; flex-direction: column; gap: 6px; position: relative; min-width: 0; }

.kpi.norte { border-color: var(--accent-line); }
.kpi .lbl { font: 500 12px var(--f-label); color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .val { font: 400 clamp(22px, 1.7vw + 8px, 30px)/1.1 var(--f-display); color: var(--text-strong); letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.kpi .val.na { color: var(--faint); }
.kpi .foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); min-height: 20px; flex-wrap: wrap; }
.kpi .spark { margin-left: auto; opacity: .9; flex: none; }
.delta { font-size: 12px; font-weight: 500; }
.delta.up { color: var(--ok); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }
.info { cursor: help; color: var(--faint); display: inline-grid; place-items: center; width: 14px; height: 14px; border: 1px solid currentColor; border-radius: 50%; font: 600 9px var(--f-text); }
.state { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.state.ok { background: var(--ok); } .state.aviso { background: var(--warn); } .state.malo { background: var(--bad); }

/* ── tablas ── */
.tbl-wrap { overflow: auto; margin: 0 -18px -16px; border-top: 1px solid var(--line-soft); max-height: 70vh; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line-soft); }
th:first-child, td:first-child { text-align: left; padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
td.l, th.l { text-align: left; }
td.l { white-space: normal; min-width: 240px; max-width: 460px; line-height: 1.35; }
td { font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; background: var(--surface); z-index: 1; font: 600 11px var(--f-label); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); cursor: pointer; user-select: none; }
th.sorted { color: var(--text-strong); }
tbody tr:hover { background: var(--hl); }
tbody tr.click { cursor: pointer; }
td .nm { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: normal;
  overflow-wrap: anywhere; vertical-align: bottom; }
td .sub { color: var(--faint); font-size: 12px; display: block; }
.thumb { width: 36px; height: 36px; border-radius: calc(var(--r) * .7); object-fit: cover; background: var(--sunken); vertical-align: middle; margin-right: 10px; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.bar-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar-cell i { display: block; height: 6px; border-radius: 3px; background: var(--accent); opacity: .75; }

/* ── gráficas ── */
.chart { width: 100%; height: 240px; display: block; }
.chart text { fill: var(--muted); font: 11px var(--f-text); }
.chart .grid line { stroke: var(--line-soft); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.tip {
  position: fixed; pointer-events: none; z-index: 50; background: var(--surface-solid); border: 1px solid var(--line-strong);
  border-radius: var(--r); padding: 8px 10px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); min-width: 140px;
}
.tip b { display: block; color: var(--text-strong); margin-bottom: 4px; }
.tip div { display: flex; justify-content: space-between; gap: 14px; }
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel .st { display: grid; grid-template-columns: minmax(64px, 112px) minmax(36px, 1fr) auto 44px; align-items: center; gap: 10px; }
.funnel .st > * { min-width: 0; }
.funnel .n { font-variant-numeric: tabular-nums; }
.funnel .track { background: var(--sunken); border-radius: var(--r); height: 26px; overflow: hidden; }
.funnel .st .b { height: 100%; border-radius: var(--r); background: var(--accent); opacity: .85; }
.funnel .n { text-align: right; color: var(--text-strong); font-weight: 500; }
.funnel .st:nth-child(n+3) .b { opacity: .7; }
.funnel .st:nth-child(n+5) .b { opacity: .55; }
.funnel .cv { color: var(--muted); font-size: 12px; text-align: right; }

/* ── login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; z-index: 1; }
.login .box { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: calc(var(--r) * 2); padding: 32px; display: flex; flex-direction: column; gap: 14px; }
.login .logo { height: 34px; aspect-ratio: var(--logo-ratio); background: var(--logo) left center / contain no-repeat; }
.login h1 { margin: 6px 0 0; font: 400 28px/1.1 var(--f-display); text-transform: var(--display-case); color: var(--text-strong); }
.login form { display: flex; flex-direction: column; gap: 10px; }
.login .or { text-align: center; color: var(--faint); font-size: 12px; }
.login .err { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ── modal ── */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; display: grid; place-items: center; padding: 20px; }
.modal { width: min(620px, 100%); max-height: 86vh; overflow: auto; background: var(--surface-solid); border: 1px solid var(--line-strong); border-radius: calc(var(--r) * 1.8); padding: 22px; }
.modal h2 { margin: 0 0 4px; font: 400 24px var(--f-display); color: var(--text-strong); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; margin-top: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

.loading { padding: 60px 0; text-align: center; color: var(--muted); }
/* carga: el logo de la marca respira y las tarjetas se insinúan, sin saltos al llegar los datos */
.cargando { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 26px 0 22px; font-size: 13px; }
.cargando.inicial { min-height: 100vh; justify-content: center; }
.logo.pulso { height: 34px; aspect-ratio: var(--logo-ratio); background: var(--logo) center / contain no-repeat;
  animation: pulso 1.6s ease-in-out infinite; }
@keyframes pulso { 0%, 100% { opacity: .35; transform: scale(.97); } 50% { opacity: 1; transform: scale(1); } }
.esq { min-height: 118px; background: linear-gradient(100deg, var(--surface) 30%, var(--sunken) 50%, var(--surface) 70%);
  background-size: 300% 100%; animation: brillo 1.8s ease-in-out infinite; }
.esq.alto { min-height: 280px; margin-top: 14px; }
@keyframes brillo { from { background-position: 100% 0; } to { background-position: 0 0; } }
#root > * { animation: aparecer .18s ease-out; }
@keyframes aparecer { from { opacity: .4; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .logo.pulso, .esq, #root > * { animation: none; } }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.syncbar { height: 2px; background: transparent; overflow: hidden; }
.syncbar.on::after { content: ''; display: block; height: 100%; width: 40%; background: var(--accent); animation: sync 1s ease-in-out infinite; }
@keyframes sync { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

.mobilenav { display: none; }
@media (max-width: 900px) {
  .layout, .layout.collapsed { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 96px; }
  .cols-2, .cols-eq { grid-template-columns: 1fr; }
  .kpis, .kpis.n6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .val { font-size: 24px; }
  .kpi .spark { display: none; }
  .topbar .seg { order: 5; width: 100%; }
  .funnel .st { grid-template-columns: 90px 1fr 70px 44px; gap: 8px; }
  .mobilenav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); overflow-x: auto;
  }
  .mobilenav button { flex: 1; min-width: 64px; border: 0; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; padding: 4px; }
  .mobilenav button.on { color: var(--text-strong); }
  .kv { grid-template-columns: 1fr; }
}
