/* OKR 系统 v2 - 全局样式 */
/* 设计原则：简洁、高效、企业微信WebView完全兼容 */

/* 不使用 Google Fonts CDN，避免企业微信WebView网络不通时阻塞CSS加载 */
/* 字体回退到系统字体即可 */

:root {
  --primary: #1E40AF;
  --primary-light: #2563EB;
  --primary-lighter: #60A5FA;
  --primary-bg: #EFF6FF;
  --success: #059669;
  --success-bg: #D1FAE5;
  --warning: #D97706;
  --warning-bg: #FEF3C7;
  --danger: #DC2626;
  --danger-bg: #FEE2E2;
  --purple: #7C3AED;
  --purple-bg: #F3E8FF;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', 'PingFang SC', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ─── 布局 ─────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: white;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
}

.sidebar-logo-text {
  font-weight: 700;
  font-size: 16px;
  color: var(--gray-900);
}

/* 导航 */
.sidebar-nav {
  padding: 12px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--gray-500);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--gray-50);
  color: var(--gray-700);
}

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

.nav-item i {
  width: 20px;
  text-align: center;
  font-size: 15px;
}

/* 侧边栏底部用户信息 */
.sidebar-user {
  padding: 16px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-lighter), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: 600;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-800);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-role {
  font-size: 12px;
  color: var(--gray-400);
}

.sidebar-logout {
  color: var(--gray-400);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
}

.sidebar-logout:hover {
  color: var(--gray-600);
}

/* 主内容区 */
.main-area {
  margin-left: 240px;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 顶部栏 */
.top-bar {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
}

.top-bar-subtitle {
  font-size: 13px;
  color: var(--gray-400);
  margin-top: 2px;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

/* 页面内容 */
.page-content {
  padding: 24px;
  flex: 1;
}

/* ─── 组件 ─────────────────────────────────────────── */

/* 卡片 */
.card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 20px;
}

.card-header {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-100);
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1.5;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-light);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-secondary:hover {
  background: var(--gray-200);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 13px;
  border-radius: 6px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--primary-light);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
}

.btn-text:hover {
  color: var(--primary);
}

.btn-text-danger {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
}

/* 表单 */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 14px;
  color: var(--gray-800);
  background: white;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* 表格 */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--gray-200);
  background: var(--gray-50);
}

.data-table td {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
}

.data-table tr:hover td {
  background: var(--gray-50);
}

/* 统计卡片 */
.stat-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 20px;
}

.stat-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  margin-bottom: 12px;
}

.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1;
}

.stat-card-label {
  font-size: 13px;
  color: var(--gray-400);
  margin-top: 4px;
}

/* 标签 */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.badge-blue { background: var(--primary-bg); color: var(--primary); }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-yellow { background: var(--warning-bg); color: var(--warning); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray { background: var(--gray-100); color: var(--gray-500); }

/* 进度条 */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--primary-light);
  transition: width 0.3s ease;
}

/* 弹窗遮罩 - 使用visibility代替display */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s;
}

.modal-overlay.show {
  visibility: visible;
  opacity: 1;
}

.modal-box {
  background: white;
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  transform: translateY(20px);
  transition: transform 0.2s;
}

.modal-overlay.show .modal-box {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--gray-900);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--gray-100);
  color: var(--gray-500);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--gray-200);
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--gray-100);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  padding: 10px 20px;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.show {
  opacity: 1;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-400);
}

.empty-state i {
  font-size: 40px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 15px;
}

/* 网格 */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.ml-auto { margin-left: auto; }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--gray-400); }
.text-primary { color: var(--primary-light); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 加载中 */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--gray-400);
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── 移动端适配 ─────────────────────────────────────────── */

/* 移动端菜单按钮（默认隐藏） */
.mobile-menu-btn {
  display: none !important;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--gray-300);
  background: white;
  color: var(--gray-600);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
}

/* 侧边栏遮罩层 */
.mobile-sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

/* 底部标签栏（默认隐藏） */
.bottom-tab-bar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-top: 1px solid var(--gray-200);
  z-index: 100;
  padding: 4px 0;
  padding-bottom: env(safe-area-inset-bottom, 4px);
  -webkit-tap-highlight-color: transparent;
}

.bottom-tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 0;
  text-decoration: none;
  color: var(--gray-400);
  font-size: 10px;
  cursor: pointer;
  position: relative;
}

.bottom-tab-item i {
  font-size: 20px;
  line-height: 1;
}

.bottom-tab-item.active {
  color: var(--primary);
}

.bottom-tab-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 0;
  text-decoration: none;
  color: white;
  cursor: pointer;
}

.bottom-tab-center-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(30,64,175,0.35);
  margin-top: -22px;
}

.bottom-tab-center-btn i {
  font-size: 20px;
  color: white;
}

.bottom-tab-center span {
  font-size: 10px;
  color: var(--gray-500);
}

/* 更多菜单弹出层 */
.bottom-more-menu {
  display: none;
  position: fixed;
  bottom: 60px; left: 0; right: 0;
  background: white;
  border-top: 1px solid var(--gray-200);
  border-radius: 16px 16px 0 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 101;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
}

.bottom-more-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-radius: 8px;
  color: var(--gray-700);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.bottom-more-item:active {
  background: var(--gray-50);
}

.bottom-more-item i {
  width: 28px;
  text-align: center;
  font-size: 16px;
  color: var(--gray-500);
}

/* 手机端响应式 */
@media (max-width: 768px) {
  /* 侧边栏 */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 200;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* 遮罩 */
  .mobile-sidebar-overlay {
    display: none;
  }
  .mobile-sidebar-overlay.show {
    display: block;
  }

  /* 主内容区 */
  .main-area {
    margin-left: 0;
    padding-bottom: 70px; /* 给底部标签栏留空间 */
  }

  /* 显示底部标签栏 */
  .bottom-tab-bar {
    display: flex;
  }

  /* 显示汉堡按钮 */
  .mobile-menu-btn {
    display: flex !important;
  }

  /* 顶部栏 */
  .top-bar {
    padding: 12px 16px;
  }
  .top-bar h1 {
    font-size: 18px;
  }
  .top-bar-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .search-box input {
    width: 100% !important;
  }
  .search-results {
    width: calc(100vw - 32px) !important;
    left: 16px !important;
    right: 16px !important;
  }

  /* 网格 */
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }

  /* 内容区 */
  .page-content { padding: 12px; }

  /* 卡片 */
  .card { padding: 16px; }
  .stat-card { padding: 16px; }
  .stat-card-value { font-size: 24px; }

  /* 表格横向滚动 */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 13px;
  }

  /* 弹窗全屏化 */
  .modal-box {
    width: 95%;
    max-width: none;
    max-height: 90vh;
    border-radius: 12px;
    padding: 20px;
  }

  /* Toast位置上移 */
  .toast {
    bottom: 80px;
  }
}

/* 超小屏幕 */
@media (max-width: 375px) {
  .grid-4 { grid-template-columns: 1fr; }
  .stat-card-value { font-size: 20px; }
  .top-bar h1 { font-size: 16px; }
}

/* ─── 系统异常弹窗 ──────────────────────────────────── */
.sys-error-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: sysErrorFadeIn 0.2s ease;
}
@keyframes sysErrorFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sys-error-dialog {
  background: #fff;
  border-radius: 12px;
  padding: 32px 36px 24px;
  max-width: 460px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: sysErrorSlideIn 0.25s ease;
}
@keyframes sysErrorSlideIn {
  from { transform: translateY(-30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sys-error-icon {
  font-size: 48px;
  color: #F59E0B;
  margin-bottom: 8px;
  line-height: 1;
}

.sys-error-title {
  font-size: 18px;
  font-weight: 700;
  color: #1F2937;
  margin: 0 0 12px;
}

.sys-error-msg {
  font-size: 14px;
  color: #6B7280;
  line-height: 1.7;
  margin: 0 0 20px;
  text-align: left;
  padding: 12px;
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-radius: 8px;
  word-break: break-word;
}

.sys-error-btn {
  background: #3B82F6;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 32px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.sys-error-btn:hover {
  background: #2563EB;
}
