@keyframes degraded-pulse {
  0%, 100% { background-position: 0 0; box-shadow: 0 0 0 0 rgba(231,165,43,.1); }
  50% { background-position: 100% 0; box-shadow: 0 0 0 4px rgba(231,165,43,.12); }
}

.badge.degradado {
  color: #f3c45d;
  background: linear-gradient(90deg,rgba(231,165,43,.12),rgba(231,165,43,.28),rgba(231,165,43,.12));
  background-size: 200% 100%;
  animation: degraded-pulse 1.8s ease-in-out infinite;
}
html[data-theme="light"] .badge.degradado { color: #936000; background: linear-gradient(90deg,#fff1c7,#ffdc76,#fff1c7); }

.session-state {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 20px;
  background: var(--surface3);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.session-state.conectada { color: #50dda7; background: rgba(32,168,118,.14); }
.session-state.pendiente { color: #f3c45d; background: rgba(231,165,43,.15); }
.session-state.notificada { color: #82a7ff; background: rgba(40,100,220,.18); }
.session-state.cerrada,.session-state.vencida { color: var(--muted); background: var(--surface3); }

.console-button {
  border: 0;
  border-radius: 7px;
  padding: 7px 10px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
}

#console-dialog {
  width: min(850px,calc(100vw - 30px));
  background: #0a111d;
  color: #d9e7dd;
  padding: 0;
  overflow: hidden;
}

.console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  background: #111c2c;
  border-bottom: 1px solid #26364d;
}

.console-head strong,.console-head small { display: block; }
.console-head small { margin-top: 3px; color: #8292a9; }
.console-head .close { position: static; color: #aebbd0; }
.console-actions { display: flex; align-items: center; gap: 10px; }
.console-actions button { border: 1px solid #3b4d66; border-radius: 7px; padding: 7px 10px; color: #c5d1e1; background: transparent; cursor: pointer; }

#terminal-output {
  height: 430px;
  margin: 0;
  padding: 18px;
  overflow: auto;
  white-space: pre-wrap;
  font: 14px/1.55 Consolas,"Courier New",monospace;
  color: #a9f3c5;
  background: #071019;
}

#terminal-form {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  background: #111c2c;
}

#terminal-form input {
  color: #e5f3e9;
  background: #071019;
  border-color: #30425c;
  font-family: Consolas,"Courier New",monospace;
}

#terminal-form .primary { margin: 0; }

.history-panel select { width: auto; min-width: 120px; }
.chart-legend { display: flex; gap: 18px; margin: -6px 0 8px; color: var(--muted); font-size: 11px; }
.chart-legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 50%; }
.chart-legend .green::before { background: var(--green); }
.chart-legend .amber::before { background: var(--amber); }
.chart-legend .red::before { background: var(--red); }
.chart-legend .blue::before { background: var(--blue); }
.history-chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart-grid line { stroke: var(--line); stroke-width: 1; }
.chart-grid text { fill: var(--muted); font-size: 10px; }
.chart-dates { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }

.device-editor { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 18px; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.device-editor label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.device-editor label small { font-size: 9px; }
@media(max-width:620px){.editor-grid{grid-template-columns:1fr}.history-chart svg{height:180px}}
.stack-form { display: grid; gap: 14px; }
.stack-form label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; }
.groups-grid { grid-template-columns: 1.5fr 1fr; }
.device-groups { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 18px; }
.group-checks { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.group-checks label { display: flex; align-items: center; gap: 6px; background: var(--surface2); padding: 7px 10px; border-radius: 8px; font-size: 11px; }
.group-checks input { width: auto; }
.empty-inline { color: var(--muted); font-size: 11px; }
@media(max-width:950px){.groups-grid{grid-template-columns:1fr}}
.login-screen { display: none; position: fixed; inset: 0; z-index: 100; place-items: center; padding: 20px; background: radial-gradient(circle at 30% 20%,#18345b,#081424 65%); }
.login-screen.visible { display: grid; }
.login-card { width: min(390px,100%); display: grid; gap: 15px; padding: 30px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 30px 90px rgba(0,0,0,.35); }
.login-card .brand-mark { margin-bottom: 4px; color: #fff; }
.login-card h1,.login-card p { margin: 0; }
.login-card p { color: var(--muted); font-size: 13px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; }
.login-card small { min-height: 18px; color: var(--red); }
.logged-out .sidebar,.logged-out main { visibility: hidden; }
.logout { display: block; margin-top: 5px; padding: 0; border: 0; color: #91a4bf; background: transparent; font-size: 10px; cursor: pointer; }
[hidden] { display: none !important; }
.settings-panel { max-width: 620px; }
.audit-tabs { display:flex; gap:8px; margin-bottom:16px; }
.audit-tabs button { border:1px solid var(--line); border-radius:8px; padding:8px 12px; color:var(--muted); background:var(--surface2); cursor:pointer; }
.audit-tabs button.active { color:#fff; border-color:var(--blue); background:var(--blue); }
.audit-filters { display:grid; grid-template-columns:minmax(190px,1.7fr) repeat(3,minmax(135px,1fr)) auto auto; gap:10px; align-items:end; margin-bottom:16px; }
.audit-filters label { display:grid; gap:5px; color:var(--muted); font-size:10px; }
.audit-filters button { margin:0; min-height:38px; }
.audit-details { max-width:430px; margin:0; white-space:pre-wrap; overflow-wrap:anywhere; color:var(--muted); font:10px/1.45 Consolas,"Courier New",monospace; }
.audit-payload { display:block; min-width:230px; max-width:560px; max-height:130px; overflow:auto; padding:9px; border:1px solid var(--line); border-radius:7px; white-space:pre-wrap; overflow-wrap:anywhere; color:#a9f3c5; background:#071019; font:11px/1.45 Consolas,"Courier New",monospace; }
.audit-direction { display:inline-block; padding:4px 7px; border-radius:12px; color:var(--muted); background:var(--surface3); font-size:9px; font-weight:700; }
.audit-direction.operator_to_device { color:#9db9ff; background:rgba(40,100,220,.18); }
.audit-direction.device_to_operator { color:#64dbaa; background:rgba(32,168,118,.14); }
@media(max-width:1100px){.audit-filters{grid-template-columns:repeat(2,minmax(150px,1fr))}.audit-filters button{width:auto}}
@media(max-width:620px){.audit-filters{grid-template-columns:1fr}.audit-payload{min-width:180px}}
.stack-form small { color: var(--muted); font-size: 10px; }
.history-scope { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.history-scope button,.history-button { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; color: var(--ink); background: var(--surface); cursor: pointer; }
.history-scope button.active { color: #fff; background: var(--blue); border-color: var(--blue); }
.history-scope span { color: var(--muted); font-size: 11px; }
.device-history-button { margin-top: 12px; }
