:root {
  --bg: #0b1120;
  --card: #162033;
  --card-border: #28354e;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --cyan: #06b6d4;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

/* =========================================================================
   登录与密钥认证页样式 (#loginView)
   ========================================================================= */
.login-viewport {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  background: radial-gradient(circle at 50% 20%, rgba(37, 99, 235, 0.18), transparent 65%), var(--bg);
}

.login-card {
  width: 100%;
  max-width: 410px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.5);
}

.login-brand {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 6px;
}

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

.input-group {
  margin-bottom: 14px;
}

.input-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 7px;
}

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.field-icon {
  position: absolute;
  left: 13px;
  pointer-events: none;
}

.password-field input {
  width: 100%;
  height: 46px;
  background: #0b1120;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 0 42px 0 40px;
  color: #ffffff;
  /* 强制 16px 防止 iOS Safari / 微信浏览器聚焦输入框时页面自动缩放 */
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.password-field input:focus {
  border-color: var(--primary);
}

.eye-btn {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  font-size: 13px;
}

.remember-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #cbd5e1;
  cursor: pointer;
}

.remember-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.author-tag {
  font-size: 11px;
  color: var(--muted);
}

.login-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: center;
}

.login-btn {
  width: 100%;
  height: 46px;
  justify-content: center;
  font-size: 15px;
  border-radius: 10px;
}

/* =========================================================================
   主控制台容器与响应式布局 (#appView)
   ========================================================================= */
.app-container {
  max-width: 1220px;
  margin: 0 auto;
  padding: 12px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  gap: 10px;
}

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

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-info {
  min-width: 0;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 520px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge.paused {
  background: rgba(239, 68, 68, 0.14);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.35);
}

.badge.waiting {
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.35);
}

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

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat-box {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 9px;
  padding: 9px 11px;
}

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

.stat-val {
  font-size: 15px;
  font-weight: 700;
  color: #38bdf8;
  margin-top: 2px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #e2e8f0;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 8px;
  gap: 8px;
  flex-wrap: wrap;
}

.title-left {
  display: flex;
  align-items: center;
  gap: 7px;
}

.card-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

textarea {
  width: 100%;
  background: #0b1120;
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 9px;
  padding: 10px 12px;
  /* 强制 16px 防止手机端点击输入框时页面放大 */
  font-size: 16px;
  resize: vertical;
  min-height: 86px;
  outline: none;
  font-family: inherit;
}

textarea:focus {
  border-color: var(--primary);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.quick-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--card-border);
  align-items: center;
}

.btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  transition: opacity 0.15s, transform 0.05s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary { background: var(--primary); }
.btn.success { background: var(--success); }
.btn.warn { background: var(--warn); color: #0b1120; }
.btn.danger { background: var(--danger); }
.btn.outline {
  background: rgba(51, 65, 85, 0.45);
  border: 1px solid #475569;
  color: #e2e8f0;
}

.btn.sm {
  padding: 6px 10px;
  font-size: 12px;
  min-height: 34px;
}

.elem-list {
  max-height: 290px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.elem-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(11, 17, 32, 0.65);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 9px 11px;
  gap: 10px;
}

.elem-item.matched {
  border-color: rgba(16, 185, 129, 0.55);
  background: rgba(16, 185, 129, 0.12);
}

.elem-name {
  font-size: 13px;
  font-weight: 600;
  word-break: break-word;
}

.elem-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.screen-Actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-chk {
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 400;
}

.screen-wrap {
  position: relative;
  background: #070b14;
  border: 1px solid var(--card-border);
  border-radius: 9px;
  overflow: hidden;
  min-height: 190px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-wrap img {
  width: 100%;
  height: auto;
  display: block;
  cursor: crosshair;
}

.screen-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

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

.switch-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.switch-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(11, 17, 32, 0.6);
  border: 1px solid var(--card-border);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  min-height: 44px;
}

.switch-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--success);
  cursor: pointer;
  flex-shrink: 0;
}

.log-box {
  background: #070b14;
  border: 1px solid var(--card-border);
  border-radius: 9px;
  padding: 10px;
  height: 230px;
  overflow-y: auto;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.log-line {
  margin-bottom: 4px;
  word-break: break-all;
}

.log-SUCCESS { color: #10b981; }
.log-OPTION { color: #06b6d4; }
.log-FILTER { color: #60a5fa; }
.log-WARN { color: #f59e0b; }
.log-ERROR { color: #ef4444; }
.log-INFO { color: #cbd5e1; }

.mobile-bottom-nav {
  display: none;
}

.toast {
  position: fixed;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid #3b82f6;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  display: none;
  z-index: 1000;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================================
   手机端专项响应式适配 (< 768px)
   ========================================================================= */
@media (max-width: 768px) {
  .app-container {
    padding: 8px 8px calc(70px + env(safe-area-inset-bottom, 0px)) 8px;
  }

  .header {
    padding: 10px 12px;
    gap: 8px;
  }

  .brand-sub {
    max-width: 220px;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
    padding-top: 6px;
    border-top: 1px solid rgba(51, 65, 85, 0.5);
  }

  .sm-mobile {
    padding: 5px 10px;
    font-size: 12px;
    min-height: 32px;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 10px;
  }

  .stat-box {
    padding: 7px 10px;
  }

  .stat-val {
    font-size: 14px;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

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

  .flex-grow-mobile {
    flex: 1 1 calc(50% - 4px);
    min-height: 42px;
  }

  /* 手机端分页切换模式：默认只显示当前选中的面板，点击“全部展开”可同屏显示 */
  body:not(.mobile-show-all) .mobile-panel {
    display: none;
  }

  body:not(.mobile-show-all) .mobile-panel.active {
    display: block;
  }

  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(15, 23, 42, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--card-border);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    z-index: 900;
  }

  .nav-tab {
    background: transparent;
    border: none;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
  }

  .nav-tab.active {
    color: #38bdf8;
  }
}
