:root {
  color-scheme: light;
  --bg: #eef4f3;
  --surface: rgba(255, 255, 255, .72);
  --surface-strong: rgba(255, 255, 255, .92);
  --surface-dark: rgba(13, 28, 32, .88);
  --text: #132126;
  --muted: #687780;
  --line: rgba(20, 44, 54, .12);
  --line-strong: rgba(20, 44, 54, .2);
  --accent: #0f766e;
  --accent-2: #155e75;
  --accent-soft: rgba(15, 118, 110, .12);
  --ok: #157f4f;
  --warn: #a86600;
  --bad: #c23a2b;
  --ink: #0f1f24;
  --shadow: 0 22px 60px rgba(17, 35, 44, .13);
  --shadow-soft: 0 12px 34px rgba(17, 35, 44, .08);
}

* { box-sizing: border-box; }
html { min-width: 0; }
body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 16% -8%, rgba(15, 118, 110, .22), transparent 30rem),
    radial-gradient(circle at 88% 4%, rgba(209, 138, 35, .18), transparent 28rem),
    linear-gradient(135deg, #f8fbfa 0%, var(--bg) 47%, #f2f3ea 100%);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(15, 31, 36, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 31, 36, .035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.75), transparent 70%);
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

.sidebar {
  position: fixed;
  inset: 18px auto 18px 18px;
  z-index: 50;
  width: 258px;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(18, 39, 44, .96), rgba(10, 24, 28, .92)),
    var(--ink);
  box-shadow: 0 26px 70px rgba(9, 26, 32, .28);
  backdrop-filter: blur(18px);
}
.brand {
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 10px;
}
.brand:hover { color: white; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 14px;
  background: linear-gradient(135deg, #10a391, #e0a13c);
  color: white;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.32), 0 12px 26px rgba(15, 118, 110, .3);
}
.brand strong { display: block; font-size: 16px; letter-spacing: 0; }
.brand small { display: block; color: rgba(255,255,255,.58); font-size: 12px; margin-top: 2px; }
.menu {
  display: grid;
  gap: 5px;
  overflow-y: auto;
  padding-right: 2px;
}
.menu a {
  color: rgba(235, 247, 247, .78);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 650;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease;
}
.menu a:hover,
.menu a.active {
  color: white;
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.14);
  transform: translateX(2px);
}
.logout { margin-top: auto; }
.logout button {
  width: 100%;
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.16);
  color: white;
}
.logout button:hover { background: rgba(255,255,255,.14); color: white; }

.shell {
  min-height: 100vh;
  margin-left: 294px;
  position: relative;
  z-index: 1;
}
.login-shell { margin-left: 0; }
.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 32px;
  margin: 0;
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(249, 252, 251, .72);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.topbar strong { display: block; font-size: 15px; }
.topbar span { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
main {
  width: min(100% - 56px, 1500px);
  margin: 0 auto;
  padding: 28px 0 42px;
}

button, .button {
  border: 1px solid rgba(15, 118, 110, .78);
  background: linear-gradient(135deg, var(--accent), #128b83);
  color: white;
  padding: 9px 13px;
  border-radius: 11px;
  cursor: pointer;
  font: inherit;
  font-weight: 750;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  box-shadow: 0 10px 24px rgba(15, 118, 110, .18);
  white-space: nowrap;
}
button:hover, .button:hover {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: white;
}
button.danger, .button.danger {
  background: linear-gradient(135deg, var(--bad), #d7644f);
  border-color: rgba(194, 58, 43, .82);
  box-shadow: 0 10px 24px rgba(194, 58, 43, .16);
}
button.danger:hover, .button.danger:hover {
  background: linear-gradient(135deg, #9f2d22, var(--bad));
}
.button.secondary, button.secondary {
  background: rgba(255,255,255,.78);
  color: var(--accent-2);
  border-color: var(--line-strong);
  box-shadow: none;
}
.button.secondary:hover, button.secondary:hover {
  background: white;
  color: var(--accent-2);
}
.button.small, button.small {
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 12px;
}
input, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  padding: 9px 11px;
  font: inherit;
  background: rgba(255,255,255,.86);
  color: var(--text);
  min-height: 38px;
  outline: none;
}
input:focus, select:focus {
  border-color: rgba(15, 118, 110, .65);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, .12);
}

.panel, .login-panel, .dashboard-hero, .page-hero {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 20px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}
.panel {
  border-color: var(--line);
  background:
    linear-gradient(180deg, rgba(255,255,255,.82), rgba(255,255,255,.64)),
    var(--surface);
  overflow-x: auto;
}
.login-panel {
  max-width: 440px;
  margin: 86px auto;
  padding: 26px;
}
.login-panel form { display: grid; gap: 14px; }
.login-panel label, .filters label, .command-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}
.dashboard-hero, .page-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  min-height: 164px;
  background:
    linear-gradient(135deg, rgba(10, 38, 44, .94), rgba(15, 118, 110, .72)),
    radial-gradient(circle at 88% 16%, rgba(224, 161, 60, .42), transparent 18rem);
  color: white;
  border-color: rgba(255,255,255,.2);
  box-shadow: var(--shadow);
}
.page-hero.compact { min-height: 138px; }
.dashboard-hero h1, .page-hero h1 {
  margin: 4px 0 8px;
  font-size: clamp(28px, 3.8vw, 46px);
  line-height: 1.02;
  letter-spacing: 0;
}
.dashboard-hero .subtle, .page-hero .subtle { color: rgba(255,255,255,.74); max-width: 720px; }
.eyebrow {
  margin: 0;
  color: rgba(255,255,255,.72);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
}
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hero-actions .button.secondary {
  background: rgba(255,255,255,.13);
  color: white;
  border-color: rgba(255,255,255,.22);
}
.summary-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 10px;
  min-width: min(100%, 430px);
}
.summary-strip span {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  padding: 10px 12px;
  color: rgba(255,255,255,.76);
  background: rgba(255,255,255,.1);
}
.summary-strip strong { color: white; display: block; margin-top: 3px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}
h1 { margin: 0 0 10px; font-size: 22px; line-height: 1.14; letter-spacing: 0; }
h2 { margin: 22px 0 12px; font-size: 17px; letter-spacing: 0; }
.panel-head h1 { margin: 0 0 4px; }
.subtle { color: var(--muted); margin: 0; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.52);
}
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.metrics div, .metric-card {
  min-height: 116px;
  background: rgba(255,255,255,.78);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 17px;
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}
.metrics div::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), #e0a13c);
}
.metrics div.attention::before { background: linear-gradient(90deg, var(--bad), #e08b70); }
.metrics div.warning::before { background: linear-gradient(90deg, var(--warn), #e0a13c); }
.metrics div.queue::before { background: linear-gradient(90deg, var(--accent-2), #7a8fef); }
.metrics span { display: block; font-size: 34px; line-height: 1; font-weight: 850; margin-top: 8px; }
.metrics label { color: var(--muted); display: block; margin-top: 10px; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.54);
}
table {
  width: 100%;
  min-width: 880px;
  border-collapse: separate;
  border-spacing: 0;
}
.logs-table { min-width: 980px; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  background: rgba(245, 248, 248, .86);
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody tr { transition: background .14s ease; }
tbody tr:hover { background: rgba(15, 118, 110, .055); }
tbody tr:last-child td { border-bottom: 0; }
pre {
  max-width: 620px;
  max-height: 190px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(245, 248, 248, .9);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin: 0;
  font-size: 12px;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.row-actions { min-width: 370px; }
.row-actions, .row-actions form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-actions select { width: 154px; }

.status, .pill, .risk {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 9px;
  background: #e9eef0;
  color: #38464d;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.2;
  white-space: nowrap;
}
.status.ENROLLED, .status.Acknowledged, .status.ACTIVE, .status.SUCCESS,
.status.RUNNING, .risk.safe, .risk.ok, .risk.info {
  background: rgba(21, 127, 79, .12);
  color: var(--ok);
}
.status.PENDING, .status.AUTHENTICATED_WAITING_TOKENUPDATE,
.status.COMMANDS_PENDING, .status.STALE_24H, .status.ATTENTION,
.risk.managed, .risk.impact, .risk.warning {
  background: rgba(168, 102, 0, .13);
  color: var(--warn);
}
.status.NOT_ACCESSIBLE, .status.NOT_FOUND, .status.ERROR,
.status.ABM_REMOVED, .status.STALE_3D, .status.STALE_7D, .status.NEVER_SEEN,
.status.DISABLED, .status.Error, .status.EXITED, .status.RESTARTING, .status.PAUSED,
.risk.destructive, .risk.error, .risk.critical {
  background: rgba(194, 58, 43, .12);
  color: var(--bad);
}
.status.CANCELED, .status.UNKNOWN, .status.CREATED, .risk.debug, .risk.unknown {
  background: #e9eef0;
  color: #38464d;
}
.details { display: grid; grid-template-columns: minmax(130px, 170px) minmax(0, 1fr); gap: 12px 18px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; min-width: 0; word-break: break-word; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 20px; }
.actions form { display: flex; gap: 8px; flex-wrap: wrap; }
.command-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.command-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  align-items: end;
}
.command-form .checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  text-transform: none;
  font-size: 13px;
}
.command-form .checkline input { width: auto; min-height: auto; }
.danger-field input { border-color: rgba(194, 58, 43, .58); }
.command-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 15px;
  background: rgba(255,255,255,.64);
}
.command-card strong { display: block; margin-bottom: 7px; }
.command-card p { margin: 0; color: var(--muted); }
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.info-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: rgba(255,255,255,.64);
}
.info-card h2 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
.info-card .details {
  grid-template-columns: minmax(120px, 160px) minmax(0, 1fr);
  gap: 8px 14px;
}

.device-info-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.device-info-list .info-row {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  align-items: baseline;
}
.device-info-list .info-row:last-child { border-bottom: none; }
.device-info-list .info-row dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.device-info-list .info-row dt[title],
.device-info-list .info-row dd span[title] { cursor: help; }
.device-info-list .info-row dd {
  margin: 0;
  font-size: 14px;
  word-break: break-word;
}

.action-buttons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.action-btn-form { margin: 0; }
.action-btn {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  justify-content: center;
}
.action-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(15, 118, 110, .22);
}
.action-btn.nanocmd-btn {
  background: linear-gradient(135deg, var(--accent-2), #1a6fa0);
  border-color: rgba(21, 94, 117, .78);
  box-shadow: 0 10px 24px rgba(21, 94, 117, .18);
}
.action-btn.danger-btn {
  background: linear-gradient(135deg, var(--bad), #d7644f);
  border-color: rgba(194, 58, 43, .82);
  box-shadow: 0 10px 24px rgba(194, 58, 43, .16);
}
.action-btn.danger-btn:hover {
  background: linear-gradient(135deg, #9f2d22, var(--bad));
}
.action-btn-label { display: block; }

.action-tabs .tab-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 0;
  flex-wrap: wrap;
}
.action-tabs .tab-btn {
  padding: 10px 20px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  border-radius: 10px 10px 0 0;
  margin-bottom: -2px;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
  box-shadow: none;
  min-height: unset;
}
.action-tabs .tab-btn:hover {
  color: var(--accent);
  background: rgba(15, 118, 110, .06);
  transform: none;
  box-shadow: none;
}
.action-tabs .tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(15, 118, 110, .08);
}
.action-tabs .tab-content {
  display: none;
}
.action-tabs .tab-content.active {
  display: block;
}

@media (max-width: 760px) {
  .info-grid { grid-template-columns: 1fr; }
  .device-info-list { grid-template-columns: 1fr; }
  .device-info-list .info-row {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 12px 14px;
  }
  .action-buttons-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 460px) {
  .action-buttons-grid { grid-template-columns: 1fr; }
}

.reasons {
  max-width: 320px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
}
.log-summary {
  display: flex;
  gap: 10px;
  color: var(--muted);
  margin: 0 0 14px;
  flex-wrap: wrap;
}
.logs-table pre {
  max-width: 820px;
  max-height: 230px;
}
.infra-health-table { min-width: 1320px; }
.infra-actions {
  min-width: 360px;
}
.infra-actions,
.infra-actions form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.infra-actions input {
  width: 136px;
  min-height: 32px;
  padding: 6px 9px;
  font-size: 12px;
}
.flash {
  padding: 11px 13px;
  border-radius: 13px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.flash.ok { background: rgba(21, 127, 79, .12); color: var(--ok); border-color: rgba(21, 127, 79, .18); }
.flash.error { background: rgba(194, 58, 43, .12); color: var(--bad); border-color: rgba(194, 58, 43, .18); }

@media (max-width: 1100px) {
  .sidebar {
    position: sticky;
    inset: 0;
    width: auto;
    border-radius: 0;
    padding: 12px 14px;
  }
  .shell { margin-left: 0; }
  .brand { padding-bottom: 4px; }
  .menu {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 0 6px;
  }
  .menu a { flex: 0 0 auto; }
  .logout { display: none; }
  main { width: min(100% - 32px, 1500px); }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    padding: 12px 16px;
    flex-direction: column;
  }
  .topbar-actions { width: 100%; }
  .topbar-actions .button { flex: 1 1 120px; }
  main { width: min(100% - 24px, 1500px); padding-top: 18px; }
  .dashboard-hero, .page-hero, .panel-head {
    display: grid;
    grid-template-columns: 1fr;
  }
  .dashboard-hero, .page-hero { min-height: unset; padding: 18px; }
  .hero-actions .button { flex: 1 1 150px; }
  .summary-strip { grid-template-columns: 1fr; min-width: 0; width: 100%; }
  .filters { grid-template-columns: 1fr; padding: 12px; }
  .panel, .login-panel { padding: 16px; border-radius: 16px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics div { min-height: 98px; padding: 14px; }
  .metrics span { font-size: 28px; }
  .actions, .actions form { display: grid; grid-template-columns: 1fr; width: 100%; }
  .details { grid-template-columns: 1fr; gap: 5px; }
}

@media (max-width: 460px) {
  .brand-mark { width: 36px; height: 36px; border-radius: 12px; }
  .metrics { grid-template-columns: 1fr; }
  .dashboard-hero h1, .page-hero h1 { font-size: 30px; }
  button, .button { width: 100%; }
  .row-actions { min-width: 300px; }
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-panel {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  max-width: 900px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  box-shadow: none;
  min-height: unset;
  border-radius: 8px;
}
.modal-close:hover { color: var(--text); background: rgba(0,0,0,.06); }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.result-meta {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
}
.result-meta strong { color: var(--text); }
.result-table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
  background: rgba(255,255,255,.5);
}
.result-table {
  width: 100%;
  min-width: 500px;
  border-collapse: separate;
  border-spacing: 0;
}
.result-table th {
  position: sticky;
  top: 0;
  background: rgba(245, 248, 248, .92);
}
.result-table td {
  max-width: 500px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.view-result-btn { cursor: pointer; }
