/**
 * Z-Claw 设计系统基础层
 * 统一 Token、无障碍、排版、组件状态、动效安全
 * 加载顺序：在 admin-responsive.css 之后
 */

/* ========== 1. Design Tokens ========== */
:root {
  /* --- 排版标尺 (1.25 ratio) --- */
  --text-xs: 0.75rem;    /* 12px - 辅助说明 */
  --text-sm: 0.8125rem;  /* 13px - 次要信息 */
  --text-base: 0.875rem; /* 14px - 正文（后台适配） */
  --text-lg: 1rem;       /* 16px - 强调正文 */
  --text-xl: 1.25rem;    /* 20px - 小标题 */
  --text-2xl: 1.5rem;    /* 24px - 卡片标题 */
  --text-3xl: 1.875rem;  /* 30px - 页面标题 */
  --text-4xl: 2.25rem;   /* 36px - 大标题 */

  /* --- 字重 --- */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* --- 间距标尺 (4px base) --- */
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */

  /* --- 语义色 --- */
  --color-primary: #5f7cff;
  --color-primary-hover: #4a65e6;
  --color-primary-light: rgba(95, 124, 255, 0.1);

  --color-success: #43a047;
  --color-success-light: rgba(67, 160, 71, 0.1);
  --color-warning: #f57c00;
  --color-warning-light: rgba(245, 124, 0, 0.1);
  --color-danger: #e53935;
  --color-danger-light: rgba(229, 57, 53, 0.1);
  --color-info: #1e88e5;
  --color-info-light: rgba(30, 136, 229, 0.1);

  /* --- 中性色 --- */
  --color-text: #1e293b;
  --color-text-secondary: #475569;
  --color-text-muted: #64748b;
  --color-text-placeholder: #94a3b8;
  --color-border: #e2e8f0;
  --color-border-light: #f1f5f9;
  --color-surface: #ffffff;
  --color-surface-raised: #f8fafc;
  --color-bg: #f4f7fb;

  /* --- 焦点环 --- */
  --focus-ring-color: rgba(95, 124, 255, 0.45);
  --focus-ring-offset: 2px;
  --focus-ring-width: 2px;

  /* --- 圆角 --- */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* --- 阴影 --- */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.12);

  /* --- 动效 --- */
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
}


/* ========== 2. 无障碍：Focus Visible (P0) ========== */

/* 恢复所有可交互元素的焦点指示器 */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
.btn:focus-visible,
.form-control:focus-visible,
.nav-tabs > li > a:focus-visible,
.sidebar-menu a:focus-visible,
.dropdown-menu a:focus-visible,
.select2-container:focus-visible,
.bootstrap-select .btn:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
  box-shadow: none;
}

/* 鼠标点击时不显示焦点环 */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
.btn:focus:not(:focus-visible),
.nav-tabs > li > a:focus:not(:focus-visible),
.sidebar-menu a:focus:not(:focus-visible) {
  outline: none;
}

/* 覆盖各页面内联 outline:none —— 键盘导航时必须可见 */
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
button:focus-visible,
[contenteditable]:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color) !important;
  outline-offset: var(--focus-ring-offset) !important;
}

/* 表单元素 focus 增强 —— 保持原有边框色，叠加外环 */
.form-control:focus-visible {
  border-color: var(--color-primary);
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: -1px;
}


/* ========== 3. 动效安全 (P0) ========== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* ========== 4. 排版修正 ========== */

/* 后台全局字体栈统一 */
body {
  font-family: "IBM Plex Sans", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

/* 最小字号保底 */
.admin-responsive.screen-tight {
  --admin-font-size: 12px;
  --admin-small-font-size: 12px;
}


/* ========== 5. Dashboard 统计卡片优化 ========== */

/* 统计卡片 - 从 float 迁移到 flexbox */
.sm-st {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  transition: box-shadow var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

.sm-st:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.sm-st-icon {
  width: 52px;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border-radius: var(--radius-lg);
  float: none;
  flex-shrink: 0;
  margin-right: 0;
  color: #fff;
}

.sm-st-info {
  padding-top: 0;
  flex: 1;
  min-width: 0;
}

.sm-st-info span {
  display: block;
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  line-height: 1.2;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

/* 统计图标颜色 - 增加文字标注（通过 aria-label 已有文字辅助） */
.st-red   { background: linear-gradient(135deg, #ef5350, #e53935); }
.st-green { background: linear-gradient(135deg, #66bb6a, #43a047); }
.st-violet{ background: linear-gradient(135deg, #7e57c2, #5e35b1); }
.st-blue  { background: linear-gradient(135deg, #42a5f5, #1e88e5); }


/* ========== 6. 底部渐变统计面板优化 ========== */

#statistics .panel {
  border: none;
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

#statistics .panel:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

#statistics .panel h5 {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  opacity: 0.9;
}

#statistics .panel h1 {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  font-variant-numeric: tabular-nums;
}

#statistics .panel .font-bold small {
  font-size: var(--text-xs);
}


/* ========== 7. 右侧统计列 ========== */

.stats .stat-icon {
  color: var(--color-primary);
  font-size: 22px;
  width: 44px;
}

.stat .value {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  line-height: 1.3;
  color: var(--color-text);
}

.stat .name {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

.stat-col .progress {
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--color-border-light);
  margin-top: var(--space-2);
}


/* ========== 8. 表格行 hover ========== */

.bootstrap-table .table > tbody > tr:hover > td,
.bootstrap-table .table > tbody > tr:hover > th {
  background-color: rgba(95, 124, 255, 0.04);
  transition: background-color var(--duration-fast) var(--ease-out);
}


/* ========== 9. 按钮状态补全 ========== */

.btn {
  transition: background var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

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

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* 主按钮 hover 增强 */
.btn-primary:hover {
  background-color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  box-shadow: var(--shadow-sm);
}


/* ========== 10. 表单错误/成功状态 ========== */

.form-group.has-error .form-control {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 3px var(--color-danger-light);
}

.form-group.has-error .help-block,
.form-group.has-error .control-label {
  color: var(--color-danger);
}

.form-group.has-success .form-control {
  border-color: var(--color-success);
  box-shadow: 0 0 0 3px var(--color-success-light);
}


/* ========== 11. 页面加载骨架动画 ========== */

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.skeleton {
  background: linear-gradient(90deg,
    var(--color-border-light) 25%,
    #e2e8f0 37%,
    var(--color-border-light) 63%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.8s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  width: 80%;
}

.skeleton-title {
  height: 24px;
  margin-bottom: 12px;
  width: 40%;
}

.skeleton-card {
  height: 80px;
  border-radius: var(--radius-lg);
}


/* ========== 12. iframe 加载指示器 ========== */

.content-wrapper .tab-pane {
  position: relative;
}

.content-wrapper .tab-pane iframe {
  transition: opacity var(--duration-normal) var(--ease-out);
}

/* 标签页内容切换淡入 */
.tab-content > .tab-pane {
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-out);
}

.tab-content > .tab-pane.active {
  opacity: 1;
}


/* ========== 13. 对比度修正 ========== */

/* 确保次要文字对比度达标（#888/#999/#bbb/#ccc 在白底上不足 4.5:1） */
.text-muted,
.help-block {
  color: var(--color-text-muted) !important;
}

/* 常见低对比度灰色 → 提升到 WCAG AA 达标值 */
.stat-label,
.depot-stat-label,
.stock-board-stat-label,
.retail-summary-stat-label,
.cps-summary-stat-label,
.order-settle-stat-label,
.cps-settle-stat-label,
.fin-depot-stat-label {
  color: #5f6368 !important;
}

/* 图标型统计数字的颜色增强 */
.stats .stat-icon i {
  color: var(--color-primary);
}


/* ========== 14. 链接颜色对比度修正 ========== */

a {
  color: #3366cc;
}

a:hover,
a:active {
  color: #1a4fa0;
}


/* ========== 15. 全局表格兜底 ========== */

/* 表头：无自定义样式的页面也有统一背景和字重 */
.bootstrap-table .table > thead > tr > th,
.fixed-table-header th {
  background: #f7f7f7;
  font-weight: 600;
  color: #444;
  border-bottom: 1px solid #e8e8e8;
  vertical-align: middle !important;
}

/* 行内容垂直居中 */
.bootstrap-table .table > tbody > tr > td {
  vertical-align: middle !important;
}

/* hover 行高亮 */
.bootstrap-table .table > tbody > tr:hover > td {
  background-color: #f9faff;
}

/* 操作列按钮圆角统一为 3px */
.bootstrap-table td .btn-xs {
  border-radius: 3px;
}
