/* Panel de vigilancia de Gofresquina — sin dependencias, sin estilos en línea (CSP estricta). */

:root {
  --bg: #fff7ec;
  --bg-2: #fdefdc;
  --surface: #ffffff;
  --surface-2: #fffaf3;
  --border: #f0dfc6;
  --text: #2a1d12;
  --text-2: #6f5a46;
  --text-3: #9c8670;
  --brand: #e07a1f;
  --brand-2: #f4a340;
  --ok: #1f9d63;
  --ok-bg: #e3f6ec;
  --warn: #c98200;
  --warn-bg: #fff1d1;
  --down: #d93d42;
  --down-bg: #ffe3e2;
  --idle: #9c8f84;
  --info: #3d7bd9;
  --shadow: 0 1px 2px rgba(80, 45, 10, 0.06), 0 8px 24px rgba(80, 45, 10, 0.07);
  --shadow-hover: 0 2px 4px rgba(80, 45, 10, 0.08), 0 14px 36px rgba(80, 45, 10, 0.12);
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14110f;
    --bg-2: #1b1714;
    --surface: #201b17;
    --surface-2: #26201b;
    --border: #3a2f26;
    --text: #f6ece1;
    --text-2: #c7b5a3;
    --text-3: #8d7a69;
    --brand: #f19a45;
    --brand-2: #ffc078;
    --ok: #3ccf8e;
    --ok-bg: #12301f;
    --warn: #f5b83d;
    --warn-bg: #3a2c0c;
    --down: #ff6b6b;
    --down-bg: #3d1517;
    --idle: #8d8178;
    --info: #74a7ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.35), 0 14px 36px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14110f;
  --bg-2: #1b1714;
  --surface: #201b17;
  --surface-2: #26201b;
  --border: #3a2f26;
  --text: #f6ece1;
  --text-2: #c7b5a3;
  --text-3: #8d7a69;
  --brand: #f19a45;
  --brand-2: #ffc078;
  --ok: #3ccf8e;
  --ok-bg: #12301f;
  --warn: #f5b83d;
  --warn-bg: #3a2c0c;
  --down: #ff6b6b;
  --down-bg: #3d1517;
  --idle: #8d8178;
  --info: #74a7ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.35), 0 14px 36px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 0% -10%, var(--bg-2), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, var(--bg-2), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
[hidden] {
  display: none !important;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ── Botones ─────────────────────────────────────────── */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 650;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 35%, transparent);
}
.btn-primary:hover {
  box-shadow: 0 10px 24px color-mix(in srgb, var(--brand) 45%, transparent);
}
.btn-primary:disabled {
  opacity: 0.7;
  cursor: progress;
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}
.btn-sm {
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 13px;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 17px;
  display: grid;
  place-items: center;
  transition: transform 0.2s ease, background 0.2s ease;
}
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn.spin {
  animation: spin 0.8s ease;
}

/* ── Entrar ──────────────────────────────────────────── */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px 26px 24px;
  box-shadow: var(--shadow-hover);
  display: grid;
  gap: 14px;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.login-logo {
  display: block;
  margin: 0 auto;
}
.login-card h1 {
  margin: 0;
  text-align: center;
  font-size: 22px;
}
.login-sub {
  margin: -6px 0 6px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
}
.login-card label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.login-card input {
  font: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-card input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent);
}
.login-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--down-bg);
  color: var(--down);
  font-size: 14px;
  animation: shake 0.4s ease;
}
.login-foot {
  margin: 4px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}

/* ── Cabecera ────────────────────────────────────────── */
.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 16px 32px;
}
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-logo {
  display: block;
}
.ico {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.brand-name {
  font-weight: 800;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: -2px;
}
.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.updated {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.updated.stale {
  color: var(--warn);
}
.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent);
  animation: pulse 2s infinite;
  flex: none;
}
.updated.stale .pulse {
  background: var(--warn);
  animation: none;
}
.user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.user-name {
  font-size: 13px;
  color: var(--text-2);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Resumen ─────────────────────────────────────────── */
.hero {
  padding: 18px 0 14px;
}
.headline {
  margin: 0 0 14px;
  font-size: clamp(22px, 3.2vw, 34px);
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-weight: 800;
  animation: rise 0.5s ease both;
}
.headline.level-down {
  color: var(--down);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 650;
  color: var(--text-2);
  transition: all 0.2s ease;
}
.chip:hover {
  transform: translateY(-1px);
}
.chip.is-active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.chip-ok .dot {
  background: var(--ok);
}
.chip-warn .dot {
  background: var(--warn);
}
.chip-down .dot {
  background: var(--down);
}
.chip.is-zero {
  opacity: 0.55;
}

/* ── Rejilla ─────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}
.group {
  margin-bottom: 22px;
}
.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 750;
}
.grid,
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 14px;
}

/* ── Tarjeta ─────────────────────────────────────────── */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 12px;
  overflow: hidden;
  transition: box-shadow 0.25s ease, transform 0.25s ease, border-color 0.4s ease;
}
.card.enter {
  animation: rise 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--st);
  transition: background 0.4s ease;
}
.card.st-ok {
  --st: var(--ok);
  --st-bg: var(--ok-bg);
}
.card.st-warn {
  --st: var(--warn);
  --st-bg: var(--warn-bg);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--border));
}
.card.st-down {
  --st: var(--down);
  --st-bg: var(--down-bg);
  border-color: color-mix(in srgb, var(--down) 45%, var(--border));
}
.card.st-down::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--down) 30%, transparent);
  animation: alarm 1.6s ease-in-out infinite;
}
.card.st-idle {
  --st: var(--idle);
  --st-bg: var(--surface-2);
}
.card.flash {
  animation: flash 1.2s ease;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar {
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--st);
  background: var(--st-bg);
}
.avatar .ico {
  width: 22px;
  height: 22px;
}
.avatar::after {
  content: "";
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--st);
  border: 2.5px solid var(--surface);
}
.card.st-down .avatar::after,
.card.st-warn .avatar::after {
  animation: blink 1.4s ease-in-out infinite;
}
.card-title {
  min-width: 0;
  flex: 1;
}
.card-title h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 750;
  letter-spacing: -0.01em;
}
.card-title .sub {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  flex: none;
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--st);
  background: var(--st-bg);
}
.message {
  margin: 12px 0 4px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}
.reasons {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--text-2);
}
.reasons li::before {
  content: "· ";
  color: var(--st);
}
.spark {
  display: block;
  width: 100%;
  height: 38px;
  margin: 10px 0 2px;
}
.spark .area {
  fill: color-mix(in srgb, var(--brand) 14%, transparent);
}
.spark .line {
  fill: none;
  stroke: var(--brand);
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.spark .err {
  fill: var(--down);
  opacity: 0.85;
}
.spark-legend {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
}
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 8px 10px;
  margin: 12px 0 4px;
}
.metric {
  min-width: 0;
}
.metric .k {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric .v {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.3s ease;
}
.metric.m-warn .v {
  color: var(--warn);
}
.metric.m-down .v {
  color: var(--down);
}
.metric .v.bump {
  animation: bump 0.6s ease;
}
.bar {
  height: 5px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: 4px;
}
.bar > i {
  display: block;
  height: 100%;
  width: var(--w, 0%);
  background: linear-gradient(90deg, var(--ok), var(--brand-2));
  border-radius: inherit;
  transition: width 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.bar.hot > i {
  background: linear-gradient(90deg, var(--warn), var(--down));
}

details.more {
  margin-top: 10px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}
details.more summary {
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
details.more summary::-webkit-details-marker {
  display: none;
}
details.more summary::before {
  content: "›";
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 16px;
}
details.more[open] summary::before {
  transform: rotate(90deg);
}
details.more .more-body.opening {
  animation: rise 0.25s ease both;
}
.rows {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
}
.rows li {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr);
  gap: 10px;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--surface-2);
}
.rows .rk {
  color: var(--text-2);
  overflow-wrap: anywhere;
}
.rows .rv {
  overflow-wrap: anywhere;
}
.rows li.r-warn {
  background: var(--warn-bg);
}
.rows li.r-down {
  background: var(--down-bg);
}
.errors {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: grid;
  gap: 6px;
}
.errors li {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.4;
  padding: 7px 9px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--down) 8%, var(--surface-2));
  border-left: 3px solid color-mix(in srgb, var(--down) 60%, transparent);
  overflow-wrap: anywhere;
}
.errors li time {
  display: block;
  font-family: var(--font);
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 2px;
}
.errors-title {
  margin: 12px 0 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.skeleton {
  min-height: 210px;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
.empty-filter {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-2);
  font-size: 15px;
}

/* ── Lo que está pasando ─────────────────────────────── */
.feed {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 92px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px 10px;
  scrollbar-width: thin;
}
.feed-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.feed-head h2 {
  margin: 0;
  font-size: 16px;
}
.feed-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-3);
}
.feed-list {
  list-style: none;
  padding: 0;
  margin: 0;
  position: relative;
}
.feed-list::before {
  content: "";
  position: absolute;
  left: 17px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--border);
  border-radius: 2px;
}
.feed-item {
  position: relative;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 8px;
  padding: 8px 0;
}
.feed-item.is-new {
  animation: slidein 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.feed-icon {
  position: relative;
  z-index: 1;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.feed-item.lv-ok .feed-icon {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: color-mix(in srgb, var(--ok) 30%, var(--border));
}
.feed-item.lv-warn .feed-icon {
  color: var(--warn);
  background: var(--warn-bg);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--border));
}
.feed-item.lv-error .feed-icon {
  color: var(--down);
  background: var(--down-bg);
  border-color: color-mix(in srgb, var(--down) 40%, var(--border));
}
.feed-text {
  font-size: 14px;
  line-height: 1.35;
  padding-top: 1px;
  overflow-wrap: anywhere;
}
.feed-meta {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.feed-comp {
  font-weight: 700;
  color: var(--text);
}
.feed-value {
  display: block;
  color: var(--text-2);
  font-size: 13px;
  font-family: var(--mono);
  margin-top: 1px;
}
.feed-empty {
  color: var(--text-2);
  font-size: 14px;
  text-align: center;
  padding: 20px 8px;
}

.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-3);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-hover);
  animation: rise 0.3s ease both;
  z-index: 50;
  max-width: calc(100vw - 32px);
}

/* ── Móvil ───────────────────────────────────────────── */
@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .feed {
    position: static;
    max-height: none;
    order: -1;
  }
  .feed-list {
    max-height: 340px;
    overflow: auto;
  }
}
@media (max-width: 640px) {
  .app {
    padding: 0 12px 24px;
  }
  .user-name,
  .brand-sub {
    display: none;
  }
  .updated {
    padding: 6px 10px;
    font-size: 12px;
  }
  .top-right {
    gap: 6px;
  }
  .rows li {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 420px) {
  #refresh {
    display: none;
  }
  .brand-name {
    font-size: 14px;
  }
}

/* ── Animaciones ─────────────────────────────────────── */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes slidein {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent);
  }
  70% {
    box-shadow: 0 0 0 8px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}
@keyframes blink {
  50% {
    opacity: 0.35;
  }
}
@keyframes alarm {
  50% {
    opacity: 0.2;
  }
}
@keyframes flash {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--st) 60%, transparent);
  }
  100% {
    box-shadow: 0 0 0 14px transparent;
  }
}
@keyframes bump {
  30% {
    color: var(--brand);
    transform: scale(1.06);
  }
}
@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes shake {
  20%,
  60% {
    transform: translateX(-5px);
  }
  40%,
  80% {
    transform: translateX(5px);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
