/*
 * Panel administrativo. Lenguaje visual inspirado en las guías de Apple (HIG / WWDC):
 * fuente del sistema con tracking por tamaño, colores del sistema que se adaptan a modo
 * claro/oscuro, materiales translúcidos para la navegación, feedback al presionar (no al
 * soltar) y transiciones que respetan "reducir movimiento" / "reducir transparencia".
 */

:root {
  color-scheme: light dark;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.2);
  --separator: rgba(60, 60, 67, 0.14);
  --separator-strong: rgba(60, 60, 67, 0.29);

  --label: #1d1d1f;
  --label-2: #6e6e73;
  --label-3: #8e8e93;

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-tint: rgba(0, 113, 227, 0.1);
  --accent-ring: rgba(0, 113, 227, 0.28);

  --red: #ff3b30;
  --red-text: #d70015;
  --red-tint: rgba(255, 59, 48, 0.1);
  --green: #34c759;
  --green-text: #248a3d;
  --green-tint: rgba(52, 199, 89, 0.12);
  --orange: #ff9500;
  --orange-text: #c93400;
  --orange-tint: rgba(255, 149, 0, 0.12);

  --material-chrome: rgba(245, 245, 247, 0.72);
  --material-sidebar: rgba(236, 236, 240, 0.78);
  --material-popover: rgba(255, 255, 255, 0.82);

  --shadow-popover: 0 0 0 0.5px rgba(0, 0, 0, 0.08), 0 10px 30px rgba(0, 0, 0, 0.12);
  --shadow-thumb: 0 0 0 0.5px rgba(0, 0, 0, 0.04), 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --sidebar-w: 236px;
  --topbar-h: 52px;
  --tabbar-h: 56px;

  /* Curva de iOS para hojas/popovers: sin rebote (equivale a un resorte críticamente amortiguado). */
  --ease-out: cubic-bezier(0.32, 0.72, 0, 1);

  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: -0.006em;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --surface: #1c1c1e;
    --surface-raised: #2c2c2e;
    --fill: rgba(118, 118, 128, 0.24);
    --fill-strong: rgba(118, 118, 128, 0.36);
    --separator: rgba(255, 255, 255, 0.08);
    --separator-strong: rgba(255, 255, 255, 0.16);

    --label: #f5f5f7;
    --label-2: rgba(235, 235, 245, 0.62);
    --label-3: rgba(235, 235, 245, 0.42);

    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-tint: rgba(10, 132, 255, 0.18);
    --accent-ring: rgba(10, 132, 255, 0.4);

    --red: #ff453a;
    --red-text: #ff6961;
    --red-tint: rgba(255, 69, 58, 0.18);
    --green: #30d158;
    --green-text: #30d158;
    --green-tint: rgba(48, 209, 88, 0.18);
    --orange: #ff9f0a;
    --orange-text: #ffb340;
    --orange-tint: rgba(255, 159, 10, 0.18);

    --material-chrome: rgba(15, 15, 16, 0.72);
    --material-sidebar: rgba(30, 30, 32, 0.72);
    --material-popover: rgba(44, 44, 46, 0.82);

    --shadow-popover: 0 0 0 0.5px rgba(255, 255, 255, 0.1), 0 12px 36px rgba(0, 0, 0, 0.5);
    --shadow-thumb: 0 0 0 0.5px rgba(0, 0, 0, 0.2), 0 3px 8px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--accent-ring); }

:focus-visible { outline: 3px solid var(--accent-ring); outline-offset: 2px; }

.icon { display: block; flex-shrink: 0; }

h1, h2, h3, p { margin: 0; }

.muted { color: var(--label-2); }

/* ------------------------------------------------------------- Tipografía */

.large-title {
  font-size: 30px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: -0.024em;
}

.page-subtitle {
  margin-top: 4px;
  font-size: 15px;
  color: var(--label-2);
  letter-spacing: -0.01em;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 36px 0 12px;
}
.section-head:first-child { margin-top: 0; }
.section-head h2 { font-size: 19px; line-height: 1.25; font-weight: 600; letter-spacing: -0.016em; }
.section-head p { margin-top: 3px; font-size: 13px; color: var(--label-2); max-width: 640px; }

.footnote { font-size: 12px; line-height: 1.4; color: var(--label-2); letter-spacing: 0; }

.numeric {
  font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "SF Pro Rounded", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

code, .mono {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  letter-spacing: 0;
}
code {
  background: var(--fill);
  padding: 2px 6px;
  border-radius: 5px;
}

/* ----------------------------------------------------------------- Login */

.login-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.login-head { text-align: center; margin-bottom: 28px; }
.login-head .app-icon { margin: 0 auto 18px; }
.login-head h1 { font-size: 24px; line-height: 1.2; font-weight: 700; letter-spacing: -0.02em; }
.login-head p { margin-top: 6px; color: var(--label-2); font-size: 14px; }

/* Campos apilados en un mismo grupo, como en los formularios de iOS/macOS. */
.stacked-fields {
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 0 0 0.5px var(--separator-strong);
}
.stacked-fields input[type] {
  display: block;
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 15px;
}
.stacked-fields input[type]:focus { background: transparent; border-color: transparent; box-shadow: none; }
.stacked-fields input[type] + input[type] { border-top: 1px solid var(--separator); }
.stacked-fields:focus-within { box-shadow: 0 0 0 0.5px var(--accent), 0 0 0 4px var(--accent-ring); }

.login-card .btn-primary { margin-top: 16px; height: 44px; font-size: 15px; justify-content: center; border-radius: var(--radius-md); }
.login-card .error { margin-top: 12px; text-align: center; }

.shake { animation: shake 0.42s var(--ease-out); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

.app-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.app-icon.lg { width: 60px; height: 60px; border-radius: 15px; }

/* ---------------------------------------------------------------- Layout */

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 14px 10px 12px;
  background: var(--material-sidebar);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  backdrop-filter: blur(30px) saturate(180%);
  border-right: 1px solid var(--separator);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.012em;
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--label);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.nav-item .icon { color: var(--label-2); }
.nav-item:hover { background: var(--fill); }
.nav-item:active { background: var(--fill-strong); }
.nav-item.active { background: var(--fill-strong); font-weight: 600; }
.nav-item.active .icon { color: var(--accent); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 2px;
  border-top: 1px solid var(--separator);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--fill-strong);
  color: var(--label-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--label-2);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.link-btn:hover { color: var(--accent); }

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

/* Barra superior: material translúcido sobre el que se desplaza el contenido. El divisor
   solo aparece cuando hay contenido debajo (scroll edge), no como borde fijo. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 32px;
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.topbar.scrolled {
  background: var(--material-chrome);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom-color: var(--separator);
}

.compact-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.012em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.3s var(--ease-out);
}
.topbar.scrolled .compact-title { opacity: 1; transform: none; }

.live-badge {
  display: none;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.live-badge.on { display: inline-flex; }
.live-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: breathe 2s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: 0.35; } }

.account-btn {
  display: none;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 50%;
}

main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  padding: 4px 32px 64px;
}

.page-header { margin-bottom: 28px; }

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

/* ------------------------------------------------------------- Superficies */

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; letter-spacing: -0.012em; }
.card-title + .footnote { margin-top: 2px; }
.card > .card-title, .card > .footnote { margin-bottom: 14px; }
.card > .card-title:has(+ .footnote) { margin-bottom: 0; }

.card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.card-actions .spacer { flex: 1; }

.empty-state {
  padding: 28px 20px;
  text-align: center;
  color: var(--label-2);
  font-size: 13px;
  background: var(--surface);
  border-radius: var(--radius-lg);
}

/* Lista agrupada (estilo Ajustes de iOS): filas con divisores con sangría. */
.group {
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.group-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 16px;
}
.group-row + .group-row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 1px;
  background: var(--separator);
}
.group-row .row-main { flex: 1; min-width: 0; }
.group-row .row-title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-row .row-sub { font-size: 12px; color: var(--label-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-row .row-trailing { display: flex; align-items: center; gap: 10px; flex-shrink: 0; text-align: right; }

/* --------------------------------------------------------------- Métricas */

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.metric { padding: 18px 20px 20px; position: relative; }
.metrics .metric + .metric::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18px;
  bottom: 18px;
  width: 1px;
  background: var(--separator);
}
.metric .metric-label { font-size: 13px; color: var(--label-2); font-weight: 500; }
.metric .metric-value {
  margin-top: 6px;
  font-size: 34px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.metrics-secondary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.metrics-secondary .metric { background: var(--surface); border-radius: var(--radius-md); padding: 14px 16px; }
.metrics-secondary .metric-value { font-size: 22px; }
.metric.is-alert .metric-value { color: var(--red-text); }

.metrics-context {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--label-2);
}
.metrics-context b { color: var(--label); font-weight: 600; }

/* ------------------------------------------------------- Estado / conectores */

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--label-3); flex-shrink: 0; }
.status-dot.good { background: var(--green); }
.status-dot.warn { background: var(--orange); }
.status-dot.bad { background: var(--red); }

.status-text { font-size: 13px; font-weight: 500; }
.status-text.good { color: var(--green-text); }
.status-text.warn { color: var(--orange-text); }
.status-text.bad { color: var(--red-text); }

.timestamp { font-size: 12px; color: var(--label-3); font-variant-numeric: tabular-nums; min-width: 64px; }

/* ---------------------------------------------------------------- Botones */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  /* Respuesta al presionar (pointer-down), no al soltar; al soltar regresa suave. */
  transition: transform 0.3s var(--ease-out), background-color 0.15s ease, opacity 0.15s ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); transition-duration: 0.06s; }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--accent-tint); color: var(--accent); }
.btn-secondary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover:not(:disabled) { background: var(--fill); }

.btn-destructive { background: transparent; color: var(--red-text); }
.btn-destructive:hover:not(:disabled) { background: var(--red-tint); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; border-radius: 7px; }

/* --------------------------------------------------------------- Formularios */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 13px; font-weight: 500; color: var(--label); }
.field .footnote { margin-top: -2px; }

.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row > * { flex: 1; min-width: 160px; }
.form-stack { display: flex; flex-direction: column; gap: 18px; }

input[type="text"], input[type="number"], input[type="password"], select, textarea {
  height: 36px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--fill);
  color: var(--label);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder { color: var(--label-3); }
input:focus, select:focus, textarea:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
input[readonly] { color: var(--label-2); }
input[aria-invalid="true"] { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-tint); }

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238e8e93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

/* Campo con prefijo fijo ("@"): deja claro el formato sin obligar a escribirlo. */
.affix {
  display: flex;
  align-items: center;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--fill);
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.affix span { padding-left: 11px; color: var(--label-3); font-size: 14px; }
.affix input { flex: 1; min-width: 0; height: 34px; padding-left: 2px; background: transparent; border: 0; box-shadow: none; }
.affix input:focus { background: transparent; border: 0; box-shadow: none; }
.affix:focus-within { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.affix:has(input[aria-invalid="true"]) { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-tint); }

/* Interruptor estilo iOS. El input real sigue siendo un checkbox accesible. */
.switch { position: relative; display: inline-flex; flex-shrink: 0; cursor: pointer; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch-track {
  width: 42px;
  height: 25px;
  border-radius: 999px;
  background: var(--fill-strong);
  position: relative;
  transition: background-color 0.25s ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-thumb);
  transition: transform 0.35s var(--ease-out), width 0.2s var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { transform: translateX(17px); }
.switch:active .switch-track::after { width: 25px; }
.switch:active input:checked + .switch-track::after { transform: translateX(13px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--accent-ring); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.45; }

.slider-field { display: flex; align-items: center; gap: 12px; }
.slider-field input[type="range"] { flex: 1; accent-color: var(--accent); margin: 0; }
.slider-field input[type="range"]:disabled { opacity: 0.4; }
.slider-field output { min-width: 42px; text-align: right; font-size: 14px; font-weight: 500; }

.disclosure { margin-top: 2px; }
.disclosure > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  list-style: none;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--accent);
  user-select: none;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary .icon { transition: transform 0.3s var(--ease-out); }
.disclosure[open] > summary .icon { transform: rotate(90deg); }
.disclosure-body { margin-top: 14px; display: flex; flex-direction: column; gap: 16px; }

.error {
  font-size: 13px;
  color: var(--red-text);
}
.card .error { margin-top: 12px; }
.card-actions .error { margin: 0; }

/* Lista agrupada dentro de una tarjeta: sin segunda capa de fondo, solo el contorno. */
.card .group { background: transparent; box-shadow: inset 0 0 0 1px var(--separator); }

/* Plataformas: una fila por plataforma, con su usuario y su interruptor. */
.channel-group .group-row { min-height: 54px; }
.channel-group .platform-name { width: 92px; flex-shrink: 0; font-weight: 500; }
.channel-group .affix { flex: 1; visibility: hidden; }
.channel-group .group-row.checked .affix { visibility: visible; }

.channel-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--fill);
  font-size: 12px;
  color: var(--label-2);
  white-space: nowrap;
}
.channel-chip b { color: var(--label); font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* ----------------------------------------------------------------- Tablas */

.table-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table { width: 100%; border-collapse: collapse; }

th, td { text-align: left; padding: 10px 16px; font-size: 13.5px; vertical-align: middle; }
th {
  font-size: 12px;
  font-weight: 500;
  color: var(--label-2);
  letter-spacing: 0;
  white-space: nowrap;
  border-bottom: 1px solid var(--separator);
}
td { border-bottom: 1px solid var(--separator); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td, table tr:not(:first-child):hover td { background: color-mix(in srgb, var(--fill) 50%, transparent); }
td.muted-cell, .muted-cell { color: var(--label-3); }
td .cell-title { font-weight: 500; }
td .cell-sub { font-size: 12px; color: var(--label-2); margin-top: 1px; }
td.truncate { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.selected td { background: var(--accent-tint); }

tr.is-new td { animation: row-arrive 1.6s ease-out; }
@keyframes row-arrive { from { background: var(--accent-tint); } }

.row-actions { display: flex; align-items: center; gap: 4px; }

.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; margin-right: 6px; box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.15); }

/* ---------------------------------------------------------- Insignias/tags */

.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
  background: var(--fill);
  color: var(--label-2);
}
.tag-good { background: var(--green-tint); color: var(--green-text); }
.tag-warn { background: var(--orange-tint); color: var(--orange-text); }
.tag-bad { background: var(--red-tint); color: var(--red-text); }
.tag-accent { background: var(--accent-tint); color: var(--accent); }

/* Selector de estado con aspecto de etiqueta: el color comunica el estado actual. */
.status-select {
  height: 26px;
  padding: 0 26px 0 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  background-position: right 9px center;
}
.status-select[data-status="LIVE"] { background-color: var(--red-tint); color: var(--red-text); }
.status-select[data-status="READY"] { background-color: var(--accent-tint); color: var(--accent); }
.status-select[data-status="PAUSED"] { background-color: var(--orange-tint); color: var(--orange-text); }
.status-select[data-status="FINISHED"] { background-color: var(--green-tint); color: var(--green-text); }

/* ------------------------------------------------------- Control segmentado */

.toolbar { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .field { min-width: 240px; }

.segmented-scroll { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented-scroll::-webkit-scrollbar { display: none; }

.segmented {
  position: relative;
  display: inline-flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
}
.segmented-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  border-radius: 7px;
  background: var(--surface-raised);
  box-shadow: var(--shadow-thumb);
  transition: transform 0.4s var(--ease-out), width 0.4s var(--ease-out);
}
.segmented button {
  position: relative;
  z-index: 1;
  height: 28px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--label);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  border-radius: 7px;
  transition: opacity 0.15s ease;
}
.segmented button:active { opacity: 0.6; transition-duration: 0.05s; }
.segmented button.active { font-weight: 600; }

/* ------------------------------------------------------------- Varios */

.code-block {
  margin: 0;
  padding: 14px 16px;
  max-height: 300px;
  overflow: auto;
  border-radius: var(--radius-md);
  background: var(--fill);
  color: var(--label-2);
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.inline-field { display: flex; gap: 8px; }
.inline-field input { flex: 1; min-width: 0; }

/* Toast: feedback de "completado". Entra y sale por el mismo camino (abajo). */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--material-popover);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--shadow-popover);
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.45s var(--ease-out);
}
.toast.visible { opacity: 1; transform: none; }
.toast .icon { color: var(--green); }
.toast.bad .icon { color: var(--red); }

/* Popover de cuenta (mobile): nace del botón que lo abre (transform-origin). */
.popover {
  position: fixed;
  top: calc(var(--topbar-h) - 4px);
  right: 12px;
  z-index: 30;
  min-width: 220px;
  padding: 6px;
  border-radius: 14px;
  background: var(--material-popover);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  backdrop-filter: blur(30px) saturate(180%);
  box-shadow: var(--shadow-popover);
  transform-origin: top right;
  opacity: 0;
  transform: scale(0.9);
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.35s var(--ease-out), visibility 0s linear 0.35s;
}
.popover.open { opacity: 1; transform: none; visibility: visible; transition-delay: 0s; }
.popover-header { padding: 8px 10px 10px; border-bottom: 1px solid var(--separator); margin-bottom: 4px; }
.popover-header .footnote { margin-top: 1px; }
.popover-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--red-text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.popover-item:active { background: var(--fill); }

/* Tab bar inferior (mobile): reemplaza a la barra lateral, patrón familiar de iOS. */
.tabbar { display: none; }

/* ---------------------------------------------------------------- Responsive */

@media (max-width: 960px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(3)::before { display: none; }
  .metric:nth-child(n + 3) { border-top: 1px solid var(--separator); }
}

@media (max-width: 760px) {
  .sidebar { display: none; }

  .topbar { padding: 0 16px; }
  .account-btn { display: inline-flex; }

  main { padding: 0 16px calc(var(--tabbar-h) + 40px + env(safe-area-inset-bottom)); }
  .large-title { font-size: 28px; }
  .page-header { margin-bottom: 22px; }

  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    padding: 6px 4px env(safe-area-inset-bottom);
    background: var(--material-chrome);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid var(--separator);
  }
  .tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    height: var(--tabbar-h);
    padding: 4px 0 0;
    border: 0;
    background: none;
    color: var(--label-3);
    font: inherit;
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: transform 0.3s var(--ease-out);
  }
  .tab-item:active { transform: scale(0.92); transition-duration: 0.06s; }
  .tab-item.active { color: var(--accent); }

  .toast-region { bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); }

  .table-card table { min-width: 640px; }
  .section-head { margin-top: 30px; }
  .card { padding: 16px; }
  .metrics-secondary { grid-template-columns: 1fr; gap: 0; background: var(--surface); border-radius: var(--radius-lg); overflow: hidden; }
  .metrics-secondary .metric { border-radius: 0; display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; }
  .metrics-secondary .metric + .metric::before {
    content: "";
    position: absolute;
    top: 0;
    left: 16px;
    right: 0;
    height: 1px;
    background: var(--separator);
  }
  .metrics-secondary .metric-value { margin-top: 0; font-size: 17px; }
  .toolbar .field { min-width: 0; flex: 1 1 100%; }
}

@media (max-width: 480px) {
  .metric { padding: 14px 16px 16px; }
  .metric .metric-value { font-size: 28px; }
  .channel-group .group-row { flex-wrap: wrap; row-gap: 8px; padding-top: 10px; padding-bottom: 10px; }
  .channel-group .platform-name { flex: 1; }
  .channel-group .affix { order: 3; flex-basis: 100%; display: none; }
  .channel-group .group-row.checked .affix { display: flex; }
  .card-actions .btn { flex: 1; }
}

/* ------------------------------------------------------------ Accesibilidad */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .toast, .popover { transition: opacity 0.2s ease !important; transform: none !important; }
  .live-badge .dot { animation: none; }
}

@media (prefers-reduced-transparency: reduce) {
  :root {
    --material-chrome: var(--bg);
    --material-sidebar: var(--bg);
    --material-popover: var(--surface-raised);
  }
  .sidebar, .topbar.scrolled, .tabbar, .toast, .popover { -webkit-backdrop-filter: none; backdrop-filter: none; }
}

@media (prefers-contrast: more) {
  :root {
    --separator: rgba(60, 60, 67, 0.45);
    --label-2: #3a3a3c;
    --label-3: #545458;
  }
  .card, .group, .metrics, .table-card, .empty-state, .metrics-secondary .metric { box-shadow: 0 0 0 1px var(--separator-strong); }
  input[type="text"], input[type="number"], input[type="password"], select, .affix { border-color: var(--separator-strong); }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root {
    --separator: rgba(255, 255, 255, 0.3);
    --label-2: rgba(235, 235, 245, 0.82);
    --label-3: rgba(235, 235, 245, 0.66);
  }
}
