/* Metrify web: mismo lenguaje visual que la app de Mac (fondo gris claro, tarjetas blancas,
   esquinas continuas, colores por tipo de dato). Modo oscuro automático. */

:root {
  --fondo: #F4F5F7;
  --tarjeta: #FFFFFF;
  --grafito: #1D1F23;
  --lateral: #E9EAEE;
  --texto: #1D1D1F;
  --texto2: #6E6E73;
  --texto3: #A1A1A6;
  --linea: rgba(0, 0, 0, 0.08);
  --linea2: rgba(0, 0, 0, 0.14);
  --resalte: rgba(0, 0, 0, 0.04);
  --seleccion: rgba(0, 122, 255, 0.08);

  --dinero: #28A745;
  --gasto: #007AFF;
  --reembolso: #FF3B30;
  --pendiente: #E6B800;
  --cancelado: #FF9500;
  --clientes: #30B0C7;
  --clics: #64738C;
  --tiempo: #32ADE6;

  --radio: 20px;
  --radio-chico: 10px;
  --sombra: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --letra: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0F1012;
    --tarjeta: #1C1C1E;
    --grafito: #292B30;
    --lateral: #161719;
    --texto: #F5F5F7;
    --texto2: #A1A1A6;
    --texto3: #6E6E73;
    --linea: rgba(255, 255, 255, 0.08);
    --linea2: rgba(255, 255, 255, 0.16);
    --resalte: rgba(255, 255, 255, 0.05);
    --seleccion: rgba(10, 132, 255, 0.16);
    --dinero: #30D158;
    --gasto: #0A84FF;
    --reembolso: #FF453A;
    --pendiente: #FFD60A;
    --cancelado: #FF9F0A;
    --clientes: #40C8E0;
    --clics: #8E9BB0;
    --tiempo: #64D2FF;
    --sombra: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--letra);
  font-size: 14px;
  color: var(--texto);
  background: var(--fondo);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.lateral {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--lateral); border-right: 0.5px solid var(--linea);
  padding: 18px 12px;
}
.marca { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-size: 19px; font-weight: 650; }
.marca img { width: 30px; height: 30px; }
#menu a, .submenu a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin: 2px 0;
  border-radius: 10px; color: var(--texto); text-decoration: none; font-size: 15px;
}
#menu a:hover { background: var(--resalte); }
#menu a.activa { background: var(--grafito); color: #fff; font-weight: 600; }
#menu a.pronto { color: var(--texto3); pointer-events: none; }
#menu a.pronto small { margin-left: auto; font-size: 11px; }
#menu .grupo { font-size: 11px; font-weight: 600; color: var(--texto3); padding: 16px 12px 4px; text-transform: none; }
.ico { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.cuerpo { min-width: 0; display: flex; flex-direction: column; }
.barra {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 28px; background: color-mix(in srgb, var(--fondo) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--linea);
}
.titulo h1 { margin: 0; font-size: 18px; font-weight: 650; }
.titulo p { margin: 2px 0 0; font-size: 12px; color: var(--texto2); }
.controles { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.boton {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px;
  border-radius: 999px; border: 0.5px solid var(--linea2); background: var(--tarjeta);
  font-size: 13px; font-weight: 500; white-space: nowrap;
}
.boton:hover { background: var(--resalte); }
.boton.icono-solo { width: 34px; padding: 0; justify-content: center; }
.boton .ico { width: 17px; height: 17px; }
.boton.primario { background: var(--grafito); color: #fff; border-color: transparent; }
.boton.peligro { color: var(--reembolso); }
.cuadro { width: 12px; height: 12px; border-radius: 3px; flex: none; }

#vista { padding: 24px 28px 48px; outline: none; }
.aviso { margin: 16px 28px 0; padding: 10px 14px; border-radius: 12px; background: color-mix(in srgb, var(--cancelado) 14%, var(--tarjeta)); color: var(--texto); font-size: 13px; }

/* ---------- Tarjetas y cifras ---------- */
.tarjeta { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 18px 20px; min-width: 0; }
.tarjeta.oscura { background: var(--grafito); color: #fff; }
.tarjeta.oscura .etiqueta, .tarjeta.oscura .detalle { color: rgba(255, 255, 255, 0.65); }
.rejilla { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.rejilla.seis { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
.seccion { margin-top: 22px; }
.seccion > h2, .encabezado-seccion h2 { font-size: 16px; font-weight: 650; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.encabezado-seccion { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.encabezado-seccion h2 { margin: 0; }
.encabezado-seccion small { color: var(--texto2); font-weight: 400; font-size: 13px; }

.indicador { display: flex; flex-direction: column; gap: 8px; }
.indicador .arriba { display: flex; justify-content: space-between; align-items: center; }
.indicador .etiqueta { font-size: 13px; color: var(--texto2); }
.indicador .simbolo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; }
.indicador .simbolo .ico { width: 16px; height: 16px; stroke-width: 2.2; }
.indicador .valor { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.indicador .detalle { font-size: 12px; color: var(--texto2); min-height: 1em; }
.verde { color: var(--dinero); } .rojo { color: var(--reembolso); } .azul { color: var(--gasto); } .gris { color: var(--texto2); }
sup.adic { font-size: 0.62em; color: var(--texto2); margin-left: 1px; font-weight: 600; }

/* ---------- Segmentos y pastillas ---------- */
.segmentos { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--tarjeta); box-shadow: var(--sombra); flex-wrap: wrap; }
.segmentos button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; font-size: 13px; color: var(--texto2); }
.segmentos button.activo { background: var(--grafito); color: #fff; font-weight: 600; }
.pastillas { display: flex; gap: 8px; flex-wrap: wrap; }
.pastilla {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 14px; border-radius: 999px;
  border: 0; background: var(--tarjeta); box-shadow: var(--sombra); font-size: 13px; font-weight: 500;
}
.pastilla.activa { background: var(--grafito); color: #fff; }
.pastilla .cuenta { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--resalte); }
.pastilla.activa .cuenta { background: rgba(255, 255, 255, 0.18); }
.pastilla .cerrar { opacity: 0.7; }
.insignia { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--resalte); white-space: nowrap; }
.insignia::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.9; }
.insignia.sin-punto::before { display: none; }

/* ---------- Tabla al estilo del Administrador de anuncios ---------- */
.caja-tabla { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); overflow: hidden; }
.desliza { overflow: auto; max-height: calc(100vh - 220px); }
table.tabla { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.tabla th, .tabla td { padding: 0 12px; height: 50px; white-space: nowrap; border-bottom: 0.5px solid var(--linea); border-right: 0.5px solid var(--linea); text-align: right; font-variant-numeric: tabular-nums; }
.tabla th:last-child, .tabla td:last-child { border-right: 0; }
.tabla thead th {
  position: sticky; top: 0; z-index: 3; background: var(--tarjeta); height: auto; padding: 10px 12px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--texto2); text-align: center; vertical-align: middle; cursor: pointer; user-select: none;
}
.tabla thead tr.grupos th { padding-bottom: 4px; cursor: default; }
.tabla thead tr.grupos th.con-grupo { border-bottom: 0.5px solid var(--linea2); }
.tabla thead tr.grupos + tr th { top: 30px; }
.tabla thead th small { display: block; font-size: 9.5px; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--texto3); margin-top: 2px; white-space: normal; }
.tabla thead th.orden { color: var(--texto); }
.tabla th.izq, .tabla td.izq { text-align: left; }
.tabla td.tenue { color: var(--texto2); }
.tabla tbody tr:hover td { background: var(--resalte); }
.tabla tbody tr.marcada td { background: var(--seleccion); }
.tabla tfoot td { position: sticky; bottom: 0; background: var(--tarjeta); font-weight: 600; height: 56px; border-top: 0.5px solid var(--linea2); border-bottom: 0; vertical-align: top; padding-top: 10px; }
.tabla tfoot td small { display: block; font-weight: 400; font-size: 11px; color: var(--texto3); }
.tabla .fija { position: sticky; z-index: 2; background: var(--tarjeta); }
.tabla thead .fija { z-index: 4; }
.tabla td.fija.ultima, .tabla th.fija.ultima { box-shadow: 1px 0 0 var(--linea2); }
.tabla .casilla { width: 42px; min-width: 42px; max-width: 42px; text-align: center; padding: 0; }
.tabla .interruptor-celda { width: 74px; min-width: 74px; max-width: 74px; padding: 0 12px 0 0; text-align: right; }
.zona-solo { position: absolute; left: -8px; top: 0; bottom: 0; width: 38px; cursor: default; }
.tabla .nombre { text-align: left; min-width: 260px; max-width: 360px; }
.nombre-linea { display: flex; align-items: center; gap: 6px; }
.nombre-linea a { color: var(--texto); text-decoration: none; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.nombre-linea a:hover { color: var(--gasto); text-decoration: underline; }
.nombre-sub { font-size: 11.5px; color: var(--texto2); overflow: hidden; text-overflow: ellipsis; }
.lapiz { visibility: hidden; border: 0; background: var(--resalte); width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; padding: 0; }
.lapiz .ico { width: 12px; height: 12px; }
tr:hover .lapiz { visibility: visible; }
.presupuesto-celda { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.presupuesto-celda small { display: block; font-size: 10.5px; color: var(--texto2); }
.miniatura { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; background: var(--resalte); flex: none; }

input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--grafito); cursor: pointer; }
.interruptor { position: relative; display: inline-block; width: 38px; height: 22px; }
.interruptor input { opacity: 0; width: 0; height: 0; position: absolute; }
.interruptor span { position: absolute; inset: 0; background: var(--linea2); border-radius: 999px; transition: 0.2s; cursor: pointer; }
.interruptor span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: 0.2s; }
.interruptor input:checked + span { background: var(--gasto); }
.interruptor input:checked + span::after { transform: translateX(16px); }
.interruptor.ocupado span { opacity: 0.4; }

.buscar { height: 34px; border-radius: 999px; border: 0.5px solid var(--linea2); background: var(--tarjeta); padding: 0 14px; min-width: 200px; }

/* ---------- Gráficas ---------- */
.grafica svg { width: 100%; height: auto; display: block; overflow: visible; }
.grafica text { font-size: 10px; fill: var(--texto3); }
.leyenda { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--texto2); }
.leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.leyenda i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ---------- Listas ---------- */
.lista { display: flex; flex-direction: column; }
.lista .fila { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 0.5px solid var(--linea); }
.lista .fila:last-child { border-bottom: 0; }
.lista .fila .crece { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barrita { height: 5px; border-radius: 999px; background: var(--resalte); width: 110px; flex: none; overflow: hidden; }
.barrita i { display: block; height: 100%; border-radius: 999px; }

.desplegable > button.cabeza { width: 100%; display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 0; text-align: left; }
.desplegable .flecha { margin-left: 8px; width: 26px; height: 26px; border-radius: 50%; background: var(--resalte); display: grid; place-items: center; transition: transform 0.25s; }
.desplegable.abierta .flecha { transform: rotate(180deg); }

.vacio { text-align: center; padding: 48px 16px; color: var(--texto2); }
.vacio .ico { width: 40px; height: 40px; color: var(--texto3); margin-bottom: 10px; }
.cargando { display: grid; place-items: center; padding: 64px; color: var(--texto2); gap: 12px; }
.girador { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--linea2); border-top-color: var(--texto2); animation: girar 0.8s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }
.punto-vivo { width: 9px; height: 9px; border-radius: 50%; background: var(--dinero); display: inline-block; animation: latir 1.6s ease-in-out infinite; }
@keyframes latir { 50% { opacity: 0.3; } }

/* ---------- Ventanitas (periodo, filtro, editar) ---------- */
.capa { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.18); display: grid; place-items: start center; padding: 72px 16px 16px; overflow-y: auto; }
.ventana { background: var(--tarjeta); border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); width: min(560px, 100%); padding: 20px; }
.ventana h3 { margin: 0 0 4px; font-size: 16px; }
.ventana p.nota { margin: 0 0 14px; font-size: 12px; color: var(--texto2); }
.ventana .acciones { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.ventana input[type="text"], .ventana input[type="number"], .ventana input[type="date"] {
  width: 100%; height: 36px; border-radius: 9px; border: 0.5px solid var(--linea2); background: var(--fondo); padding: 0 12px;
}
.ventana .error { color: var(--reembolso); font-size: 12px; margin-top: 8px; }
.opciones-periodo { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.opciones-periodo button, .opcion-filtro {
  border: 0; background: var(--fondo); border-radius: 10px; padding: 10px 12px; text-align: left; font-size: 13px;
  display: flex; align-items: center; gap: 10px;
}
.opciones-periodo button.activa, .opcion-filtro.activa { background: var(--grafito); color: #fff; }
.fechas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.fechas label { font-size: 12px; color: var(--texto2); display: grid; gap: 4px; }

/* ---------- Celular ---------- */
.pestanas-movil { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .lateral { display: none; }
  .barra { padding: 12px 16px; }
  #vista { padding: 16px 16px 96px; }
  .aviso { margin: 12px 16px 0; }
  .rejilla { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .rejilla.seis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tarjeta { padding: 14px; border-radius: 16px; }
  .indicador .valor { font-size: 22px; }
  .tabla .nombre { min-width: 180px; max-width: 220px; }
  .desliza { max-height: none; }
  .buscar { min-width: 0; flex: 1; }
  .barrita { width: 60px; }
  .pestanas-movil {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: color-mix(in srgb, var(--tarjeta) 92%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--linea); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .pestanas-movil a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; color: var(--texto2); text-decoration: none; padding: 4px 0; }
  .pestanas-movil a.activa { color: var(--gasto); font-weight: 600; }
  .pestanas-movil .ico { width: 22px; height: 22px; }
  .capa { padding-top: 24px; }
}
