:root{
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.5);
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --muted: #94a3b8;
  --line: rgba(255,255,255,0.08);
  --bg: #0f172a;
  --card-bg: rgba(30, 41, 59, 0.5);
  --card-hover: rgba(30, 41, 59, 0.8);
  --text: #f8fafc;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
*{ box-sizing:border-box; outline: none; }
body{
  margin:0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color:var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
header{
  position: sticky;
  top:0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(15, 23, 42, 0.8);
  border-bottom: 1px solid var(--line);
  z-index: 100;
  height: 64px;
}
.wrap{ max-width: 1200px; margin: 0 auto; padding: 0 24px; width: 100%; height: 100%; }
.titlebar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.header-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.badge{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  transition: var(--transition);
}
.badge:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.1);
}
.dot{
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.dot.ok{ background: var(--good); box-shadow: 0 0 8px var(--good); }
.dot.bad{ background: var(--bad); }
.grid{
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  padding: 16px 0;
  align-items: stretch; /* 让同一行的卡片高度自动对齐 */
}
.card{
  grid-column: span 6;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}
.card.wide {
  grid-column: span 12;
}
.card:hover{
  border-color: rgba(255,255,255,0.15);
  background: var(--card-hover);
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}
.card .hd{
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card .hd .t{ font-size: 15px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 10px; }
.card .hd .t i { font-style: normal; font-size: 18px; }
.card .hd .s{ font-size: 12px; color: var(--muted); font-weight: 400; }
.card .bd{ 
  padding: 16px; 
  flex: 1; 
  display: flex;
  flex-direction: column;
}

/* Dashboard UI Components */
.stat-card-grid, .stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  flex: 1;
}
.stat-mini {
  background: rgba(255,255,255,0.02);
  padding: 16px 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  text-align: left;
  transition: var(--transition);
  height: 100px; /* 固定高度确保整齐 */
  position: relative;
  overflow: visible; /* 允许内容溢出显示或通过调整缩小 */
}
.stat-mini::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}
.stat-mini:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(59, 130, 246, 0.3);
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.1);
}
.stat-mini .label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; font-weight: 600; }
.stat-mini .value { 
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  line-height: 1.4;
  color: var(--muted);
  font-size: 16px;
  margin-top: 4px;
  width: 100%; /* 确保填满 */
}
.stat-mini .value span, 
.stat-mini .value div {
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
  color: var(--text);
  font-size: 18px; /* 降低默认数值大小 */
  font-weight: 800;
  text-shadow: 0 0 10px rgba(255,255,255,0.1);
}

/* 核心状态板块专用统一字体 */
.stat-card-grid.large-font .stat-mini {
  padding: 16px 15px;
}

.stat-card-grid.large-font .stat-mini .value span,
.stat-card-grid.large-font .stat-mini .value div {
  font-size: 21px; /* 统一核心状态字体大小，兼顾单值与多值显示 */
  font-weight: 800;
}

/* 统一管理员与用户模式下的多项数据显示 */
.stat-card-grid.large-font .stat-mini .value .adminOnly,
.stat-card-grid.large-font .stat-mini .value .userOnly {
  font-size: 16px; /* 分隔符 '/' 的大小 */
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 3px;
  color: rgba(255,255,255,0.2); /* 降低分隔符亮度 */
}

.stat-card-grid.large-font .stat-mini .value .adminOnly span,
.stat-card-grid.large-font .stat-mini .value .userOnly span {
  font-size: 21px; /* 强制多项数据数值与单项数据一致 */
  color: var(--text);
}

.stat-mini .unit { 
  font-size: 12px;
  color: var(--muted); 
  margin-left: 1px; 
  font-weight: 600; 
  opacity: 0.7;
}

/* SOC Progress */
.soc-widget {
  background: rgba(255,255,255,0.03);
  padding: 16px 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin-bottom: 24px;
}
.soc-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; }
.soc-label { font-size: 12px; font-weight: 500; color: var(--muted); }
.soc-val-big { font-size: 28px; font-weight: 800; line-height: 1; color: var(--text); }
.soc-track {
  height: 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.05);
}
.soc-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ef4444, #f59e0b, #10b981, #3b82f6);
  background-size: 100% 100%;
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}

/* Prediction Card */
.prediction-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  flex: 1; /* 撑满高度 */
}
.pred-item {
  padding: 16px 20px;
  background: rgba(59, 130, 246, 0.03);
  border-radius: 12px;
  border: 1px solid var(--line); /* 统一边框 */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  text-align: left;
  height: 100px;
  position: relative;
  transition: var(--transition);
}
.pred-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(59, 130, 246, 0.3);
  transform: translateY(-2px);
}
.mini-hd {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 4px;
  gap: 8px;
}
.mini-title{
  display: flex;
  flex-direction: row;
  gap: 0;
  align-items: baseline;
}
.mini-hd .label{
  margin-bottom: 0;
}
.pred-item.highlight {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.05));
  border-color: rgba(59, 130, 246, 0.3);
  grid-column: span 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  text-align: left;
  min-height: 120px;
  padding: 20px;
}

.data-date{
  font-size: 9px;
  color: var(--muted);
  opacity: 0.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* Controls */
#picoControlGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.control-item-pico {
  background: rgba(255,255,255,0.02);
  border-radius: 12px;
  border: 1px solid var(--line);
  margin-bottom: 16px;
  overflow: hidden;
  transition: var(--transition);
}
.control-item-pico:hover {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.12);
}
.pico-header {
  padding: 12px 16px;
  background: rgba(255,255,255,0.03);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.pico-title { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.pico-actions { display: flex; gap: 6px; }

.pico-body { padding: 16px; }
.pico-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.pico-stat-row:last-child { border-bottom: none; }
.pico-stat { display: flex; flex-direction: column; gap: 2px; }
.pico-stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.pico-stat .value { font-size: 14px; font-weight: 600; }

.pico-footer {
  padding: 8px 16px;
  background: rgba(0,0,0,0.1);
  border-top: 1px solid var(--line);
}
.pico-info-mini {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.online { background: var(--good); box-shadow: 0 0 8px var(--good); }
.status-dot.offline { background: var(--muted); }

.text-good { color: var(--good); }
.text-bad { color: var(--bad); }
.text-muted { color: var(--muted); }

.btn-sm { padding: 4px 8px; font-size: 11px; }
.btn-xs { padding: 2px 6px; font-size: 10px; }

.btn-group { display: flex; gap: 8px; }

.btn{
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:hover:not(:disabled){ background: rgba(255,255,255,0.1); border-color: var(--muted); }
.btn:active:not(:disabled){ transform: scale(0.96); }
.btn.active { background: var(--accent); border-color: var(--accent); color: white; box-shadow: 0 0 10px var(--accent-glow); }
.btn:disabled{ opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border: none; color: white; }
.btn.primary:hover:not(:disabled) { background: #2563eb; }
.btn.danger { color: var(--bad); border-color: rgba(239, 68, 68, 0.2); background: rgba(239, 68, 68, 0.05); }
.btn.danger:hover:not(:disabled) { background: var(--bad); color: white; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }

/* Utilities */
.hidden { display: none !important; }
.adminOnly, .userOnly { 
  position: relative;
}

#p12Status {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  width: 100%;
}

@media (max-width: 1024px) {
  .card { grid-column: span 12; }
}
@media (max-width: 900px){
  .cells{ grid-template-columns: repeat(4, 1fr); }
  .kv{ grid-template-columns: 1fr; }
  /* 让管理员调试工具在移动端也垂直排列 */
  .card.wide .bd { flex-direction: column !important; }
}
@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .grid { gap: 16px; }
  .stat-card-grid { grid-template-columns: 1fr 1fr; }
}

/* Forms & UI */
.input{
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(11,18,32,.22);
  color: var(--text);
  outline: none;
  font-size: 14px;
}
.input:focus{ border-color: rgba(96,165,250,.45); box-shadow: 0 0 0 6px rgba(96,165,250,.10); }
.err{ color: rgba(239,68,68,.95); font-size: 12px; }
.jsonBox{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(11,18,32,.22);
  padding: 10px 12px;
  max-height: 360px;
  overflow: auto;
}

/* Modal System */
.modal{
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
  z-index: 500;
  padding: 18px;
  backdrop-filter: blur(4px);
}
.modal.open{ display:flex; }
.modal .panel{
  width: min(980px, 100%);
  max-height: min(720px, 100%);
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--bg);
  box-shadow: var(--shadow);
}
.modal .panel .hd{
  position: sticky;
  top: 0;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  z-index: 10;
}
.modal .panel .bd{ padding: 20px; }

/* Cell Details */
.cells{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 12px;
}
.cell{
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  padding: 12px;
  text-align: center;
}
.cell .n{ font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.cell .vv{ font-size: 15px; font-weight: 700; }
.cell .vv.max-v{ color: var(--bad); }
.cell .vv.min-v{ color: var(--good); }

/* 单体电压网格 */
.cell-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  padding: 16px;
  background: rgba(0,0,0,0.1);
  border-radius: 12px;
  border: 1px solid var(--line);
}
.cell-item {
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid rgba(255,255,255,0.03);
  border-radius: 12px;
  padding: 12px;
  text-align: left;
  transition: all 0.2s ease;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 64px;
}
.cell-item:hover {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
}
.cell-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.cell-value {
  font-size: 16px;
  font-weight: 800;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--text);
  margin-top: 4px;
}
.cell-progress-bg {
  height: 3px;
  background: rgba(255,255,255,0.05);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.cell-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}
.cell-value.high { color: #f87171; }
.cell-value.low { color: #34d399; }
.cell-progress-bar.high { background: #f87171; box-shadow: 0 0 8px rgba(248, 113, 113, 0.4); }
.cell-progress-bar.low { background: #34d399; box-shadow: 0 0 8px rgba(52, 211, 153, 0.4); }

.foot{
  max-width: 1200px;
  margin: 40px auto;
  padding: 0 24px;
  color: var(--muted);
  font-size: 12px;
  display:flex;
  justify-content:space-between;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}

/* MQTT Debug Panel */
.mqtt-debug-panel {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.panel-icon { font-size: 18px; }
.panel-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.panel-actions { margin-left: auto; }

.command-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.cmd-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text);
}
.cmd-btn:hover {
  background: rgba(59, 130, 246, 0.1);
  border-color: var(--accent);
  transform: translateY(-2px);
}
.cmd-btn:active { transform: translateY(0); }
.cmd-btn .cmd-icon { font-size: 20px; }
.cmd-btn .cmd-label { font-size: 11px; font-weight: 600; }

.terminal-container {
  background: #000;
  border-radius: 8px;
  border: 1px solid var(--line);
  overflow: hidden;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}
.terminal-header {
  background: #1e293b;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--line);
}
.terminal-dot { width: 8px; height: 8px; border-radius: 50%; }
.terminal-dot.red { background: #ff5f56; }
.terminal-dot.yellow { background: #ffbd2e; }
.terminal-dot.green { background: #27c93f; }
.terminal-title {
  margin-left: 10px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 1px;
}
.terminal-body {
  height: 150px;
  padding: 12px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #34d399; /* Green terminal text */
}
.terminal-placeholder {
  color: var(--muted);
  font-style: italic;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  opacity: 0.5;
}
.terminal-log-item {
  margin-bottom: 4px;
  border-left: 2px solid transparent;
  padding-left: 8px;
  animation: fadeIn 0.3s ease;
}
.terminal-log-item.sent { border-left-color: var(--accent); color: var(--text); }
.terminal-log-item.received { border-left-color: var(--good); color: #34d399; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-5px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255,255,255,0.1);
  transition: .4s;
  border: 1px solid var(--line);
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .4s;
}
input:checked + .slider {
  background-color: var(--accent);
}
input:focus + .slider {
  box-shadow: 0 0 1px var(--accent);
}
input:checked + .slider:before {
  transform: translateX(20px);
}
.slider.round {
  border-radius: 24px;
}
.slider.round:before {
  border-radius: 50%;
}

.hidden { display: none !important; }
