:root {
  --bg: #eef2f6;
  --ink: #111827;
  --muted: #667085;
  --line: #d7dee8;
  --primary: #0b5cab;
}

html {
  font-size: 15px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

.app-header {
  background: #111827;
  color: #fff;
}

.navbar-brand,
.app-header .nav-link {
  color: #fff;
}

.app-header .nav-link:hover,
.navbar-brand:hover {
  color: #dbeafe;
}

.app-install-button[hidden] {
  display: none;
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 18px;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-heading h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
}

.page-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

.panel,
.metric-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metric-card {
  display: block;
  text-decoration: none;
  color: var(--ink);
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-weight: 600;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
}

.target-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 220px) auto auto;
  gap: 12px;
  align-items: end;
}

.license-create-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(110px, 160px) minmax(110px, 160px) auto;
  gap: 12px;
  align-items: end;
}

.check-line {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 38px;
}

.code-input,
code {
  font-family: Consolas, "Courier New", monospace;
}

.auth-page {
  min-height: calc(100vh - 120px);
  display: grid;
  place-items: center;
}

.auth-panel {
  width: min(100%, 440px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.auth-heading {
  margin-bottom: 14px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 12px;
}

.section-title h2,
.live-toolbar h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.section-title span,
.live-toolbar p,
.viewer-status-row {
  color: var(--muted);
}

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

.live-targets {
  padding: 12px;
}

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

.live-target {
  width: 100%;
  text-align: left;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  color: var(--ink);
}

.live-target:hover,
.live-target.is-active {
  border-color: var(--primary);
  background: #eef6ff;
}

.live-target.is-offline {
  opacity: .72;
}

.live-target-main,
.live-target-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.live-target-main strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-target-meta {
  margin-top: 5px;
  justify-content: flex-start;
  color: var(--muted);
  font-size: .86rem;
}

.dot-separator {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #98a2b3;
}

.live-target-status,
.target-status-pill {
  font-weight: 700;
}

.live-target-status[data-state="online"],
.target-status-pill[data-state="online"] {
  color: #027a48;
}

.live-target-status[data-state="offline"],
.target-status-pill[data-state="offline"] {
  color: #b42318;
}

.target-status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f2f4f7;
}

.target-status-pill[data-state="online"] {
  background: #ecfdf3;
}

.target-status-pill[data-state="offline"] {
  background: #fef3f2;
}

.live-viewer {
  min-width: 0;
}

.live-toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.live-actions {
  display: flex;
  gap: 8px;
  align-items: end;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.live-actions label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
}

.live-actions .btn {
  min-width: 120px;
}

.live-source-bar {
  display: grid;
  grid-template-columns: minmax(220px, 420px) auto minmax(180px, 1fr);
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.live-source-bar label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
}

.live-source-bar > span {
  align-self: center;
  color: var(--muted);
  font-size: .86rem;
}

.live-source-bar > span[data-state="busy"] {
  color: #9a3412;
}

.live-source-bar > span[data-state="ok"] {
  color: #027a48;
}

.live-source-bar > span[data-state="error"] {
  color: #b42318;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.icon-button:disabled {
  opacity: .45;
}

.viewer-stage {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 100%;
  background: #0f172a;
  border-radius: 8px;
  min-height: 220px;
  max-height: min(68vh, 720px);
  aspect-ratio: var(--viewer-aspect-ratio, 16 / 9);
}

.viewer-stage.has-frame {
  min-height: 0;
}

.viewer-stage img {
  display: none;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: min(68vh, 720px);
  object-fit: contain;
  background: #000;
}

.viewer-stage img.is-visible {
  display: block;
}

.viewer-placeholder {
  display: grid;
  gap: 6px;
  place-items: center;
  color: #dbeafe;
  text-align: center;
  padding: 18px;
}

.viewer-placeholder strong {
  color: #fff;
  font-size: 1.05rem;
}

.viewer-placeholder.is-hidden {
  display: none;
}

.viewer-status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
  font-size: .9rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--ink);
  font-weight: 600;
}

.status-pill[data-state="busy"] {
  background: #fff7ed;
  color: #9a3412;
}

.status-pill[data-state="ok"] {
  background: #ecfdf3;
  color: #027a48;
}

.status-pill[data-state="error"] {
  background: #fef3f2;
  color: #b42318;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafc;
}

.log-filter-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(3, minmax(140px, .8fr)) minmax(120px, .55fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.log-filter-panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 600;
}

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

.license-filter-panel {
  grid-template-columns: minmax(220px, 1.2fr) repeat(4, minmax(140px, .8fr)) repeat(2, minmax(90px, .45fr)) auto;
}

.license-key-cell {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 220px;
}

.license-key-actions {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.license-code {
  min-width: 150px;
  overflow-wrap: anywhere;
}

.license-status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--ink);
  font-weight: 700;
}

.license-status[data-state="active"],
.license-status[data-state="used"] {
  background: #ecfdf3;
  color: #027a48;
}

.license-status[data-state="unused"] {
  background: #eef6ff;
  color: var(--primary);
}

.license-status[data-state="expired"],
.license-status[data-state="revoked"] {
  background: #fef3f2;
  color: #b42318;
}

.table-summary,
.pagination-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.table-summary {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 10px;
}

.pagination-bar {
  margin-top: 12px;
}

.page-number-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.page-number {
  min-width: 34px;
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}

.page-number:hover,
.page-number.is-active {
  border-color: var(--primary);
  background: #eef6ff;
  color: var(--primary);
}

.system-info-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.system-info-panel.is-hidden {
  display: none;
}

.system-info-body {
  display: grid;
  gap: 12px;
}

.system-info-summary,
.system-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.system-info-priority,
.sensor-groups {
  display: grid;
  gap: 10px;
}

.info-item {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.info-item span,
.temperature-list > span {
  color: var(--muted);
  font-size: .85rem;
}

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

.info-item[data-category="temperature"] strong {
  color: #b42318;
}

.info-item[data-category="load"] strong {
  color: var(--primary);
}

.info-item[data-category="level"] strong {
  color: #067647;
}

.meter {
  height: 6px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  margin-top: 5px;
}

.meter span {
  display: block;
  height: 100%;
  background: currentColor;
  border-radius: inherit;
}

.sensor-group {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.sensor-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: baseline;
  color: var(--muted);
}

.sensor-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sensor-row strong {
  color: var(--ink);
}

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

@media (max-width: 760px) {
  .app-shell {
    padding: 16px 12px;
  }

  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

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

  .license-create-form,
  .license-filter-panel {
    grid-template-columns: 1fr;
  }

  .log-filter-panel {
    grid-template-columns: 1fr;
  }

  .pagination-bar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .live-actions {
    justify-content: stretch;
  }

  .live-actions .btn {
    flex: 1 1 140px;
  }

  .live-source-bar {
    grid-template-columns: 1fr;
  }

  .viewer-stage {
    min-height: 210px;
  }
}

@media (max-width: 480px) {
  .live-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .live-actions label,
  .live-actions .btn {
    min-width: 0;
    width: 100%;
  }

  .live-actions .icon-button {
    width: 100%;
    border-radius: 8px;
  }

  .viewer-stage {
    min-height: 180px;
  }
}
