:root {
  --bg: #002f7a;
  --bg-deep: #001b49;
  --surface: #0b4f9f;
  --surface-soft: #eaf2fb;
  --text: #f8fbff;
  --panel-text: #102033;
  --muted: #bfd2ee;
  --panel-muted: #607086;
  --line: rgba(255, 255, 255, 0.18);
  --panel-line: #d9e2ef;
  --panel: #ffffff;
  --accent: #16a394;
  --accent-2: #ffd166;
  --danger: #c2414b;
  --shadow: 0 20px 50px rgba(0, 12, 36, 0.34);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg-deep);
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 30px; font-weight: 800; letter-spacing: 0; }
h2 { font-size: 18px; }
h3 { font-size: 17px; }

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

button.secondary {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text);
  border: 1px solid var(--line);
}

.panel button.secondary,
.device-card button.secondary,
.modal button.secondary {
  background: #edf2f8;
  color: var(--panel-text);
  border: 1px solid var(--panel-line);
}

button.danger {
  background: var(--danger);
  color: #ffffff;
}

.panel button.danger,
.device-card button.danger,
.modal button.danger {
  background: var(--danger);
  color: #ffffff;
}

button:hover { filter: brightness(0.96); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  background: white;
  color: var(--panel-text);
  padding: 10px 11px;
}

input::placeholder,
textarea::placeholder {
  color: #a8b3c2;
}

label {
  display: grid;
  gap: 6px;
  color: var(--panel-muted);
  font-size: 13px;
  font-weight: 700;
}

.muted { color: var(--muted); }
.panel .muted, .device-card .muted, .report .muted { color: var(--panel-muted); }
.eyebrow {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 22px clamp(18px, 4vw, 42px);
  background: var(--bg-deep);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(145deg, #19c7aa, #ffe082);
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
  display: inline-flex;
  height: 38px;
  justify-content: center;
  position: relative;
  width: 38px;
}

.brand-logo {
  color: #001b49;
  display: block;
  height: 24px;
  width: 24px;
}

.actions, .form-actions, .card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions {
  justify-content: flex-end;
}

.layout {
  background: var(--surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  margin: 0 auto;
  min-height: calc(100vh - 83px);
  padding: 22px clamp(16px, 4vw, 42px) 48px;
  width: 100%;
}

.layout > * {
  margin-left: auto;
  margin-right: auto;
  max-width: 1500px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(4, minmax(130px, 180px));
  gap: 10px;
  margin-bottom: 16px;
}

.toolbar input,
.toolbar select {
  border-color: rgba(255, 255, 255, 0.46);
  background: rgba(255, 255, 255, 0.98);
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 22px;
}

.stat, .panel, .device-card {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--panel-text);
}

.stat {
  align-items: center;
  display: flex;
  gap: 9px;
  min-width: 0;
  padding: 10px 12px;
  white-space: nowrap;
}

.stat strong {
  display: block;
  flex: 0 0 auto;
  font-size: 22px;
}

.stat span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-alert {
  border-color: #fca5a5;
}

.stat-alert strong {
  color: #b91c1c;
}

.stat-ok {
  border-color: #86efac;
}

.stat-ok strong {
  color: #15803d;
}

.workspace {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.device-card {
  padding: 16px;
  display: grid;
  gap: 14px;
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.device-card:hover,
.device-card:focus-visible {
  border-color: #86d9cf;
  box-shadow: 0 24px 54px rgba(0, 12, 36, 0.42);
  outline: none;
  transform: translateY(-1px);
}

.device-card-head {
  display: grid;
  align-items: start;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.device-card-head.without-image {
  grid-template-columns: minmax(0, 1fr) auto;
}

.device-image {
  align-self: center;
  background: #edf2f8;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  height: 58px;
  object-fit: contain;
  padding: 6px;
  width: 58px;
}

.card-badges,
.device-detail-badges {
  align-items: end;
  display: grid;
  gap: 6px;
  justify-items: end;
}

.badge {
  border-radius: 999px;
  background: #d8fff7;
  color: #006156;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.os-pill {
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 8px;
  white-space: nowrap;
}

.os-current {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.os-outdated {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.os-unknown {
  background: #eef2f7;
  border-color: #d6e0ec;
  color: #53657c;
}

dl {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 6px 10px;
  margin: 0;
}

dt { color: var(--panel-muted); }
dd { margin: 0; overflow-wrap: anywhere; }

.side-column {
  display: grid;
  gap: 14px;
}

.panel {
  padding: 16px;
}

.reports-panel {
  margin-top: 18px;
}

.panel h2 {
  margin-bottom: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
}

.wide { grid-column: 1 / -1; }
.stack { display: grid; gap: 12px; }
.hidden { display: none; }
.error { color: #b91c1c; min-height: 22px; }

.token-box {
  margin-top: 14px;
  border: 1px solid #83cfc5;
  border-radius: 8px;
  background: #ecfdf5;
  padding: 12px;
  overflow-wrap: anywhere;
}

.device-details-modal {
  width: min(840px, calc(100% - 28px));
}

.device-details {
  display: grid;
  gap: 16px;
}

.device-details-hero {
  align-items: center;
  background: #f3f7fc;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  padding: 14px;
}

.device-details-hero.without-image {
  grid-template-columns: minmax(0, 1fr) auto;
}

.device-details-hero h3 {
  font-size: 22px;
}

.device-details-hero p {
  color: var(--panel-muted);
  margin-top: 2px;
}

.device-details-image {
  background: #ffffff;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  height: 82px;
  object-fit: contain;
  padding: 8px;
  width: 82px;
}

.device-details-list {
  background: #ffffff;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  grid-template-columns: minmax(120px, 0.32fr) minmax(0, 1fr);
  padding: 14px;
}

.device-details-list dt,
.device-details-list dd {
  border-top: 1px solid #eef3f8;
  padding-top: 8px;
}

.device-details-list dt:nth-of-type(1),
.device-details-list dd:nth-of-type(1) {
  border-top: 0;
  padding-top: 0;
}

.device-notes {
  background: #f8fafc;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  padding: 14px;
}

.device-notes p {
  color: var(--panel-muted);
  overflow-wrap: anywhere;
}

.detail-actions {
  border-top: 1px solid var(--panel-line);
  justify-content: flex-end;
  padding-top: 14px;
}

.token-modal {
  width: min(520px, calc(100% - 28px));
}

.token-modal .token-box {
  margin-top: 0;
}

.token-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

.report-list {
  display: grid;
  gap: 10px;
}

.user-manager {
  display: grid;
  gap: 18px;
}

.people-list {
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  display: grid;
  max-height: 300px;
  overflow: auto;
}

.person-row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 12px;
}

.person-row + .person-row {
  border-top: 1px solid var(--panel-line);
}

.person-row p {
  color: var(--panel-muted);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.empty-state,
.form-message {
  color: var(--panel-muted);
}

.empty-state {
  padding: 14px;
}

.report {
  border-top: 1px solid var(--panel-line);
  padding-top: 10px;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  display: grid;
  gap: 24px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 26px;
  box-shadow: var(--shadow);
  color: var(--panel-text);
}

.login-brand {
  justify-content: center;
}

.login-brand h1 {
  color: var(--panel-text);
}

.modal {
  width: min(760px, calc(100% - 28px));
  max-height: min(820px, calc(100vh - 36px));
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--panel-text);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(0, 18, 48, 0.72);
}

.modal-shell {
  display: grid;
}

.modal-head {
  align-items: center;
  border-bottom: 1px solid var(--panel-line);
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
}

.modal-body {
  padding: 18px;
}

.icon-button {
  align-items: center;
  background: #edf2f8;
  border: 1px solid var(--panel-line);
  border-radius: 50%;
  color: var(--panel-text);
  display: inline-grid;
  height: 34px;
  justify-content: center;
  place-items: center;
  padding: 0;
  width: 34px;
}

.icon-button span,
.icon-button span::after {
  background: #36506f;
  border-radius: 999px;
  content: "";
  display: block;
  height: 2px;
  position: relative;
  width: 14px;
}

.icon-button span {
  transform: rotate(45deg);
}

.icon-button span::after {
  left: 0;
  position: absolute;
  top: 0;
  transform: rotate(90deg);
}

@media (max-width: 1000px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .stat { padding: 8px; }
  .stat strong { font-size: 20px; }
  .stat span { font-size: 13px; }
}

@media (max-width: 620px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .toolbar, .form-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .stat {
    display: grid;
    gap: 1px;
    justify-items: center;
    padding: 7px 3px;
    text-align: center;
  }
  .stat strong { font-size: 18px; }
  .stat span { font-size: 11px; }
  .wide { grid-column: auto; }
  dl, .device-details-list { grid-template-columns: 1fr; }
  .device-details-hero, .device-details-hero.without-image { grid-template-columns: minmax(0, 1fr); }
  .card-badges, .device-detail-badges { justify-items: start; }
  .device-details-image { height: 74px; width: 74px; }
  .person-row { grid-template-columns: 1fr; }
  .row-actions { justify-content: stretch; }
  .row-actions button { flex: 1; }
}
