﻿@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

/* Tokens de diseno: todo color/radio/sombra del sitio sale de aqui. */
:root {
  --font: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, "Liberation Mono", monospace;

  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --surface-2: #f6f8fb;
  --surface-3: #e9eef5;
  --text: #0f1b2d;
  --text-2: #334155;
  --muted: #64748b;
  --border: #dbe2ec;
  --border-soft: #e8edf4;
  --border-strong: #c3cddb;

  color-scheme: light;

  --accent: #1f5bd8;
  --accent-strong: #1f5bd8;
  --accent-2: #1847ad;
  --accent-3: #0e9f9d;
  --accent-soft: rgba(31, 91, 216, 0.09);
  --accent-soft-2: rgba(31, 91, 216, 0.16);
  --ink: #0f2742;

  --ok: #1e8a4c;
  --warn: #b7791f;
  --bad: #c9352b;

  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 8px;
  --ring: 0 0 0 3px rgba(31, 91, 216, 0.22);
  --shadow: 0 1px 2px rgba(15, 27, 45, 0.05), 0 4px 14px rgba(15, 27, 45, 0.05);
  --shadow-lg: 0 18px 40px rgba(15, 27, 45, 0.16);
  --nav-bg: rgba(255, 255, 255, 0.92);
}

/* Utilitarios (evitar style="..." en HTML y JS para poder endurecer CSP). */
.hidden { display: none !important; }
.actions-end { margin-left: auto; }
.u-mt-10 { margin-top: 10px; }
.u-mt-12 { margin-top: 12px; }
.u-items-end { align-items: flex-end; }
.u-clickable { cursor: pointer; }
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Modal */
.modal-body { margin-top: 10px; }
.modal-body h3 { margin: 12px 0 6px; font-size: 14px; color: var(--ink); }
.modal-body p, .modal-body li { line-height: 1.55; }
.modal-body.scroll { max-height: 58vh; overflow: auto; padding-right: 6px; }

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1;
}

::selection {
  background: var(--accent-soft-2);
}

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Scrollbars discretos en tablas, graficos y menus. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body.menu-open {
  overflow: hidden;
}

body.app-locked {
  overflow: hidden;
}

body.app-locked .shell,
body.app-locked .menu-fab,
body.app-locked .mobile-menu {
  display: none;
}

body.ui-busy {
  cursor: progress;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 35, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000;
}

.loading-card {
  min-width: 170px;
  max-width: 240px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 14px 30px rgba(15, 23, 35, 0.24);
  padding: 16px 14px;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.loading-text {
  font-size: 13px;
  color: var(--ink);
  font-weight: 600;
}

.spinner-border {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  border: 0.24em solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spinner-border 0.75s linear infinite;
}

.text-info {
  color: var(--accent);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    radial-gradient(900px 480px at 0% 0%, rgba(31, 91, 216, 0.18), transparent 60%),
    radial-gradient(800px 420px at 100% 100%, rgba(14, 159, 157, 0.14), transparent 60%),
    linear-gradient(160deg, #f5f8fc 0%, var(--bg) 100%);
}

body:not(.app-locked) .login-screen {
  display: none;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 30px 28px 24px;
  display: grid;
  gap: 14px;
}

.login-card .actions {
  justify-content: center;
}

.login-card .actions .btn {
  width: 100%;
  max-width: 320px;
}

.login-local-form {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  justify-self: center;
}

.login-local-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
}

.login-local-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.login-local-form .btn {
  width: 100%;
}

.btn.ms-signin {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  height: 44px;
  padding: 0 16px 0 14px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #2f2f2f;
  color: #ffffff;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: none;
  transform: none;
  opacity: 1;
}

.btn.ms-signin::before {
  content: "";
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  background-repeat: no-repeat;
  background-size: contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 21 21'%3E%3Crect x='0' y='0' width='10' height='10' fill='%23F25022'/%3E%3Crect x='11' y='0' width='10' height='10' fill='%237FBA00'/%3E%3Crect x='0' y='11' width='10' height='10' fill='%2300A4EF'/%3E%3Crect x='11' y='11' width='10' height='10' fill='%23FFB900'/%3E%3C/svg%3E");
}

.btn.ms-signin:hover {
  background: #242424;
  transform: none;
  opacity: 1;
}

.btn.ms-signin:active {
  background: #1b1b1b;
  transform: none;
  opacity: 1;
}

.btn.ms-signin:focus-visible {
  outline: 2px solid rgba(0, 164, 239, 0.75);
  outline-offset: 2px;
}

.login-logo {
  width: 90px;
  height: 42px;
  object-fit: contain;
  justify-self: center;
}

.login-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.login-sub {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.login-locale {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
}

.login-locale .locale-label {
  margin: 0;
  display: inline-block;
  color: var(--muted);
  font-size: 12px;
  min-width: 48px;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin: 2px 0;
  user-select: none;
}

.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.shell {
  max-width: none;
  width: 100%;
  margin: 0 auto;
  padding: 18px clamp(12px, 1.6vw, 28px) 48px;
}

body.hisbox-wide-mode .shell {
  max-width: none;
}

body.hisbox-wide-mode main,
body.hisbox-wide-mode .panel[data-panel="hisbox"],
body.hisbox-wide-mode .hisbox-section.active {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  background: var(--surface);
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.locale-dropdown {
  position: relative;
  display: inline-flex;
}

.locale-switch {
  display: inline-flex;
}

.locale-switch .locale-trigger {
  min-width: 58px;
  padding: 0 10px;
}

.locale-switch .locale-trigger-label {
  display: none;
}

.locale-switch .locale-caret {
  margin-left: 0;
}

.locale-trigger {
  min-width: 156px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.locale-trigger:hover {
  border-color: rgba(31, 91, 216, 0.35);
}

.locale-trigger:focus-visible {
  outline: 2px solid rgba(31, 91, 216, 0.35);
  outline-offset: 2px;
}

.locale-trigger.pulse {
  animation: localePulse 2.6s ease-in-out infinite;
}

.locale-dropdown.open .locale-trigger.pulse {
  animation: none;
}

.locale-trigger-flag,
.locale-flag {
  width: 22px;
  height: 14px;
  border-radius: 2px;
  object-fit: cover;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.locale-trigger-label {
  font-size: 13px;
  font-weight: 500;
}

.locale-caret {
  margin-left: auto;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid rgba(28, 36, 52, 0.8);
}

.locale-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 34px rgba(15, 23, 35, 0.16);
  padding: 8px;
  z-index: 80;
  display: none;
}

.login-locale .locale-menu {
  left: 0;
  right: auto;
}

.locale-dropdown.open .locale-menu {
  display: block;
  animation: localeMenuIn 0.16s ease-out;
}

.locale-item {
  width: 100%;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  text-align: left;
  cursor: pointer;
}

.locale-item:hover {
  background: var(--accent-soft);
}

.locale-item.active {
  background: var(--accent-soft-2);
  color: #1c2f80;
}

@keyframes localeMenuIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes localePulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 var(--accent-soft-2);
  }
  60% {
    box-shadow: 0 0 0 7px rgba(31, 91, 216, 0);
  }
}

.topbar-meta {
  font-size: 12px;
  color: var(--muted);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 72px;
  height: 32px;
  object-fit: contain;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2), var(--accent-3));
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--ink);
}

.brand-sub {
  font-size: 13px;
  color: var(--muted);
}

.toast-stack {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 5000;
  width: min(380px, calc(100vw - 20px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  border-radius: 12px;
  border: 1px solid rgba(20, 30, 55, 0.1);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 22px rgba(20, 30, 55, 0.16);
  backdrop-filter: blur(8px);
  overflow: hidden;
  opacity: 0;
  transform: translateX(8px);
  animation: toast-in 0.2s ease forwards;
}

.toast.toast-closing {
  animation: toast-out 0.16s ease forwards;
}

.toast-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(20, 30, 55, 0.08);
  background: rgba(245, 248, 255, 0.82);
}

.toast-avatar {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  object-fit: contain;
  border: 1px solid rgba(20, 30, 55, 0.12);
  background: rgba(255, 255, 255, 0.8);
}

.toast-title {
  font-size: 12px;
  font-weight: 700;
  color: #1d2738;
  margin-right: auto;
}

.toast-time {
  font-size: 11px;
  color: #647084;
}

.toast-close {
  border: 0;
  background: transparent;
  color: #647084;
  width: 20px;
  height: 20px;
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.toast-close:hover {
  background: rgba(20, 30, 55, 0.08);
  color: #2b3547;
}

.toast-close::before {
  content: "×";
  font-size: 14px;
  line-height: 1;
}

.toast-body {
  padding: 10px 12px;
  font-size: 13px;
  color: #1f2a3b;
  line-height: 1.4;
  word-break: break-word;
}

.toast.toast-error .toast-header {
  background: rgba(231, 76, 60, 0.12);
}

.toast.toast-error .toast-body {
  color: #7a2f2a;
}

.toast.toast-success .toast-header {
  background: rgba(46, 204, 113, 0.13);
}

.toast.toast-success .toast-body {
  color: #1e5a3b;
}

.toast.toast-warning .toast-header {
  background: rgba(244, 211, 94, 0.24);
}

.toast.toast-warning .toast-body {
  color: #6b5b22;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateX(8px);
  }
}

@media (max-width: 780px) {
  .toast-stack {
    left: 10px;
    right: 10px;
    width: auto;
    top: max(10px, env(safe-area-inset-top));
  }
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  color: #2b3342;
  background: rgba(108, 117, 125, 0.12);
}

.status-pill.status-ok {
  background: rgba(46, 204, 113, 0.16);
  border-color: rgba(46, 204, 113, 0.28);
  color: #1e5a3b;
}

.status-pill.status-warn {
  background: rgba(244, 211, 94, 0.2);
  border-color: rgba(244, 211, 94, 0.38);
  color: #6b5b22;
}

.status-pill.status-info {
  background: var(--accent-soft-2);
  border-color: rgba(31, 91, 216, 0.28);
  color: #2b3b8b;
}

.status-pill.status-bad {
  background: rgba(231, 76, 60, 0.16);
  border-color: rgba(231, 76, 60, 0.3);
  color: #7a2f2a;
}

.status-pill.status-neutral {
  background: rgba(108, 117, 125, 0.12);
  border-color: rgba(108, 117, 125, 0.24);
  color: #2b3342;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 20px;
  padding: 6px;
  background: var(--nav-bg);
  backdrop-filter: saturate(1.4) blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.tabs > .tab,
.tabs > .tab-dropdown > .tab {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
}

.tabs > .tab:hover,
.tabs > .tab-dropdown > .tab:hover {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}

.tabs > .tab.active,
.tabs > .tab-dropdown > .tab.active {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(31, 91, 216, 0.28);
}

.tabs > .tab-logout {
  margin-left: auto;
  color: var(--bad);
}

.tabs > .tab-logout:hover {
  background: rgba(201, 53, 43, 0.08);
  color: var(--bad);
}

.config-nav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.config-nav .tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  margin-bottom: -1px;
  padding: 9px 14px;
  color: var(--muted);
  font-weight: 500;
}

.config-nav .tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.6);
}

.config-nav .tab.active {
  background: transparent;
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
  box-shadow: none;
}

.config-section {
  display: none;
}

.config-section.active {
  display: block;
}

.historico-section {
  display: none;
}

.historico-section.active {
  display: block;
}

.hisbox-section {
  display: none;
}

.hisbox-section.active {
  display: block;
}

.menu-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent-strong);
  box-shadow: 0 12px 26px rgba(31, 91, 216, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  z-index: 1100;
  cursor: pointer;
}

.menu-fab span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--surface);
  border-radius: 999px;
}

.mobile-menu {
  position: fixed;
  inset: 0;
  background: rgba(12, 16, 24, 0.45);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 1090;
}

body.menu-open .mobile-menu {
  opacity: 1;
  pointer-events: auto;
}

.mobile-menu-panel {
  position: absolute;
  right: 16px;
  bottom: 86px;
  width: min(260px, 86vw);
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 18px 30px rgba(15, 23, 35, 0.25);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mobile-menu-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 4px;
}

.mobile-menu .tab {
  width: 100%;
  justify-content: flex-start;
}

.tab-dropdown {
  position: relative;
}

.tab-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tab-dropdown-toggle::after {
  content: "";
  width: 0;
  height: 0;
  margin-top: 3px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.7;
}

.tab-menu {
  position: absolute;
  top: 42px;
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.12);
  display: none;
  z-index: 20;
}

.tab-dropdown.open .tab-menu {
  display: block;
}

.tab-menu .tab {
  width: 100%;
  justify-content: flex-start;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  transform: none;
}

.tab-menu .tab:hover {
  background: var(--accent-soft);
}

.btn-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.btn-menu {
  position: absolute;
  top: 42px;
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.12);
  display: none;
  z-index: 20;
}

.btn-dropdown.open .btn-menu {
  display: block;
}

.btn-menu .btn {
  width: 100%;
  justify-content: flex-start;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  transform: none;
}

.btn-menu .btn:hover,
.btn-menu .btn:focus-visible {
  background: var(--accent-soft);
}

.tab {
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  border: 1px solid var(--border);
}

.tab.active {
  background: var(--accent-soft);
  border-color: rgba(31, 91, 216, 0.35);
  color: var(--accent);
}

.tab:hover {
  border-color: var(--border-strong);
}

.tab-logout {
  border-color: rgba(231, 76, 60, 0.3);
  color: #d94a3a;
}

.tab-logout:hover {
  background: rgba(231, 76, 60, 0.1);
}

.panel {
  display: none;
  animation: fade 0.25s ease;
}

.panel.active {
  display: block;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 27, 45, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal-backdrop.floating {
  background: transparent;
  backdrop-filter: none;
  align-items: flex-start;
  justify-content: flex-end;
  pointer-events: none;
}

.modal-backdrop.floating .modal {
  pointer-events: auto;
  margin-top: 90px;
  margin-right: 24px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  width: min(420px, 100%);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 12px;
}

.modal-wide {
  width: min(900px, 100%);
}

.modal-help {
  width: min(1080px, 100%);
}

.help-frame {
  width: 100%;
  min-height: 68vh;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.footer {
  margin-top: 28px;
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.footer-main {
  font-weight: 600;
  color: var(--muted);
}

.footer-meta {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
}

.footer-tech {
  color: var(--muted);
}

.footer-link {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.footer-link:hover {
  color: var(--text);
}

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card.wide {
  grid-column: 1 / -1;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-2);
  margin-bottom: 12px;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.card-metric {
  font-size: 30px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.card-metric a {
  color: var(--accent);
  text-decoration: none;
}

.card-metric a:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.card-sub {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.nested-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.nested-card {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
}

.nested-card-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.nested-card-sub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.nested-card-info {
  background: linear-gradient(180deg, rgba(246, 248, 252, 0.9), rgba(255, 255, 255, 1));
}

.nested-card .card-sub {
  margin-top: 0;
}

.periodic-live-toolbar {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(245, 248, 255, 0.9), rgba(255, 255, 255, 0.96));
  padding: 10px 12px;
}

.periodic-live-head {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.periodic-live-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.periodic-live-item {
  border: 1px solid rgba(120, 136, 168, 0.2);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.72);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.periodic-live-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.periodic-live-item strong {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.periodic-live-item small {
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.periodic-live-error {
  margin-top: 8px;
  min-height: 16px;
  font-size: 12px;
  color: #7a2f2a;
  overflow-wrap: anywhere;
}

.periodic-live-error.is-empty {
  color: var(--muted);
}

.security-live-toolbar {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(244, 250, 247, 0.92), rgba(255, 255, 255, 0.96));
  padding: 10px 12px;
}

.security-live-head {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.security-live-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.security-live-item {
  border: 1px solid rgba(120, 136, 168, 0.2);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.72);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.security-live-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.security-live-item strong {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.security-live-item small {
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.security-live-error {
  margin-top: 8px;
  min-height: 16px;
  font-size: 12px;
  color: #7a2f2a;
  overflow-wrap: anywhere;
}

.security-live-error.is-empty {
  color: var(--muted);
}

.auto-trigger-card {
  grid-column: 1 / -1;
}

.auto-trigger-grid {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px 12px;
}

.auto-trigger-grid label {
  gap: 5px;
  font-size: 12px;
}

.auto-trigger-grid input:not([type="checkbox"]),
.auto-trigger-grid select {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

.auto-trigger-grid label:has(> input[type="checkbox"]) {
  grid-column: 1 / -1;
  min-height: 32px;
}

.mono {
  font-family: var(--font-mono);
  white-space: pre-wrap;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.chart {
  width: 100%;
  min-height: 200px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
}

.chart svg {
  width: 100%;
  height: 180px;
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.chart-controls select {
  min-width: 180px;
}

.chart-metric {
  font-size: 20px;
  font-weight: 600;
  margin-left: auto;
}

.bar-wrap {
  display: flex;
  flex-wrap: nowrap;
  align-items: end;
  gap: 1px;
  min-height: 240px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface);
}

.bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 44px;
  flex: 1 1 0;
}

.bar {
  width: 26px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
}

.bar-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  min-height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}

.bar-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.donut-wrap {
  width: 100%;
  min-height: 240px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.donut-side {
  min-width: 120px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: rgb(241, 94, 36);
  font-weight: 600;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.donut-side-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.donut-side-value {
  font-size: 22px;
  font-weight: 700;
}

.donut-side-sub {
  font-size: 14px;
  font-weight: 600;
}


.line-chart {
  width: 100%;
  min-height: 240px;
  height: 240px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

.line-chart.tall {
  min-height: 380px;
  height: 380px;
}

.line-chart #histChart {
  width: 100%;
  height: 100%;
  flex: 1;
}

.line-chart .chart-canvas {
  width: 100%;
  height: 100%;
  flex: 1;
}

.hisbox-general-kpis {
  grid-template-columns: minmax(260px, 0.9fr) repeat(2, minmax(220px, 0.55fr));
}

.hisbox-gauge {
  width: 100%;
  height: 210px;
}

.hisbox-summary-chart {
  width: 100%;
  height: 280px;
  min-height: 280px;
}

.hisbox-summary-chart.compact {
  height: 132px;
  min-height: 132px;
}

.hisbox-sector-layout {
  grid-template-columns: minmax(220px, 0.58fr) minmax(180px, 0.44fr) minmax(280px, 0.7fr) minmax(420px, 1.4fr);
}

.sector-daily-card {
  min-width: 0;
}

.hisbox-sector-tables {
  grid-template-columns: minmax(300px, 0.7fr) minmax(620px, 1.7fr);
}

.hisbox-sector-mini table {
  min-width: 460px;
}

.hisbox-sector-mini th,
.hisbox-sector-mini td {
  white-space: nowrap;
}

.hisbox-sector-pivot table {
  min-width: 1180px;
}

.hisbox-lastday-layout {
  grid-template-columns: minmax(210px, 0.5fr) minmax(260px, 0.62fr) minmax(320px, 1fr) minmax(420px, 1.35fr);
}

/* En el ultimo dia el grafico es el unico contenido de la tarjeta: altura suficiente para ejes legibles. */
.hisbox-lastday-layout .hisbox-summary-chart.compact,
body.hisbox-wide-mode .hisbox-lastday-layout .hisbox-summary-chart.compact {
  height: 250px;
  min-height: 250px;
}

.hisbox-lastday-table {
  max-height: calc(100vh - 330px);
}

.hisbox-lastday-table table {
  min-width: 1180px;
}

body.hisbox-wide-mode .panel[data-panel="hisbox"] .row {
  gap: 12px;
  margin-bottom: 12px;
}

body.hisbox-wide-mode .panel[data-panel="hisbox"] .card {
  padding: 14px;
}

body.hisbox-wide-mode .hisbox-summary-chart {
  height: 300px;
  min-height: 300px;
}

body.hisbox-wide-mode .hisbox-summary-chart.compact {
  height: 136px;
  min-height: 136px;
}

body.hisbox-wide-mode .hisbox-pivot {
  max-height: calc(100vh - 300px);
  overflow: auto;
}

.section-spacer {
  margin-top: 12px;
}

.hisbox-pivot table {
  min-width: 980px;
}

.hisbox-pivot th {
  text-align: center;
}

.hisbox-pivot td.pivot-sticky,
.hisbox-pivot th.pivot-sticky {
  min-width: 150px;
  background: inherit;
  color: inherit;
}

.hisbox-pivot td.pivot-ssee,
.hisbox-pivot th.pivot-ssee {
  min-width: 130px;
  background: inherit;
  color: inherit;
}

.hisbox-pivot th.pivot-sticky,
.hisbox-pivot th.pivot-ssee {
  color: var(--muted);
}

.pivot-cell {
  min-width: 78px;
  text-align: right;
  white-space: nowrap;
}

.pivot-total {
  font-weight: 700;
  background: var(--ink);
  color: #fff;
}

.pivot-dot {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -2px;
  border: 1px solid rgba(0, 0, 0, 0.18);
}

.pivot-good {
  background: #4caf72;
}

.pivot-warn {
  background: #d49a25;
}

.pivot-bad {
  background: #e45858;
}


.line-chart #histChart svg {
  width: 100%;
  height: 220px;
}

.hbar-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface);
  overflow-x: hidden;
  width: 100%;
  container-type: inline-size;
}

.hbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.hbar-row > * {
  min-width: 0;
}

:where(#chartCoordinado) .hbar-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 0.8fr);
}

.hbar-row.hbar-data {
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 12px;
  transition: background 0.2s ease, border-color 0.2s ease;
  border: 1px solid transparent;
}

.hbar-row.hbar-data:hover {
  background: var(--accent-soft);
}

.hbar-row.hbar-data.active {
  background: var(--accent-soft-2);
  border-color: rgba(31, 91, 216, 0.24);
}

.hbar-label {
  font-size: 12px;
  color: var(--muted);
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.2;
  max-width: 100%;
}

.hbar-track {
  height: 8px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}

.hbar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.hbar-value {
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}

@container (max-width: 560px) {
  .hbar-row {
    grid-template-columns: 1fr;
  }
  .hbar-row.hbar-header .hbar-track {
    display: none;
  }
  .hbar-track {
    order: 3;
  }
  .hbar-value {
    order: 2;
    justify-content: flex-start;
    text-align: left;
    flex-wrap: wrap;
    gap: 4px;
  }
  .hbar-current,
  .hbar-affected {
    min-width: 0;
  }
  .hbar-sep {
    display: none;
  }
}

.hbar-current,
.hbar-affected {
  min-width: 52px;
  text-align: right;
  display: inline-block;
}

.hbar-sep {
  color: var(--muted);
}

.hbar-affected {
  color: var(--bad);
  font-weight: 600;
}

.hbar-header .hbar-track {
  height: auto;
  background: transparent;
}

.hbar-header .hbar-value {
  text-align: left;
  align-items: center;
}

.hbar-sort {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 0;
}

.sort-arrow {
  font-size: 11px;
  color: var(--muted);
}

.hbar-header .hbar-label,
.hbar-header .hbar-track,
.hbar-header .hbar-value {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#dashboardCoordClear {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  min-height: 36px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.btn-xs {
  padding: 4px 10px;
  min-height: 26px;
  font-size: 12px;
}

.btn.primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 27, 45, 0.14);
}

.btn.primary:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.btn.ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
}

.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn.danger {
  background: #c9352b;
  border-color: #c9352b;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 27, 45, 0.14);
}

.btn.danger:hover {
  background: #a92a21;
  border-color: #a92a21;
}

.btn.danger.ghost {
  background: transparent;
  border: 1px solid rgba(217, 45, 32, 0.45);
  color: #d92d20;
  box-shadow: none;
}

.btn:hover {
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.table {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius-sm);
}

.scada-pi-table {
  width: 100%;
  border-collapse: collapse;
}

.scada-pi-table tbody tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

.scada-pi-table tbody tr:hover {
  background: var(--accent-soft);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 18px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(20, 83, 45, 0.08);
  color: rgba(20, 83, 45, 0.95);
  border: 1px solid rgba(20, 83, 45, 0.18);
  font-size: 12px;
  line-height: 1;
}

.users-online {
  margin: 10px 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.6);
}

.users-online-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.users-online-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.users-online-meta {
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
}

.users-online-list {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text);
}

.users-online-list .online-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 6px;
  border-radius: 10px;
}

.users-online-list .online-user:nth-child(odd) {
  background: rgba(0, 0, 0, 0.03);
}

.users-online-list .online-user .meta {
  color: var(--muted);
  font-size: 12px;
}

/* Estado de carga por-tabla (para filtros/consultas lentas). */
.table.is-loading {
  position: relative;
  min-height: 120px;
  cursor: progress;
}
.table.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(1px);
  z-index: 10;
}
.table.is-loading::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2rem;
  height: 2rem;
  margin-left: -1rem;
  margin-top: -1rem;
  border: 0.24em solid var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spinner-border 0.75s linear infinite;
  z-index: 11;
}

.table.scroll {
  max-height: 360px;
  overflow: auto;
}

.table-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.table-toolbar .actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.table-toolbar .actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.table-toolbar .actions label {
  min-width: auto;
}

.table-toolbar label {
  min-width: 140px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.table-toolbar input {
  min-width: 140px;
  padding: 8px 12px;
}

.table-toolbar.compact {
  gap: 8px;
}

.table-toolbar.compact label {
  min-width: 110px;
  font-size: 11px;
}

.table-toolbar.compact input,
.table-toolbar.compact select {
  min-width: 110px;
  padding: 6px 10px;
  font-size: 12px;
}

.coord-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.coord-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.coord-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.coord-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.coord-delete {
  margin-left: auto;
  border: none;
  background: transparent;
  color: #ee6c4d;
  cursor: pointer;
  font-size: 13px;
}

.coord-edit {
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
}

.heat {
  color: #0b1320;
  font-weight: 600;
  border-radius: 6px;
  padding: 3px 8px;
  display: inline-block;
  font-variant-numeric: tabular-nums;
}

.table table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.table.collapsed {
  display: none;
}

.table th,
.table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
}

.table th.col-center,
.table td.col-center {
  text-align: center;
}

/* Encabezado fijo dentro del contenedor con scroll (solo filas de encabezado simples). */
.table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 0;
  box-shadow: inset 0 -1px 0 var(--border);
}

.table th.pivot-sticky,
.table th.pivot-ssee {
  background: var(--surface-2);
}

.table th.pivot-total {
  background: var(--ink);
  color: #ffffff;
}

.table tbody tr:hover td {
  background: var(--surface-2);
}

.table tr.hist-run-row td {
  transition: background-color 0.15s ease;
}

.table tr.hist-run-row:hover td {
  background: var(--accent-soft);
  cursor: pointer;
}

.table tr.hist-run-row.is-selected td {
  background: var(--accent-soft-2);
}

.table tr.hist-row-invalid td {
  background: rgba(241, 94, 36, 0.10);
}

.table tr.hist-row-selected td {
  background: rgba(17, 24, 39, 0.06);
}

.table tr.hist-row-selected.hist-row-invalid td {
  /* Selected + invalid: destacar un poco mas */
  background: rgba(241, 94, 36, 0.16);
}

.table tr.hisbox-row td {
  transition: background-color 0.15s ease;
}

.table tr.hisbox-row:hover td {
  background: rgba(246, 138, 52, 0.10);
  cursor: pointer;
}

.table tr.hisbox-row.is-selected td {
  background: rgba(246, 138, 52, 0.22);
}

.role-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.role-cell select {
  min-width: 110px;
  height: 30px;
}

.user-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.user-badge-sso {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid rgba(47, 47, 47, 0.15);
  background: rgba(47, 47, 47, 0.06);
  color: rgba(18, 18, 18, 0.9);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  user-select: none;
}

.user-badge-sso::before {
  content: "";
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  background-repeat: no-repeat;
  background-size: contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 21 21'%3E%3Crect x='0' y='0' width='10' height='10' fill='%23F25022'/%3E%3Crect x='11' y='0' width='10' height='10' fill='%237FBA00'/%3E%3Crect x='0' y='11' width='10' height='10' fill='%2300A4EF'/%3E%3Crect x='11' y='11' width='10' height='10' fill='%23FFB900'/%3E%3C/svg%3E");
}

.user-badge-local {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid rgba(220, 38, 38, 0.25);
  background: rgba(220, 38, 38, 0.06);
  color: rgba(127, 29, 29, 0.95);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  user-select: none;
}

.user-sso-note {
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
}

/* Checkboxes compactos: checkbox a la izquierda y texto a la derecha. */
label:has(> input[type="checkbox"]) {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

label:has(> input[type="checkbox"]) > input[type="checkbox"] {
  order: -1;
  margin-right: 2px;
}

input:not([type="checkbox"]),
textarea,
select {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-height: 36px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  box-shadow: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:not([type="checkbox"]):hover,
textarea:hover,
select:hover {
  border-color: var(--border-strong);
}

input:not([type="checkbox"]):focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

input:disabled,
textarea:disabled,
select:disabled {
  background-color: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}

/* Flecha propia para que los select se vean iguales en todos los navegadores. */
select:not([multiple]) {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
  box-shadow: none;
}

textarea {
  width: 100%;
  min-height: 140px;
  border-radius: 12px;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spinner-border {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 20px 14px 48px;
  }
  .tabs {
    display: none;
  }
  .menu-fab {
    display: flex;
  }
  .config-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }
  .config-nav .tab {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .topbar-right {
    width: 100%;
    justify-content: flex-start;
  }
  .brand {
    width: 100%;
    flex-wrap: wrap;
  }
  .brand-logo {
    width: 56px;
    height: 26px;
  }
  .brand-title {
    font-size: 18px;
  }
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }
  .tab {
    white-space: nowrap;
    flex: 0 0 auto;
  }
  .row {
    grid-template-columns: 1fr;
  }
  .card.wide {
    grid-column: auto;
  }
  .chart-controls {
    align-items: stretch;
  }
  .chart-controls select {
    min-width: 0;
    width: 100%;
  }
  .bar-wrap {
    overflow-x: auto;
    padding-bottom: 8px;
  }
  .donut-wrap {
    flex-direction: column;
  }
  .donut-wrap svg {
    max-width: 100%;
    height: auto;
  }
  .donut-side-value {
    font-size: 18px;
  }
  .donut-side-sub {
    font-size: 12px;
  }
  .hbar-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .hbar-label {
    word-break: break-word;
  }
  .hbar-value {
    justify-content: flex-start;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    font-size: 11px;
  }
  .hbar-current,
  .hbar-affected {
    min-width: 0;
    width: auto;
  }
  .hbar-sep {
    display: none;
  }
  .table-toolbar,
  .table-toolbar.compact {
    flex-direction: column;
    align-items: stretch;
  }
  .table-toolbar label,
  .table-toolbar.compact label {
    min-width: 0;
    width: 100%;
  }
  .table-toolbar input,
  .table-toolbar select,
  .table-toolbar.compact input,
  .table-toolbar.compact select {
    min-width: 0;
    width: 100%;
  }
  .table-toolbar .actions {
    margin-left: 0;
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-start;
  }
  .periodic-live-grid {
    grid-template-columns: 1fr;
  }
  .coord-list {
    grid-template-columns: 1fr;
  }
  .modal-backdrop.floating .modal {
    margin-right: 12px;
    margin-top: 70px;
  }

  .help-frame {
    min-height: 62vh;
  }
}

@media (max-width: 900px), (pointer: coarse) {
  .tabs {
    display: none;
  }
  .menu-fab {
    display: flex;
  }
  .hbar-row {
    grid-template-columns: 1fr;
  }
  .hbar-row.hbar-header .hbar-track {
    display: none;
  }
  .hbar-track {
    order: 3;
  }
  .hbar-value {
    order: 2;
    justify-content: flex-start;
    text-align: left;
    flex-wrap: wrap;
  }
  .hbar-current,
  .hbar-affected {
    min-width: 0;
  }
  .hbar-sep {
    display: none;
  }
  .auto-trigger-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1100px) {
  .table-toolbar {
    flex-wrap: nowrap;
  }
}

/* ---------------------------------------------------------------------------
   Boton de modo claro/oscuro (cabecera y login).
   --------------------------------------------------------------------------- */
.theme-toggle {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.theme-toggle:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}

.login-locale .theme-toggle {
  margin-left: auto;
}

.theme-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-icon-moon {
  display: none;
}

/* Donut SVG del dashboard: texto y pista siguen el tema. */
.donut-wrap svg text {
  fill: var(--text);
}

.donut-wrap svg circle[stroke="rgba(28,36,52,0.08)"] {
  stroke: var(--surface-3);
}

/* ---------------------------------------------------------------------------
   Modo oscuro. app.theme.js deja el tema efectivo en <html data-theme>.
   Solo se redefinen tokens y los componentes que tenian colores fijos.
   --------------------------------------------------------------------------- */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b1220;
  --surface: #111a2b;
  --surface-strong: #111a2b;
  --surface-2: #152036;
  --surface-3: #1e2a42;
  --text: #e6edf6;
  --text-2: #c3cedd;
  --muted: #8b9ab0;
  --border: #24324a;
  --border-soft: #1c2940;
  --border-strong: #34455f;

  --accent: #6ea0ff;
  --accent-strong: #2f6fe4;
  --accent-2: #4581f0;
  --accent-3: #22c5c2;
  --accent-soft: rgba(110, 160, 255, 0.14);
  --accent-soft-2: rgba(110, 160, 255, 0.24);
  --ink: #f1f5fb;

  --ok: #4cc488;
  --warn: #e3ac45;
  --bad: #f2756b;

  --ring: 0 0 0 3px rgba(110, 160, 255, 0.35);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.22);
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.55);
  --nav-bg: rgba(17, 26, 43, 0.9);
}

:root[data-theme="dark"] .login-screen {
  background:
    radial-gradient(900px 480px at 0% 0%, rgba(47, 111, 228, 0.22), transparent 60%),
    radial-gradient(800px 420px at 100% 100%, rgba(34, 197, 194, 0.12), transparent 60%),
    linear-gradient(160deg, #0d1526 0%, var(--bg) 100%);
}

:root[data-theme="dark"] .config-nav .tab:hover {
  background: var(--surface-2);
}

:root[data-theme="dark"] .locale-caret {
  border-top-color: var(--muted);
}

:root[data-theme="dark"] .locale-item.active {
  color: var(--accent);
}

:root[data-theme="dark"] .toast {
  background: rgba(17, 26, 43, 0.96);
  border-color: var(--border);
  box-shadow: var(--shadow-lg);
}

:root[data-theme="dark"] .toast-header {
  background: var(--surface-2);
  border-bottom-color: var(--border);
}

:root[data-theme="dark"] .toast-title {
  color: var(--text);
}

:root[data-theme="dark"] .toast-time,
:root[data-theme="dark"] .toast-close {
  color: var(--muted);
}

:root[data-theme="dark"] .toast-close:hover {
  background: var(--surface-3);
  color: var(--text);
}

:root[data-theme="dark"] .toast-body {
  color: var(--text-2);
}

:root[data-theme="dark"] .toast.toast-error .toast-body {
  color: #ffb4ad;
}

:root[data-theme="dark"] .toast.toast-success .toast-body {
  color: #93e2b7;
}

:root[data-theme="dark"] .toast.toast-warning .toast-body {
  color: #f3d58a;
}

:root[data-theme="dark"] .status-pill,
:root[data-theme="dark"] .status-pill.status-neutral {
  color: var(--text-2);
}

:root[data-theme="dark"] .status-pill.status-ok {
  color: #93e2b7;
}

:root[data-theme="dark"] .status-pill.status-warn {
  color: #f3d58a;
}

:root[data-theme="dark"] .status-pill.status-info {
  color: #b5ccff;
}

:root[data-theme="dark"] .status-pill.status-bad {
  color: #ffb4ad;
}

:root[data-theme="dark"] .nested-card-info,
:root[data-theme="dark"] .periodic-live-toolbar,
:root[data-theme="dark"] .security-live-toolbar {
  background: var(--surface-2);
}

:root[data-theme="dark"] .periodic-live-item,
:root[data-theme="dark"] .security-live-item {
  background: var(--surface);
  border-color: var(--border);
}

:root[data-theme="dark"] .periodic-live-error,
:root[data-theme="dark"] .security-live-error {
  color: #ffb4ad;
}

:root[data-theme="dark"] .periodic-live-error.is-empty,
:root[data-theme="dark"] .security-live-error.is-empty {
  color: var(--muted);
}

:root[data-theme="dark"] .pill {
  background: rgba(76, 196, 136, 0.12);
  border-color: rgba(76, 196, 136, 0.3);
  color: #93e2b7;
}

:root[data-theme="dark"] .users-online {
  background: var(--surface-2);
}

:root[data-theme="dark"] .users-online-list .online-user:nth-child(odd) {
  background: rgba(255, 255, 255, 0.03);
}

:root[data-theme="dark"] .table.is-loading::after {
  background: rgba(11, 18, 32, 0.6);
}

:root[data-theme="dark"] .table tr.hist-row-selected td {
  background: rgba(255, 255, 255, 0.06);
}

:root[data-theme="dark"] .pivot-total,
:root[data-theme="dark"] .table th.pivot-total {
  background: #1d3a63;
  color: #ffffff;
}

:root[data-theme="dark"] .user-badge-sso {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}

:root[data-theme="dark"] .user-badge-local {
  border-color: rgba(242, 117, 107, 0.4);
  background: rgba(242, 117, 107, 0.1);
  color: #ffb4ad;
}

:root[data-theme="dark"] .help-frame {
  background: #ffffff;
}

/* El logo de relleno es un PNG blanco: en oscuro se veria como un rectangulo. */
:root[data-theme="dark"] img[src*="blank-logo"] {
  visibility: hidden;
}

/* Barra de frescura de datos (bajo el menu principal). */
.freshness-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: -8px 0 16px;
  font-size: 12.5px;
}

.freshness-title {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  margin-right: 2px;
}

.freshness-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.freshness-chip strong {
  color: var(--text);
  font-weight: 600;
}

.freshness-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  flex: 0 0 8px;
}

.freshness-warn {
  border-color: rgba(183, 121, 31, 0.45);
  background: rgba(183, 121, 31, 0.08);
}

.freshness-warn .freshness-dot {
  background: var(--warn);
}

.freshness-bad {
  border-color: rgba(201, 53, 43, 0.45);
  background: rgba(201, 53, 43, 0.08);
}

.freshness-bad .freshness-dot {
  background: var(--bad);
}

/* ---------------------------------------------------------------------------
   Barra lateral de navegacion (grupos: Monitoreo, Analisis, Ingenieria, Administracion).
   Las opciones conservan class="tab" y data-tab: la navegacion y los permisos por rol no cambian.
   --------------------------------------------------------------------------- */
:root {
  --sidebar-w: 236px;
}

body.sidebar-collapsed {
  --sidebar-w: 68px;
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  column-gap: 20px;
  align-items: start;
}

.shell > * {
  grid-column: 2;
  min-width: 0;
}

.shell > .sidebar {
  grid-column: 1;
  grid-row: 1 / span 20;
}

.sidebar {
  position: sticky;
  top: 18px;
  height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow-x: hidden;
  overflow-y: auto;
  transition: width 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 6px 12px;
  border-bottom: 1px solid var(--border-soft);
}

.sidebar .brand-logo {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
}

.sidebar-brand-text {
  min-width: 0;
}

.sidebar .brand-title {
  font-size: 15px;
  line-height: 1.25;
}

.sidebar .brand-sub {
  font-size: 11.5px;
  line-height: 1.3;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-group-title {
  padding: 0 10px 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

.sidebar-item:hover {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}

.sidebar-item.active {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

.sidebar .tab-logout {
  color: var(--bad);
}

.sidebar .tab-logout:hover {
  background: rgba(201, 53, 43, 0.08);
  color: var(--bad);
}

.sidebar-collapse .nav-icon {
  transition: transform 0.2s ease;
}

body.sidebar-collapsed .sidebar-collapse .nav-icon {
  transform: rotate(180deg);
}

body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .sidebar-group-title,
body.sidebar-collapsed .sidebar-brand-text {
  display: none;
}

body.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding-inline: 0;
}

body.sidebar-collapsed .sidebar-item {
  justify-content: center;
  padding-inline: 0;
}

body.sidebar-collapsed .sidebar-group + .sidebar-group {
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

/* Cabecera: seccion actual a la izquierda, controles a la derecha. */
.page-heading {
  min-width: 0;
}

.page-group {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.page-title {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink);
}

/* Menu movil con los mismos grupos. */
.mobile-menu-panel {
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.mobile-menu .sidebar-group-title {
  padding: 8px 4px 2px;
}

.mobile-menu .tab {
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (max-width: 900px), (pointer: coarse) {
  .shell {
    display: block;
  }

  .sidebar {
    display: none;
  }
}

/* Sin logo configurado (imagen de relleno): monograma en su lugar. */
.brand-monogram {
  display: none;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--accent-strong);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.sidebar-brand:has(img[src*="blank-logo"]) .brand-logo {
  display: none;
}

.sidebar-brand:has(img[src*="blank-logo"]) .brand-monogram {
  display: inline-flex;
}

/* Estado de hoy (dashboard). */
.today-row {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.today-card {
  border-top: 3px solid var(--border-strong);
}

.today-card.today-ok {
  border-top-color: var(--ok);
}

.today-card.today-bad {
  border-top-color: var(--bad);
}

.today-card.today-ok .card-metric {
  color: var(--ok);
}

.today-card.today-bad .card-metric {
  color: var(--bad);
}

.today-worse .card-metric {
  color: var(--bad);
}

.today-better .card-metric {
  color: var(--ok);
}

/* Mantenedor de carpeta de origen SCADA */
.scada-source { display: grid; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border, rgba(127,127,127,.25)); }
.scada-source-field { display: grid; gap: 4px; font-size: 12px; }
.scada-source-field input { width: 100%; box-sizing: border-box; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* Ficha tecnica HIS SCADA en el cuadro flotante de TAG */
.tag-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 16px; margin: 8px 0 4px; }
.tag-sheet > div { min-width: 0; }
.tag-sheet dt { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #6b7280); }
.tag-sheet dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }

/* Destinatarios WhatsApp */
.wa-recipients { display: grid; gap: 4px; }
.wa-recipients textarea { width: 100%; box-sizing: border-box; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* Asistente IA */
.ai-card { display: flex; flex-direction: column; gap: 12px; }
.ai-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.ai-messages { display: flex; flex-direction: column; gap: 14px; min-height: 280px; max-height: 62vh; overflow-y: auto; padding: 12px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface-2); }
.ai-empty { display: grid; gap: 8px; }
.ai-examples { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-examples .btn { white-space: normal; text-align: left; height: auto; line-height: 1.35; padding: 6px 10px; }
.ai-msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.ai-msg-user { align-items: flex-end; }
.ai-msg-user .ai-bubble { background: var(--accent); color: #fff; border-radius: 14px 14px 4px 14px; max-width: min(720px, 90%); }
.ai-msg-assistant .ai-bubble { background: var(--surface); color: var(--text); border: 1px solid var(--border-soft); border-radius: 14px 14px 14px 4px; max-width: min(980px, 100%); }
.ai-bubble { padding: 10px 14px; overflow-wrap: anywhere; line-height: 1.5; }
.ai-bubble p { margin: 0 0 8px; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble ul, .ai-bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.ai-bubble code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--surface-3); padding: 1px 4px; border-radius: 4px; }
.ai-bubble pre { overflow-x: auto; background: var(--surface-3); padding: 8px; border-radius: var(--radius-sm); }
.ai-h { font-weight: 700; margin: 8px 0 4px; }
.ai-h1, .ai-h2 { font-size: 15px; }
.ai-table { overflow-x: auto; margin: 6px 0 10px; }
.ai-table table { border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.ai-table th, .ai-table td { border-bottom: 1px solid var(--border-soft); padding: 5px 10px; text-align: left; white-space: nowrap; }
.ai-table th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
.ai-table td.num { text-align: right; }
.ai-pending { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); }
.ai-spinner { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: ai-spin .8s linear infinite; }
@keyframes ai-spin { to { transform: rotate(360deg); } }
.ai-error { border-color: var(--bad) !important; color: var(--bad) !important; }
.ai-queries { font-size: 12px; color: var(--muted); max-width: min(980px, 100%); }
.ai-queries summary { cursor: pointer; }
.ai-query { margin-top: 8px; }
.ai-query-head { margin-bottom: 4px; }
.ai-query pre { margin: 0; overflow-x: auto; background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 8px; font-size: 11.5px; }
.ai-q-error { color: var(--bad); }
.ai-foot { font-size: 11px; color: var(--muted); }
.ai-compose { display: flex; gap: 10px; align-items: flex-end; }
.ai-compose textarea { flex: 1; min-height: 44px; resize: vertical; }
.ai-note { font-size: 11.5px; }
@media (max-width: 640px) { .ai-compose { flex-direction: column; align-items: stretch; } }

/* Informe por enlace ICCP */
.report-link { display: grid; gap: 16px; margin-top: 12px; }
.report-link.is-loading { opacity: .55; transition: opacity .2s; }
.link-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.link-kpi .card-metric { font-variant-numeric: tabular-nums; }
.link-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.link-chart-card .chart { width: 100%; min-height: 180px; }
.link-trend { height: 340px; }
.report-print-title { display: none; }
@media (max-width: 640px) { .link-grid { grid-template-columns: 1fr; } }

@media print {
  .sidebar, .topbar, .freshness-bar, .footer, .mobile-nav, .no-print, .tab-dropdown, #reportMeta { display: none !important; }
  body, .app, .main, .panel, .card { background: #fff !important; box-shadow: none !important; }
  .panel:not(.active) { display: none !important; }
  .report-print-title { display: block; font-size: 16px; font-weight: 700; margin-bottom: 8px; color: #0f1b2d; }
  .card { break-inside: avoid; page-break-inside: avoid; border: 1px solid #dbe2ec; }
  .link-table-card { break-inside: auto; page-break-inside: auto; }
  .link-grid { grid-template-columns: 1fr 1fr; }
  .table { overflow: visible !important; max-height: none !important; }
}

[data-report-only][hidden], .report-link[hidden] { display: none !important; }
.link-table-card td:nth-child(2) { white-space: normal; min-width: 180px; max-width: 420px; }

.report-pdf-status { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Ayuda rapida con IA y pie de pagina */
.help-ai { border: 1px solid var(--border-soft); background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; display: grid; gap: 6px; }
.help-ai-title { font-weight: 700; font-size: 13px; }
.help-ai-row { display: flex; gap: 8px; }
.help-ai-row input { flex: 1; min-width: 0; }
.help-ai-answer { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 8px 12px; max-height: 220px; overflow-y: auto; line-height: 1.5; font-size: 13px; }
.help-ai-answer p { margin: 0 0 6px; }
.help-ai-answer ul, .help-ai-answer ol { margin: 2px 0 6px; padding-left: 20px; }
.help-ai-note { font-size: 11px; color: var(--muted); margin-top: 4px; }
.footer-brand { font-weight: 600; }
@media (max-width: 640px) { .help-ai-row { flex-direction: column; } }

/* Seguridad: 2FA, cambio de clave, clave temporal */
.login-mfa { display: grid; gap: 8px; margin-top: 4px; }
.login-mfa-title { font-weight: 700; }
.login-mfa-qr { justify-self: center; background: #fff; padding: 8px; border-radius: var(--radius-sm); line-height: 0; }
.login-mfa-qr svg { width: 200px; height: 200px; }
.login-mfa code, .temp-password code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--surface-3); padding: 2px 6px; border-radius: 6px; user-select: all; }
.login-pwd-form { display: grid; gap: 8px; }
.temp-password { border: 1px solid var(--warn); background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; margin: 8px 0; font-size: 13px; }
.my-pwd-form { grid-template-columns: 1fr; }

/* Los paneles del login respetan el atributo hidden aunque tengan display propio */
.login-mfa[hidden], .login-local-form[hidden], .temp-password[hidden], #navPassword.hidden { display: none !important; }
