/* ==================== Reset & Base ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --bg-hover: #22272e;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #7d8590;
  --text-muted: #484f58;
  --accent: #2f81f7;
  --accent-hover: #388bfd;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --orange: #db6d28;
  --cyan: #39c5cf;
  --purple: #a371f7;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* ==================== Login Page ==================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #0d1117 0%, #161b22 100%);
  position: relative;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 400px;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 30px;
}

.logo-icon { font-size: 36px; width: 48px; height: 48px; vertical-align: middle; }
.logo-icon-sm { width: 28px; height: 28px; }

.login-logo h1 {
  font-size: 22px;
  font-weight: 600;
  margin-top: 8px;
}

.login-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 24px;
}

.login-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.login-tab.active {
  background: var(--accent);
  color: #fff;
}

/* QR Code Login */
.qr-login-area {
  text-align: center;
  padding: 10px 0;
}
.qr-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.qr-code-box {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 16px;
}
.qr-code-box canvas,
.qr-code-box img {
  border-radius: 8px;
  border: 1px solid var(--border);
}
.qr-status {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.qr-status.qr-success {
  color: #2ea043;
  font-weight: 600;
}
.qr-status.qr-error {
  color: #f85149;
}

/* ==================== Forms ==================== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group { flex: 1; }

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.required { color: var(--red); }

/* ==================== Buttons ==================== */
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover { background: var(--border); }

.btn-danger {
  padding: 10px 20px;
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-text {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
}

.btn-text:hover { color: var(--red); }

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.form-actions .btn-primary { flex: 1; }

.error-msg {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* ==================== Main App Layout ==================== */
.main-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.main-app-row {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ==================== Sidebar ==================== */
.sidebar {
  width: 320px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 16px;
  font-weight: 600;
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

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

#changePwdBtn {
  font-size: 15px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

#changePwdBtn:hover {
  color: var(--accent);
  background: rgba(47, 129, 247, 0.1);
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 12px 16px;
}

.sidebar-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.btn-network-config {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
  text-align: center;
}

.btn-network-config:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-admin-link {
  display: block;
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid rgba(210, 153, 34, 0.3);
  border-radius: 8px;
  color: var(--yellow);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
  text-align: center;
  text-decoration: none;
  margin-top: 8px;
}

.btn-admin-link:hover {
  border-color: var(--yellow);
  background: rgba(210, 153, 34, 0.1);
}

.btn-add-device {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 12px;
  transition: all 0.2s;
}

.btn-add-device:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.device-list { display: flex; flex-direction: column; gap: 4px; }

.device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.device-item:hover { background: var(--bg-hover); }

.device-item.active { background: var(--bg-hover); }

.device-item.active .device-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.device-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}

.device-item.online .device-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.device-item.offline .device-dot {
  background: var(--text-muted);
}

.device-item-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-item-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.device-item-id {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 报警设备列表项样式 */
.device-item.alarm {
  border-left: 3px solid var(--red);
  background: rgba(239, 68, 68, 0.08);
  padding-left: 9px; /* 补偿 border-left 宽度 */
}

.device-item.alarm:hover {
  background: rgba(239, 68, 68, 0.14);
}

/* 报警标签 */
.device-item-alarm-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  border-radius: 3px;
  line-height: 1.6;
  vertical-align: middle;
  animation: alarmPulse 1.2s ease-in-out infinite;
}

@keyframes alarmPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.settings-hint code {
  background: rgba(63, 133, 244, 0.15);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  font-family: monospace;
}

/* ==================== Main Content ==================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

/* ==================== No Device View ==================== */
.no-device-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  text-align: center;
}

.no-device-view .empty-icon { font-size: 64px; margin-bottom: 20px; }

.no-device-view h2 { font-size: 20px; margin-bottom: 8px; }

.no-device-view p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.no-device-view .btn-primary { width: auto; padding: 12px 24px; }

/* ==================== Dashboard ==================== */
.dashboard-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 20px 10px 20px;
  overflow: hidden;
  min-height: 0;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.dashboard-header h2 { font-size: 18px; }

.device-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  display: block;
}

.dash-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 4px;
}

.dash-tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.dash-tab.active {
  background: var(--accent);
  color: #fff;
}

/* ==================== Connection Status ==================== */
.conn-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.conn-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.conn-status.connected .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.conn-status.connected { color: var(--green); }
.conn-status.disconnected .status-dot { background: var(--text-muted); }
.conn-status.disconnected { color: var(--text-secondary); }
.conn-status.waiting .status-dot { background: var(--yellow); animation: pulse 1.5s infinite; }
.conn-status.waiting { color: var(--yellow); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ==================== MQTT Status Badge ==================== */
.conn-status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.conn-status-bar .conn-status {
  margin-bottom: 0;
}

.mqtt-status-badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
  border: 1px solid var(--border);
}

.mqtt-online {
  color: var(--green);
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.3);
}

.mqtt-reconnecting {
  color: var(--yellow);
  background: rgba(250, 204, 21, 0.1);
  border-color: rgba(250, 204, 21, 0.3);
  animation: pulse 1.5s ease-in-out infinite;
}

.mqtt-offline {
  color: var(--text-muted);
  background: rgba(130, 140, 160, 0.1);
}

.mqtt-error {
  color: var(--red);
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.3);
}

.mqtt-unknown {
  color: var(--text-muted);
}

.btn-reconnect {
  padding: 4px 12px;
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-reconnect:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ==================== Stats Overview (sidebar) ==================== */
.stats-overview {
  display: flex;
  flex-direction: row;
  gap: 10px;
  margin: 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 14px 16px;
  align-items: center;
}

.stats-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.stats-number-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stats-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 32px;
  text-align: right;
  line-height: 1;
}

.stats-num.online {
  color: var(--green);
}

.stats-num.offline {
  color: var(--text-muted);
}

.stats-number-card .stats-label {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.stats-pie {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.pie-chart {
  width: 96px;
  height: 96px;
}

@media (max-width: 768px) {
  .stats-overview {
    flex-wrap: wrap;
    justify-content: center;
  }
  .stats-summary {
    flex-direction: row;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* ==================== Gas Cards ==================== */
.gas-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  flex-shrink: 0;
  margin-bottom: 0;
}

.gas-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s;
}

.gas-card.alarm {
  border-color: var(--red);
  box-shadow: 0 0 12px rgba(248,81,73,0.2);
}

.gas-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.gas-card-name {
  font-size: 13px;
  color: var(--text-secondary);
}

.gas-card-unit {
  font-size: 10px;
  color: var(--text-muted);
  padding: 2px 6px;
  background: var(--bg-hover);
  border-radius: 4px;
}

.gas-card-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

.gas-card.alarm .gas-card-value { color: var(--red); }

.gas-card-footer {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.gas-card .alarm-badge {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

.gas-card.alarm .alarm-badge { display: block; }

/* ==================== Charts ==================== */
.realtime-charts {
  flex: 1;
  margin-bottom: 0;
  min-height: 0;
}

.chart-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  height: 100%;
  min-height: 100px;
}

.chart-large { height: 100%; min-height: 200px; }

/* ==================== View Sections (flex fill) ==================== */
.view-section {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ==================== Realtime View ==================== */
#realtimeView {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

#historyView {
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#settingsView {
  overflow-y: auto;
  min-height: 0;
}

/* ==================== Realtime Two-Column Layout ==================== */
.realtime-layout {
  flex: 1;
  display: flex;
  gap: 16px;
  overflow: hidden;
  min-height: 0;
}

.realtime-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.realtime-right {
  flex-shrink: 0;
  width: 340px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ==================== Alarm Statistics Panel ==================== */
.alarm-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.alarm-panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.alarm-panel-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.alarm-panel-summary {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.alarm-summary-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.alarm-summary-num {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.alarm-summary-card:first-child .alarm-summary-num {
  color: var(--red);
}

.alarm-summary-card:last-child .alarm-summary-num {
  color: var(--accent);
}

.alarm-summary-label {
  font-size: 10px;
  color: var(--text-secondary);
}

.alarm-panel-chart {
  flex-shrink: 0;
  height: 200px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.alarm-dist-chart {
  flex: 1;
  width: 100%;
  min-height: 40px;
}

.alarm-panel-table {
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 42%;
}

.alarm-table-row {
  display: flex;
  align-items: center;
  padding: 7px 14px;
  border-bottom: 1px solid var(--border);
  gap: 6px;
  font-size: 12px;
  transition: background 0.2s;
}

.alarm-table-row:last-child {
  border-bottom: none;
}

.alarm-table-row:hover {
  background: var(--bg-hover);
}

.alarm-table-row .gas-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.alarm-table-row .gas-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
  font-size: 12px;
}

.alarm-table-row .gas-value {
  font-weight: 600;
  min-width: 50px;
  text-align: right;
  font-size: 13px;
}

.alarm-table-row .gas-alarm-count {
  min-width: 36px;
  text-align: center;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.alarm-table-row .gas-alarm-count.has-alarm {
  background: rgba(248, 81, 73, 0.15);
  color: var(--red);
  font-weight: 600;
}

.alarm-table-row .gas-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.alarm-table-row .gas-status-dot.normal {
  background: var(--green);
}

.alarm-table-row .gas-status-dot.alarm {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}

.alarm-table-header {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  gap: 6px;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.alarm-table-header .gas-icon { width: 20px; text-align: center; }
.alarm-table-header .gas-name { flex: 1; }
.alarm-table-header .gas-value { min-width: 50px; text-align: right; }
.alarm-table-header .gas-alarm-count { min-width: 36px; text-align: center; }
.alarm-table-header .gas-status-dot { width: 8px; }

.alarm-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 1100px) {
  .realtime-layout {
    flex-direction: column;
    overflow-y: auto;
  }
  .realtime-right {
    width: 100%;
    flex-shrink: 0;
  }
  .gas-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==================== Device Info Bar ==================== */
.device-info-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
  padding-top: 10px;
}

.info-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}

.info-pill .pill-label { color: var(--text-secondary); }
.info-pill .pill-value { color: var(--text-primary); font-weight: 500; }

.info-pill.clickable {
  cursor: pointer;
  transition: all 0.2s;
}

.info-pill.clickable:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  box-shadow: 0 0 8px rgba(47, 129, 247, 0.2);
}

.info-pill.clickable .pill-value {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ==================== History View ==================== */
#historyView {
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.history-layout {
  flex: 1;
  display: flex;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.history-left {
  flex: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

#historyChart {
  flex: 1;
  min-height: 200px;
  margin-bottom: 8px;
}

.history-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.history-alarm-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-alarm-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.history-alarm-chart {
  flex-shrink: 0;
  height: 180px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.history-alarm-list-header {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  gap: 6px;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.history-alarm-list-header .ha-time { flex: 1; }
.history-alarm-list-header .ha-type { min-width: 60px; text-align: center; }
.history-alarm-list-header .ha-value { min-width: 60px; text-align: right; }

.history-alarm-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.history-alarm-row {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  gap: 6px;
  font-size: 12px;
  transition: background 0.2s;
}

.history-alarm-row:last-child {
  border-bottom: none;
}

.history-alarm-row:hover {
  background: var(--bg-hover);
}

.history-alarm-row .ha-time {
  flex: 1;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-alarm-row .ha-type {
  min-width: 60px;
  text-align: center;
  font-weight: 600;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
}

.history-alarm-row .ha-value {
  min-width: 60px;
  text-align: right;
  font-weight: 600;
  font-size: 13px;
}

.history-alarm-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .history-layout {
    flex-direction: column;
    overflow-y: auto;
  }
  .history-left {
    flex-shrink: 0;
    min-height: 300px;
  }
  .history-right {
    flex-shrink: 0;
  }
  .history-alarm-list {
    max-height: 250px;
  }
}

@media (max-width: 700px) {
  .history-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==================== App Footer (备案号) ==================== */
.app-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  letter-spacing: 0.3px;
}

.app-footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.app-footer a:hover { color: var(--accent); }

.login-page .app-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  border-top: 1px solid var(--border);
  background: transparent;
}

.history-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.history-controls label { font-size: 14px; color: var(--text-secondary); }

.history-controls select {
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
  flex-shrink: 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.stat-card .stat-label { font-size: 11px; color: var(--text-secondary); }
.stat-card .stat-value { font-size: 16px; font-weight: 600; margin-top: 3px; }

/* ==================== Settings View ==================== */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 700px;
  flex-shrink: 0;
}

.settings-card h3 { font-size: 16px; margin-bottom: 20px; }

/* ==================== Modal ==================== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 560px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 { font-size: 18px; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--text-primary); }

/* ==================== Map Modal ==================== */
.map-modal-card {
  width: 820px;
  max-width: 95vw;
  padding: 20px 24px 24px 24px;
}

.map-modal-card .modal-header {
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.map-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  margin-left: 12px;
}

.map-coords-text {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.map-external-link {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.map-external-link:hover {
  color: var(--accent);
  background: rgba(47, 129, 247, 0.1);
}

.map-container {
  width: 100%;
  height: 480px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
}

/* Baidu Map info window style override */
.BMap_bubble_title {
  font-weight: 600;
  font-size: 14px;
}

.BMap_bubble_content {
  font-size: 12px;
  color: #666;
}

/* ==================== Config Password Modal ==================== */
.config-pwd-card {
  width: 420px;
}

.config-pwd-body {
  margin-bottom: 20px;
}

.config-pwd-hint {
  color: var(--text-primary);
  font-size: 15px;
  margin-bottom: 8px;
}

.config-pwd-format {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.6;
}

.config-pwd-format strong {
  color: var(--accent);
}

#configPwdInput {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  letter-spacing: 1px;
}

#configPwdInput:focus {
  border-color: var(--accent);
}

#configPwdInput::placeholder {
  color: var(--text-muted);
  letter-spacing: normal;
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  z-index: 2000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transition: opacity 0.3s;
}

.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ==================== Scrollbar ==================== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .dashboard-view { padding: 12px; }
  .dashboard-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .form-row { flex-direction: column; }
  .gas-cards { grid-template-columns: 1fr 1fr; }
}

/* ==================== Settings Hint ==================== */
.settings-hint {
  padding: 10px 14px;
  background: rgba(63, 133, 244, 0.08);
  border: 1px solid rgba(63, 133, 244, 0.2);
  border-radius: 8px;
  font-size: 13px;
  color: var(--accent);
  margin: 12px 0;
}

.form-section-divider {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  padding: 14px 0 8px 0;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.topic-preview {
  display: block;
  font-size: 11px;
  color: var(--green);
  font-family: monospace;
  margin-top: 4px;
  word-break: break-all;
  min-height: 16px;
}
