/* El atributo hidden debe ganarle a cualquier regla display de autor (ej. .modal
   usa display:grid, que sin esto anula el hidden y el modal nunca se oculta). */
[hidden] { display: none !important; }

:root {
  --bg: #eef1f6;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-2: #f3f5f9;
  --line: #e2e6ee;
  --line-strong: #d3d9e4;
  --txt: #1a2233;
  --muted: #667085;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-md: 0 6px 16px rgba(16,24,40,.10), 0 2px 6px rgba(16,24,40,.06);
  --shadow-lg: 0 -8px 40px rgba(16,24,40,.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1100px 500px at 50% -12%, #ffffff 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--txt);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

.brand { font-weight: 800; letter-spacing: .2px; font-size: 20px; display: flex; align-items: center; gap: 8px; color: var(--txt); }
.brand-dot { filter: drop-shadow(0 1px 3px rgba(37,99,235,.35)); }
.brand-sub { color: var(--muted); margin: 2px 0 18px; }
.muted { color: var(--muted); }

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(255,255,255,.82);
  backdrop-filter: saturate(150%) blur(10px);
  -webkit-backdrop-filter: saturate(150%) blur(10px);
  z-index: 5; padding-top: max(12px, env(safe-area-inset-top));
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { color: var(--muted); font-size: 13px; }

.wrap { max-width: 900px; margin: 0 auto; padding: 18px; }

/* ---- botones ---- */
.btn {
  appearance: none; border: 1px solid var(--line-strong); background: var(--card);
  color: var(--txt); padding: 11px 16px; border-radius: 12px; font-size: 15px;
  cursor: pointer; font-weight: 600; min-height: 44px; line-height: 1.1;
  transition: transform .05s, box-shadow .15s, background .15s, opacity .15s, border-color .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { border-color: #c3cad8; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid rgba(37,99,235,.35); outline-offset: 1px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  border-color: transparent; color: #fff; box-shadow: var(--shadow-sm);
}
.btn-primary:hover { border-color: transparent; filter: brightness(1.03); }
.btn-ghost { background: var(--card); }
.btn-danger { background: linear-gradient(180deg, #ef4444, var(--err)); border-color: transparent; color: #fff; }
.btn-icon { min-height: 44px; min-width: 44px; padding: 10px; font-size: 16px; flex: 0 0 auto !important; }

.toolbar { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.toolbar .btn { flex: 1 1 auto; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-md); }
.login-card { width: min(370px, 100%); }
.login-card label { display: block; margin: 14px 0 5px; color: var(--muted); font-size: 13px; font-weight: 600; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--bg-soft); color: var(--txt); font-size: 16px;
}
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.login-card .btn { width: 100%; margin-top: 20px; }

/* ---- alerts ---- */
.alert { padding: 11px 14px; border-radius: 12px; margin: 10px 0; font-size: 14px; }
.alert-error { background: #fdecec; border: 1px solid #f5c2c2; color: #a01c1c; }
.alert-warn { background: #fef3e2; border: 1px solid #f6d79a; color: #92580a; }

/* ---- grid de slots ---- */
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.slot {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .05s;
}
.slot:hover { box-shadow: var(--shadow-md); }
.slot-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.slot-name { font-weight: 700; font-size: 16px; }
.slot-id { color: var(--muted); font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.slot-sync { font-size: 12.5px; color: var(--muted); }
.sigbar { flex: 1; height: 8px; border-radius: 999px; background: var(--card-2); overflow: hidden; }
.sigbar-fill { height: 100%; border-radius: 999px; transition: width .3s ease, background .3s; }
.sigbar-pct { font-size: 12.5px; color: var(--muted); font-weight: 600; min-width: 54px; text-align: right; }

/* ---- indicador de señal (modal): compacto y sutil ---- */
.gauge { display: flex; align-items: center; gap: 8px; margin: -8px 0 14px; font-size: 12.5px; }
.gauge .sig-lbl { color: var(--muted); }
.gauge .sigbar { max-width: 150px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.fresh { background: var(--ok); }
.dot.stale { background: var(--warn); }
.dot.old  { background: #b6bfce; }
.slot-actions { display: flex; gap: 8px; margin-top: 2px; }
.slot-actions .btn { flex: 1; }

/* ---- modal (bottom-sheet en mobile, centrado en desktop) ---- */
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: end center; z-index: 20; backdrop-filter: blur(2px); }
.modal-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 20px 20px 0 0; width: min(560px, 100%);
  padding: 18px; max-height: 88vh; overflow: auto;
  box-shadow: var(--shadow-lg);
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}
@media (min-width: 620px) {
  .modal { place-items: center; }
  .modal-card { border-radius: 20px; padding-bottom: 18px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#modal-title, .dialog-title { font-weight: 800; font-size: 18px; }
.modal-status { color: var(--muted); margin: 6px 0 16px; font-size: 14px; font-weight: 600; }
.modal-status.ok { color: var(--ok); }
.modal-status.err { color: var(--err); }
.modal-status.busy { color: var(--warn); }
.modal-actions { display: flex; gap: 10px; margin-bottom: 10px; }
.modal-actions.secondary { flex-wrap: wrap; }
.modal-actions.secondary .btn { flex: 1; font-size: 13.5px; }
#monto, .dialog-input {
  flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--bg-soft); color: var(--txt); font-size: 16px; width: 100%;
}
#monto:focus, .dialog-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.modal-log {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font: 12px/1.5 ui-monospace, "SF Mono", Menlo, monospace; color: #3b4557;
  line-height: 1.5; height: calc(7 * 1.5em + 24px); max-height: calc(7 * 1.5em + 24px);
  white-space: pre-wrap; word-break: break-word; overflow-y: auto; overflow-x: hidden; margin: 6px 0 0;
  -webkit-overflow-scrolling: touch;
}

/* ---- diálogo genérico (reemplaza alert/confirm/prompt) ---- */
.dialog-msg { color: var(--muted); font-size: 14.5px; margin: 8px 0 16px; }
.dialog-actions { margin-top: 4px; }
.dialog-actions .btn { flex: 1; }

/* ---- pending note ---- */
.pending-note {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--txt); color: #fff;
  padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 600; z-index: 30;
  box-shadow: var(--shadow-md);
}

/* ---- navegación del topbar ---- */
.topbar-nav { display: flex; gap: 4px; margin-left: 12px; margin-right: auto; }
.nav-link {
  padding: 8px 12px; border-radius: 10px; font-size: 14px; font-weight: 600;
  color: var(--muted); text-decoration: none; white-space: nowrap;
}
.nav-link:hover { background: var(--card-2); color: var(--txt); }
.nav-link.active { background: var(--card-2); color: var(--primary); }

/* ---- tabla de usuarios ---- */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow-sm);
}
.utable { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.utable th, .utable td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.utable thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--card-2); }
.utable tbody tr:last-child td { border-bottom: none; }
.utable tbody tr:hover { background: var(--card-2); }
.utable .col-acc { text-align: right; white-space: nowrap; }
.utable .c-acc { display: flex; gap: 6px; justify-content: flex-end; }
.utable .c-acc .btn-icon { min-height: 36px; min-width: 36px; padding: 6px; font-size: 15px; }

/* ---- dot de presencia + chips ---- */
.live-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.live-dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
.live-dot.off { background: #b6bfce; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--card-2); color: var(--muted); border: 1px solid var(--line); }
.chip-rol { text-transform: uppercase; letter-spacing: .03em; color: var(--primary); border-color: rgba(37,99,235,.25); background: rgba(37,99,235,.08); }
.chip-block { color: var(--err); background: #fdecec; border-color: #f5c2c2; }

/* ---- campos de formulario en modal (alta/edición de usuario) ---- */
.field { display: block; margin: 12px 0 0; color: var(--muted); font-size: 13px; font-weight: 600; }
.field input, .field select {
  display: block; width: 100%; margin-top: 5px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--bg-soft); color: var(--txt);
  font-size: 16px; font-weight: 400;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.field input:disabled { background: var(--card-2); color: var(--muted); }

/* ---- auditoría: toggle segmentado + filtros + chips de resultado ---- */
.seg { display: inline-flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 14px; }
.seg-btn { appearance: none; border: 0; background: transparent; color: var(--muted); font-weight: 600; font-size: 14px; padding: 8px 18px; border-radius: 9px; cursor: pointer; min-height: 40px; }
.seg-btn.active { background: var(--card); color: var(--txt); box-shadow: var(--shadow-sm); }
.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filtros select, .filtros input {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--bg-soft); color: var(--txt); font-size: 14px; min-height: 40px;
}
.filtros input { flex: 1 1 160px; min-width: 120px; }
.filtros select:focus, .filtros input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.filtros .btn { min-height: 40px; }
.filtros a.btn { margin-left: auto; }
.aud-resumen { font-size: 13.5px; font-weight: 600; margin: 4px 2px 12px; }
.utable .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip-ok { color: var(--ok); background: #e7f6ec; border-color: #b7e4c5; }
.chip-err { color: var(--err); background: #fdecec; border-color: #f5c2c2; }

/* ---- chip de usuario como link a perfil ---- */
.user-chip-link { text-decoration: none; padding: 6px 10px; border-radius: 10px; }
.user-chip-link:hover { background: var(--card-2); color: var(--txt); }
.user-chip-link.active { background: var(--card-2); color: var(--primary); }

/* ---- dashboard: KPIs ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 4px 0 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow-sm); min-width: 0; }
.kpi-val { font-size: 22px; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-lbl { color: var(--muted); font-size: 12.5px; font-weight: 600; margin-top: 2px; }

/* ---- dashboard: tarjetas + gráficos de barras (sin libs) ---- */
.panel-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.panel-card { padding: 16px 18px; }
.panel-h { margin: 0 0 12px; font-size: 15px; font-weight: 700; }
.panel-h .muted { font-weight: 500; font-size: 13px; }
.chart { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 10px; font-size: 12.5px; min-width: 0; }
.bar-lbl { color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--card-2); border-radius: 999px; height: 12px; overflow: hidden; min-width: 0; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--primary-2)); }
.bar-fill.alt { background: linear-gradient(90deg, #22c55e, #16a34a); }
.bar-val { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---- perfil ---- */
.perfil-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-msg { margin-top: 10px; font-size: 13.5px; font-weight: 600; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--err); }

/* ---- mobile ---- */
@media (max-width: 560px) {
  .wrap { padding: 14px; }
  .topbar { padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); flex-wrap: wrap; }
  .brand { font-size: 18px; }
  .user-chip-link { font-size: 12px; padding: 6px 8px; }
  .topbar-nav { order: 3; width: 100%; margin: 8px 0 0; overflow-x: auto; }
  .slot-grid { grid-template-columns: 1fr; gap: 12px; }
  .toolbar { position: sticky; top: 0; }
  .utable .c-acc .btn-icon { min-height: 40px; min-width: 40px; }
  .seg { display: flex; }
  .seg-btn { flex: 1; }
  .filtros a.btn { margin-left: 0; flex: 1 1 auto; }
  .panel-cols, .perfil-cols { grid-template-columns: 1fr; }
  /* KPIs: el valor grande (ej. "$3.763.470,00") no entra a 22px en 2 columnas;
     escala con el ancho y baja el padding para que nunca desborde la tarjeta. */
  .kpi { padding: 12px 14px; }
  .kpi-val { font-size: clamp(15px, 4.6vw, 20px); }
  .kpi-lbl { font-size: 12px; }
  /* Barras: menos ancho fijo de etiqueta/gap para dar aire al monto. */
  .bar-row { grid-template-columns: 44px 1fr auto; gap: 8px; }
}
