:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #f8fafc;
  --ink: #1f2937;
  --muted: #6c757d;
  --line: #d8dee8;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --surface-tint: #eef2f6;
  --sidebar-bg: #102f63;
  --sidebar-muted: #c9ddf6;
  --sidebar-active: #1d9ee5;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  min-height: 36px;
  border: 1px solid #ced4da;
  border-radius: 0.375rem;
  background: #ffffff;
  color: #212529;
  cursor: pointer;
  padding: 0.375rem 0.75rem;
  font-weight: 500;
}

button:hover {
  border-color: #a8b3c4;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

button.primary:hover {
  background: var(--accent-strong);
}

button.danger {
  border-color: #f3b4ae;
  color: var(--danger);
}

.locate-cell {
  align-items: flex-start;
  display: grid;
  gap: 4px;
}

.locate-button {
  color: #ffffff;
  min-width: 96px;
}

.locate-button.locate-fresh {
  background: var(--ok);
  border-color: var(--ok);
}

.locate-button.locate-aging {
  background: #d99500;
  border-color: #d99500;
  color: #1f2937;
}

.locate-button.locate-stale {
  background: var(--danger);
  border-color: var(--danger);
}

.locate-button:hover {
  filter: brightness(0.94);
}

.locate-timestamp {
  color: var(--danger);
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
}

button.icon {
  width: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid #ced4da;
  border-radius: 0.375rem;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--bg);
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 78px;
  min-height: 78px;
  padding: 6px 22px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 4%);
}

.brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: 100%;
  padding-left: 0;
}

.brand-logo {
  display: block;
  width: auto;
  height: 254px;
  max-width: 1651px;
  object-fit: contain;
  position: absolute;
  left: 0;
  top: 50%;
  z-index: 2;
  transform: translateY(-50%);
  pointer-events: none;
}

.brand span {
  border-left: 1px solid var(--line);
  color: #495057;
  font-size: 14px;
  font-weight: 600;
  margin-left: 440px;
  padding-left: 12px;
}

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

.account span {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-mode-switch {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  color: var(--sidebar-bg);
  display: inline-flex;
  gap: 6px;
  min-height: 36px;
  padding: 0.375rem 0.75rem;
  text-decoration: none;
  white-space: nowrap;
}

.topbar-mode-switch:hover {
  background: var(--surface-tint);
  color: var(--sidebar-bg);
  text-decoration: none;
}

.main {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.admin-main {
  max-width: none;
  margin: 0;
  padding-left: 16px;
  padding-right: 24px;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(180deg, rgb(38 50 56 / 7%), transparent 36%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 26px;
  box-shadow: 0 0.5rem 1rem rgb(0 0 0 / 8%);
}

.login-panel h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.login-logo {
  display: block;
  width: min(260px, 100%);
  height: auto;
  margin: 0 auto 10px;
}

.mode-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  color: var(--sidebar-bg);
  font-weight: 600;
  text-decoration: none;
}

.mode-switch:hover {
  background: var(--surface-tint);
  color: var(--sidebar-bg);
  text-decoration: none;
}

.login-panel p,
.muted {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

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

.field label {
  font-size: 13px;
  font-weight: 650;
}

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

.page-toolbar {
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.toolbar h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 650;
}

.toolbar h3,
.toolbar p {
  margin: 0;
}

.admin-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.admin-sidebar {
  position: sticky;
  top: 16px;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--sidebar-bg);
  color: #ffffff;
  overflow: hidden;
  box-shadow: 0 0.125rem 0.25rem rgb(0 0 0 / 8%);
}

.sidebar-title {
  border-bottom: 1px solid rgb(255 255 255 / 12%);
  padding: 14px 16px;
  color: var(--sidebar-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.admin-workspace {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.tabs {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 10px;
}

.tab-section {
  display: grid;
  gap: 4px;
  padding-bottom: 8px;
}

.tab-section + .tab-section {
  border-top: 1px solid rgb(255 255 255 / 10%);
  padding-top: 10px;
}

.tab-section-title {
  color: #90a4ae;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  text-transform: uppercase;
}

.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  width: 100%;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: #cfd8dc;
  padding: 8px 11px;
  text-align: left;
}

.tab:hover {
  background: rgb(255 255 255 / 8%);
  color: #ffffff;
}

.tab.active {
  background: var(--sidebar-active);
  color: #ffffff;
}

.tab .bi {
  width: 18px;
  font-size: 16px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 18px;
  align-items: start;
}

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

.devices-grid > .panel .stack {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.devices-grid > .panel .field:has(textarea),
.devices-grid > .panel .actions {
  grid-column: span 2;
}

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

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 16px;
  box-shadow: 0 0.125rem 0.25rem rgb(0 0 0 / 5%);
}

.panel h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  box-shadow: 0 0.125rem 0.25rem rgb(0 0 0 / 5%);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.devices-table {
  min-width: 1040px;
}

.devices-table th,
.devices-table td {
  white-space: nowrap;
}

.devices-table td:first-child,
.devices-table td:last-child {
  white-space: normal;
}

.devices-table-wrap {
  min-width: 0;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: var(--surface-tint);
  color: #495057;
  font-size: 12px;
  text-transform: uppercase;
}

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

tr:last-child td {
  border-bottom: 0;
}

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

.inline-status-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--ok);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #344054;
  font-size: 12px;
  font-weight: 650;
}

.badge.warn {
  background: #fff4e5;
  color: var(--warn);
}

.badge.ok {
  background: #e7f8ef;
  color: var(--ok);
}

.badge.neutral {
  background: #eef2f7;
  color: #344054;
}

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

.user-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.user-tabs .tab {
  background: #ffffff;
  border: 1px solid var(--line);
  color: #344054;
  flex: 0 0 auto;
  justify-content: center;
  min-height: 40px;
  width: auto;
}

.user-tabs .tab:hover {
  background: var(--surface-tint);
  color: var(--sidebar-bg);
}

.user-tabs .tab.active {
  background: var(--sidebar-bg);
  border-color: var(--sidebar-bg);
  color: #ffffff;
}

.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.subtabs button {
  background: #ffffff;
  border-color: var(--line);
  color: #344054;
}

.subtabs button:hover {
  background: var(--surface-tint);
}

.subtabs button.active {
  background: var(--sidebar-bg);
  border-color: var(--sidebar-bg);
  color: #ffffff;
}

.threshold-input {
  align-items: center;
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(76px, 1fr) auto;
}

.threshold-input span {
  color: var(--muted);
  font-weight: 700;
}

.user-device-controls {
  display: grid;
  gap: 12px;
}

.alphabet-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.alphabet-filter button {
  align-items: center;
  border-radius: 0.375rem;
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  justify-content: center;
  min-height: 36px;
  min-width: 36px;
  padding: 0.375rem 0.625rem;
}

.alphabet-filter button.active {
  background: var(--sidebar-bg);
  border-color: var(--sidebar-bg);
  color: #fff;
}

.device-pager {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr);
  margin-top: 14px;
}

.device-page-button {
  align-items: center;
  display: inline-flex;
  font-size: 16px;
  font-weight: 750;
  gap: 8px;
  justify-content: center;
  min-height: 56px;
  padding: 0.75rem 1rem;
}

.device-page-count {
  align-items: center;
  color: #344054;
  display: grid;
  gap: 2px;
  justify-items: center;
  min-width: 140px;
  text-align: center;
}

.device-page-count span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.event-pager {
  margin-bottom: 2px;
}

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.battery {
  display: grid;
  gap: 5px;
  min-width: 120px;
}

.battery-value {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.battery-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2f7;
}

.battery-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--ok);
}

.battery.watch .battery-fill {
  background: var(--warn);
}

.battery.replace .battery-fill {
  background: #d97706;
}

.battery.critical .battery-fill {
  background: var(--danger);
}

.battery-status {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  min-height: 28px;
  min-width: 82px;
  justify-content: center;
  padding: 4px 10px;
}

.battery-status-ok,
.battery-status-good {
  background: #e7f8ef;
  color: var(--ok);
}

.battery-status-low,
.battery-status-watch {
  background: #fef3c7;
  color: #92400e;
}

.battery-status-replace {
  background: #fff0ee;
  color: var(--danger);
}

.battery-status-unknown {
  background: #eef2f7;
  color: var(--muted);
}

.last-mqtt-health {
  display: grid;
  gap: 4px;
  max-width: 760px;
}

.last-mqtt-health span,
.last-mqtt-health code,
.last-mqtt-health pre {
  overflow-wrap: anywhere;
}

.last-mqtt-health span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.last-mqtt-health code {
  background: #eef2f7;
  border-radius: 0.25rem;
  color: #344054;
  display: inline-block;
  font-size: 12px;
  padding: 3px 6px;
}

.last-mqtt-health pre {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  color: #344054;
  font-size: 12px;
  margin: 0;
  max-height: 160px;
  overflow: auto;
  padding: 8px;
  white-space: pre-wrap;
}

.battery-reference {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.compact-stack {
  gap: 8px;
  min-width: 220px;
}

.compact-checkbox {
  width: auto;
  min-height: 0;
}

.dual-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.dual-list h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

.document-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.document-card {
  display: grid;
  gap: 8px;
  min-height: 142px;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #ffffff;
  color: var(--ink);
  padding: 16px;
  text-decoration: none;
}

.document-card:hover {
  border-color: var(--accent);
  color: var(--ink);
  text-decoration: none;
}

.document-card .bi {
  color: var(--accent);
  font-size: 28px;
}

.document-card span {
  color: var(--muted);
  font-size: 13px;
}

.sound-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.sound-card {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #ffffff;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.sound-card h4 {
  margin: 0 0 6px;
  font-size: 16px;
}

.sound-card audio {
  width: 100%;
}

.sound-card input[type="file"] {
  min-height: 0;
  padding: 8px;
}

.diagnostics-controls {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.diagnostics-controls .field {
  width: min(420px, 100%);
}

.mqtt-feed-table-wrap table {
  min-width: 980px;
}

.mqtt-payload {
  max-width: 560px;
  max-height: 140px;
  overflow: auto;
  margin: 0;
  border-radius: 0.375rem;
  background: #f8f9fa;
  color: #212529;
  font-size: 12px;
  white-space: pre-wrap;
}

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

.scan-item {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(300px, 1.2fr);
  gap: 14px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

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

.scan-meta strong {
  width: 100%;
  color: var(--ink);
  font-size: 14px;
}

.scan-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(180px, 1fr) minmax(160px, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.scan-form textarea {
  min-height: 38px;
}

.delay-input,
.repeat-input {
  min-width: 76px;
  max-width: 92px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: start;
  justify-items: center;
  overflow: auto;
  background: rgb(24 33 47 / 45%);
  padding: 36px 20px;
}

.modal {
  position: static;
  display: block;
  width: min(1120px, 100%);
  max-height: calc(100vh - 72px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  padding: 16px;
  box-shadow: 0 20px 44px rgb(24 33 47 / 22%);
}

.modal .toolbar {
  margin-bottom: 12px;
}

.modal h3,
.modal p {
  margin: 0;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.info-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.info-grid span,
.info-grid strong {
  display: block;
}

.info-grid span {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.info-grid strong {
  overflow-wrap: anywhere;
}

.alert-backdrop {
  z-index: 30;
  align-items: center;
}

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

.link-button {
  background: transparent;
  border: 0;
  color: var(--sidebar-active);
  min-height: 0;
  padding: 0;
  text-align: left;
  text-decoration: underline;
}

.link-button:hover {
  background: transparent;
  color: var(--sidebar-bg);
}

.event-message-link {
  max-width: 360px;
  overflow-wrap: anywhere;
}

.event-message-modal {
  width: min(720px, 100%);
}

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

.event-message-detail strong,
.event-message-detail p {
  display: block;
  margin: 4px 0 0;
}

.event-message-detail pre {
  background: #f8f9fa;
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  margin: 6px 0 0;
  max-height: 320px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.alert-message {
  display: grid;
  gap: 6px;
  margin: 14px 0;
  padding: 14px;
  border: 1px solid #f3b4ae;
  border-radius: 8px;
  background: #fff7f5;
}

.alert-message strong {
  font-size: 20px;
  line-height: 1.25;
}

.locate-modal {
  width: min(560px, 100%);
}

.locate-result {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--warn);
  border-radius: 0.5rem;
  background: #ffffff;
  padding: 16px;
}

.locate-result strong {
  font-size: 20px;
  line-height: 1.3;
}

.locate-result.confidence-high {
  border-left-color: var(--ok);
}

.locate-result.confidence-medium {
  border-left-color: var(--warn);
}

.locate-result.confidence-low {
  border-left-color: var(--danger);
}

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

.alert-message span,
.alert-details {
  color: var(--muted);
}

.alert-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 16px;
  font-size: 13px;
}

.gateway-results {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.gateway-result {
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 10px;
}

.gateway-result.ok {
  border-color: rgba(28, 128, 91, 0.35);
}

.gateway-result.warn {
  border-color: rgba(183, 83, 28, 0.35);
}

.gateway-result span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

@media (max-width: 840px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 16px;
  }

  .brand-logo {
    height: 134px;
    max-width: 614px;
  }

  .brand span {
    margin-left: 220px;
  }

  .account {
    width: 100%;
    justify-content: space-between;
  }

  .main {
    padding: 16px;
  }

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

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
  }

  .tabs {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .tab-section + .tab-section {
    border-top: 0;
    padding-top: 0;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .scan-item,
  .scan-form,
  .info-grid,
  .device-pager,
  .diagnostics-controls,
  .dual-list {
    grid-template-columns: 1fr;
  }

  .diagnostics-controls {
    align-items: flex-start;
    flex-direction: column;
  }
}
