/* ==============================================================
   Apple Design System - 工业级极简设计语言 (iOS & macOS 风格)
   规范与原则：
   1. 严格统一图标尺度 (严格封顶 14px / 16px / 18px，杜绝失控)
   2. 经典 Squircle 连续曲率超椭圆徽章 (iOS Settings 原生质感)
   3. 原生 iOS 触感滑动开关 (iOS Toggle Switch，34C759 系统绿)
   4. 极致通透温润的苹果灰阶与平滑圆角 (#F5F5F7 + #FFFFFF + 1px Hairline)
   5. 深度自适应移动端手机屏幕与桌面宽屏
   ============================================================== */

:root {
  /* 苹果核心色彩系统 */
  --apple-bg: #F5F5F7;
  --apple-card: #FFFFFF;
  --apple-nav: rgba(255, 255, 255, 0.88);
  --apple-subtle: #F2F2F7;
  --apple-hover: #E8E8ED;
  --apple-input: #FFFFFF;

  /* 边框与微阴影 (Apple Hairline & Soft Diffuse) */
  --apple-border: rgba(0, 0, 0, 0.07);
  --apple-border-light: rgba(0, 0, 0, 0.04);
  --apple-divider: rgba(60, 60, 67, 0.09);

  /* 苹果语义色 */
  --apple-blue: #0071E3;
  --apple-blue-hover: #0077ED;
  --apple-blue-tint: rgba(0, 113, 227, 0.08);
  --apple-green: #34C759;
  --apple-green-tint: rgba(52, 199, 89, 0.1);
  --apple-red: #FF3B30;
  --apple-red-tint: rgba(255, 59, 48, 0.1);
  --apple-orange: #FF9500;
  --apple-purple: #5856D6;

  /* 文字层级 */
  --text-primary: #1D1D1F;
  --text-secondary: #6E6E73;
  --text-tertiary: #86868B;
  --text-link: #0071E3;

  /* 圆角规范 */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-card: 18px;
  --radius-pill: 9999px;

  /* 阴影规范 */
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.04), 0 2px 6px -1px rgba(0, 0, 0, 0.02);
  --shadow-hover: 0 10px 30px -4px rgba(0, 0, 0, 0.08), 0 4px 10px -2px rgba(0, 0, 0, 0.03);
  --shadow-switch: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
  --shadow-focus: 0 0 0 3.5px rgba(0, 113, 227, 0.22);

  /* 动效 */
  --transition: all 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ================= 全局重置与排版 ================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--apple-bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }

/* ================= 严格的全局 SVG 尺寸防护 =================
   彻底解决图标被撑爆成整屏的问题，严格封顶在 Apple 规范内 */
svg {
  width: 16px;
  height: 16px;
  max-width: 16px;
  max-height: 16px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  stroke-width: 1.8px;
}

.svg-icon {
  width: 16px !important;
  height: 16px !important;
  max-width: 16px !important;
  max-height: 16px !important;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.svg-icon.xs {
  width: 13px !important;
  height: 13px !important;
  max-width: 13px !important;
  max-height: 13px !important;
}

.svg-icon.sm {
  width: 15px !important;
  height: 15px !important;
  max-width: 15px !important;
  max-height: 15px !important;
}

.svg-icon.md {
  width: 17px !important;
  height: 17px !important;
  max-width: 17px !important;
  max-height: 17px !important;
}

.svg-icon.lg {
  width: 20px !important;
  height: 20px !important;
  max-width: 20px !important;
  max-height: 20px !important;
}

/* 颜色工具类 */
.text-primary { color: var(--apple-blue); }
.text-success { color: var(--apple-green); }
.text-warning { color: var(--apple-orange); }
.text-danger { color: var(--apple-red); }
.text-muted { color: var(--text-tertiary); }

/* ================= 苹果 Squircle 超椭圆彩色徽章 =================
   类似 iOS 设置与 macOS 控制中心中的精致图标背景 */
.squircle-badge {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.squircle-badge svg {
  width: 17px !important;
  height: 17px !important;
  max-width: 17px !important;
  max-height: 17px !important;
  color: #FFFFFF;
  stroke: #FFFFFF;
}

.squircle-blue { background: linear-gradient(145deg, #0A84FF, #0071E3); }
.squircle-discord { background: linear-gradient(145deg, #5865F2, #4752C4); }
.squircle-gray { background: linear-gradient(145deg, #8E8E93, #636366); }
.squircle-green { background: linear-gradient(145deg, #34C759, #28A745); }

/* ================= 布局容器 ================= */
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

@media (max-width: 768px) {
  .app-container {
    padding: 12px 10px 60px;
  }
}

/* ================= 顶部导航栏 (Apple Glass Bar) ================= */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--apple-nav);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--apple-border);
  border-radius: var(--radius-card);
  margin-bottom: 22px;
  box-shadow: var(--shadow-card);
  gap: 16px;
  flex-wrap: wrap;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-text h1 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

.brand-text .badge-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--apple-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin-top: 1px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* ================= iOS 原生触感滑动开关 (iOS Toggle) ================= */
.ios-switch-container {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  background: #FFFFFF;
  padding: 5px 12px 5px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--apple-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  transition: var(--transition);
}

.ios-switch-container:hover {
  background: #FCFCFD;
  border-color: rgba(0, 0, 0, 0.12);
}

.ios-switch-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot-mini {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot-mini.dot-green {
  background: var(--apple-green);
  box-shadow: 0 0 6px rgba(52, 199, 89, 0.6);
}

.status-dot-mini.dot-red {
  background: var(--apple-red);
}

/* 纯正 iOS 51x31 比例微缩版 (38x22) */
.ios-switch-track {
  width: 38px;
  height: 22px;
  border-radius: 12px;
  background-color: #E9E9EB;
  position: relative;
  transition: background-color 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}

.ios-switch-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: #FFFFFF;
  position: absolute;
  top: 2px;
  left: 2px;
  box-shadow: var(--shadow-switch);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* 激活状态 */
.ios-switch-container.online .ios-switch-track {
  background-color: var(--apple-green);
}

.ios-switch-container.online .ios-switch-thumb {
  transform: translateX(16px);
}

/* ================= 栅格系统 ================= */
.grid-layout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }

@media (max-width: 1024px) {
  .grid-layout { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: span 1; }
}

/* ================= Apple 纯净卡片 ================= */
.card {
  background: var(--apple-card);
  border: 1px solid var(--apple-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--apple-divider);
  background: #FFFFFF;
}

.header-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.title-row h2 {
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding-left: 44px; /* 对齐标题文字 */
}

@media (max-width: 768px) {
  .card-subtitle { padding-left: 0; margin-top: 4px; }
}

.card-body {
  padding: 22px;
}

/* ================= Apple 调度策略单选卡片 ================= */
.routing-section {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--apple-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--apple-border-light);
}

.routing-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.routing-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (max-width: 768px) {
  .routing-cards-grid { grid-template-columns: 1fr; }
}

.apple-radio-card {
  position: relative;
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: #FFFFFF;
  border: 1px solid var(--apple-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.apple-radio-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.apple-radio-content {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.apple-radio-card:has(input:checked) {
  border-color: var(--apple-blue);
  background: #FFFFFF;
  box-shadow: 0 0 0 1px var(--apple-blue), 0 2px 8px rgba(0, 113, 227, 0.1);
}

.apple-radio-card:has(input:checked) .apple-radio-content {
  color: var(--apple-blue);
  font-weight: 600;
}

/* ================= 全局人设输入框 ================= */
.global-prompt-wrapper {
  margin-top: 14px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.field-hint-inline {
  font-size: 0.74rem;
  font-weight: 400;
  color: var(--text-tertiary);
}

textarea, input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-primary);
  background: #FFFFFF;
  border: 1px solid var(--apple-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  transition: var(--transition);
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 58px;
  line-height: 1.45;
}

textarea:focus, input:focus, select:focus {
  border-color: var(--apple-blue);
  box-shadow: var(--shadow-focus);
}

/* ================= 站子横向选择栏 (macOS Segmented Chips) ================= */
.profiles-bar-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--apple-divider);
}

.profiles-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.profiles-bar-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.profile-chips-scroller {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px;
  scrollbar-width: none;
}

.profile-chips-scroller::-webkit-scrollbar { display: none; }

.profile-chip {
  display: flex;
  flex-direction: column;
  padding: 7px 14px;
  background: var(--apple-subtle);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
  user-select: none;
  min-width: 100px;
}

.profile-chip:hover {
  background: var(--apple-hover);
}

.profile-chip.selected {
  background: #FFFFFF;
  border-color: var(--apple-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.profile-chip.active-main {
  border-color: rgba(52, 199, 89, 0.4);
}

.chip-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.chip-model {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ================= 当前站子编辑表单 ================= */
.profile-editor-box {
  background: #FFFFFF;
}

.editor-sub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--apple-divider);
  flex-wrap: wrap;
  gap: 10px;
}

.editor-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-main {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--apple-green);
  background: var(--apple-green-tint);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.editor-actions-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ================= 表单网格 ================= */
.form-group {
  margin-bottom: 15px;
}

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

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

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

@media (max-width: 640px) {
  .form-row { flex-direction: column; gap: 0; }
}

/* ================= macOS 原生分段控制器 (Segmented Control) ================= */
.apple-segmented-control {
  display: flex;
  background: var(--apple-subtle);
  border-radius: var(--radius-sm);
  padding: 3px;
  border: 1px solid var(--apple-border-light);
  gap: 2px;
}

.segment-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  white-space: nowrap;
}

.segment-btn.active {
  background: #FFFFFF;
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ================= 输入框组合 (模型拉取 & 密码查看) ================= */
.input-group-addon {
  display: flex;
  gap: 8px;
}

.btn-addon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 12px;
  background: var(--apple-subtle);
  border: 1px solid var(--apple-border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.btn-addon:hover {
  background: var(--apple-hover);
}

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

.input-password-box input {
  padding-right: 36px;
}

.btn-eye {
  position: absolute;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.tag-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  background: var(--apple-subtle);
  color: var(--text-tertiary);
}

.quick-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.quick-tag {
  font-size: 0.72rem;
  padding: 2px 8px;
  background: var(--apple-subtle);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.quick-tag:hover {
  background: var(--apple-blue-tint);
  color: var(--apple-blue);
}

/* ================= 局部人设 iOS 滑动开关条 ================= */
.custom-prompt-ios-box {
  margin: 14px 0 18px;
  background: var(--apple-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--apple-border-light);
  padding: 12px 16px;
  transition: var(--transition);
}

.ios-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.ios-toggle-left {
  display: flex;
  flex-direction: column;
}

.ios-toggle-title {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-primary);
}

.ios-toggle-sub {
  font-size: 0.74rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.custom-prompt-content {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--apple-divider);
}

/* 滑块控件 (Temperature) */
.slider-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--apple-blue);
}

.val-badge {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--apple-blue);
  min-width: 28px;
}

/* ================= 按钮系统 (Apple Buttons) ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.83rem;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

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

.btn-sm {
  font-size: 0.78rem;
  padding: 5px 12px;
  border-radius: var(--radius-xs);
}

.btn-primary {
  background: var(--apple-blue);
  color: #FFFFFF;
}

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

.btn-secondary {
  background: var(--apple-subtle);
  border-color: var(--apple-border);
  color: var(--text-primary);
}

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

.btn-outline {
  background: transparent;
  border-color: var(--apple-border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: var(--apple-subtle);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--apple-red-tint);
  color: var(--apple-red);
}

.btn-danger:hover {
  background: rgba(255, 59, 48, 0.18);
}

.btn-block { width: 100%; }

.action-bar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--apple-divider);
}

/* ================= 连通性测试结果面板 ================= */
.test-panel {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--apple-subtle);
  border: 1px solid var(--apple-border);
  font-size: 0.8rem;
}

.test-panel-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-weight: 600;
}

.test-reply-text {
  color: var(--text-secondary);
  font-family: monospace;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
}

/* ================= Gateway 运行监视卡片 ================= */
.monitor-box {
  margin-top: 18px;
  padding: 14px;
  background: var(--apple-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--apple-border-light);
}

.monitor-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.monitor-box-header h3 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.monitor-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  padding: 4px 0;
  border-bottom: 1px solid var(--apple-divider);
}

.monitor-row:last-child { border-bottom: none; }
.monitor-label { color: var(--text-tertiary); }
.monitor-val { font-weight: 600; font-family: monospace; }

/* ================= 认证弹窗 (Apple Modal) ================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.apple-modal-card {
  width: 100%;
  max-width: 420px;
  background: #FFFFFF;
  border-radius: var(--radius-card);
  padding: 32px 28px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12);
  border: 1px solid var(--apple-border);
}

.modal-header-center {
  text-align: center;
  margin-bottom: 24px;
}

.modal-header-center .squircle-badge {
  margin: 0 auto 14px;
}

.modal-header-center h2 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-header-center p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.alert-error {
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  background: var(--apple-red-tint);
  color: var(--apple-red);
  font-size: 0.78rem;
  margin-bottom: 14px;
}

/* ================= Toast 浮动通知 ================= */
.toast {
  position: fixed;
  top: 24px;
  right: 24px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: rgba(29, 29, 31, 0.92);
  color: #FFFFFF;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  z-index: 2000;
  transition: var(--transition);
}
