﻿/* ============================================
   components.css
   企业级后台组件体系（专业版）
   ============================================ */

/* --------------------------------------------
   1. 按钮组件（Button）
-------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: all 0.15s ease-in-out;
  background: #fff;
  color: var(--color-text);
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 主按钮 */
.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

/* 次按钮 */
.btn-secondary {
  background: #fff;
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-secondary:hover {
  background: #fafafa;
}

/* 危险按钮 */
.btn-danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: #fff;
}
.btn-danger:hover {
  background: #d9363e;
}

/* 小尺寸按钮 */
.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* 大尺寸按钮 */
.btn-lg {
  padding: 8px 18px;
  font-size: 15px;
}

/* --------------------------------------------
   2. 输入框组件（Input）
-------------------------------------------- */
.input {
  width: 100%;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: #fff;
}

.input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.15);
}

.input[disabled] {
  background: #f5f5f5;
  cursor: not-allowed;
}

/* --------------------------------------------
   3. 下拉框（Select）
-------------------------------------------- */
.select {
  width: 100%;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
  background: #fff;
  cursor: pointer;
}

/* --------------------------------------------
   4. 标签组件（Tag）
-------------------------------------------- */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-md);
  font-size: 12px;
  white-space: nowrap;
}

.tag-success { background: #f6ffed; color: #389e0d; }
.tag-warning { background: #fff7e6; color: #d48806; }
.tag-danger  { background: #fff1f0; color: #cf1322; }
.tag-info    { background: #e6f7ff; color: #1677ff; }

/* --------------------------------------------
   5. 卡片组件（Card）
-------------------------------------------- */
.card {
  background: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-card);
  border: 1px solid #f0f0f0;
}

.card-header {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.card-body {
  padding-top: 4px;
}

/* --------------------------------------------
   6. 弹窗组件（Modal）
-------------------------------------------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal {
  width: 420px;
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 20px;
}

.modal-header {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

/* --------------------------------------------
   8. 表单项（FormItem）
-------------------------------------------- */
.form-item {
  margin-bottom: 16px;
}

.form-item label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--color-text-light);
}

/* --------------------------------------------
   9. 栅格布局（Grid）
-------------------------------------------- */
.row {
  display: flex;
  gap: 16px;
}

.col-6 { width: 50%; }
.col-4 { width: 33.33%; }
.col-3 { width: 25%; }

/* --------------------------------------------
   10. 交互规范（Interaction Rules）
-------------------------------------------- */

/* 按钮 hover */
.btn:hover:not([disabled]) {
  filter: brightness(0.95);
}

/* 输入框 hover */
.input:hover:not([disabled]) {
  border-color: var(--color-primary);
}

/* 表格行 hover */
.table tbody tr:hover {
  background: #f5f7fa;
}

/* 卡片 hover（可选） */
.card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* 按钮 active（按下） */
.btn:active:not([disabled]) {
  transform: translateY(1px);
  filter: brightness(0.9);
}

/* 按钮 disabled（禁用） */
.btn[disabled],
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* 按钮 loading（加载中） */
.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.8;
}

.btn-loading::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  position: absolute;
  right: 10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 输入框 focus（聚焦） */
.input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.15);
}

/* 全局过渡动画（Transitions） */
.btn,
.input,
.card,
.tag {
  transition: all 0.15s ease-in-out;
}

/* --------------------------------------------
   11. 图标体系（Icon System）
-------------------------------------------- */

.icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  stroke-width: 2;
}

/* 按钮内图标 */
.btn .icon {
  margin-right: 6px;
}

/* 表格操作列图标 */
.actions .icon {
  margin-right: 8px;
  cursor: pointer;
}
.actions .icon:hover {
  opacity: 0.7;
}

/* 侧边栏图标 */
.nav-item .icon {
  width: 20px;
  height: 20px;
  margin-right: 10px;
}
.nav-item.active .icon {
  color: var(--color-primary);
}

/* 顶部导航图标 */
.topbar-icon {
  width: 20px;
  height: 20px;
  cursor: pointer;
}
.topbar-icon:hover {
  opacity: 0.7;
}

/* --------------------------------------------
   12. 页面状态体系（Page States System）
-------------------------------------------- */

.state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-light);
}

.state-icon {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: #fff3f3;
  color: #ff4d4f;
}

.state-icon i {
  width: 36px;
  height: 36px;
}

.state-content {
  max-width: 420px;
  margin: 0 auto;
}

.state-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 8px;
}

.state-desc {
  font-size: 14px;
  color: var(--color-text-light);
  margin-bottom: 20px;
}

.state-actions .btn {
  padding: 6px 14px;
  font-size: 13px;
}

/* Loading Spinner（保留原有 Loading 能力） */
.state-loading .spinner {
  width: 36px;
  height: 36px;
  border: 4px solid #ddd;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error 状态（可按需继续细化） */
.state-error .state-icon {
  background: #fff1f0;
  color: #cf1322;
}

/* No Permission 状态（专门为 state_no_permission.php 服务） */
.state-no-permission .state-icon {
  background: #fff7e6;
  color: #d48806;
}

/* ================================
 Section Error（局部错误组件）
 ================================ */
.section-error {
  position: absolute;
  inset: 0;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #d9363e;
  font-size: 14px;
  gap: 6px;
  z-index: 20;
}

/* ================================
   Global Loading
================================ */

.global-loading {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 9999;
}

.global-loading .loader {
  width: 40px;
  height: 40px;
  border: 4px solid #ddd;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.global-loading.show {
  display: flex;
}

/* ================================
   Section Loading
================================ */

.section-loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.section-loading .loader {
  width: 28px;
  height: 28px;
  border: 3px solid #ddd;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.section-loading.show {
  display: flex;
}

/* ================================
   Button Loading
================================ */

.btn-loading .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 6px;
}

/* ================================
   Table Skeleton Loading
================================ */

.table-skeleton {
  width: 100%;
  padding: 12px;
}

.skeleton-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.skeleton-cell {
  height: 16px;
  background: linear-gradient(
    90deg,
    #f2f2f2 0%,
    #e6e6e6 50%,
    #f2f2f2 100%
  );
  background-size: 200% 100%;
  border-radius: 4px;
  animation: skeleton-loading 1.2s ease-in-out infinite;
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --------------------------------------------
   13. 通知体系（Toast / Message / Alert）
-------------------------------------------- */

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  top: 20px;
  background: #fff;
  padding: 12px 16px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  animation: toast-in 0.3s ease;
  z-index: 9999;
}

.toast-success { border-left: 4px solid #4caf50; }
.toast-error { border-left: 4px solid #f44336; }
.toast-info { border-left: 4px solid #2196f3; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Message */
.message {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  border-radius: 4px;
  margin-bottom: 16px;
}

.message-success { background: #e8f5e9; color: #2e7d32; }
.message-error { background: #ffebee; color: #c62828; }
.message-info { background: #e3f2fd; color: #1565c0; }

/* Alert */
.alert {
  padding: 14px 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 14px;
}

.alert-warning { background: #fff8e1; color: #f9a825; }
.alert-info { background: #e3f2fd; color: #1565c0; }

/* --------------------------------------------
   14. 弹窗体系（Modal / Dialog）
-------------------------------------------- */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9998;
}

.modal.show {
  display: block;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  animation: fade-in 0.2s ease;
}

.modal-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 420px;
  background: #fff;
  border-radius: 8px;
  transform: translate(-50%, -50%);
  animation: modal-in 0.25s ease;
  overflow: hidden;
}

@keyframes modal-in {
  from { opacity: 0; transform: translate(-50%, -48%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  font-size: 14px;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --------------------------------------------
   16. 表单体系（Form System）
-------------------------------------------- */

.form-group {
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
}

.form-label {
  width: 120px;
  font-size: 14px;
  color: #555;
  padding-top: 6px;
}

.form-label .required {
  color: #f44336;
  margin-left: 2px;
}

.form-control-wrapper {
  flex: 1;
}

.form-input,
.form-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 4px;
  border: 1px solid #ddd;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fff;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.15);
}

.form-help {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
}

.form-error {
  font-size: 12px;
  color: #f44336;
  margin-top: 4px;
}

.form-group.has-error .form-input,
.form-group.has-error .form-select {
  border-color: #f44336;
}

/* Switch */
.form-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.form-switch input {
  display: none;
}

.form-switch-slider {
  width: 40px;
  height: 20px;
  background: #ccc;
  border-radius: 20px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.form-switch-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.form-switch input:checked + .form-switch-slider {
  background: var(--color-primary);
}

.form-switch input:checked + .form-switch-slider::before {
  transform: translateX(20px);
}

/* Checkbox */
.form-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 14px;
}

.form-checkbox input {
  display: none;
}

.checkbox-mark {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid #ccc;
  position: relative;
}

.form-checkbox input:checked + .checkbox-mark {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.form-checkbox input:checked + .checkbox-mark::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* Radio */
.form-radio-group {
  display: flex;
  gap: 16px;
}

.form-radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 14px;
}

.form-radio input {
  display: none;
}

.radio-mark {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #ccc;
  position: relative;
}

.form-radio input:checked + .radio-mark {
  border-color: var(--color-primary);
}

.form-radio input:checked + .radio-mark::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--color-primary);
}

.hidden {
    display: none !important;
}

.global-error {
    display: none;
}

