:root {
  color-scheme: light;
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --text: #1d2733;
  --muted: #687586;
  --line: #d8e0e8;
  --blue: #2458d3;
  --green: #178a5b;
  --orange: #b95f13;
  --red: #b42318;
  --shadow: 0 16px 38px rgba(29, 39, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.sidebar {
  background: #182230;
  color: #e9eef5;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #9fb0c4;
  margin-top: 3px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #f4f7fb;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 9px;
}

.brand-mark span {
  border-radius: 50%;
  background: var(--blue);
}

.brand-mark span:nth-child(2) {
  background: var(--green);
}

.brand-mark span:nth-child(3) {
  background: var(--orange);
}

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

.nav-btn {
  min-height: 40px;
  border-radius: 8px;
  background: transparent;
  color: #dbe5ef;
  text-align: left;
  padding: 0 12px;
}

.nav-btn.active,
.nav-btn:hover {
  background: #27364a;
}

.nav-link {
  min-height: 40px;
  border-radius: 8px;
  color: #dbe5ef;
  display: flex;
  align-items: center;
  padding: 0 12px;
  text-decoration: none;
}

.nav-link:hover {
  background: #27364a;
}

.sidebar-metrics {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.sidebar-metrics div {
  border: 1px solid #34465c;
  border-radius: 8px;
  padding: 12px;
  background: #202d3d;
}

.sidebar-metrics span,
.sidebar-metrics strong {
  display: block;
}

.sidebar-metrics span {
  color: #9fb0c4;
  font-size: 12px;
}

.sidebar-metrics strong {
  font-size: 24px;
  margin-top: 6px;
}

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

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 17px;
}

.topbar p,
.panel p {
  color: var(--muted);
  margin-top: 5px;
}

.topbar-actions,
.toolbar,
.inline-fields,
.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.session-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.sync-progress {
  min-width: 260px;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.sync-progress-track {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce5ef;
}

.sync-progress-track span {
  display: block;
  width: 45%;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  animation: sync-progress-slide 1.2s ease-in-out infinite;
}

.sync-progress.complete .sync-progress-track span {
  width: 100%;
  animation: none;
  background: var(--green);
}

.sync-progress.failed .sync-progress-track span {
  width: 100%;
  animation: none;
  background: var(--red);
}

@keyframes sync-progress-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(230%); }
}

.select-label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.select-label select {
  min-width: 220px;
}

input,
select {
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  color: var(--text);
  padding: 0 10px;
  min-width: 0;
}

button.icon-text,
button.icon-only {
  min-height: 38px;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button.icon-only {
  width: 38px;
  padding: 0;
  font-size: 22px;
}

button.secondary {
  background: #e8edf4;
  color: var(--text);
}

button.warn {
  background: var(--orange);
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.1fr);
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

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

.count-pill,
.status-pill,
.sensor-chip {
  border-radius: 999px;
  background: #edf2f7;
  color: #324256;
  padding: 4px 9px;
  font-size: 12px;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.status-online,
.status-ready,
.status-completed,
.status-ok {
  background: #e8f7ef;
  color: var(--green);
}

.status-idle,
.status-sent,
.status-unavailable,
.status-provider_unavailable {
  background: #fff2df;
  color: var(--orange);
}

.status-queued,
.status-unknown,
.status-unchecked,
.status-token_unknown {
  background: #edf2f7;
  color: #546274;
}

.status-failed,
.status-invalid,
.status-token_failed {
  background: #feecec;
  color: var(--red);
}

.readonly-pill {
  min-height: 41px;
  border-radius: 8px;
  background: #edf2f7;
  color: #324256;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  font-size: 15px;
}

.stack-form {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.stack-form button {
  justify-self: start;
}

.tariff-load-row select {
  flex: 1;
  min-width: 0;
}

.form-row {
  margin-bottom: 14px;
}

.form-row input {
  flex: 1;
}

.list {
  display: grid;
  gap: 8px;
}

.list-item {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 11px;
  display: grid;
  gap: 5px;
}

.list-item strong,
.list-item small {
  display: block;
}

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

.equipment-cell {
  display: grid;
  gap: 2px;
  margin-bottom: 8px;
}

.equipment-cell:last-child {
  margin-bottom: 0;
}

.integrator-card {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.integrator-admin-form {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.plain-list-button {
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.connection-card {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.connection-card-main {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.connection-sync-btn {
  align-self: center;
}

.connection-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
  align-self: center;
}

.connection-actions .icon-text {
  white-space: nowrap;
}

.token-check-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.connection-settings-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px auto;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.connection-settings-form input,
.connection-settings-form select {
  width: 100%;
}

.hidden {
  display: none !important;
}

.toolbar {
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.toolbar .form-row {
  margin: 0;
}

.toolbar input,
.toolbar select {
  min-width: 180px;
}

.combo {
  position: relative;
  min-width: 240px;
}

.combo-button {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 34px 0 10px;
  text-align: left;
  position: relative;
}

.combo-button::after {
  content: "⌄";
  position: absolute;
  right: 12px;
  top: 8px;
  color: var(--muted);
}

.combo-menu {
  position: absolute;
  z-index: 15;
  left: 0;
  top: calc(100% + 6px);
  width: min(360px, 90vw);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px;
}

.combo-search {
  width: 100%;
  margin-bottom: 8px;
}

.combo-options {
  max-height: 260px;
  overflow: auto;
  display: grid;
  gap: 2px;
}

.combo-option {
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0 9px;
}

.combo-option:hover,
.combo-option.active {
  background: #eef4ff;
  color: var(--blue);
}

.combo-empty {
  color: var(--muted);
  padding: 8px;
  font-size: 12px;
}

.app-version {
  position: fixed;
  right: 12px;
  bottom: 10px;
  z-index: 40;
  padding: 3px 8px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  pointer-events: none;
}

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

.table-panel {
  padding: 0;
  overflow: hidden;
}

.table-footer {
  min-height: 68px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface);
}

.pager-actions {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-left: auto;
}

.pager-actions .page-size-label {
  flex: 0 0 190px;
  width: 190px;
}

.pager-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.pager-buttons .icon-text {
  justify-content: center;
  min-width: 92px;
}

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

.objects-table th:nth-child(6),
.objects-table td:nth-child(6) {
  width: 112px;
  text-align: center;
}

.objects-table th:nth-child(6) {
  white-space: nowrap;
  overflow-wrap: normal;
}

.audit-table th:nth-child(1),
.audit-table td:nth-child(1) {
  width: 120px;
}

.audit-table th:nth-child(3),
.audit-table td:nth-child(3) {
  width: 150px;
}

.audit-table th:nth-child(6),
.audit-table td:nth-child(6) {
  width: 130px;
}

.object-command-btn {
  margin: 0 auto;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  background: #f3f6f9;
  color: #4d5d70;
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr {
  background: var(--surface);
}

tbody tr:hover,
tbody tr.selected {
  background: #f7fbff;
}

.object-name {
  font-weight: 700;
}

.muted,
.meta-line {
  color: var(--muted);
  font-size: 12px;
}

.sensor-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.detail-panel {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.object-detail {
  display: grid;
  gap: 14px;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: grid;
  gap: 8px;
}

.ble-sensor-list {
  display: grid;
  gap: 8px;
}

.ble-sensor-card {
  border-bottom: 1px solid var(--line);
  background: transparent;
  border-radius: 0;
  padding: 0 0 10px;
  display: grid;
  gap: 3px;
}

.ble-sensor-card:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.ble-sensor-title {
  font-size: 15px;
}

.ble-sensor-model {
  font-size: 16px;
  line-height: 1.25;
}

.ble-sensor-head {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

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

.audit-item {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 9px;
  display: grid;
  gap: 4px;
}

.audit-item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.audit-values {
  color: var(--text);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.audit-value-line {
  display: block;
}

.audit-value-line + .audit-value-line {
  margin-top: 2px;
}

.audit-value-line span {
  color: var(--muted);
  margin-right: 4px;
}

.detail-actions {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  margin: -4px 0 2px;
  padding: 4px 0 10px;
}

.empty-detail {
  min-height: 220px;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(24, 34, 48, 0.38);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.modal-meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
}

.ntc-session-panel {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  display: grid;
  gap: 10px;
}

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

.field-label input {
  width: 100%;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

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

.command-catalog-panel {
  display: grid;
  gap: 14px;
}

.command-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.command-client-combo {
  min-width: 260px;
}

.combo-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.command-catalog-list {
  display: grid;
  gap: 8px;
}

.command-list button {
  justify-content: flex-start;
}

.command-list button:disabled {
  cursor: not-allowed;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 260px;
  max-width: min(420px, calc(100vw - 40px));
  border-radius: 8px;
  background: #182230;
  color: #fff;
  padding: 13px 15px;
  box-shadow: var(--shadow);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.login-brand {
  margin-bottom: 18px;
}

.login-brand .brand-mark {
  background: #eef3f9;
}

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

  .sidebar {
    min-height: auto;
  }

  .panel-grid,
  .object-layout {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 720px) {
  .workspace,
  .sidebar {
    padding: 14px;
  }

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

  .toolbar,
  .form-row,
  .inline-fields {
    align-items: stretch;
    flex-direction: column;
  }

  .select-label select,
  .toolbar input,
  .toolbar select,
  .page-size-label {
    width: 100%;
  }

  .table-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .pager-actions,
  .pager-buttons {
    width: 100%;
  }

  .pager-actions {
    margin-left: 0;
  }

  .pager-actions .page-size-label {
    flex-basis: auto;
  }

  .pager-buttons .icon-text {
    flex: 1 1 0;
  }

  .connection-card {
    grid-template-columns: 1fr;
  }

  .connection-actions {
    justify-items: start;
  }

  .integrator-card {
    grid-template-columns: 1fr;
  }

  .connection-settings-form {
    grid-template-columns: 1fr;
  }

  .connection-sync-btn {
    justify-self: start;
  }
}
