/* 基础元素与共享组件原语。组件细节由 components.css / organize.css 扩展。 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: var(--accent);
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

img {
  display: block;
  max-width: 100%;
}

::selection {
  background: var(--accent-soft-2);
}

/* 跳到主要内容：键盘用户首个 Tab 可达（index.html 内联脚本避免改动 hash 路由）。 */
.skip-link {
  position: fixed;
  top: -100px;
  left: 12px;
  z-index: 300;
  display: inline-flex;
  align-items: center;
  min-height: var(--control-h);
  padding: 0 16px;
  border-radius: var(--r-2);
  background: var(--surface);
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: 600;
  box-shadow: var(--shadow-2);
  transition: top var(--dur-fast) var(--ease);
}

.skip-link:focus-visible {
  top: 12px;
}

.view-root:focus,
.view-root:focus-visible {
  outline: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--r-2);
  font-size: 14px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: var(--border-strong);
}

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

.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  /* 实心填充用 --accent-solid：暗色下白字仍有 5.18:1（--accent 只有 2.6:1）。 */
  background: var(--accent-solid);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-solid-hover);
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: var(--surface-3);
}

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

.btn-sm {
  min-height: var(--control-h-sm);
  padding: 0 12px;
  font-size: 13px;
  border-radius: var(--r-1);
}

.btn-icon {
  position: relative;
  width: var(--control-h-sm);
  min-width: var(--control-h-sm);
  height: var(--control-h-sm);
  min-height: var(--control-h-sm);
  padding: 0;
  border-radius: var(--r-2);
}

/* 视觉 36×36，命中区补到 44×44（HIG 触控目标）。 */
.btn-icon::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: inherit;
}

@media (pointer: coarse) {
  .btn-icon {
    width: var(--control-h);
    min-width: var(--control-h);
    height: var(--control-h);
    min-height: var(--control-h);
  }
}

/* ---------- 输入 ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.field > label,
.label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-2);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

/* 单行控件固定 44px，避免 font/padding 叠加出 45px 的行高抖动。 */
.input,
.select {
  height: var(--control-h);
  padding-top: 0;
  padding-bottom: 0;
}

.input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

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

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea {
  min-height: 88px;
  resize: vertical;
  line-height: 1.5;
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

.hint {
  font-size: var(--fs-xs);
  color: var(--text-3);
}

.error-text {
  font-size: var(--fs-xs);
  color: var(--danger);
}

/* ---------- 卡片 / 面板 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-1);
}

.panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-2);
}

/* ---------- 徽标 / 状态 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text-2);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

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

.badge-warn {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-ok {
  background: var(--success-soft);
  color: var(--success);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  flex: none;
}

.dot-ok {
  background: var(--success);
}

.dot-warn {
  background: var(--warning);
}

.dot-danger {
  background: var(--danger);
}

.dot-busy {
  background: var(--accent);
  animation: pulse 1.4s var(--ease) infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  max-width: min(560px, calc(100vw - 32px));
  padding: 8px 16px;
  border-radius: var(--r-pill);
  background: rgba(29, 29, 31, 0.92);
  color: #fff;
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-2);
  animation: toast-in 180ms var(--ease);
}

.toast-error {
  background: rgba(178, 0, 18, 0.95);
}

.toast-success {
  background: rgba(24, 96, 50, 0.95);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 对话框 ---------- */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.32);
  animation: fade-in 160ms var(--ease);
}

.dialog {
  width: min(440px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 20px;
  border-radius: var(--layer-r);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  animation: dialog-in 180ms var(--ease);
}

.dialog:focus {
  outline: none;
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: var(--fs-h2);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.dialog p {
  margin: 0 0 20px;
  color: var(--text-2);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

/* ---------- 空状态 ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 72px 24px;
  text-align: center;
  color: var(--text-2);
}

.empty h2 {
  margin: 0;
  font-size: var(--fs-h2);
  font-weight: 600;
  color: var(--text);
}

.empty p {
  margin: 0;
  max-width: 380px;
  font-size: var(--fs-sm);
}

.skeleton {
  border-radius: var(--r-2);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

html {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  background-clip: content-box;
}

::-webkit-scrollbar-track {
  background: transparent;
}
