﻿/* =========================================================================
   FACTURAS RETENIDAS · Sistema de diseño (tema claro)
   Concepto: continúa el lenguaje visual que ya usan en su informe de Power BI
   — barra de título gris oscuro por tarjeta, borde dorado alrededor, fondo
   claro, azul como color de dato principal — para que este reporte web se
   sienta como una extensión natural de lo que el área de costos ya conoce,
   no como una herramienta distinta.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500;600&display=swap');

:root{
  --bg:            #EEF1F4;
  --bg-elevated:   #F7F8FA;
  --surface:       #FFFFFF;
  --surface-hover: #F3F5F8;
  --border:        #E1E5EA;
  --header-bar:    #52585F;
  --header-bar-2:  #3F454C;

  --text:          #1D2430;
  --text-muted:    #5B6472;
  --text-faint:    #93A0AF;

  --azul:          #1E88E5;
  --azul-soft:     rgba(30,136,229,.10);
  --ambar:         #D99A26;
  --ambar-soft:    rgba(217,154,38,.12);
  --turquesa:      #0EA396;
  --turquesa-soft: rgba(14,163,150,.10);
  --coral:         #E0453C;
  --coral-soft:    rgba(224,69,60,.10);
  --lila:          #7C6FE0;
  --lila-soft:     rgba(124,111,224,.10);

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(30,40,55,.06), 0 1px 2px rgba(30,40,55,.05);
  --transition: 180ms cubic-bezier(.4,0,.2,1);
}

*{ box-sizing: border-box; }
html{ -webkit-text-size-adjust: 100%; }
html, body{ height:100%; }
body{
  margin:0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
h1,h2,h3,.num-display{ font-family: var(--font-display); letter-spacing: -0.01em; }
.mono{ font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
a{ color: inherit; }
button{ font-family: inherit; }

/* Respeta preferencia de reducir movimiento */
@media (prefers-reduced-motion: reduce){
  *{ animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Barra superior ---------- */
.topbar{
  position: sticky; top:0; z-index: 40;
  display:flex; align-items:center; justify-content:space-between;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand{ display:flex; align-items:center; gap:10px; min-width:0; }
.brand-mark{
  width:34px; height:34px; border-radius: 9px; flex:none;
  background: linear-gradient(135deg, var(--ambar), #B97F16);
  display:grid; place-items:center; font-weight:700; color:#fff; font-family: var(--font-display);
}
.brand-text{ display:flex; flex-direction:column; line-height:1.15; min-width:0; }
.brand-text b{ font-family: var(--font-display); font-size: 15px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; color:var(--text);}
.brand-text span{ font-size: 11.5px; color: var(--text-muted); }

.tabs{
  display:flex; gap:4px; background: var(--bg-elevated); border:1px solid var(--border);
  border-radius: 999px; padding: 4px;
}
.tab-btn{
  border:none; background:transparent; color: var(--text-muted);
  padding: 8px 16px; border-radius: 999px; font-weight:600; font-size: 13.5px;
  cursor:pointer; transition: var(--transition);
  white-space: nowrap;
}
.tab-btn.active{ background: var(--ambar); color:#fff; }
.tab-btn:not(.active):hover{ color: var(--text); background: var(--surface-hover); }

/* ---------- Layout general ---------- */
.page{ max-width: 1360px; margin: 0 auto; padding: 20px 20px 64px; }
.view{ display:none; animation: fade .35s ease; }
.view.active{ display:block; }
@keyframes fade{ from{opacity:0; transform: translateY(6px);} to{opacity:1; transform:none;} }

.section-title{
  display:flex; align-items:baseline; gap:10px; margin: 30px 0 14px;
}
.section-title h2{ font-size: 15px; margin:0; text-transform:uppercase; letter-spacing:.08em; color: var(--text-muted); }
.section-title .line{ flex:1; height:1px; background: var(--border); }

.grid{ display:grid; gap: 16px; }
.grid-2{ grid-template-columns: 1fr 1fr; }
.grid-3{ grid-template-columns: repeat(3, 1fr); }
.grid-4{ grid-template-columns: repeat(4, 1fr); }
@media (max-width: 980px){
  .grid-2, .grid-3, .grid-4{ grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px){
  .grid-2, .grid-3, .grid-4{ grid-template-columns: 1fr; }
  .page{ padding: 14px 12px 48px; }
}

/* ---------- Tarjetas: barra de título gris oscuro + borde dorado (estilo Power BI) ---------- */
.card{
  background: var(--surface);
  border: 1px solid var(--ambar); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
  overflow: hidden;
}
.card h3{
  margin: -18px -18px 16px -18px; padding: 12px 18px;
  font-size: 12.5px; color:#fff; font-weight:700; text-transform:uppercase; letter-spacing:.06em;
  background: linear-gradient(180deg, var(--header-bar), var(--header-bar-2));
}

/* Tarjetas simples sin barra de título (KPIs, dial, cierre) usan borde neutro */
.card.kpi, .card.dial-card, .cierre-box.card{ border-color: var(--border); }

/* ---------- KPI hero: anillos tipo "dial" (elemento firma) ---------- */
.hero{
  display:grid; grid-template-columns: 1.1fr 1fr; gap:16px;
}
@media (max-width: 900px){ .hero{ grid-template-columns: 1fr; } }

.dial-card{ display:flex; align-items:center; gap:18px; border:1px solid var(--border) !important; }
.dial{ position:relative; width:132px; height:132px; flex:none; }
.dial svg{ transform: rotate(-90deg); }
.dial-track{ fill:none; stroke: var(--border); stroke-width:10; }
.dial-fill{ fill:none; stroke-width:10; stroke-linecap:round; transition: stroke-dashoffset 1s cubic-bezier(.4,0,.2,1); }
.dial-value{
  position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center;
}
.dial-value b{ font-size: 22px; font-family: var(--font-display); color:var(--text); }
.dial-value span{ font-size: 10.5px; color: var(--text-muted); }
.dial-meta{ min-width:0; }
.dial-meta .label{ color: var(--text-muted); font-size: 13px; margin-bottom:4px; font-weight:600;}
.dial-meta .big{ font-size: 30px; font-weight:800; font-family: var(--font-display); color:var(--text); }
.dial-meta .delta{ font-size: 12.5px; margin-top:6px; display:inline-flex; align-items:center; gap:5px; padding: 3px 9px; border-radius:999px; font-weight:600; }
.delta.up{ background: rgba(224, 69, 60, 0.12); color: #D32F2F; border: 1px solid rgba(224, 69, 60, 0.3); font-weight: 700; }
.delta.down{ background: rgba(14, 163, 150, 0.12); color: #0EA396; border: 1px solid rgba(14, 163, 150, 0.3); font-weight: 700; }

/* ---------- Tarjetas KPI simples: fondo con tinte de color para que resalten ---------- */
.kpi{ padding: 18px 20px; border-width:1px; border-style:solid; }
.kpi .label{ color: var(--text-muted); font-size: 12.5px; text-transform:uppercase; letter-spacing:.05em; font-weight:700; }
.kpi .value{ font-size: 28px; font-weight:800; margin-top:8px; font-family: var(--font-display); }
.kpi .sub{ font-size: 12.5px; color: var(--text-muted); margin-top:4px; font-weight:600; }
.kpi.ambar{ background: var(--ambar-soft); border-color: rgba(217,154,38,.35); }
.kpi.ambar .value{ color: #A97315; }
.kpi.turquesa{ background: var(--turquesa-soft); border-color: rgba(14,163,150,.3); }
.kpi.turquesa .value{ color: #0B7F75; }
.kpi.coral{ background: var(--coral-soft); border-color: rgba(224,69,60,.3); }
.kpi.coral .value{ color: #B8342C; }
.kpi.lila{ background: var(--lila-soft); border-color: rgba(124,111,224,.3); }
.kpi.lila .value{ color: #5B4FC4; }
.kpi.azul{ background: var(--azul-soft); border-color: rgba(30,136,229,.3); }
.kpi.azul .value{ color: #1467AD; }

/* ---------- Gráficas ---------- */
.chart-wrap{ position:relative; height: 300px; padding-bottom: 14px; }
.chart-wrap.tall{ height: 380px; }
.chart-wrap.short{ height: 230px; }

/* ---------- Treemap (proveedores) ---------- */
.treemap{ display:grid; gap:3px; height: 360px; border-radius: var(--radius-sm); overflow:hidden; margin-bottom:18px; }
.treemap-cell{
  position:relative; border-radius: 4px; overflow:hidden; padding:8px 10px;
  display:flex; flex-direction:column; justify-content:flex-end;
  font-size: 12px; color: #fff; font-weight:600; text-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: filter var(--transition), transform var(--transition);
  cursor: default;
}
.treemap-cell:hover{ filter: brightness(1.08); transform: scale(0.985); z-index:2; }
.treemap-cell .tm-name{ line-height:1.2; }
.treemap-cell .tm-value{ font-family: var(--font-mono); font-size: 11px; opacity:.92; }

/* ---------- Tabla ---------- */
.table-wrap{ overflow-x:auto; border-radius: var(--radius-sm); border:1px solid var(--border); margin-bottom:18px; }
table{ width:100%; border-collapse: collapse; font-size: 13px; min-width: 620px; }
thead th{
  text-align:left; padding: 11px 14px; background: var(--bg-elevated);
  color: var(--text-muted); font-weight:700; font-size:11.5px; text-transform:uppercase;
  letter-spacing:.04em; position: sticky; top:0;
  border-bottom: 1px solid var(--border);
}
tbody td{ padding: 10px 14px; border-bottom: 1px solid var(--border); }
tbody tr:hover{ background: var(--surface-hover); }
tbody tr.fila-total, tfoot td{ background: var(--bg-elevated); font-weight:700; }
td.num, th.num{ text-align:right; font-family: var(--font-mono); }
th.divisor-cuenta{ border-left: 2px solid var(--border); }
td.divisor-cuenta{ border-left: 2px solid var(--border); }
.pill{ display:inline-flex; align-items:center; gap:4px; padding:2px 9px; border-radius:999px; font-size:11.5px; font-weight:600; }
.pill.venc{ background: var(--coral-soft); color: var(--coral); }
.pill.cte{ background: var(--turquesa-soft); color: var(--turquesa); }

/* ---------- Heatmap mensual ---------- */
.heatmap{ display:grid; grid-auto-flow:column; grid-template-rows: repeat(12, 26px); gap:3px; overflow-x:auto; padding-bottom:18px; }
.heatmap-cell{ border-radius:4px; position:relative; }
.heatmap-cell[data-tip]:hover::after{
  content: attr(data-tip); position:absolute; bottom:120%; left:50%; transform:translateX(-50%);
  background: var(--header-bar-2); color:#fff; padding:4px 8px; border-radius:6px; font-size:11px; white-space:nowrap; z-index:10;
}

/* ---------- Botón de cierre / flujo modal ---------- */
.cierre-box{
  display:flex; align-items:center; justify-content:space-between; gap:16px; flex-wrap:wrap;
  padding: 18px 20px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--ambar-soft), transparent 60%), var(--surface);
  border: 1px solid var(--border);
}
.cierre-box p{ margin:0; color: var(--text-muted); font-size: 13.5px; max-width: 520px; }
.btn{
  border:none; cursor:pointer; font-weight:700; font-size: 13.5px;
  padding: 12px 22px; border-radius: 999px; transition: var(--transition);
  display:inline-flex; align-items:center; gap:8px;
}
.btn-primary{ background: var(--ambar); color:#fff; }
.btn-primary:hover{ filter: brightness(1.08); transform: translateY(-1px); }
.btn-primary:disabled{ opacity:.5; cursor:not-allowed; transform:none; }
.btn-ghost{ background: transparent; border:1px solid var(--border); color: var(--text); }
.btn-ghost:hover{ background: var(--surface-hover); }

.modal-backdrop{
  position:fixed; inset:0; background: rgba(20,26,34,.45); backdrop-filter: blur(3px);
  display:flex; align-items:center; justify-content:center; z-index:100; padding:16px;
  opacity:0; pointer-events:none; transition: opacity var(--transition);
}
.modal-backdrop.open{ opacity:1; pointer-events:auto; }
.modal{
  width: 100%; max-width: 420px; background: #fff; border:1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: 0 12px 32px rgba(20,26,34,.18);
  transform: translateY(10px); transition: transform var(--transition);
}
.modal-backdrop.open .modal{ transform: translateY(0); }
.modal h3{ margin:0 0 6px; font-size:18px; font-family: var(--font-display); color:var(--text); }
.modal p.hint{ color: var(--text-muted); font-size: 13px; margin: 0 0 18px; }
.modal input{
  width:100%; padding: 12px 14px; border-radius: var(--radius-sm); border:1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size:14px; margin-bottom: 10px;
}
.modal input:focus{ outline:2px solid var(--ambar); outline-offset:1px; }
.modal .msg{ font-size: 12.5px; min-height: 18px; margin-bottom: 8px; }
.modal .msg.error{ color: var(--coral); }
.modal .msg.ok{ color: var(--turquesa); }
.modal .actions{ display:flex; gap:10px; margin-top:6px; }
.modal .actions .btn{ flex:1; justify-content:center; }
.close-x{ position:absolute; top:14px; right:16px; background:none; border:none; color:var(--text-muted); font-size:20px; cursor:pointer; }
.modal{ position:relative; }

.step{ display:none; }
.step.active{ display:block; }

.loader-inline{
  display:inline-block; width:14px; height:14px; border-radius:50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color:#fff; animation: spin .7s linear infinite;
}
@keyframes spin{ to{ transform: rotate(360deg); } }

.empty-state{ text-align:center; padding: 40px 16px; color: var(--text-muted); }
.toast{
  position:fixed; bottom:20px; left:50%; transform:translateX(-50%);
  background: var(--header-bar-2); border:1px solid var(--header-bar-2); color:#fff;
  padding: 12px 20px; border-radius: 999px; box-shadow: var(--shadow);
  font-size: 13.5px; z-index: 200; opacity:0; pointer-events:none; transition: var(--transition);
}
.toast.show{ opacity:1; transform: translateX(-50%) translateY(-6px); }
.toast.ok{ border-color: var(--turquesa); }
.toast.error{ border-color: var(--coral); }

.skeleton{ background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--surface-hover) 37%, var(--bg-elevated) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer{ 0%{background-position: 100% 50%;} 100%{background-position: 0 50%;} }

.footer-note{ text-align:center; color: var(--text-faint); font-size:11.5px; margin-top: 40px; }
