/* 组件库：按钮、表单、标签、进度、面板、提示、对话框。页面不得自造同类组件。 */

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: var(--h-ctl); padding: 0 var(--s-3);
  border: var(--bw) solid transparent; border-radius: var(--r-m);
  background: transparent; color: var(--ink);
  font-size: var(--fs-base); font-weight: var(--fw-medium); line-height: 1;
  white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.btn .ic { width: 16px; height: 16px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.4; cursor: default; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not([disabled]) { background: var(--primary-hover); }
.btn-primary:active:not([disabled]) { background: var(--primary-press); }

.btn-secondary { background: var(--surface); border-color: var(--line-strong); }
.btn-secondary:hover:not([disabled]) { background: var(--surface-2); }
.btn-secondary:active:not([disabled]) { background: var(--surface-3); }

.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover:not([disabled]) { background: var(--surface-2); color: var(--ink); }
.btn-ghost:active:not([disabled]) { background: var(--surface-3); }

.btn-danger { background: var(--err); color: var(--on-err); }
.btn-danger:hover:not([disabled]) { opacity: 0.88; }

.btn-sm { height: var(--h-sm); padding: 0 var(--s-2); font-size: var(--fs-sm); gap: var(--s-1); border-radius: var(--r-s); }
.btn-icon { width: var(--h-ctl); padding: 0; }
.btn-icon.btn-sm { width: 32px; height: 32px; }
.btn-icon .ic { width: 20px; height: 20px; }
.btn .ic-caret, summary.btn .ic-caret { margin: 0 -2px 0 -2px; color: var(--ink-3); }

/* ---------- 表单 ---------- */
.field { display: grid; gap: var(--s-1); align-content: start; }
.label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--ink); }
.hint, .footnote { font-size: var(--fs-sm); color: var(--ink-3); }  /* 字段提示和页面底部说明：同一种文字 */
.field-error { font-size: var(--fs-sm); color: var(--err); }

.input, .select {
  width: 100%; height: var(--h-ctl); padding: 0 var(--s-3);
  background: var(--surface); color: var(--ink);
  border: var(--bw) solid var(--line-strong); border-radius: var(--r-m);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input::placeholder { color: var(--ink-3); }
.input:focus, .select:focus { border-color: var(--ink-3); outline: none; box-shadow: 0 0 0 3px var(--focus-soft); }
.input.is-invalid { border-color: var(--err); }
.select { appearance: none; padding-right: var(--s-6); cursor: pointer; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: ""; position: absolute; right: var(--s-3); top: 50%; width: 6px; height: 6px;
  border: solid var(--ink-3); border-width: 0 1.5px 1.5px 0; transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

/* 分段选择：灰色轨道 + 白色选中块 */
.seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: var(--r-m); background: var(--surface-3); }
.seg label { position: relative; }
.seg span { display: inline-flex; align-items: center; gap: var(--s-1); height: calc(var(--h-ctl) - 4px);
            padding: 0 var(--s-3); border-radius: var(--r-s); cursor: pointer; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--ink-2);
            transition: background-color var(--t-fast), color var(--t-fast); }
.seg span .ic { width: 16px; height: 16px; }
.seg span:hover { color: var(--ink); }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

/* 复选框 */
.check { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; }
.check input {
  appearance: none; width: 16px; height: 16px; margin: 0; flex: none;
  background: var(--surface) center / 12px no-repeat; border: var(--bw) solid var(--line-strong);
  border-radius: 4px; cursor: pointer; transition: background-color var(--t-fast);
}
.check input:hover { border-color: var(--ink-3); }
.check input:checked {
  background-color: var(--primary); border-color: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5 9-10'/%3E%3C/svg%3E");
}
.check input:indeterminate {      /* 部分选中：一条横线 */
  background-color: var(--primary); border-color: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  .check input:indeterminate {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f1e1c' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E");
  }
  .check input:checked {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f1e1c' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5 9-10'/%3E%3C/svg%3E");
  }
}

/* ---------- 状态标签（文字必须在，不能只靠颜色） ---------- */
.chip { display: inline-flex; align-items: center; gap: var(--s-1); height: var(--h-chip); padding: 0 6px;
        border-radius: var(--r-s); font-size: var(--fs-xs); font-weight: var(--fw-medium); white-space: nowrap; }
.chip .ic { width: 16px; height: 16px; }
.chip-run  { background: var(--run-soft);  color: var(--run); }
.chip-ok   { background: var(--ok-soft);   color: var(--ok); }
.chip-err  { background: var(--err-soft);  color: var(--err); }
.chip-wait { background: var(--wait-soft); color: var(--wait); }
.chip-src  { background: var(--surface-2); color: var(--ink-2); }

/* ---------- 进度 ---------- */
.progress { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--run); border-radius: 2px;
                transition: width 300ms linear; }
.progress.is-ok > i { background: var(--ok); }
.progress.is-err > i { background: var(--err); }

/* ---------- 缩略图 ---------- */
.thumb { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: var(--r-s); background: var(--surface-2); }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb-badge { position: absolute; right: var(--s-1); bottom: var(--s-1); padding: 0 var(--s-1); border-radius: 4px;
               background: var(--badge-bg); color: var(--badge-fg); font-size: 11px; font-weight: var(--fw-medium); line-height: 16px; }
.thumb-ph { display: grid; place-items: center; color: var(--ink-3); }
.thumb-ph .ic { width: 20px; height: 20px; }
.thumb-ph:has(.thumb-badge) .ic { margin-top: -8px; }

/* ---------- 面板与列表 ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
              padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); }
.panel-body { padding: var(--s-4); }
.panel-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-4);
              border-top: 1px solid var(--line); }
.rows > :first-child { border-top-left-radius: var(--r-l); border-top-right-radius: var(--r-l); }
.rows > :last-child { border-bottom-left-radius: var(--r-l); border-bottom-right-radius: var(--r-l); }
.rows > * + * { border-top: 1px solid var(--line); }

/* ---------- 行内提示 ---------- */
.notice { display: flex; gap: var(--s-2); padding: var(--s-2) var(--s-3); border-radius: var(--r-m);
          background: var(--surface-2); color: var(--ink-2); font-size: var(--fs-sm); }
.notice .ic { width: 16px; height: 16px; margin-top: 2px; }
.notice-err { background: var(--err-soft); color: var(--err); }
.notice-ok  { background: var(--ok-soft); color: var(--ok); }

/* ---------- 空状态 ---------- */
.empty { display: grid; justify-items: center; gap: var(--s-2); padding: var(--s-7) var(--s-5); text-align: center; }
.empty .ic { width: 32px; height: 32px; color: var(--ink-3); }
.empty h3 { font-size: var(--fs-base); }
.empty p { max-width: 36ch; color: var(--ink-3); font-size: var(--fs-sm); }
.empty .btn { margin-top: var(--s-2); }

/* ---------- 提示条 ---------- */
.toasts { position: fixed; left: 50%; bottom: var(--s-5); transform: translateX(-50%); z-index: 50;
          display: grid; gap: var(--s-2); width: min(92vw, 400px); }
.toast { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3);
         background: var(--primary); color: var(--on-primary); border-radius: var(--r-m); box-shadow: var(--shadow-pop);
         font-size: var(--fs-sm); animation: toast-in 160ms ease-out; }
.toast span { flex: 1; }
.toast button { background: none; border: 0; color: inherit; font-weight: var(--fw-medium); text-decoration: underline; cursor: pointer; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- 对话框 ---------- */
dialog.dlg { width: min(92vw, 400px); padding: var(--s-5); border: 0; border-radius: var(--r-xl);
             background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
dialog.dlg::backdrop { background: var(--overlay); }
.dlg h3 { margin-bottom: var(--s-2); }
.dlg-actions { display: flex; justify-content: flex-end; gap: var(--s-2); margin-top: var(--s-5); }
