:root {
  --navy: #071c40;
  --navy-2: #0f2d5c;
  --bg: #f4f6fa;
  --card: #ffffff;
  --texto: #1b2333;
  --muted: #6b7489;
  --borde: #e3e7ef;
  --verde: #15803d;
  --rojo: #b91c1c;
  /* Grafica (paleta validada: azul / naranja; gris para la referencia) */
  --serie-1: #2a78d6;
  --serie-2: #eb6834;
  --referencia: #8a92a5;
  --rejilla: #edf0f5;
  --cero: #b9c0cd;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--texto);
  font-size: 15px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--rojo); }

.btn {
  border: 1px solid var(--borde); background: var(--card); color: var(--texto);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit;
}
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--navy); padding: 16px; }
.login-card {
  background: var(--card); border-radius: 14px; padding: 32px 28px; width: 100%; max-width: 360px;
  text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-card p { margin: 0 0 12px; }
.brand-logo { width: 48px; height: 48px; border-radius: 12px; background: var(--navy); color: #fff; display: grid; place-items: center; flex: none; }
.brand-logo svg { width: 28px; height: 28px; }
.brand-logo.small { width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,.12); }
.brand-logo.small svg { width: 20px; height: 20px; }

/* Estructura: menu lateral + contenido */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: 230px; flex: none; background: var(--navy); color: #fff; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 16px 12px;
}
#sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
#sidebar .brand-text strong { display: block; font-size: 15px; }
#sidebar .brand-text small { opacity: .65; font-size: 12px; }
#mainNav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
#mainNav a, #mainNav .deshabilitado {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: rgba(255,255,255,.85); text-decoration: none; font-size: 14px;
}
#mainNav svg { width: 18px; height: 18px; flex: none; }
#mainNav a:hover { background: rgba(255,255,255,.08); }
#mainNav a.activo { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
#mainNav .deshabilitado { color: rgba(255,255,255,.4); cursor: default; }
#mainNav .deshabilitado small { margin-left: auto; font-size: 11px; border: 1px solid rgba(255,255,255,.25); border-radius: 10px; padding: 1px 7px; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer .user { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 0 6px; }
.sidebar-footer .user img { width: 26px; height: 26px; border-radius: 50%; }
.sidebar-footer .btn { color: #fff; border-color: rgba(255,255,255,.3); align-self: flex-start; margin-left: 6px; }

#vista { flex: 1; min-width: 0; max-width: 1150px; padding: 22px 24px 40px; }
.titulo { font-size: 22px; margin: 0 0 14px; }

.toolbar { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar label { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.toolbar select { font: inherit; font-weight: 400; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--borde); background: var(--card); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--borde); border-radius: 12px; padding: 14px 16px; }
.kpi .etq { color: var(--muted); font-size: 13px; }
.kpi .val { font-size: 24px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.kpi .val.neg { color: var(--rojo); }
.kpi .delta { font-size: 13px; font-variant-numeric: tabular-nums; }

.sube { color: var(--verde); }
.baja { color: var(--rojo); }

.card { background: var(--card); border: 1px solid var(--borde); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 6px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }

/* Grafica */
.leyenda { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.leyenda span, .tooltip div { display: flex; align-items: center; gap: 6px; }
.ln { display: inline-block; width: 18px; height: 0; border-top: 2px solid; }
.ln.serie { border-color: var(--serie-1); }
.ln.anual { border-color: var(--serie-2); border-top-style: dashed; }
.ln.hist { border-color: var(--referencia); border-top-style: dashed; }
.nav-graf { display: flex; align-items: center; gap: 8px; }
.grafica { position: relative; touch-action: pan-y; user-select: none; cursor: grab; }
.grafica:active { cursor: grabbing; }
.grafica svg { display: block; }
.grafica .eje { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.grafica .eje.anio { font-weight: 600; fill: var(--texto); }
.grafica .rejilla { stroke: var(--rejilla); }
.grafica .cero { stroke: var(--cero); }
.grafica .l-serie { fill: none; stroke: var(--serie-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.grafica .l-anual { stroke: var(--serie-2); stroke-width: 2; stroke-dasharray: 6 4; }
.grafica .l-hist { fill: none; stroke: var(--referencia); stroke-width: 2; stroke-dasharray: 3 4; stroke-linejoin: round; }
.grafica .p-sel { fill: var(--serie-1); stroke: #fff; stroke-width: 2; }
.grafica .p-vs { fill: #fff; stroke: var(--serie-1); stroke-width: 2; }
.grafica .p-hover { fill: var(--serie-1); stroke: #fff; stroke-width: 2; pointer-events: none; }
.grafica .cruz { stroke: var(--cero); stroke-width: 1; pointer-events: none; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--borde); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(7,28,64,.12); padding: 8px 10px; font-size: 13px; min-width: 210px;
  display: flex; flex-direction: column; gap: 3px;
}
.tooltip div { justify-content: flex-start; color: var(--muted); }
.tooltip b { margin-left: auto; color: var(--texto); font-variant-numeric: tabular-nums; }

/* Tabla */
.tabla-wrap { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tabla th, .tabla td { padding: 7px 10px; border-bottom: 1px solid var(--borde); text-align: right; white-space: nowrap; }
.tabla th:first-child, .tabla td:first-child { text-align: left; }
.tabla thead th { color: var(--muted); font-weight: 600; font-size: 13px; }
.tabla tr.grupo td { background: #f0f3f8; font-weight: 700; color: var(--navy-2); text-align: left; }
.tabla tr.total td { font-weight: 700; }

/* Gastos extra */
.gastos { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.gastos h3 { font-size: 14px; margin: 0 0 6px; color: var(--muted); }
.gastos ul { list-style: none; margin: 0; padding: 0; }
.gastos li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--borde); font-size: 14px; }
.gastos li span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }

.fuente { margin-top: 8px; }

/* Celular: el menu pasa arriba */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  #sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 16px; }
  #sidebar .brand { padding: 0; }
  #mainNav { flex-direction: row; order: 3; width: 100%; overflow-x: auto; flex: none; }
  #mainNav a, #mainNav .deshabilitado { white-space: nowrap; }
  #mainNav .deshabilitado { display: none; }
  .sidebar-footer { border: 0; padding: 0; margin-left: auto; flex-direction: row; align-items: center; }
  .sidebar-footer .user span { display: none; }
  #vista { padding: 16px; }
  .kpi .val { font-size: 20px; }
}

/* Documentos */
.migas { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14px; flex: 1; min-width: 0; }
.migas a { color: var(--serie-1); text-decoration: none; }
.migas a:hover { text-decoration: underline; }
.migas span:last-child { font-weight: 600; }
.migas .sep { color: var(--muted); font-weight: 400 !important; }
.filtro { font: inherit; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--borde); background: var(--card); min-width: 220px; }
.card.sin-pad { padding: 0; overflow: hidden; }
.docs { list-style: none; margin: 0; padding: 0; }
.docs li { display: flex; align-items: center; border-bottom: 1px solid var(--borde); }
.docs li:last-child { border-bottom: 0; }
.docs li.vacio { padding: 18px 16px; display: block; }
.doc { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: none; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.doc:hover { background: #f6f8fb; }
.doc-icono { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; flex: none; background: #eef2f8; color: var(--navy-2); }
.doc-icono svg { width: 18px; height: 18px; }
.doc-icono.carpeta { background: #e8f0fc; color: var(--serie-1); }
.doc-icono.pdf { background: #fdecec; color: var(--rojo); }
.doc-icono.excel { background: #e7f5ec; color: var(--verde); }
.doc-texto { display: flex; flex-direction: column; min-width: 0; }
.doc-nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-bajar { margin-right: 10px; color: var(--muted); }
.doc-bajar svg { width: 18px; height: 18px; display: block; }

.visor { position: fixed; inset: 0; z-index: 50; background: rgba(7,28,64,.85); display: flex; flex-direction: column; }
.visor-barra { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--navy); color: #fff; }
.visor-barra strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.visor-acciones { display: flex; gap: 8px; }
.visor-acciones .btn { color: #fff; background: transparent; border-color: rgba(255,255,255,.3); }
.visor-medio { flex: 1; min-height: 0; position: relative; display: flex; }
.visor-cuerpo { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.visor-contador { font-size: 13px; opacity: .75; font-variant-numeric: tabular-nums; white-space: nowrap; }
.visor-flecha {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 48px; height: 64px;
  border: 0; border-radius: 10px; background: rgba(7,28,64,.55); color: #fff; font-size: 40px; line-height: 1; cursor: pointer;
}
.visor-flecha:hover { background: rgba(7,28,64,.85); }
.visor-flecha.izq { left: 12px; }
.visor-flecha.der { right: 12px; }
.visor-cuerpo iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.visor-cuerpo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.visor-cuerpo .centro { color: #fff; }
body.sin-scroll { overflow: hidden; }

@media (max-width: 760px) {
  .filtro { min-width: 0; width: 100%; }
  .visor-acciones #visorPestana { display: none; }
}

/* Campo con etiqueta + switch */
.toolbar .campo { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .pista { width: 38px; height: 22px; border-radius: 11px; background: #c9d0dc; position: relative; transition: background .15s; flex: none; }
.switch .pista::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + .pista { background: var(--serie-1); }
.switch input:checked + .pista::after { transform: translateX(16px); }
.switch input:focus-visible + .pista { outline: 2px solid var(--serie-1); outline-offset: 2px; }

/* Selector de mes tipo arbol */
.selector-mes { position: relative; font-weight: 400; }
.sm-boton { font: inherit; display: flex; align-items: center; gap: 10px; justify-content: space-between; min-width: 170px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--borde); background: var(--card); color: var(--texto); cursor: pointer; }
.sm-boton i { font-style: normal; color: var(--muted); font-size: 12px; }
.sm-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; width: 240px; max-height: 340px; overflow-y: auto; background: var(--card); border: 1px solid var(--borde); border-radius: 10px; box-shadow: 0 8px 24px rgba(7,28,64,.14); padding: 6px; }
.sm-anio-btn { width: 100%; display: flex; align-items: center; gap: 8px; padding: 7px 8px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--texto); cursor: pointer; border-radius: 6px; text-align: left; }
.sm-anio-btn:hover { background: #f2f5f9; }
.sm-anio-btn i { font-style: normal; width: 12px; color: var(--muted); font-size: 12px; }
.sm-meses { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 2px 4px 8px 24px; }
.sm-meses.hidden { display: none; }
.sm-mes { font: inherit; font-size: 13px; padding: 6px 0; border: 1px solid var(--borde); border-radius: 6px; background: var(--card); color: var(--texto); cursor: pointer; }
.sm-mes:hover { border-color: var(--serie-1); }
.sm-mes.activo { background: var(--serie-1); border-color: var(--serie-1); color: #fff; font-weight: 600; }
