*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

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

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* 演示模式横幅（仅 mode === "mock" 时展示） */
.mock-banner {
  background: var(--warning-bg);
  border-bottom: 1px solid var(--warning-border);
  color: var(--warning-text);
  font-size: 13px;
  padding: 9px 16px;
}

.mock-banner__inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.mock-banner__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* 通用卡片 */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card__header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.card__body {
  padding: 24px;
}

.card__footer {
  padding: 16px 24px;
  background: var(--bg-subtle);
  border-top: 1px solid var(--border-subtle);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.25;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: var(--text-inverse);
}

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

.btn--secondary {
  background: var(--bg-surface);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: #94a3b8;
}

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

.btn--ghost:hover:not(:disabled) {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.btn--danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

.btn--danger:hover:not(:disabled) {
  background: #ffe4e6;
}

.btn--danger-solid {
  background: #e11d48;
  color: var(--text-inverse);
}

.btn--danger-solid:hover:not(:disabled) {
  background: #be123c;
}

.btn--sm {
  padding: 6px 11px;
  font-size: 13px;
}

.btn--xs {
  padding: 4px 8px;
  font-size: 12px;
}

.btn--block {
  width: 100%;
}

/* 表单 */
.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-label .required {
  color: var(--danger-text);
  margin-left: 2px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-control[readonly],
.form-control:disabled {
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.form-control.is-invalid {
  border-color: #e11d48;
  box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.08);
}

.input-with-action {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-action .form-control {
  padding-right: 68px;
}

.input-action-btn {
  position: absolute;
  right: 6px;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
}

.input-action-btn:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.form-hint {
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.field-error {
  margin-top: 5px;
  font-size: 12px;
  color: var(--danger-text);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* 提示条 */
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  line-height: 1.5;
  margin-bottom: 16px;
}

.alert--info {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: #1e40af;
}

.alert--success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.alert--warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}

.alert--danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

/* 状态徽章 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge--success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.badge--warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}

.badge--danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

.badge--neutral {
  background: var(--neutral-bg);
  border-color: var(--neutral-border);
  color: var(--neutral-text);
}

.badge--info {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: #1d4ed8;
}

/* 加载旋转指示器 */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 弹窗 */
html:has(.modal-backdrop:not(.hidden)) {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  overflow: hidden;
}

.modal {
  width: 100%;
  max-width: 580px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.modal--sm {
  max-width: 440px;
}

/* 表单是弹窗的直接 flex 子项；只让正文滚动，标题与底部操作留在卡片内。 */
.modal > form {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.modal__header,
.modal__footer {
  flex: none;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal__title {
  font-size: 16px;
  font-weight: 600;
}

.modal__close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.modal__close:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.modal__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 20px 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
}

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  background: var(--bg-subtle);
  border-top: 1px solid var(--border-subtle);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

@media (max-height: 240px) {
  .modal-backdrop {
    align-items: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .modal {
    max-height: none;
  }
}

/* 轻提示 Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1200;
  max-width: 360px;
}

.toast {
  background: var(--text-primary);
  color: var(--text-inverse);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
}

.toast--success {
  background: #065f46;
}

.toast--danger {
  background: #9f1239;
}

/* 响应式两列网格 */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 640px) {
  .card__header,
  .card__body,
  .card__footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .toast-container {
    left: 12px;
    right: 12px;
    max-width: none;
  }
}
