:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f4;
  --text: #162023;
  --muted: #627174;
  --line: #d8e1e3;
  --primary: #0f7b78;
  --primary-2: #0b5d5b;
  --good: #1e9a62;
  --bad: #d44242;
  --warn: #d89422;
  --idle: #7b8790;
  --purple: #6e56cf;
  --shadow: 0 10px 28px rgba(22, 32, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 15px;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--primary);
}

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

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

button.danger {
  border-color: #efb7b7;
  background: #fff4f4;
  color: #a52c2c;
}

button.danger:hover {
  border-color: var(--bad);
  background: #ffe7e7;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

textarea {
  resize: vertical;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 16px;
  margin-bottom: 14px;
}

main {
  padding: 18px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.package-info {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

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

.user-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.role-hidden {
  display: none !important;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #edf2f3;
}

.auth-overlay.hidden {
  display: none;
}

.auth-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel h2 {
  font-size: 20px;
}

.form-error {
  color: #a52c2c;
  font-size: 13px;
}

.password-dialog {
  width: min(420px, calc(100% - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.password-dialog::backdrop {
  background: rgba(22, 32, 35, 0.45);
}

.password-dialog form {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.setup-import {
  margin-bottom: 16px;
}

.gateway-admin {
  margin-bottom: 16px;
}

.agent-token-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.agent-token-result input {
  min-width: 0;
  font-family: Consolas, "Courier New", monospace;
}

.compact-toolbar {
  padding: 0;
  margin-bottom: 12px;
}

#setupCsvFile {
  max-width: 340px;
}

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

.tab {
  min-width: 92px;
  background: var(--surface-2);
}

.tab.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.toolbar p {
  color: var(--muted);
  margin-top: 4px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.actions input {
  width: 160px;
}

.actions select {
  width: auto;
}

.inline-field {
  display: grid;
  gap: 4px;
  min-width: 220px;
  color: var(--muted);
  font-size: 13px;
}

.inline-field select {
  width: 100%;
}

.debug-camera-info {
  margin: -6px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.flow-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.flow-steps div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.flow-steps b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
}

.summary-card,
.panel,
.pot-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-card {
  padding: 14px;
}

.summary-card strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
}

.summary-card span {
  color: var(--muted);
}

.alert {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #efb7b7;
  background: #fff1f1;
  color: #9b2525;
  border-radius: 8px;
  font-weight: 700;
}

.alert.good-alert {
  border-color: #9bd7ba;
  background: #effaf4;
  color: #11663e;
}

.hidden {
  display: none !important;
}

.pot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(188px, 1fr));
  gap: 12px;
}

.pot-card {
  position: relative;
  min-height: 150px;
  padding: 14px;
  overflow: hidden;
}

.pot-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 7px;
  background: var(--idle);
}

.pot-card.released::before {
  background: var(--good);
}

.pot-card.not-released::before {
  background: var(--bad);
}

.pot-card.waiting::before {
  background: var(--warn);
}

.pot-card.no-plan::before {
  background: var(--idle);
}

.pot-card.exception {
  border-color: #ef9f9f;
  background: #fffafa;
}

.pot-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-left: 4px;
}

.pot-code {
  font-size: 21px;
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 25px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
}

.badge.good { background: var(--good); }
.badge.bad { background: var(--bad); }
.badge.warn { background: var(--warn); }
.badge.idle { background: var(--idle); }
.badge.purple { background: var(--purple); }

.pot-detail {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.pot-detail b {
  color: var(--text);
}

.config-grid,
.lamp-grid,
.plan-layout,
.history-grid,
.tables {
  display: grid;
  gap: 14px;
}

.config-grid {
  grid-template-columns: repeat(4, minmax(190px, 1fr));
  margin-bottom: 14px;
}

.plan-layout {
  grid-template-columns: 1fr 1fr 2fr;
  margin-bottom: 14px;
}

.lamp-grid {
  grid-template-columns: 1fr 1fr 1.2fr;
  margin-bottom: 14px;
}

.panel.wide {
  grid-column: 1 / -1;
}

.service-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.service-status {
  margin: -4px 0 12px;
  color: var(--muted);
  font-weight: 700;
}

.service-hint {
  margin: -6px 0 12px;
  padding: 10px 12px;
  border-left: 4px solid var(--primary);
  background: rgba(20, 128, 120, 0.08);
  color: var(--text);
  font-weight: 700;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.tables {
  grid-template-columns: repeat(4, minmax(220px, 1fr));
}

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

.debug-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.7fr);
  gap: 14px;
  margin-bottom: 14px;
}

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

.debug-stage {
  position: relative;
  min-height: 420px;
  background: #101820;
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.debug-stage img {
  display: none;
  max-width: 100%;
  max-height: 70vh;
  width: auto;
  height: auto;
}

.debug-stage img.has-frame {
  display: block;
}

.debug-stage canvas {
  position: absolute;
  inset: 0;
  margin: auto;
  cursor: crosshair;
}

#debugPlaceholder {
  color: #d6e2e5;
  font-weight: 700;
}

.region-test {
  display: grid;
  gap: 14px;
}

.region-test.empty {
  color: var(--muted);
}

.region-test.good {
  border-left: 4px solid var(--green);
}

.region-test.warn {
  border-left: 4px solid #d89422;
}

.region-test.bad {
  border-left: 4px solid var(--red);
}

.region-test-media {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.region-test-media img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: #101820;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.mini-title {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.region-test-result {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 8px 10px;
  align-items: start;
}

.region-test-result span {
  color: var(--muted);
}

.region-test-result b {
  overflow-wrap: anywhere;
}

.qw-box,
.qw-audit-result {
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid #9ab3ef;
  border-left: 4px solid #2d62d6;
  background: #f3f7ff;
  color: var(--text);
  border-radius: 6px;
  font-size: 13px;
}

.qw-audit {
  display: grid;
  gap: 10px;
}

.panel {
  padding: 16px;
  overflow: hidden;
}

.tables .panel {
  overflow-x: auto;
  overflow-y: hidden;
}

.panel.compact {
  margin-bottom: 14px;
}

form.panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.quad,
.dual,
.form-row {
  display: grid;
  gap: 10px;
}

.quad {
  grid-template-columns: repeat(4, 1fr);
}

.dual {
  grid-template-columns: repeat(2, 1fr);
}

.form-row {
  grid-template-columns: repeat(4, minmax(140px, 1fr));
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 13px;
}

#camerasTable table {
  min-width: 720px;
}

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

.table-actions button {
  min-height: 30px;
  padding: 0 10px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: var(--surface-2);
}

.cell-clip {
  display: inline-block;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

.empty {
  color: var(--muted);
  padding: 12px 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (max-width: 1080px) {
  .topbar,
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .user-actions {
    width: 100%;
  }

  .summary-grid,
  .flow-steps,
    .config-grid,
    .lamp-grid,
    .debug-layout,
    .plan-layout,
    .service-grid,
    .tables,
    .history-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  main,
  .topbar {
    padding: 12px;
  }

  .tabs,
  .actions,
  .form-row,
  .quad,
  .dual {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .tab,
  .actions input {
    width: 100%;
  }

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