:root {
  color-scheme: light;
  --ink: #16202a;
  --muted: #647282;
  --line: #d8e0e8;
  --panel: #ffffff;
  --canvas: #f4f7fa;
  --nav: #101923;
  --nav-soft: #1a2633;
  --blue: #2563eb;
  --teal: #0f766e;
  --green: #15803d;
  --amber: #b45309;
  --red: #b91c1c;
  --violet: #6d28d9;
  --shadow: 0 18px 42px rgba(20, 31, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

[hidden] {
  display: none !important;
}

.auth-gate {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2633, var(--nav));
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-brand {
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

.auth-brand span {
  color: var(--muted);
}

.auth-card h1 {
  font-size: 22px;
}

.auth-sub {
  margin: -8px 0 4px;
  color: var(--muted);
  font-size: 14px;
}

.auth-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.auth-field input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.auth-card .primary-action {
  margin-top: 4px;
  width: 100%;
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.session-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  color: #e8eef5;
  background: var(--nav);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand strong {
  display: block;
  font-size: 20px;
}

.brand span,
.tenant-card span,
.tenant-card small {
  color: #9fb0c1;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #e8f4ff;
}

.brand-mark svg {
  width: 30px;
  fill: none;
  stroke: var(--teal);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  color: #c9d5e2;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  color: #ffffff;
  background: var(--nav-soft);
  border-color: rgba(255, 255, 255, 0.08);
}

.tenant-card {
  display: grid;
  gap: 6px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: var(--nav-soft);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

h3 {
  margin-bottom: 6px;
  font-size: 15px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 12px;
}

.search {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search input {
  width: min(360px, 36vw);
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.primary-action,
.ghost-action {
  height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
}

.link-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.primary-action {
  color: #fff;
  border: 1px solid #174dc0;
  background: var(--blue);
}

.ghost-action {
  color: var(--ink);
  border: 1px solid var(--line);
  background: #fff;
}

.ghost-action.danger {
  height: 34px;
  padding: 0 12px;
  color: #b42318;
  border: 1px solid #f3b9b3;
  background: #fff5f4;
}

.ghost-action.danger:hover {
  color: #fff;
  border-color: #b42318;
  background: #b42318;
}

/* Compact inline action buttons inside inventory tables (Instalar parche). */
.compact-table .ghost-action {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
  color: var(--blue);
  border: 1px solid #b9ccf3;
  background: #f2f6ff;
}

.compact-table .ghost-action:hover {
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

.compact-table .ghost-action.danger {
  height: 30px;
  color: #b42318;
  border-color: #f3b9b3;
  background: #fff5f4;
}

.compact-table .ghost-action.danger:hover {
  color: #fff;
  border-color: #b42318;
  background: #b42318;
}

.compact-table .ghost-action:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Live progress bar shown in a row while a remote action runs. */
.action-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
}

.action-progress-track {
  position: relative;
  flex: 1;
  height: 10px;
  border-radius: 6px;
  background: #e7ebf0;
  overflow: hidden;
}

.action-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 6px;
  background-color: #1aa34a;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.22) 0,
    rgba(255, 255, 255, 0.22) 8px,
    transparent 8px,
    transparent 16px
  );
  background-size: 22px 22px;
  transition: width 0.5s ease;
  animation: action-stripes 0.7s linear infinite;
}

@keyframes action-stripes {
  0% { background-position: 0 0; }
  100% { background-position: 22px 0; }
}

.action-progress-fill.is-fail,
.action-progress.is-fail .action-progress-fill {
  background: linear-gradient(90deg, #b42318, #e0584b);
  animation: none;
}

.action-progress-label {
  font-size: 11px;
  font-weight: 600;
  color: #1aa34a;
  white-space: nowrap;
}

.action-progress.is-fail .action-progress-label {
  color: #b42318;
}

.action-progress.is-done .action-progress-label {
  color: #1aa34a;
}

/* Endpoints table: multiple inline actions + "update available" badge. */
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
}

.ver-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: #8a5a00;
  background: #fff4e0;
  border: 1px solid #f0c88a;
}

/* Search box above the installed-software list. */
.inv-search-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.inv-search {
  flex: 1;
  max-width: 360px;
  height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink);
  background: #fff;
}

.inv-search:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 77, 192, 0.12);
}

.inv-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted, #667085);
}

.content {
  display: grid;
  gap: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.metrics {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.grid.two {
  grid-template-columns: minmax(0, 1.3fr) minmax(340px, 0.7fr);
}

.panel,
.metric,
.record-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.metric {
  display: grid;
  gap: 10px;
  min-height: 128px;
  padding: 16px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  font-size: 30px;
}

.metric small {
  color: var(--muted);
}

.metric .trend.good {
  color: var(--green);
}

.metric .trend.warn {
  color: var(--amber);
}

.metric .trend.bad {
  color: var(--red);
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.pill.ok {
  color: #075b2c;
  background: #dcfce7;
}

.pill.warn {
  color: #7a3c00;
  background: #fef3c7;
}

.pill.bad {
  color: #7f1d1d;
  background: #fee2e2;
}

.pill.info {
  color: #164b8f;
  background: #dbeafe;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f7;
}

.segmented button {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.segmented button.active {
  background: #fff;
  box-shadow: 0 1px 4px rgba(20, 31, 43, 0.12);
}

.record-list {
  display: grid;
  gap: 12px;
}

.record-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.risk-bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef5;
}

.risk-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--amber), var(--red));
}

.automation-grid {
  grid-template-columns: repeat(3, minmax(210px, 1fr));
}

.script-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.script-card code {
  display: block;
  padding: 10px;
  overflow-x: auto;
  color: #dbeafe;
  border-radius: 8px;
  background: #0b1220;
}

.inventory-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.inventory-sidebar {
  position: sticky;
  top: 18px;
}

.endpoint-selector-list {
  display: grid;
  gap: 8px;
}

.endpoint-selector {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 74px;
  padding: 11px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.endpoint-selector strong,
.endpoint-selector span,
.endpoint-selector small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.endpoint-selector span,
.endpoint-selector small {
  color: var(--muted);
}

.endpoint-selector.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.inventory-detail {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.inventory-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.inventory-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inventory-panel {
  box-shadow: none;
}

.inv-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.inv-tab {
  height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.inv-tab:hover {
  color: var(--ink);
  background: #eef3f7;
}

.inv-tab.active {
  color: #fff;
  background: var(--blue);
  border-color: #174dc0;
}

.inv-tab-content > .inventory-panel {
  box-shadow: var(--shadow);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.field-row {
  display: grid;
  gap: 4px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.field-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field-row strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.compact-table th,
.compact-table td {
  padding: 9px 8px;
  font-size: 13px;
}

.toolbar-cluster {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.download-menu {
  position: relative;
}

.download-menu summary {
  display: inline-flex;
  align-items: center;
  list-style: none;
  user-select: none;
}

.download-menu summary::-webkit-details-marker {
  display: none;
}

.download-menu summary::marker {
  content: "";
}

.download-menu-list {
  position: absolute;
  right: 0;
  z-index: 20;
  display: grid;
  gap: 4px;
  min-width: 260px;
  margin-top: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.download-menu-list a,
.download-menu-list button {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  background: transparent;
  cursor: pointer;
}

.download-menu-list a small,
.download-menu-list button small {
  color: var(--muted);
}

.download-menu-list a:hover,
.download-menu-list button:hover {
  background: #eef3f7;
}

.head-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  height: 26px;
  border-radius: 999px;
  background: #ecfdf3;
  color: #067647;
  font-size: 12px;
  font-weight: 800;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #12b76a;
  animation: live-pulse 1.6s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(18, 183, 106, 0.5); }
  50% { opacity: 0.6; box-shadow: 0 0 0 5px rgba(18, 183, 106, 0); }
}

.control-tag {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f1f5f9;
  font-size: 11px;
  font-weight: 700;
}

.ai-plan {
  margin: 0;
  padding: 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.empty-state {
  display: grid;
  gap: 8px;
  padding: 40px 24px;
  text-align: center;
}

.empty-state p,
.muted-note {
  margin: 0;
  color: var(--muted);
}

.empty-state p {
  max-width: 560px;
  margin: 0 auto;
}

.muted-note {
  padding: 10px 2px;
  font-size: 14px;
}

.toast {
  display: none;
  padding: 12px 14px;
  color: #063f3a;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  background: #ccfbf1;
}

.toast.show {
  display: block;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid.metrics,
  .grid.two,
  .automation-grid,
  .inventory-layout,
  .inventory-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .inventory-sidebar {
    position: static;
  }

  .topbar,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search input {
    width: 100%;
  }
}

/* ITSM / Help Desk */
.tickets-layout { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .tickets-layout { grid-template-columns: 1fr; } }
.ticket-create { gap: 8px; flex-wrap: wrap; }
.ticket-create input[type="text"] { min-width: 240px; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; }
.ticket-create select { height: 36px; }
.ticket-row { cursor: pointer; }
.ticket-row:hover { background: #f3f6ff; }
.ticket-row.active { background: #e7eefc; }
.ticket-thread { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.ticket-comment { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; }
.ticket-comment.internal { background: #fff7e6; border-color: #f0c88a; }
.ticket-comment-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.ticket-comment-head small { color: var(--muted, #667085); }
.ticket-reply { display: flex; flex-direction: column; gap: 8px; }
.ticket-reply textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; resize: vertical; }
.ticket-internal { font-size: 12px; color: var(--muted, #667085); display: inline-flex; align-items: center; gap: 6px; }

/* Control remoto / escritorio remoto */
#remoteOverlay { position: fixed; inset: 0; z-index: 9999; display: flex; flex-direction: column;
  background: #0b1220; outline: none; }
.remote-bar { display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  background: #111a2e; color: #e8eef5; border-bottom: 1px solid rgba(255,255,255,.1); }
.remote-bar strong { font-size: 14px; }
.remote-bar #remoteStatus { color: #9fb0c1; font-size: 12px; margin-right: auto; }
.remote-bar .primary-action.danger { background: #b42318; border-color: #8a1a12; }
.remote-stage { flex: 1; display: grid; place-items: center; overflow: hidden; }
#remoteImg { max-width: 100%; max-height: 100%; cursor: crosshair;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); background: #000; user-select: none; }
