*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

/* the [hidden] attribute loses to any author rule of equal specificity that
   sets display (e.g. .field{display:flex}), since author styles come after
   the UA stylesheet in the cascade — force it to actually hide. */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--pri); }

:focus-visible {
  outline: 2px solid var(--pri);
  outline-offset: 2px;
}

.jt td, .jt th, .jf, .btn { outline-offset: 1px; }

h1, h2, h3 { margin: 0; font-weight: 700; }

/* ---------- shell ---------- */

.shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.page {
  flex: 1;
  padding: 24px 32px;
}

.narrow {
  max-width: 680px;
  margin-inline: auto;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head h1 { font-size: 24px; font-weight: 800; }
.page-head .subtitle { margin-top: 4px; color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; flex-shrink: 0; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 8px;
}
.back-link:hover { color: var(--ink); }

/* ---------- sidebar ---------- */

.side {
  width: var(--side-w);
  flex-shrink: 0;
  background: var(--side-bg);
  color: var(--side-muted);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  z-index: 20;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  color: var(--side-ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.side-brand img { width: 28px; height: 28px; display: block; }

.side-nav { flex: 1; padding: 4px 10px; }

.side-group { margin-bottom: 2px; border-radius: var(--r-sm); }
.side-group.is-active { background: var(--side-active-bg); }

.side-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 500;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: left;
}
.side-group.is-active > .side-group-head { color: var(--side-active); font-weight: 700; }
.side-group-head:hover { background: var(--side-hover); }
.side-group-head i.icon { width: 16px; text-align: center; }
.side-group-head .chev { margin-left: auto; transition: transform .15s; font-size: 12px; }
.side-group.is-open .side-group-head .chev { transform: rotate(90deg); }

.side-sub { list-style: none; margin: 0; padding: 2px 0 6px 22px; display: none; }
.side-group.is-open .side-sub { display: block; }

.side-sub li { border-left: 2px solid var(--side-line); }
.side-sub a {
  display: block;
  padding: 7px 10px;
  color: var(--side-muted);
  text-decoration: none;
  font-size: 13px;
  margin-left: -1px;
}
.side-sub a:hover { color: var(--side-ink); }
.side-sub li.is-active { border-left-color: var(--side-active); }
.side-sub li.is-active a { color: var(--side-active); font-weight: 700; }

.side-foot {
  position: sticky;
  bottom: 0;
  background: var(--side-bg);
  border-top: 1px solid var(--side-line);
  padding: 12px 16px;
  flex-shrink: 0;
}
.side-foot .who { color: var(--side-ink); font-size: 13px; margin-bottom: 6px; overflow-wrap: anywhere; }
.side-foot form { margin: 0; }
.side-foot button {
  border: 0;
  background: none;
  color: var(--side-muted);
  font: inherit;
  font-size: 13px;
  padding: 0;
  cursor: pointer;
}
.side-foot button:hover { color: var(--side-ink); }

/* ---------- topbar (mobile) ---------- */

.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 15;
}
.topbar .menu-btn {
  border: 1px solid var(--line-strong);
  background: var(--card);
  border-radius: var(--r-sm);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(12, 26, 32, .45);
  z-index: 19;
}

@media (max-width: 900px) {
  .side {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .shell.is-drawer-open .side { transform: translateX(0); }
  .shell.is-drawer-open .scrim { display: block; }
  .topbar { display: flex; }
  .page { padding: 16px; }
  .page-head { flex-direction: column; align-items: stretch; }
}

/* ---------- card ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh);
}
.card-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  font-weight: 700;
}
.card-body { padding: 18px 20px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.25;
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-pri { background: var(--pri); color: var(--pri-ink); }
.btn-pri:hover:not(:disabled) { background: var(--pri-hover); }

.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin .6s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ---------- badge ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-pri { background: var(--pri-soft); color: var(--pri-soft-ink); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-neutral { background: var(--line); color: var(--muted); }

/* ---------- messages / toasts ---------- */

.msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  margin-bottom: 14px;
}
.msg-success { background: var(--ok-soft); color: var(--ok); }
.msg-danger { background: var(--danger-soft); color: var(--danger); }
.msg-warning { background: var(--warn-soft); color: var(--warn); }
.msg-info { background: var(--pri-soft); color: var(--pri-soft-ink); }

.toast-region {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 60;
  width: 100%;
  max-width: 420px;
  padding: 0 16px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 13px 18px;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--sh-lg);
  background: var(--card);
  border: 1px solid var(--line);
  pointer-events: auto;
  animation: toast-in .25s ease-out;
}
.toast i { font-size: 16px; flex-shrink: 0; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast-success { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.toast-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.toast-warning { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* ---------- table ---------- */

.jt-wrap { overflow-x: auto; }
.jt { width: 100%; border-collapse: collapse; }
.jt th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.jt td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.jt tbody tr:hover { background: var(--bg); }
.jt .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.jt a.row-link { color: var(--ink); text-decoration: none; font-weight: 500; }
.jt a.row-link:hover { color: var(--pri); }
.jt a.id-link { color: var(--ok); text-decoration: none; font-weight: 700; }
.jt a.id-link:hover { text-decoration: underline; }

.jt-empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label { font-size: 13px; font-weight: 500; }

.jf {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 9px 12px;
}
.jf:focus-visible {
  outline: none;
  border-color: var(--pri);
  box-shadow: 0 0 0 3px var(--pri-soft);
}

.field .help { font-size: 12px; color: var(--muted); }
.field .errors { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--danger); }

/* interruptor sobre un checkbox nativo, sin librería — .field > label (0,1,1)
   le gana en especificidad a .toggle (0,1,0) si no se escribe así. */
.field > label.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
}
.toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toggle .track {
  display: block;
  flex: none;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  transition: background .15s ease;
}
.toggle .track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--card);
  transition: transform .15s ease;
}
.toggle input:checked + .track { background: var(--pri); }
.toggle input:checked + .track::after { transform: translateX(16px); }
.toggle input:focus-visible + .track { box-shadow: 0 0 0 3px var(--pri-soft); }

.form-actions {
  display: flex;
  gap: 8px;
  padding-top: 16px;
  margin-top: 4px;
  border-top: 1px solid var(--line);
}

.password-field { position: relative; }
.password-field .jf { padding-right: 44px; }

.filters-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.filter-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--pri);
  color: var(--pri-ink);
  font-size: 11px;
  font-weight: 600;
}

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--pri-soft);
  color: var(--pri-soft-ink);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 4px 4px 10px;
  border-radius: 999px;
  max-width: 260px;
}
.filter-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 10px;
}
.filter-chip-remove:hover { background: rgba(8, 102, 112, .15); }

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px 20px;
}
.filters-grid .field { margin-bottom: 0; }

/* ---------- modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 26, 32, .45);
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-dialog {
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--sh-lg);
  width: 100%;
  max-width: 880px;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}
.modal-close:hover { background: var(--bg); color: var(--ink); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--r-sm);
}
.password-toggle:hover { color: var(--ink); }

/* ---------- login ---------- */

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 16px;
}
.login-box { width: 100%; max-width: 360px; }
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}
.login-brand img { width: 32px; height: 32px; }
.login-brand span { font-weight: 700; font-size: 18px; }


/* ---------- lista de metadatos (detalle de una petición) ---------- */
.meta-list { display: flex; flex-direction: column; }
.meta-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.meta-row:last-child { border-bottom: 0; padding-bottom: 0; }
.meta-row:first-child { padding-top: 0; }
.meta-row .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  flex-shrink: 0;
  padding-top: 1px;
}
.meta-row .value { text-align: right; overflow-wrap: anywhere; }
.meta-row .value .when { color: var(--muted); font-size: 12px; }

/* tooltip instantáneo (ver shell.js): cualquier elemento con data-tip */
.tip {
  position: fixed; z-index: 300; top: 0; left: 0;
  background: #1f2937; color: #fff; font-size: 12px; line-height: 1.3;
  padding: 4px 8px; border-radius: 6px; white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity .08s;
}
.tip.is-visible { opacity: 1; }

/* ---------- análisis ---------- */
.an-filters { margin-bottom: 16px; }
.an-filter-row { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: start; }
.an-filter-row .field { margin-bottom: 0; min-width: 180px; }
.an-filter-row .field:first-child { flex: 1 1 320px; }
.an-filter-row .field[hidden] { display: none; }
#an-content { transition: opacity .15s; }
#an-content.is-loading { opacity: .5; pointer-events: none; }
.an-range { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.an-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.an-kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh); padding: 14px 16px; }
.an-kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.an-kpi .value { font-size: 26px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.an-kpi .delta { font-size: 12px; margin-top: 4px; color: var(--muted); }
.an-kpi .delta.good { color: var(--ok); }
.an-kpi .delta.bad { color: var(--danger); }
.an-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 16px; }
.an-block { margin-top: 16px; }
.an-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.an-chart { position: relative; height: 260px; }
.an-mode { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; }
.an-mode button { border: 0; background: var(--card); color: var(--muted); font: inherit; font-size: 12px; padding: 4px 10px; cursor: pointer; }
.an-mode button[aria-pressed="true"] { background: var(--pri-soft); color: var(--pri-soft-ink); font-weight: 600; }
.an-details { margin-top: 12px; font-size: 13px; }
.an-details summary { cursor: pointer; color: var(--muted); }
.an-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
/* enlace suelto de la barra lateral (sin submenú), mismo aspecto que un grupo */
.side-link { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: var(--r-sm); color: inherit; text-decoration: none; font-weight: 500; }
.side-link:hover { background: var(--side-hover); }
.side-link i.icon { width: 16px; text-align: center; }
.side-link.is-active { color: var(--side-active); font-weight: 700; background: var(--side-active-bg); }

/* ---------- eagleeye ---------- */
/* Lo que sigue no existe en FlowDesk: son piezas propias de un panel de
   tráfico, armadas con los mismos tokens y las mismas reglas de la guía. */

.badge-danger { background: var(--danger-soft); color: var(--danger); }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.jt .when, .when { color: var(--muted); font-size: 12px; }
.jt td.cell-path {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12.5px;
}
.jt td.cell-wrap { white-space: normal; overflow-wrap: anywhere; font-size: 12.5px; }
.jt tbody tr.is-clickable { cursor: pointer; }
.jt tfoot td { font-weight: 700; border-bottom: 0; }

/* un KPI que es un enlace: toda la tarjeta lleva al detalle */
a.an-kpi { display: block; color: inherit; text-decoration: none; }
a.an-kpi:hover { border-color: var(--line-strong); box-shadow: var(--sh-lg); }
.an-kpi .value.is-danger { color: var(--danger); }

.an-note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.an-block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 12px; }
.pager .when { font-family: var(--mono); }

.meter { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--pri-bright); }
.meter.is-warn > span { background: var(--warn); }
.meter.is-danger > span { background: var(--danger); }

.modal-body .meta-row .value { font-family: var(--mono); font-size: 12.5px; }
