:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: #f5f6f8;
  color: #20262e;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 22px 14px;
  border-right: 1px solid #dfe3e8;
  background: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px;
  color: #20262e;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.brandMark {
  display: grid;
  width: 40px;
  height: 34px;
  place-items: center;
  border-radius: 5px;
  background: #4f008c;
  color: #fff;
  font-size: 18px;
}

.boardNav { display: grid; gap: 4px; }
.boardNav a {
  display: flex;
  min-height: 42px;
  align-items: center;
  padding: 0 12px;
  border-left: 3px solid transparent;
  color: #525c69;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.boardNav a:hover { background: #f7f3fa; color: #4f008c; }
.boardNav a.active { border-left-color: #4f008c; background: #f2eaf7; color: #4f008c; }
.navBadge { min-width: 20px; margin-left: auto; padding: 2px 6px; border-radius: 10px; background: #ff375e; color: #fff; font-size: 10px; text-align: center; }

.sourceNote {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding: 14px 10px 0;
  border-top: 1px solid #e8eaee;
}
.sourceNote span, .sourceNote small { color: #7a8491; font-size: 11px; }
.sourceNote strong { font-size: 12px; }
.logoutForm { margin-top: 14px; }
.logoutForm button {
  width: 100%;
  min-height: 36px;
  border: 1px solid #ccd2da;
  border-radius: 6px;
  background: #fff;
  color: #4f008c;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.workspace { min-width: 0; padding: 24px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
h1 { margin: 0; font-size: 26px; line-height: 1.2; letter-spacing: 0; }
p { margin: 5px 0 0; color: #697382; font-size: 14px; }

.actions, .toolbar { display: flex; align-items: flex-end; gap: 10px; }
.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border: 1px solid #ccd2da;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}
.button.primary { border-color: #4f008c; background: #4f008c; color: #fff; }
.button.secondary { background: #fff; color: #4f008c; }
.button:disabled { cursor: wait; opacity: .65; }
.button.wide { width: 100%; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid #dfe3e8;
  border-radius: 8px;
  background: #fff;
  margin-bottom: 14px;
}
.metric { min-height: 82px; padding: 16px 18px; border-right: 1px solid #e5e8ec; }
.metric:last-child { border-right: 0; }
.metric strong { display: block; font-size: 25px; }
.metric span { display: block; margin-top: 6px; color: #6c7683; font-size: 12px; font-weight: 700; }

.toolbar { margin-bottom: 12px; }
.field { display: grid; min-width: 170px; gap: 5px; }
.field.searchField { flex: 1; min-width: 240px; }
.field span { color: #66717e; font-size: 11px; font-weight: 800; text-transform: uppercase; }
input, select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid #ccd2da;
  border-radius: 6px;
  background: #fff;
  color: #20262e;
  font-size: 13px;
}
input:focus, select:focus { border-color: #4f008c; outline: 2px solid #eadcf3; }

.statusbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  min-height: 32px;
  color: #6c7683;
  font-size: 12px;
  font-weight: 600;
}
.statusbar strong { color: #20262e; }
#status[data-mode="ok"] { color: #087443; }
#status[data-mode="error"] { color: #b42318; }

.tableWrap {
  max-height: calc(100vh - 255px);
  overflow: auto;
  border: 1px solid #dfe3e8;
  border-radius: 8px;
  background: #fff;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 11px; border-bottom: 1px solid #eceff2; text-align: left; vertical-align: top; font-size: 12px; }
th { position: sticky; top: 0; z-index: 1; background: #4f008c; color: #fff; font-weight: 800; white-space: nowrap; }
td { max-width: 420px; overflow-wrap: anywhere; word-break: normal; }
.nameColumn { min-width: 120px; }
.deviceNameColumn { min-width: 230px; }
.itemGroupColumn { min-width: 230px; }
.descriptionColumn { min-width: 360px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #faf7fc; }
.empty { padding: 36px; color: #7a8491; text-align: center; }
.tableLink { color: #4f008c; font-weight: 800; text-decoration: none; }
.tableLink:hover { text-decoration: underline; }

.statusPill {
  display: inline-flex;
  min-width: 78px;
  justify-content: center;
  padding: 4px 7px;
  border-radius: 999px;
  background: #e8ebef;
  color: #4b5563;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}
.statusPill.active, .statusPill.existing, .statusPill.in-stock { background: #e4f5ec; color: #087443; }
.statusPill.added { background: #e8f1ff; color: #175cd3; }
.statusPill.new { background: #fde7f3; color: #a1105a; }
.statusPill.removed, .statusPill.out-of-stock { background: #fdecec; color: #b42318; }
.statusPill.unknown { background: #f1f3f5; color: #59636f; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #d9c7e6;
  border-top-color: #4f008c;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 10;
  width: min(440px, 100vw);
  height: 100vh;
  padding: 22px;
  overflow: auto;
  border-left: 1px solid #dfe3e8;
  background: #fff;
  box-shadow: -16px 0 40px rgba(24, 32, 43, .16);
  transform: translateX(105%);
  transition: transform 180ms ease;
}
.drawer.open { transform: translateX(0); }
.close { float: right; height: 34px; border: 1px solid #ccd2da; border-radius: 6px; background: #fff; cursor: pointer; font-weight: 700; }
.drawer img { width: 100%; max-height: 260px; margin: 14px 0 8px; object-fit: contain; background: #f6f7f9; }
.drawer h2 { margin: 8px 0 3px; font-size: 22px; }
.drawer h3 { margin: 18px 0 8px; font-size: 14px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.fact { padding: 9px; border: 1px solid #e3e6ea; border-radius: 6px; background: #f8f9fa; }
.fact span, .detailList span { display: block; color: #727d89; font-size: 11px; }
.fact strong { display: block; margin-top: 4px; font-size: 12px; word-break: break-word; }
.detailList { display: grid; gap: 7px; padding: 0; margin: 0 0 12px; list-style: none; }
.detailList li { padding: 9px; border: 1px solid #e8eaee; border-radius: 6px; font-size: 12px; }
.detailList strong { display: block; margin-bottom: 3px; }
.muted { color: #87919d; }

.accountWorkspace { display: block; }
.accountManager {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 12px;
  padding: 18px;
  border: 1px solid #dfe3e8;
  border-radius: 8px;
  background: #fff;
}
.accountManager h2 { margin: 0; font-size: 17px; letter-spacing: 0; }
.accountManager p { max-width: 520px; font-size: 12px; }
.accountForm { display: flex; align-items: flex-end; gap: 10px; }
.accountForm .field { min-width: 190px; }
.connectionMessage { margin-bottom: 12px; padding: 11px 14px; border-left: 4px solid; font-size: 13px; font-weight: 800; }
.connectionMessage.success { border-color: #087443; background: #e9f7ef; color: #087443; }
.connectionMessage.error { border-color: #b42318; background: #fdecec; color: #b42318; }
.accountList { display: grid; gap: 8px; margin-bottom: 14px; }
.accountRow {
  display: grid;
  grid-template-columns: minmax(150px, .8fr) auto minmax(260px, 1.5fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 62px;
  padding: 10px 14px;
  border: 1px solid #dfe3e8;
  border-radius: 7px;
  background: #fff;
}
.accountRow div { min-width: 0; }
.accountRow strong, .accountRow span { display: block; }
.accountRow span { margin-top: 3px; color: #727d89; font-size: 11px; }
.accountRow .statusPill { color: inherit; }
.accountMeta strong { overflow: hidden; text-overflow: ellipsis; font-size: 12px; white-space: nowrap; }
.accountActions { display: flex; gap: 6px; }
.iconButton { width: 36px; height: 36px; border: 1px solid #ccd2da; border-radius: 6px; background: #fff; color: #4f008c; font-size: 18px; cursor: pointer; }
.iconButton.danger { color: #b42318; }
.accountEmpty { padding: 18px; border: 1px dashed #ccd2da; border-radius: 7px; color: #727d89; font-size: 12px; text-align: center; }
.accountTableWrap { max-height: calc(100vh - 390px); }

.publicAccessPage { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: #f4f5f7; }
.accessRequestPanel { width: min(500px, 100%); padding: 28px; border: 1px solid #dfe3e8; border-radius: 8px; background: #fff; box-shadow: 0 14px 35px rgba(32, 38, 46, .1); }
.accessRequestPanel .brand { padding-left: 0; }
.accessRequestPanel h1 { font-size: 24px; }
.requestAccessForm { display: grid; gap: 4px; margin-top: 22px; }
.requestAccessForm .field { min-width: 0; }
.backToLogin { display: block; margin-top: 18px; color: #4f008c; font-size: 13px; font-weight: 800; text-align: center; text-decoration: none; }

.accessWorkspace { display: block; }
.accessSection { margin-bottom: 18px; padding: 18px; border-top: 1px solid #dfe3e8; border-bottom: 1px solid #dfe3e8; background: #fff; }
.sectionHeading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.sectionHeading h2 { margin: 0; font-size: 18px; letter-spacing: 0; }
.sectionHeading p { font-size: 12px; }
.sectionHeading select, .sectionHeading input { width: 220px; }
.accessList { display: grid; gap: 10px; }
.accessRow { display: grid; grid-template-columns: minmax(190px, .8fr) minmax(150px, .5fr) minmax(420px, 2fr); gap: 18px; align-items: start; padding: 14px 0; border-bottom: 1px solid #eceff2; }
.accessRow:last-child { border-bottom: 0; }
.accessIdentity strong, .accessIdentity span, .accessRow small, .decisionSummary span { display: block; }
.accessIdentity span, .accessRow small, .decisionSummary span { margin-top: 4px; color: #727d89; font-size: 11px; }
.requestDecision { display: grid; grid-template-columns: 160px 220px; gap: 10px; }
.requestDecision .permissionSet { grid-column: 1 / -1; }
.decisionActions { display: flex; grid-column: 1 / -1; justify-content: flex-end; gap: 8px; }
.permissionSet { min-width: 0; margin: 0; padding: 10px 12px; border: 1px solid #dde1e6; border-radius: 6px; }
.permissionSet legend { padding: 0 5px; color: #59636f; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.permissionGrid { display: grid; grid-template-columns: repeat(4, minmax(100px, 1fr)); gap: 8px; }
.permissionSet label, .toggleField { display: flex; align-items: center; gap: 6px; color: #3f4853; font-size: 12px; font-weight: 700; }
.permissionSet input, .toggleField input { width: 16px; height: 16px; }
.featurePermissions { display: flex; gap: 22px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #eceff2; }
.userRow { grid-template-columns: 220px minmax(0, 1fr); }
.userRow .permissionSet { grid-column: 1 / -1; }
.userControls { display: grid; grid-template-columns: 140px 110px minmax(200px, 1fr); align-items: end; gap: 10px; }
.toggleField { min-height: 40px; }
.saveUser { display: flex; grid-column: 1 / -1; align-items: center; justify-content: flex-end; gap: 14px; }
.saveUser span { color: #727d89; font-size: 11px; }

@media (max-width: 980px) {
  .appShell { display: block; }
  .sidebar { position: static; height: auto; padding: 12px; border-right: 0; border-bottom: 1px solid #dfe3e8; }
  .brand { padding-bottom: 10px; }
  .boardNav { display: flex; overflow-x: auto; }
  .boardNav a { flex: 0 0 auto; border-left: 0; border-bottom: 3px solid transparent; }
  .boardNav a.active { border-bottom-color: #4f008c; }
  .sourceNote { display: none; }
  .logoutForm { position: absolute; top: 12px; right: 12px; width: 78px; margin: 0; }
  .workspace { padding: 18px; }
  .tableWrap { max-height: none; }
  .accountManager { align-items: stretch; flex-direction: column; }
  .accessRow, .userRow { grid-template-columns: 1fr; }
  .saveUser { grid-column: 1; }
}

@media (max-width: 720px) {
  .topbar, .actions, .toolbar { align-items: stretch; flex-direction: column; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid #e5e8ec; }
  .field, .field.searchField { min-width: 100%; }
  .statusbar { grid-template-columns: 1fr; gap: 5px; padding: 5px 0 9px; }
  h1 { font-size: 22px; }
  .accountForm { align-items: stretch; flex-direction: column; }
  .accountForm .field { min-width: 100%; }
  .accountRow { grid-template-columns: 1fr auto; }
  .accountMeta { grid-column: 1 / -1; }
  .sectionHeading, .requestDecision, .userControls { align-items: stretch; grid-template-columns: 1fr; flex-direction: column; }
  .sectionHeading select, .sectionHeading input { width: 100%; }
  .permissionGrid { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .requestDecision .permissionSet, .decisionActions { grid-column: 1; }
}
