﻿:root {
  --bg-0: #f3f6fb;
  --bg-1: #e9f0ff;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --subtle: #94a3b8;
  --line: #dbe4f1;
  --primary: #1d4ed8;
  --primary-soft: #e0eaff;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --radius-lg: 16px;
  --radius-md: 12px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 30%, #f7f9fd 100%);
  color: var(--text);
  line-height: 1.5;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--space-3) + env(safe-area-inset-top)) var(--space-4) var(--space-3);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.top-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.top-bar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.top-logo {
  user-select: none;
}

.top-device {
  font-size: 12px;
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  background: #eef2ff;
  border: 1px solid #dbe4ff;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 1.5s infinite ease-in-out;
}

.pulse-dot.ok {
  background: #16c784;
}

.pulse-dot.warn {
  background: #f79009;
}

.pulse-dot.err {
  background: #f04438;
}

@keyframes pulse {
  0% {
    transform: scale(0.9);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(0.9);
    opacity: 0.8;
  }
}

.offline-banner {
  margin: var(--space-3) var(--space-4) 0;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid #fecaca;
  background: #fff1f2;
  color: #9f1239;
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 99;
  max-width: calc(100vw - 24px);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: #fff;
  background: rgba(15, 23, 42, 0.9);
  font-size: 13px;
}

.hidden {
  display: none;
}

main {
  padding: var(--space-4) var(--space-4) calc(90px + env(safe-area-inset-bottom));
}

h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

p {
  margin: 6px 0;
}

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.06);
}

.hero-card {
  background: linear-gradient(145deg, #e6efff 0%, #ffffff 68%);
}

.hero-title {
  font-size: 14px;
  color: #475569;
  font-weight: 600;
}

.hero-value {
  font-size: 34px;
  font-weight: 800;
  line-height: 1.1;
  margin: 8px 0;
}

.hero-value span {
  font-size: 14px;
  font-weight: 500;
  margin-left: 4px;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.row-center {
  align-items: center;
}

.kpi {
  flex: 1 1 46%;
  min-width: 140px;
  background: #f8fbff;
  border: 1px solid #e0e8f5;
  border-radius: var(--radius-md);
  padding: 11px;
}

.kpi .label {
  color: var(--muted);
  font-size: 12px;
}

.kpi .value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
}

.kpi .value .unit {
  font-size: 12px;
  font-weight: 500;
  margin-left: 4px;
  color: var(--muted);
}

.input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d7deea;
  border-radius: 12px;
  padding: 10px 12px;
  background: #f2f4f7;
  margin: 6px 0;
  color: var(--text);
  appearance: none;
}

.btn {
  border: 1px solid #d2dae8;
  border-radius: 12px;
  min-height: 44px;
  padding: 10px 14px;
  background: #fff;
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
}

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

.btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.small {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.muted {
  color: var(--muted);
}

.chart-wrap {
  border: 1px solid #e0e8f5;
  border-radius: var(--radius-md);
  padding: 10px;
  background: #fbfdff;
}

.chart-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 4px;
}

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

.socket-card {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  min-height: 140px;
  border-left-width: 5px;
  border-left-color: #cbd5e1;
  background: #fff;
}

.socket-card.on {
  border-left-color: #16c784;
}

.socket-card.off {
  border-left-color: #94a3b8;
}

.socket-card.high {
  border-color: #f04438;
  background: #fff5f5;
}

.socket-card.pending {
  border-color: #f59e0b;
  background: #fffbeb;
}

.socket-title {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.socket-state {
  font-size: 12px;
  color: #475569;
}

.socket-ops {
  margin: 6px 0 8px;
}

.socket-correct {
  min-height: 38px;
  padding: 8px 10px;
}

.learn-panel {
  margin: 8px 0 10px;
  padding: 8px;
  border: 1px dashed #c8d7ef;
  border-radius: 10px;
  background: #f8fbff;
}

.learn-panel .input {
  margin: 6px 0;
}

.socket-learn-submit {
  width: 100%;
}

.socket-power {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 4px;
}

.socket-power span {
  font-size: 12px;
  color: #64748b;
  margin-left: 3px;
}

.event-list,
.alert-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-item,
.alert-item {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px;
  min-height: 56px;
  background: #f8fafc;
}

.alert-item.warn {
  border-color: #f79009;
  background: #fff4e5;
}

.alert-item.err {
  border-color: #fca5a5;
  background: #fff1f2;
}

.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(8px);
  padding: 6px var(--space-2) calc(6px + env(safe-area-inset-bottom));
}

.tab {
  border: 0;
  background: transparent;
  min-height: 56px;
  padding: 4px 6px;
  border-radius: 12px;
  color: #64748b;
}

.tab-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1;
}

.tab-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
}

.tab-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.tab-label {
  font-size: 11px;
  font-weight: 600;
}

.tab-badge {
  position: absolute;
  top: -4px;
  right: -14px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

.tab.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.btn:focus-visible,
.tab:focus-visible,
.input:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

@media (max-width: 380px) {
  main {
    padding-left: 12px;
    padding-right: 12px;
  }

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