/* ===== CSS Variables ===== */
:root {
  --bg: #fafafa;
  --card-bg: #ffffff;
  --primary: #ef4444;
  --primary-light: rgba(239,68,68,0.08);
  --secondary: #3b82f6;
  --success: #22c55e;
  --success-light: rgba(34,197,94,0.08);
  --warning: #f59e0b;
  --warning-light: rgba(245,158,11,0.08);
  --danger: #ef4444;
  --danger-light: rgba(239,68,68,0.08);
  --info: #3b82f6;
  --info-light: rgba(59,130,246,0.08);

  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e5e7eb;
  --border-light: #f3f4f6;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --transition: all 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

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

.logo-img {
  height: 36px;
  width: auto;
  border-radius: 8px;
  display: block;
}

.header-title h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.header-stats {
  display: flex;
  gap: 28px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-value.stat-alert {
  color: var(--danger);
}

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

.update-time {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.btn-icon {
  background: var(--border-light);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

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

.btn-icon.active {
  background: var(--primary-light);
}

/* ===== Alert Banner ===== */
.alert-banner-container {
  position: sticky;
  top: 69px;
  z-index: 99;
}

.alert-banner {
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  animation: slideDown 0.3s ease;
  border-bottom: 1px solid var(--border);
}

.alert-banner.critical {
  background: var(--danger-light);
  color: var(--danger);
  border-left: 4px solid var(--danger);
}

.alert-banner.warning {
  background: var(--warning-light);
  color: var(--warning);
  border-left: 4px solid var(--warning);
}

.alert-banner .alert-icon {
  font-size: 18px;
  animation: pulse 1.5s ease infinite;
}

.alert-banner .alert-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: inherit;
  opacity: 0.6;
}

.alert-banner .alert-close:hover {
  opacity: 1;
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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

/* ===== Main ===== */
.main {
  padding: 20px 24px;
  max-width: 1600px;
  margin: 0 auto;
}

.section {
  margin-bottom: 28px;
}

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

.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.section-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Account Grid ===== */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

/* ===== Account Card ===== */
.account-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px;
  transition: var(--transition);
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}

.account-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.account-card.status-live {
  border-color: var(--success);
}

.account-card.status-banned {
  border-color: var(--danger);
  background: var(--danger-light);
}

.account-card.status-offline {
  opacity: 0.65;
}

.account-card.alert-active {
  animation: alertPulse 2s ease infinite;
}

@keyframes alertPulse {
  0%, 100% { box-shadow: var(--shadow-sm), 0 0 0 0 rgba(244,67,54,0.3); }
  50% { box-shadow: var(--shadow-sm), 0 0 0 6px rgba(244,67,54,0); }
}

.card-header-link {
  display: block;
  text-decoration: none;
  position: relative;
  cursor: pointer;
}

.card-header-link:hover .enter-hint {
  opacity: 1;
}

.enter-hint {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 10px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 10;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.card-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  overflow: hidden;
}

.card-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-info {
  flex: 1;
  min-width: 0;
}

.card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-id {
  font-size: 11px;
  color: var(--text-muted);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.status-badge.live {
  background: var(--success-light);
  color: var(--success);
}

.status-badge.offline {
  background: var(--border-light);
  color: var(--text-muted);
}

.status-badge.banned {
  background: var(--danger-light);
  color: var(--danger);
}

.status-badge.connecting {
  background: var(--border-light);
  color: var(--warning, #fbbf24);
}

.status-badge.connecting .status-dot {
  animation: blink 0.8s ease infinite;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.live .status-dot {
  animation: blink 1.5s ease infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ===== Metrics ===== */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.metric-item {
  background: var(--border-light);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
}

.metric-item.highlight {
  background: var(--primary-light);
}

.metric-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 1px;
}

.metric-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: var(--transition);
}

.metric-value.changed {
  animation: flash 0.5s ease;
}

@keyframes flash {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); color: var(--primary); }
  100% { transform: scale(1); }
}

.metric-trend {
  font-size: 10px;
  margin-left: 4px;
}

.metric-trend.up { color: var(--success); }
.metric-trend.down { color: var(--danger); }

/* ===== Sparkline ===== */
.sparkline-container {
  margin-top: 8px;
  height: 28px;
}

/* ===== Live Video ===== */
.live-video-wrapper {
  position: relative;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  aspect-ratio: 16 / 9;
}

.live-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.live-video-overlay {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  pointer-events: none;
}

/* ===== Card Footer ===== */
.card-footer {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--text-muted);
}

.duration-badge {
  background: var(--info-light);
  color: var(--info);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--primary-light, #eff6ff);
  transition: all 0.2s;
  white-space: nowrap;
}

.card-link:hover {
  background: var(--primary);
  color: #ffffff;
}

/* ===== Charts ===== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
}

.chart-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.chart-wrapper {
  position: relative;
  height: 220px;
}

/* ===== Alert History ===== */
.alert-history {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  max-height: 400px;
  overflow-y: auto;
}

.alert-history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  transition: var(--transition);
}

.alert-history-item:hover {
  background: var(--border-light);
}

.alert-history-item:last-child {
  border-bottom: none;
}

.alert-history-item .ah-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.alert-history-item .ah-content {
  flex: 1;
  min-width: 0;
}

.alert-history-item .ah-title {
  font-weight: 600;
  color: var(--text);
}

.alert-history-item .ah-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.alert-history-item .ah-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.alert-history-item.resolved .ah-title {
  color: var(--text-muted);
  text-decoration: line-through;
}

.alert-history-item.critical {
  border-left: 3px solid var(--danger);
}

.alert-history-item.warning {
  border-left: 3px solid var(--warning);
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  width: 560px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.btn-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-muted);
  padding: 4px 8px;
}

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

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.settings-group {
  margin-bottom: 24px;
}

.settings-group h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
}

.form-row label {
  min-width: 120px;
  color: var(--text-secondary);
}

.form-row input[type="number"] {
  width: 70px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.form-row input[type="text"] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.form-row input[type="radio"] {
  margin-right: 4px;
}

.account-list-settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.account-setting-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--border-light);
  border-radius: var(--radius-sm);
}

.account-setting-item input {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}

.account-setting-item .emoji-input {
  width: 40px;
  text-align: center;
}

.btn-add {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px dashed var(--primary);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  width: 100%;
}

.btn-add:hover {
  background: var(--primary);
  color: white;
}

.btn-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--danger);
  font-size: 16px;
  padding: 2px 6px;
}

/* ===== Buttons ===== */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}

.btn-primary:hover {
  background: #dc2626;
}

.btn-secondary {
  background: var(--border-light);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}

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

.btn-text {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--primary);
  font-size: 12px;
  font-weight: 500;
}

.btn-text:hover {
  text-decoration: underline;
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== 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);
}

/* ===== Login Page ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f0f4f8 0%, #fafafa 50%, #fee2e2 100%);
}

.login-container {
  width: 100%;
  max-width: 420px;
  padding: 20px;
}

.login-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  animation: loginSlideUp 0.5s ease;
}

@keyframes loginSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
  margin-bottom: 16px;
}

.login-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.login-input-wrapper {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.login-input-icon {
  padding: 0 12px;
  font-size: 16px;
  flex-shrink: 0;
}

.login-input-wrapper input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 12px 12px 0;
  font-size: 14px;
  color: var(--text);
  outline: none;
}

.login-input-wrapper input::placeholder {
  color: var(--text-muted);
}

.login-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
}

.login-remember input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.login-error {
  background: var(--danger-light);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border-left: 3px solid var(--danger);
  animation: loginShake 0.4s ease;
}

@keyframes loginShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 4px;
}

.login-btn:hover {
  background: #dc2626;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.login-btn:active {
  transform: translateY(0);
}

.login-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.login-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: loginSpin 0.6s linear infinite;
}

@keyframes loginSpin {
  to { transform: rotate(360deg); }
}

.login-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Header: Logout Button ===== */
.btn-logout {
  background: var(--border-light);
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-logout:hover {
  background: var(--danger-light);
  color: var(--danger);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
  }

  .header-stats {
    order: 3;
    width: 100%;
    justify-content: space-around;
    gap: 12px;
  }

  .main {
    padding: 12px 16px;
  }

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

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