:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #1f2730;
  --muted: #687483;
  --line: #d7dee8;
  --nav: #202936;
  --teal: #0f8f7f;
  --blue: #2f6fbb;
  --amber: #bf7a22;
  --red: #ba3d3d;
  --green: #25845a;
  font-family: "Microsoft JhengHei", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(238, 242, 246, 0.88), rgba(238, 242, 246, 0.92)),
    url("/static/images/JV43W1m-bg.png") center / cover;
}

.login-panel {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 50px rgba(31, 39, 48, 0.16);
}

.login-brand,
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

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

.login-brand img,
.brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 0;
  font-size: 26px;
}

h3 {
  margin-bottom: 0;
  font-size: 18px;
}

h4 {
  margin-bottom: 8px;
  font-size: 14px;
}

.login-form {
  display: grid;
  gap: 16px;
}

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

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 11px;
  background: #fbfcfe;
  color: var(--ink);
}

input:focus {
  outline: 2px solid rgba(15, 143, 127, 0.22);
  border-color: var(--teal);
}

.message {
  min-height: 20px;
  margin-bottom: 0;
  color: var(--red);
  font-size: 13px;
}

.muted-text,
.meta,
.metric span,
.metric small,
.panel-head span {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 18px;
  background: var(--nav);
  color: #eef6f4;
}

.brand small {
  display: block;
  color: #aab7c4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-list {
  display: grid;
  align-content: start;
  gap: 6px;
  overflow: auto;
}

.site-button,
.ghost-button {
  width: 100%;
  min-height: 38px;
  text-align: left;
  background: transparent;
  color: inherit;
  border: 1px solid transparent;
}

.site-button {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
}

.site-button strong,
.site-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-button span {
  color: #aab7c4;
  font-size: 12px;
}

.site-button.active,
.site-button:hover,
.ghost-button:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.14);
}

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

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

.refresh-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
}

.dot.muted {
  background: var(--muted);
}

.dot.warn {
  background: var(--amber);
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  min-height: 38px;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: 0;
}

.tab-button.active {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}

.page {
  display: none;
}

.page.active {
  display: grid;
  gap: 12px;
}

.overview-band {
  min-height: 118px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.overview-band img {
  width: min(180px, 28vw);
  max-height: 84px;
  object-fit: contain;
}

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

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

.metric {
  min-height: 112px;
  padding: 16px;
  display: grid;
  align-content: space-between;
}

.metric strong {
  font-size: 28px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

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

.panel {
  min-width: 0;
  padding: 14px;
}

.span-2 {
  grid-column: 1 / -1;
}

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

canvas {
  width: 100%;
  min-height: 240px;
}

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

.data-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.data-row:first-child {
  border-top: 0;
}

.data-row strong,
.data-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  justify-content: center;
  min-width: 58px;
  border-radius: 6px;
  padding: 4px 7px;
  background: #edf7f3;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.status-badge.warn {
  background: #fff5e6;
  color: var(--amber);
}

.status-badge.danger {
  background: #fdeceb;
  color: var(--red);
}

.table-wrap {
  overflow: auto;
}

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

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

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
}

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

.channel-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(68px, 1fr));
  gap: 8px;
}

.channel,
.do-control,
.sensor-chip {
  min-height: 34px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 8px;
  font-size: 13px;
  white-space: nowrap;
}

.channel.on,
.do-control.on {
  background: rgba(37, 132, 90, 0.1);
  border-color: rgba(37, 132, 90, 0.34);
  color: var(--green);
}

.do-control {
  width: 100%;
  color: var(--ink);
  background: #f4f7fa;
}

.do-control.on {
  font-weight: 700;
}

.sensor-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
}

.confirm-dialog::backdrop {
  background: rgba(16, 24, 32, 0.42);
}

.confirm-dialog form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

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

.secondary-button {
  background: #e6ebf1;
  color: var(--ink);
}

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

  .sidebar {
    grid-template-rows: auto auto auto;
  }

  .site-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(180px, 1fr);
    overflow-x: auto;
  }

  .metrics-grid,
  .content-grid,
  .io-layout {
    grid-template-columns: 1fr;
  }
}

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

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

  .tabs {
    overflow-x: auto;
  }

  .tab-button {
    min-width: 104px;
  }

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

  .overview-band img {
    display: none;
  }

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