/* ==========================================================================
   仓储与巡检多维综合管理系统 - 核心视觉与现代样式规范
   ========================================================================== */

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-rgb: 79, 70, 229;

  --secondary: #0ea5e9;
  --secondary-hover: #0284c7;

  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --info: #64748b;

  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-sub: #94a3b8;

  --border-color: #e2e8f0;
  --border-focus: #818cf8;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --sidebar-width: 250px;
  --header-height: 64px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}
a:hover {
  color: var(--primary-hover);
}

/* ================= 布局框架 ================= */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: #0f172a;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  transition: var(--transition);
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.logo-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
}
.logo-text span {
  font-size: 11px;
  color: #94a3b8;
  display: block;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #64748b;
  padding: 12px 12px 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: #94a3b8;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #f8fafc;
}
.nav-item.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}
.nav-item .icon {
  font-size: 18px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: #64748b;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top-navbar {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition);
}
.user-profile-badge:hover {
  background: #e2e8f0;
}

.avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #3b82f6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.content-body {
  padding: 24px;
  flex: 1;
}

/* ================= 卡片与统计 ================= */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.stat-info .stat-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
}
.stat-info .stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}
.stat-info .stat-sub {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 4px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}
.stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning); }
.stat-icon.danger { background: var(--danger-light); color: var(--danger); }

.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 20px;
}

/* ================= 表格系统 ================= */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13.5px;
}

table.data-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

table.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

table.data-table tbody tr {
  transition: var(--transition);
}
table.data-table tbody tr:hover {
  background-color: #f8fafc;
}

/* ================= 标签与徽章 ================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-admin { background: #fee2e2; color: #b91c1c; }
.badge-manager { background: #fef3c7; color: #b45309; }
.badge-user { background: #e0e7ff; color: #3730a3; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #e2e8f0; color: #334155; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.badge-locked { background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; }

/* ================= 按钮系统 ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: #059669;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

/* ================= 表单系统 ================= */
.form-group {
  margin-bottom: 18px;
}

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

.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

textarea.form-control {
  min-height: 90px;
  resize: vertical;
}

.form-row {
  display: flex;
  gap: 16px;
}
.form-row .form-group {
  flex: 1;
}

/* ================= 图片上传与拍照专用容器 ================= */
.image-upload-wrapper {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-lg);
  padding: 20px;
  background: #f8fafc;
  text-align: center;
  transition: var(--transition);
  position: relative;
}
.image-upload-wrapper.dragover {
  border-color: var(--primary);
  background: #eef2ff;
}

.upload-actions-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.paste-tip-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  margin-top: 6px;
}

.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.preview-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #000;
}
.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: var(--transition);
}
.preview-thumb:hover img {
  opacity: 0.85;
}
.preview-thumb .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(239, 68, 68, 0.9);
  color: #fff;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: var(--transition);
}
.preview-thumb .remove-btn:hover {
  background: #dc2626;
  transform: scale(1.1);
}

/* ================= 模态弹窗 Modal ================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
  padding: 20px;
}
.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-container {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  transform: translateY(20px) scale(0.98);
  transition: var(--transition);
  overflow: hidden;
}
.modal-overlay.active .modal-container {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
}
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-sub);
  cursor: pointer;
}
.modal-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: #f8fafc;
}

/* ================= 拍照捕获 Modal 样式 (全局最高层级，确保在多层弹窗之上) ================= */
#cameraModal {
  z-index: 9999 !important;
}
#cameraModal .modal-container {
  z-index: 10000 !important;
  box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.7);
}

.camera-view-container {
  width: 100%;
  height: 340px;
  min-height: 260px;
  max-height: 55vh;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.camera-view-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ================= Toast 通知 ================= */
#toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 12px 20px;
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 280px;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ================= 移动端菜单按钮与抽屉遮罩 ================= */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border-color);
  font-size: 18px;
  cursor: pointer;
  color: var(--text-main);
  padding: 6px 10px;
  line-height: 1;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
}
.mobile-menu-toggle:hover {
  background: var(--bg-input);
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 95;
  transition: opacity 0.25s ease;
  opacity: 0;
  pointer-events: none;
}
.sidebar-backdrop.active {
  display: block;
  opacity: 1;
  pointer-events: auto;
}
.sidebar-close-btn {
  display: none;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 26px;
  cursor: pointer;
  margin-left: auto;
  line-height: 1;
  padding: 4px 8px;
}
.sidebar-close-btn:hover {
  color: #ffffff;
}

/* 响应式仪表盘分割网格 */
.dashboard-split-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
}

/* ================= 移动端与全终端响应式适配 ================= */
@media (max-width: 992px) {
  .dashboard-split-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

@media (max-width: 900px) {
  .mobile-menu-toggle {
    display: inline-flex;
  }
  .sidebar-close-btn {
    display: block;
  }
  .sidebar {
    transform: translateX(-100%);
    z-index: 100;
    width: 270px;
    max-width: 82vw;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.35);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
    width: 100%;
    min-width: 0;
  }
  .form-row {
    flex-direction: column;
    gap: 0;
  }
}

@media (max-width: 768px) {
  :root {
    --header-height: 58px;
  }
  
  body {
    font-size: 14px;
  }

  .hide-mobile {
    display: none !important;
  }
  .show-mobile {
    display: inline-block !important;
  }

  /* 顶部导航自适应 */
  .top-navbar {
    padding: 0 12px;
  }
  .page-title {
    font-size: 15px;
    font-weight: 700;
    gap: 6px;
  }
  .nav-actions {
    gap: 6px;
  }
  .user-profile-badge {
    padding: 4px 8px;
    gap: 6px;
  }
  .user-profile-badge #topRoleBadge {
    display: none;
  }

  /* 主体内容内边距 */
  .content-body {
    padding: 12px 8px;
  }
  
  /* 前台容器 */
  .portal-container {
    padding: 10px 8px;
  }
  .portal-nav {
    padding: 12px 14px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .profile-hero {
    padding: 18px 14px;
    margin-bottom: 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }
  .profile-details {
    gap: 14px;
  }
  .profile-avatar {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
  .profile-stats-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
  }
  .profile-stat-box {
    padding: 8px 10px;
  }
  .profile-stat-box .val {
    font-size: 18px;
  }

  /* 选项卡栏触控横向平滑滚动 */
  .tab-bar {
    overflow-x: auto;
    white-space: nowrap;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
    margin-bottom: 14px;
  }
  .tab-bar::-webkit-scrollbar {
    display: none;
  }
  .tab-item {
    flex-shrink: 0;
    padding: 8px 13px;
    font-size: 13.5px;
  }

  /* 统计卡片网格移动端自适应 (手机端双列整齐排布) */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
  .stat-card {
    padding: 12px 10px;
  }
  .stat-info .stat-value {
    font-size: 19px;
  }
  .stat-info .stat-label {
    font-size: 11.5px;
  }
  .stat-info .stat-sub {
    font-size: 10px;
  }
  .stat-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  /* 筛选工具栏响应式 */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .filter-bar > * {
    width: 100% !important;
    min-width: 0 !important;
  }
  .filter-bar .btn {
    justify-content: center;
  }

  /* 表格响应式横向滑动 */
  .table-responsive {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    -webkit-overflow-scrolling: touch;
    width: 100%;
    overflow-x: auto;
  }
  .data-table th, .data-table td {
    padding: 10px 8px;
    font-size: 12.5px;
    white-space: nowrap;
  }

  /* 弹窗全屏/大屏自适应，杜绝超屏截断 */
  .modal-overlay {
    padding: 8px;
    align-items: center;
    justify-content: center;
  }
  .modal-container {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh;
    border-radius: 14px;
    margin: 0;
  }
  .modal-header {
    padding: 14px 16px;
  }
  .modal-title {
    font-size: 15px;
  }
  .modal-body {
    padding: 14px 16px;
    max-height: calc(92vh - 110px);
  }
  .modal-footer {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .modal-footer .btn {
    flex: 1;
    min-width: 80px;
    justify-content: center;
  }

  /* 移动端防止输入框获取焦点时页面被自动放大 (iOS 16px准则) */
  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="datetime-local"],
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Toast 消息在移动端居顶充满 */
  #toast-container {
    top: 10px;
    left: 10px;
    right: 10px;
    width: auto;
  }
  .toast {
    min-width: 0;
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .top-navbar .nav-actions .btn {
    padding: 4px 7px;
    font-size: 11px;
  }
  .user-profile-badge {
    padding: 2px 6px;
  }
  .avatar-circle {
    width: 26px;
    height: 26px;
    font-size: 11px;
  }
}
