/* ============================================================
   Portal v3 Components
   按钮 / 输入 / 卡片 / KPI / 表格 / 徽章 / Toast / 筛选条
   ============================================================ */

/* === 按钮 === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 var(--sp-5);
  border-radius: var(--r-ctrl);
  font-size: var(--fs-body);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-normal);
  border: 1px solid transparent;
  transition: all var(--tr-fast);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  font-family: inherit;
}

.btn svg { width: 16px; height: 16px; stroke-width: 2; }

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--text-on-primary);
  box-shadow: var(--shadow-btn);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-btn-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  background: var(--primary-active);
  transform: translateY(0);
}

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

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

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

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

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

.btn-danger:hover {
  background: #B91C1C;
}

.btn-success {
  background: var(--success);
  color: #FFFFFF;
}

.btn-sm {
  height: 32px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-body-sm);
  border-radius: var(--r-md);
}

.btn-lg {
  height: 48px;
  padding: 0 var(--sp-8);
  font-size: var(--fs-body-lg);
  border-radius: var(--r-md);
}

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

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
}

/* === 输入框 === */
.input,
.select,
.textarea {
  width: 100%;
  height: 40px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-ctrl);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: var(--fs-body);
  transition: all var(--tr-fast);
  outline: none;
  font-family: inherit;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-hover);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--border-focus);
  box-shadow: var(--ring);
}

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

.textarea {
  height: auto;
  min-height: 96px;
  padding: var(--sp-3);
  resize: vertical;
  line-height: var(--lh-normal);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  padding-right: 36px;
}

/* === 字段容器 === */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.field-label {
  font-size: var(--fs-caption);
  font-weight: var(--fw-medium);
  color: var(--text-tertiary);
  letter-spacing: var(--ls-wide);
}

.field-error {
  font-size: var(--fs-caption);
  color: var(--danger);
  margin-top: var(--sp-1);
}

/* === 卡片 === */
.card {
  background: var(--bg-card);
  border-radius: var(--r-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  transition: all var(--tr-base);
}

.card-pad {
  padding: var(--sp-6);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border);
}

.card-head-title {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-h3);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}

.card-head-title svg {
  width: 20px;
  height: 20px;
  color: var(--accent);
}

.card-head-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.card-body {
  padding: var(--sp-6);
}

/* === Hero 区域（标题+统计项）=== */
.hero {
  position: relative;
  padding: var(--sp-1) var(--sp-3) var(--sp-3);
  margin-bottom: var(--sp-4);
  overflow: visible;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--sp-6);
}

.hero-content {
  position: relative;
  z-index: 1;
  min-width: 0;
  flex: 0 0 auto;
  align-self: center;
}

.hero h1 {
  margin: 0 0 var(--sp-1);
  font-size: 28px;
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.hero .hero-sub {
  font-size: var(--fs-body);
  color: var(--text-tertiary);
  margin: 0;
  line-height: var(--lh-normal);
}

/* === KPI 卡片 === */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
}

.kpi-row.kpi-3 { grid-template-columns: repeat(3, 1fr); }
.kpi-row.kpi-5 { grid-template-columns: repeat(5, 1fr); }
.kpi-row.kpi-6 { grid-template-columns: repeat(6, 1fr); }

@media (max-width: 1280px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--r-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: var(--sp-5);
  transition: all var(--tr-base);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-height: 144px;
}

.kpi-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
  border-color: var(--border-hover);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-icon svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}

.kpi-icon.orange { background: var(--data-1-bg); color: var(--data-1); }
.kpi-icon.indigo { background: var(--data-2-bg); color: var(--data-2); }
.kpi-icon.emerald { background: var(--data-3-bg); color: var(--data-3); }
.kpi-icon.rose { background: var(--data-4-bg); color: var(--data-4); }

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-caption);
}

.kpi-trend.up { color: var(--success); background: var(--success-bg); }
.kpi-trend.down { color: var(--danger); background: var(--danger-bg); }
.kpi-trend.flat { color: var(--text-tertiary); background: var(--bg-hover); }

.kpi-trend svg { width: 12px; height: 12px; }

.kpi-label {
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  color: var(--text-tertiary);
  letter-spacing: var(--ls-wide);
}

.kpi-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: auto;
}

.kpi-num {
  font-size: var(--fs-data);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  letter-spacing: var(--ls-tight);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.kpi-unit {
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-regular);
  color: var(--text-tertiary);
}

/* === 统计卡片（statcards 风格，参考 review/statcards_group120_127.html） === */
.stat-card-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-left: auto;
}

.stat-card {
  width: 145px;
  height: 96px;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: transform var(--tr-base), box-shadow var(--tr-base);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-card:hover .stat-icon {
  transform: scale(1.08);
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--tr-base);
}

.stat-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stat-label {
  margin: 8px 0 0 0;
  font-size: 13px;
  font-weight: var(--fw-semibold);
  color: #3e435f;
  text-align: center;
  line-height: 1;
}

.stat-value {
  margin: 5px 0 0 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  line-height: 1.2;
}

.stat-num {
  font-size: 20px;
  font-weight: var(--fw-regular);
  color: #3e435f;
  letter-spacing: var(--ls-tight);
  font-variant-numeric: tabular-nums;
}

.stat-unit {
  font-size: 13px;
  font-weight: var(--fw-semibold);
  color: #3e435f;
}

/* ===== 统计卡片配色（与页面背景 #FFFBF5 对比）===== */
/* 蓝色系 - 靛蓝 */
.stat-card[data-tone="blue"]   { background: #DBEAFE; }
.stat-card[data-tone="blue"]   .stat-icon { background: #2563EB; }

/* 绿色系 - 翡翠 */
.stat-card[data-tone="green"]  { background: #D1FAE5; }
.stat-card[data-tone="green"]  .stat-icon { background: #059669; }

/* 橙色系 - 珊瑚 */
.stat-card[data-tone="coral"]  { background: #FED7AA; }
.stat-card[data-tone="coral"]  .stat-icon { background: #EA580C; }

/* 紫色系 - 紫罗兰 */
.stat-card[data-tone="indigo"] { background: #EDE9FE; }
.stat-card[data-tone="indigo"] .stat-icon { background: #7C3AED; }

/* 青色系 - 青瓷 */
.stat-card[data-tone="cyan"] { background: #CFFAFE; }
.stat-card[data-tone="cyan"] .stat-icon { background: #0891B2; }

@keyframes stat-pop {
  0% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}
.stat-value.pop { animation: stat-pop 0.5s ease-out both; }

@media (max-width: 760px) {
  .stat-card-row { gap: 16px; }
}

/* === 徽章 === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-caption);
  font-weight: var(--fw-semibold);
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.badge-primary { background: var(--accent-light); color: var(--accent); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-accent { background: var(--accent-light); color: var(--accent); }

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: currentColor;
}

/* === 筛选条 === */
.filter-bar {
  background: var(--bg-card);
  border-radius: var(--r-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-field-label {
  font-size: var(--fs-overline);
  font-weight: var(--fw-semibold);
  color: var(--text-tertiary);
  letter-spacing: var(--ls-wider);
  text-transform: uppercase;
}

.filter-field .input,
.filter-field .select {
  height: 36px;
  font-size: var(--fs-body-sm);
  min-width: 140px;
  border-radius: var(--r-md);
}

.filter-divider {
  width: 1px;
  height: 32px;
  background: var(--border);
}

/* === 日期选择单元格（双层 input：可见 text + 透明 date 覆盖） === */
/* 目的：强制显示 yyyy-mm-dd 格式，统一字号 15px，消除原生 date 在不同浏览器下 yyyy/mm/dd 的不一致 */
.date-cell {
  position: relative;
  width: 160px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.date-text {
  flex: 1;
  width: 0;
  height: 36px;
  padding: 0 var(--sp-3);
  padding-right: 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: var(--fs-body-sm);
  font-family: inherit;
  cursor: pointer;
  transition: all var(--tr-fast);
  box-sizing: border-box;
}

.date-text:hover { border-color: var(--border-hover); }
.date-text:focus { border-color: var(--border-focus); box-shadow: var(--ring); outline: 0; }
.date-text::placeholder { color: var(--text-placeholder); }

.date-real {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  z-index: 2;
}

.date-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-tertiary);
  pointer-events: none;
  flex-shrink: 0;
  transition: color var(--tr-fast);
}

.date-cell:hover .date-icon { color: var(--text-primary); }

.filter-break {
  flex-basis: 100%;
  height: 0;
  padding: 0;
  margin: 0;
}

.filter-actions {
  margin-left: auto;
  display: flex;
  gap: var(--sp-2);
}

/* === 分段按钮组（segmented control） === */
.seg {
  display: inline-flex;
  align-items: center;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}

.seg-item {
  height: 30px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  border-radius: 7px;
  cursor: pointer;
  transition: all var(--tr-fast);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.seg-item:hover { color: var(--text-primary); }
.seg-item.is-active {
  background: var(--bg-card);
  color: var(--accent);
  font-weight: var(--fw-semibold);
  box-shadow: 0 1px 2px rgba(31, 41, 55, 0.08);
}
.seg-item .dot {
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: currentColor;
  opacity: 0.55;
}
.seg-item.is-active .dot { opacity: 1; }
.seg-item.is-active.tone-has { color: var(--success); }
.seg-item.is-active.tone-zero { color: var(--text-quaternary); }

/* === 快捷日期 === */
.quick-dates {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.quick-date {
  height: 32px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--tr-fast);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
}

.quick-date:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.quick-date.active {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.30);
}

/* === 表格 === */
.table-wrap {
  background: var(--bg-card);
  border-radius: var(--r-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

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

.table thead th {
  background: var(--bg-subtle);
  padding: var(--sp-3) var(--sp-5);
  text-align: left;
  font-size: var(--fs-overline);
  font-weight: var(--fw-semibold);
  color: var(--text-tertiary);
  letter-spacing: var(--ls-wider);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table tbody td {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

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

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

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

.table .col-num { font-variant-numeric: tabular-nums; }
.table .col-actions { text-align: right; white-space: nowrap; }

.table-actions {
  display: inline-flex;
  gap: var(--sp-1);
}

.table-action {
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: all var(--tr-fast);
  cursor: pointer;
}

.table-action:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.table-action svg { width: 16px; height: 16px; }

.table-action.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* === 进度条 === */
.progress {
  height: 6px;
  background: var(--bg-hover);
  border-radius: var(--r-pill);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width var(--tr-slow);
}

.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }
.progress-bar.gradient {
  background: linear-gradient(90deg, var(--accent), var(--accent-active));
}

/* === 底部 ICP 备案（公共 layout.js buildFooter 注入） === */
.foot {
  padding: var(--sp-8) 0;
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--fs-caption);
  letter-spacing: var(--ls-normal);
}

.foot a {
  color: var(--text-tertiary);
  margin: 0 var(--sp-2);
  transition: color var(--tr-fast);
  text-decoration: none;
}

.foot a:hover {
  color: var(--accent);
}

/* === Toast === */
.toast-wrap {
  position: fixed;
  top: var(--sp-6);
  right: var(--sp-6);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 280px;
  max-width: 400px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-ctrl);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-popover);
  font-size: var(--fs-body-sm);
  animation: toast-in 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info { border-left: 3px solid var(--info); }

.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success svg { color: var(--success); }
.toast.error svg { color: var(--danger); }
.toast.warning svg { color: var(--warning); }
.toast.info svg { color: var(--info); }

.toast .toast-content {
  flex: 1;
  color: var(--text-primary);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* === Empty state === */
.empty {
  padding: var(--sp-12) var(--sp-6);
  text-align: center;
  color: var(--text-tertiary);
}

.empty .empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--sp-4);
  border-radius: var(--r-card);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-quaternary);
}

.empty .empty-icon svg { width: 32px; height: 32px; }

.empty .empty-title {
  font-size: var(--fs-body-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}

.empty .empty-desc {
  font-size: var(--fs-body-sm);
  color: var(--text-tertiary);
}
