/* =========================================================================
   组件库 —— 基础控件
   按钮 / 表单 / 徽章 / 头像 / 开关 / 提示条 / 加载态
   ========================================================================= */

/* ── 按钮 ─────────────────────────────────────────────────────────────── */
.btn {
  --btn-bg: var(--c-surface);
  --btn-fg: var(--c-text);
  --btn-border: var(--c-border);
  --btn-shadow: var(--sh-xs);

  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: 38px;
  padding: 0 var(--s-4);
  border: 1px solid var(--btn-border);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  box-shadow: var(--btn-shadow);
  font-size: var(--f-base);
  font-weight: var(--fw-medium);
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  transition: transform var(--t-fast), box-shadow var(--t-fast),
              background-color var(--t-fast), border-color var(--t-fast),
              color var(--t-fast);
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--sh-sm); }
.btn:active { transform: translateY(0) scale(0.985); box-shadow: var(--sh-xs); }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: var(--sh-xs) !important;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* 尺寸 */
.btn-sm { height: 32px; padding: 0 var(--s-3); font-size: var(--f-sm); border-radius: var(--r-sm); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: 46px; padding: 0 var(--s-6); font-size: var(--f-md); border-radius: var(--r-lg); }
.btn-lg svg { width: 18px; height: 18px; }
.btn-xl { height: 54px; padding: 0 var(--s-7); font-size: var(--f-lg); border-radius: var(--r-lg); }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-block { width: 100%; }

/* 变体：主色 */
.btn-primary {
  --btn-bg: linear-gradient(180deg, var(--c-primary-500), var(--c-primary-600));
  --btn-fg: #fff;
  --btn-border: transparent;
  --btn-shadow: var(--sh-primary);
}
.btn-primary:hover {
  --btn-shadow: 0 6px 20px -2px rgba(99, 102, 241, 0.45);
  --btn-bg: linear-gradient(180deg, var(--c-primary-400), var(--c-primary-500));
}

/* 变体：成功 */
.btn-success {
  --btn-bg: linear-gradient(180deg, #34d399, var(--c-success));
  --btn-fg: #fff;
  --btn-border: transparent;
  --btn-shadow: 0 4px 14px -2px rgba(16, 185, 129, 0.35);
}

/* 变体：危险 */
.btn-danger {
  --btn-bg: linear-gradient(180deg, #fb7185, var(--c-danger));
  --btn-fg: #fff;
  --btn-border: transparent;
  --btn-shadow: 0 4px 14px -2px rgba(244, 63, 94, 0.35);
}

/* 变体：幽灵 */
.btn-ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-shadow: none;
  --btn-fg: var(--c-text-soft);
}
.btn-ghost:hover {
  --btn-bg: var(--c-gray-100);
  --btn-fg: var(--c-text-strong);
  box-shadow: none;
}
[data-theme="dark"] .btn-ghost:hover { --btn-bg: rgba(255,255,255,0.06); }

/* 变体：浅色 */
.btn-soft {
  --btn-bg: var(--c-primary-50);
  --btn-fg: var(--c-primary-700);
  --btn-border: transparent;
  --btn-shadow: none;
}
.btn-soft:hover { --btn-bg: var(--c-primary-100); box-shadow: none; }

/* 变体：描边 */
.btn-outline {
  --btn-bg: transparent;
  --btn-fg: var(--c-primary-600);
  --btn-border: var(--c-primary-200);
  --btn-shadow: none;
}
.btn-outline:hover {
  --btn-bg: var(--c-primary-50);
  --btn-border: var(--c-primary-300);
  box-shadow: none;
}

/* 危险描边（删除类操作） */
.btn-outline-danger {
  --btn-bg: transparent;
  --btn-fg: var(--c-danger-text);
  --btn-border: var(--c-gray-200);
  --btn-shadow: none;
}
.btn-outline-danger:hover {
  --btn-bg: var(--c-danger-bg);
  --btn-border: #fecdd3;
  box-shadow: none;
}

/* 加载态：文字替换为旋转环 */
.btn[data-loading="true"] {
  color: transparent !important;
  pointer-events: none;
}
.btn[data-loading="true"]::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--btn-fg);
  animation: btn-spin 0.6s linear infinite;
}
.btn[data-loading="true"] svg { visibility: hidden; }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ── 表单 ─────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: var(--s-2); }

.field-label {
  font-size: var(--f-sm);
  font-weight: var(--fw-medium);
  color: var(--c-text);
  display: flex;
  align-items: center;
  gap: var(--s-1);
}

.field-label .req { color: var(--c-danger); font-weight: var(--fw-bold); }

.field-hint { font-size: var(--f-xs); color: var(--c-text-faint); line-height: var(--lh-snug); }

.field-error {
  font-size: var(--f-xs);
  color: var(--c-danger-text);
  display: flex;
  align-items: center;
  gap: var(--s-1);
}

.input,
.select,
.textarea {
  width: 100%;
  height: 40px;
  padding: 0 var(--s-3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: var(--f-base);
  transition: border-color var(--t-fast), box-shadow var(--t-fast),
              background-color var(--t-fast);
  appearance: none;
}

.input::placeholder,
.textarea::placeholder { color: var(--c-text-faint); }

.input:hover,
.select:hover,
.textarea:hover { border-color: var(--c-gray-300); }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--c-primary-400);
  box-shadow: 0 0 0 3px var(--c-primary-50);
}
[data-theme="dark"] .input:focus,
[data-theme="dark"] .select:focus,
[data-theme="dark"] .textarea:focus {
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--c-gray-50);
  color: var(--c-text-faint);
  cursor: not-allowed;
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--c-danger);
  box-shadow: 0 0 0 3px var(--c-danger-bg);
}

.textarea {
  height: auto;
  min-height: 96px;
  padding: var(--s-3);
  line-height: var(--lh-normal);
  resize: vertical;
  font-family: inherit;
}

.textarea.mono { font-family: var(--font-mono); font-size: var(--f-sm); }

.select {
  padding-right: var(--s-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  cursor: pointer;
}

/* 输入组：图标前置 */
.input-group { position: relative; display: flex; align-items: center; }
.input-group > .input { padding-left: var(--s-9); }
.input-group > svg.input-icon {
  position: absolute;
  left: var(--s-3);
  width: 16px; height: 16px;
  color: var(--c-text-faint);
  pointer-events: none;
  transition: color var(--t-fast);
}
.input-group > .input:focus + svg.input-icon,
.input-group:focus-within > svg.input-icon { color: var(--c-primary-500); }

.input-group > .input-suffix {
  position: absolute;
  right: var(--s-2);
  display: flex;
  align-items: center;
  gap: var(--s-1);
}

/* 输入组：前后缀按钮拼接 */
.input-addon { display: flex; }
.input-addon > .input { border-radius: var(--r-md) 0 0 var(--r-md); }
.input-addon > .btn { border-radius: 0 var(--r-md) var(--r-md) 0; border-left: none; }

/* 复选框 / 单选 */
.checkbox,
.radio {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  cursor: pointer;
  font-size: var(--f-base);
  user-select: none;
}
.checkbox input,
.radio input {
  width: 16px; height: 16px;
  margin: 0;
  accent-color: var(--c-primary-600);
  cursor: pointer;
  flex-shrink: 0;
}

/* 开关 */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  width: 40px; height: 22px;
  border-radius: var(--r-full);
  background: var(--c-gray-300);
  transition: background-color var(--t-base);
  flex-shrink: 0;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15,23,42,0.25);
  transition: transform var(--t-base);
}
.switch input:checked + .switch-track { background: var(--c-primary-600); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--c-primary-500); outline-offset: 2px; }

/* ── 徽章 ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  height: 22px;
  padding: 0 var(--s-2);
  border-radius: var(--r-sm);
  font-size: var(--f-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
}
.badge-neutral { background: var(--c-gray-100); color: var(--c-gray-600); }
.badge-primary { background: var(--c-primary-50); color: var(--c-primary-700); }
.badge-success { background: var(--c-success-bg); color: var(--c-success-text); }
.badge-warning { background: var(--c-warning-bg); color: var(--c-warning-text); }
.badge-danger  { background: var(--c-danger-bg);  color: var(--c-danger-text); }
.badge-info    { background: var(--c-info-bg);    color: var(--c-info-text); }
.badge-dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-lg { height: 26px; padding: 0 var(--s-3); font-size: var(--f-sm); border-radius: var(--r-md); }

/* ── 头像 ─────────────────────────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--c-primary-400), var(--c-violet));
  color: #fff;
  font-size: var(--f-sm);
  font-weight: var(--fw-bold);
  flex-shrink: 0;
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 28px; height: 28px; font-size: var(--f-xs); }
.avatar-lg { width: 44px; height: 44px; font-size: var(--f-base); }

/* ── 提示条 ───────────────────────────────────────────────────────────── */
.alert {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: var(--f-sm);
  line-height: var(--lh-normal);
}
.alert > svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-title { font-weight: var(--fw-semibold); margin-bottom: 2px; }
.alert-info    { background: var(--c-info-bg);    border-color: #bfdbfe; color: var(--c-info-text); }
.alert-success { background: var(--c-success-bg); border-color: #a7f3d0; color: var(--c-success-text); }
.alert-warning { background: var(--c-warning-bg); border-color: #fde68a; color: var(--c-warning-text); }
.alert-danger  { background: var(--c-danger-bg);  border-color: #fecdd3; color: var(--c-danger-text); }
[data-theme="dark"] .alert-info    { border-color: #1e3a8a; }
[data-theme="dark"] .alert-success { border-color: #065f46; }
[data-theme="dark"] .alert-warning { border-color: #78350f; }
[data-theme="dark"] .alert-danger  { border-color: #881337; }

/* ── 骨架屏 ───────────────────────────────────────────────────────────── */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--c-gray-100);
  border-radius: var(--r-sm);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  animation: skeleton-sweep 1.4s infinite;
}
[data-theme="dark"] .skeleton { background: #1a2237; }
[data-theme="dark"] .skeleton::after {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
}
@keyframes skeleton-sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ── 空状态 ───────────────────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  padding: var(--s-9) var(--s-4);
  text-align: center;
  color: var(--c-text-faint);
}
.empty-icon {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-xl);
  background: var(--c-gray-100);
  color: var(--c-gray-400);
}
.empty-icon svg { width: 26px; height: 26px; }
.empty-title { font-size: var(--f-md); font-weight: var(--fw-semibold); color: var(--c-text-soft); }
.empty-desc { font-size: var(--f-sm); max-width: 36ch; line-height: var(--lh-normal); }
[data-theme="dark"] .empty-icon { background: #1a2237; }

/* ── 分割线 ───────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--c-border-soft);
  border: none;
  margin: var(--s-4) 0;
}
.divider-text {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  color: var(--c-text-faint);
  font-size: var(--f-xs);
}
.divider-text::before,
.divider-text::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--c-border-soft);
}

/* ── 进度条 ───────────────────────────────────────────────────────────── */
.progress {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--c-gray-100);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--c-primary-500), var(--c-violet));
  transition: width var(--t-slow);
}
[data-theme="dark"] .progress { background: #1a2237; }
/* ── 栅格工具类 ────────────────────────────────────────────────────────
   表单里的「两列/三列/四列并排」。这些类之前被多处模板引用但根本没定义，
   导致字段全部垂直堆叠、宽屏下留大片空白。
   断点：≥1024 用满；768~1023 三列降两列；<768 全部单列（手机上并排会挤成一团）。
   不用 auto-fit：字段宽窄不一，自动列数会让同一表单里每行列数不同，很乱。 */
.grid-2,
.grid-3,
.grid-4 {
  display: grid;
  gap: var(--s-4);
  align-items: start;
}
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1023px) {
  .grid-3,
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
    gap: var(--s-3);
  }
}

/* 手机上的表单细节：输入框字号 ≥16px 防 iOS 聚焦自动放大 */
@media (max-width: 720px) {
  .input,
  .select,
  .textarea {
    font-size: 16px;
  }
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .form-actions .btn {
    width: 100%;
  }
}

/* ── 传输配置页 ────────────────────────────────────────────────────────
   31 个调用码输入框在小屏上要能快速筛。头部操作按钮在窄屏应换行，
   而不是被 flex 挤成竖排窄条。 */
.cf-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  align-items: flex-start;
  justify-content: space-between;
}
.cf-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.cf-codes-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  align-items: flex-end;
  justify-content: space-between;
}
.cf-search {
  flex: 0 1 240px;
  min-width: 180px;
}
.cf-search .input {
  width: 100%;
}
.cf-code-group + .cf-code-group {
  margin-top: var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px solid var(--c-border-soft);
}
.cf-code-item {
  min-width: 0;
}
.cf-code-item .input {
  width: 100%;
  text-overflow: ellipsis;
}

@media (max-width: 720px) {
  .cf-head,
  .cf-codes-head {
    flex-direction: column;
    align-items: stretch;
  }
  .cf-actions {
    width: 100%;
  }
  .cf-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
  .cf-search {
    flex: 1 1 auto;
    width: 100%;
  }
}

/* ── 通用数据表 ────────────────────────────────────────────────────────
   `.table` 一直被 t3_data / t3_logs 引用但从未定义，实际渲染成浏览器
   默认表格（无边框、无内边距、窄屏直接溢出）。这里补齐，并让容器可横向滚动。 */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--c-border-soft);
  border-radius: var(--r-lg);
  background: var(--c-surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--f-sm);
}
.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--s-3) var(--s-4);
  text-align: left;
  font-size: var(--f-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--c-text-soft);
  white-space: nowrap;
  background: var(--c-gray-50);
  border-bottom: 1px solid var(--c-border-soft);
}
.table tbody td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--c-border-soft);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: rgba(127,127,127,.04); }

@media (max-width: 720px) {
  .table thead th,
  .table tbody td {
    padding: var(--s-2) var(--s-3);
    white-space: nowrap;
  }
  .table { font-size: var(--f-xs); }
}
