/*
 * 基础组件样式（P2.7）：按钮、表单、胶囊与状态点、分组列表、卡片、分段控件、表格、对话框与 sheet、
 * 提示条、状态行、键盘徽记。只引用 tokens.css 的变量，禁止硬编码颜色与尺寸（design.test.ts 扫描）。
 * 触控目标：粗指针设备上交互元素最小 44 × 44（§6.2）。
 */

/* —— 图标 —— */

.ico {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* —— 按钮 —— */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 32px;
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-weight: var(--fw-strong);
  font-size: var(--fs-body);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--dur-press) var(--ease-out),
    border-color var(--dur-press) var(--ease-out),
    transform var(--dur-press) var(--ease-out);
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn .ico {
  width: 16px;
  height: 16px;
}

.btn-lg {
  min-height: 44px;
  padding: 0 var(--sp-6);
  font-size: var(--fs-headline);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent-strong);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--fill-2);
  color: var(--text-1);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--fill-3);
}

.btn-ghost {
  background: transparent;
  color: var(--accent-text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--fill-1);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--sep);
  color: var(--text-1);
}

.btn-outline:hover:not(:disabled) {
  background: var(--fill-1);
}

.btn-danger {
  background: var(--danger-strong);
  color: var(--on-danger);
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.06);
}

/* 图标按钮（等宽方钮） */
.btn-icon {
  width: 32px;
  padding: 0;
  border-radius: var(--r-control);
  color: var(--text-2);
  background: transparent;
}

.btn-icon:hover:not(:disabled) {
  background: var(--fill-1);
  color: var(--text-1);
}

.btn-icon .ico {
  width: 18px;
  height: 18px;
}

/* 触摸设备：触控目标 ≥ 44 × 44（§6.2） */
@media (pointer: coarse) {
  .btn {
    min-height: 44px;
  }

  .btn-icon {
    width: 44px;
  }
}

/* 按钮行（横排、换行） */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* —— 表单 —— */

.field {
  display: grid;
  gap: var(--sp-1);
}

.field > label {
  font-size: var(--fs-footnote);
  font-weight: var(--fw-strong);
  color: var(--text-2);
}

.input {
  min-height: 36px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--sep);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--text-1);
  font: inherit;
}

.input::placeholder {
  color: var(--text-3);
}

.input:focus-visible {
  outline-offset: 1px;
}

/* 输入字号 ≥ 16px（§6.4：避免 Safari 自动放大）；--fs-body 在窄屏已经是 17px */
@media (max-width: 767px) {
  .input {
    min-height: 44px;
    font-size: var(--fs-body);
  }
}

/* —— 胶囊与状态点 —— */

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-caption);
  font-weight: var(--fw-strong);
  line-height: 1.4;
  white-space: nowrap;
  background: var(--fill-2);
  color: var(--text-1);
}

.pill-ok {
  background: var(--ok-soft);
  color: var(--ok-text);
}

.pill-warn {
  background: var(--warn-soft);
  color: var(--warn-text);
}

.pill-danger {
  background: var(--danger-soft);
  color: var(--danger-text);
}

.pill-accent {
  background: var(--accent-soft);
  color: var(--tint-accent-fg);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--fill-3);
}

.dot-ok {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.dot-warn {
  background: var(--warn);
  box-shadow: 0 0 0 3px var(--warn-soft);
}

.dot-danger {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.dot-accent {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* 在线状态点缓慢呼吸（§6.5）；prefers-reduced-motion 时关闭 */
@keyframes breathe {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

.dot-live {
  animation: breathe 2.4s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .dot-live {
    animation: none;
  }
}

/* —— 分组列表 —— */

.list {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.list-header {
  padding: var(--sp-3) var(--sp-4) var(--sp-1);
  font-size: var(--fs-footnote);
  font-weight: var(--fw-strong);
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.list-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-4);
  border-top: 1px solid var(--sep);
}

.list-row:first-child {
  border-top: 0;
}

.list-row-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.list-row-title {
  font-size: var(--fs-body);
  color: var(--text-1);
}

.list-row-sub {
  font-size: var(--fs-footnote);
  color: var(--text-2);
}

.list-row-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--r-control);
  background: var(--fill-2);
  color: var(--accent-text);
}

.list-row .chevron {
  color: var(--text-3);
}

/* 可点击的行（链接或按钮整行） */
a.list-row,
button.list-row {
  width: 100%;
  margin: 0;
  border-left: 0;
  border-right: 0;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

a.list-row:hover,
button.list-row:hover {
  background: var(--hover);
}

a.list-row .list-row-title,
button.list-row .list-row-title {
  color: var(--accent-text);
}

.list-footnote {
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-caption);
  color: var(--text-2);
}

/* —— 卡片 —— */

.card {
  display: grid;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
}

.card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.card-title {
  font-size: var(--fs-headline);
  font-weight: var(--fw-strong);
  line-height: var(--lh-tight);
}

.card-sub {
  font-size: var(--fs-footnote);
  color: var(--text-2);
}

/* —— 分段控件 —— */

.seg {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--fill-2);
  border-radius: var(--r-control);
}

/* 原生 radio 视觉上藏起来但保持可聚焦，样式打在相邻 span 上（components.tsx 的 Segmented） */
.seg label {
  position: relative;
  display: inline-flex;
}

.seg input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.seg span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-control-inner);
  font-size: var(--fs-footnote);
  font-weight: var(--fw-strong);
  line-height: 1;
  color: var(--text-1);
  transition:
    background-color var(--dur-press) var(--ease-out),
    box-shadow var(--dur-press) var(--ease-out);
}

/* 悬停底：选中态规则排在其后，同特异性时以选中态为准 */
.seg input:hover + span {
  background: var(--fill-1);
}

.seg input:checked + span {
  background: var(--surface);
  box-shadow: var(--shadow-seg);
}

/* 焦点环画在可见的 span 上（input 本身透明） */
.seg input:focus-visible + span {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* 触摸设备：分段选项 ≥ 44px 高 */
@media (pointer: coarse) {
  .seg span {
    min-height: 40px;
    padding: 0 var(--sp-4);
  }
}

/* —— 表格 —— */

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-footnote);
}

.table th {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--sep);
  font-size: var(--fs-caption);
  font-weight: var(--fw-strong);
  text-align: left;
  color: var(--text-2);
  white-space: nowrap;
}

.table td {
  height: 36px;
  padding: 0 var(--sp-3);
  border-bottom: 1px solid var(--sep);
  white-space: nowrap;
}

.table-compact td {
  height: 30px;
}

.table th.num,
.table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover {
  background: var(--hover);
}

/* —— 对话框与 sheet —— */

.dialog {
  width: min(420px, calc(100vw - var(--sp-8)));
  margin: auto;
  padding: var(--sp-5);
  border: 0;
  border-radius: var(--r-card);
  background: var(--surface);
  color: var(--text-1);
  box-shadow: var(--shadow-sheet);
}

.dialog::backdrop,
.sheet::backdrop {
  background: var(--scrim);
}

.dialog-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.dialog-title {
  font-size: var(--fs-headline);
  font-weight: var(--fw-strong);
  line-height: var(--lh-tight);
}

.dialog-body {
  font-size: var(--fs-footnote);
  color: var(--text-2);
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

/* 窄屏上 sheet 从底部弹出（§6.4），桌面端就是普通居中对话框 */
.sheet-grabber {
  width: 36px;
  height: 5px;
  margin: 0 auto var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--fill-3);
}

@media (min-width: 768px) {
  .sheet-grabber {
    display: none;
  }
}

@media (max-width: 767px) {
  .dialog.sheet {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: var(--r-sheet) var(--r-sheet) 0 0;
    padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
    background: var(--elevated);
  }
}

/* —— 提示条 —— */

.notice {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-start;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid;
  border-radius: var(--r-control);
  font-size: var(--fs-footnote);
}

.notice-info {
  color: var(--tint-accent-fg);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.notice-ok {
  color: var(--ok-text);
  background: var(--ok-soft);
  border-color: var(--ok-border);
}

.notice-error {
  color: var(--danger-text);
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

/* —— 状态行：按 data-kind 着色（_http.ts 的 setStatus） —— */

[data-kind="ok"] {
  color: var(--ok-text);
}

[data-kind="error"] {
  color: var(--danger-text);
}

/* —— 键盘徽记 —— */

.kbd {
  padding: 1px var(--sp-1);
  border: 1px solid var(--sep);
  border-radius: var(--r-control-inner);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: var(--fs-caption-2);
  color: var(--text-2);
}

/* —— 认证页（登录、登记、500 与未登录的 404）：居中的卡片，不带导航；登录后的外壳在 layout.css —— */

/* viewport-fit=cover 之后内容会铺到刘海下面：四边至少让开安全区（§6.4） */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(var(--sp-5), env(safe-area-inset-top)) max(var(--sp-5), env(safe-area-inset-right))
    max(var(--sp-5), env(safe-area-inset-bottom)) max(var(--sp-5), env(safe-area-inset-left));
}

.auth-card {
  width: min(420px, 100%);
  gap: var(--sp-4);
  padding: var(--sp-8);
}

.auth-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--r-control);
  background: var(--accent-soft);
  color: var(--tint-accent-fg);
}

.auth-card .notice {
  margin: 0;
}

/* —— 登录页的恢复密钥折叠区（details/summary） —— */

.recover-summary {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 32px;
  font-size: var(--fs-footnote);
  font-weight: var(--fw-strong);
  color: var(--accent-text);
  cursor: pointer;
  list-style: none;
}

.recover-summary::-webkit-details-marker {
  display: none;
}

.recover-summary:hover {
  text-decoration: underline;
}

.recover-form,
.enroll-form {
  display: grid;
  gap: var(--sp-3);
}

.recover-form {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--sep);
}

@media (pointer: coarse) {
  .recover-summary {
    min-height: 44px;
  }
}
