/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #f0f2f5;
  color: #303133;
}

/* ===== Loading ===== */
.app-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
  color: #409eff;
}
.app-loading-spinner {
  width: 40px; height: 40px;
  border: 4px solid #dcdfe6;
  border-top-color: #409eff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Login Page ===== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.login-title {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  color: #303133;
  margin-bottom: 8px;
}
.login-subtitle {
  text-align: center;
  font-size: 14px;
  color: #909399;
  margin-bottom: 32px;
}
.login-form .el-button { width: 100%; }
.login-hint {
  margin-top: 20px;
  padding: 12px 16px;
  background: #f5f7fa;
  border-radius: 8px;
  font-size: 13px;
  color: #606266;
  line-height: 1.8;
}
.login-hint strong { color: #409eff; }

/* ===== Main Layout ===== */
.app-layout {
  height: 100vh;
}
.layout-aside {
  background: #001529;
  transition: width 0.3s;
  overflow-x: hidden;
}
.layout-logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  gap: 8px;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.layout-logo .logo-icon { font-size: 24px; }
.layout-aside .el-menu {
  border-right: none;
  background: #001529;
}
.layout-aside .el-menu-item {
  color: rgba(255,255,255,0.65);
}
.layout-aside .el-menu-item:hover {
  background: rgba(255,255,255,0.06) !important;
  color: #fff;
}
.layout-aside .el-menu-item.is-active {
  background: #409eff !important;
  color: #fff;
}

.layout-header {
  background: #fff;
  border-bottom: 1px solid #e8e8e8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  box-shadow: 0 1px 4px rgba(0,21,41,0.08);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-title {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #606266;
}
.header-user .role-tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: #ecf5ff;
  color: #409eff;
}
.menu-toggle-btn {
  padding: 6px !important;
}

.layout-main {
  background: #f0f2f5;
  padding: 20px;
  overflow-y: auto;
}

/* ===== Dashboard ===== */
.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}
.stat-icon {
  width: 56px; height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #fff;
  flex-shrink: 0;
}
.stat-icon.blue   { background: linear-gradient(135deg, #409eff, #66b1ff); }
.stat-icon.green  { background: linear-gradient(135deg, #67c23a, #85ce61); }
.stat-icon.orange { background: linear-gradient(135deg, #e6a23c, #ebb563); }
.stat-icon.purple { background: linear-gradient(135deg, #9b59b6, #b370c9); }
.stat-icon.red    { background: linear-gradient(135deg, #f56c6c, #f89898); }
.stat-info .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #303133;
  line-height: 1.2;
}
.stat-info .stat-label {
  font-size: 14px;
  color: #909399;
  margin-top: 4px;
}
.dashboard-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) {
  .dashboard-row { grid-template-columns: 1fr; }
}
.section-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Product Management ===== */
.product-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.product-toolbar .left { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.product-toolbar .right { display: flex; gap: 12px; }

.tree-node {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  width: 100%;
}
.tree-node-img {
  width: 36px; height: 36px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid #ebeef5;
  flex-shrink: 0;
}
.tree-node-img-placeholder {
  width: 36px; height: 36px;
  border-radius: 6px;
  background: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #c0c4cc;
  flex-shrink: 0;
  border: 1px dashed #dcdfe6;
}
.tree-node-label {
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-node-badge {
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}
.tree-node-badge.category { background: #ecf5ff; color: #409eff; }
.tree-node-badge.product  { background: #f0f9eb; color: #67c23a; }
.tree-node-badge.sub      { background: #fdf6ec; color: #e6a23c; }
.tree-node-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.tree-node-stock {
  font-size: 12px;
  color: #909399;
  flex-shrink: 0;
  margin-right: 8px;
}

.product-tree-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.product-tree-card .el-tree {
  background: transparent;
}
.product-tree-card .el-tree-node__content {
  height: auto !important;
  min-height: 48px;
  padding: 4px 0;
}

/* ===== Image Upload ===== */
.image-uploader {
  width: 120px;
  height: 120px;
  border: 1px dashed #dcdfe6;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: border-color 0.2s;
}
.image-uploader:hover { border-color: #409eff; }
.image-uploader img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.image-uploader .upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #c0c4cc;
  font-size: 13px;
}
.image-uploader .upload-placeholder .el-icon { font-size: 28px; }

/* ===== Tables ===== */
.table-image {
  width: 40px; height: 40px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid #ebeef5;
}
.table-image-placeholder {
  width: 40px; height: 40px;
  border-radius: 6px;
  background: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #c0c4cc;
  border: 1px dashed #dcdfe6;
}

/* ===== Stock Level ===== */
.stock-normal  { color: #67c23a; }
.stock-low     { color: #e6a23c; }
.stock-empty   { color: #f56c6c; }

/* ===== Export Page ===== */
.export-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  max-width: 700px;
  margin: 0 auto;
}
.export-option {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid #ebeef5;
  border-radius: 8px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.export-option:hover {
  border-color: #409eff;
  background: #f5f9ff;
}
.export-option .el-icon {
  font-size: 24px;
  color: #409eff;
}
.export-option-info { flex: 1; }
.export-option-info .title { font-weight: 600; font-size: 15px; }
.export-option-info .desc { font-size: 13px; color: #909399; margin-top: 4px; }

/* ===== Misc ===== */
.page-container {
  max-width: 1400px;
  margin: 0 auto;
}
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #909399;
}
.empty-state .el-icon { font-size: 48px; margin-bottom: 16px; }

/* ===== Payment Screenshot Uploader ===== */
.payment-uploader {
  width: 80px;
  height: 80px;
  border: 1px dashed #dcdfe6;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s;
}
.payment-uploader:hover { border-color: #409eff; }
.payment-uploader img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.upload-placeholder-sm {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #c0c4cc;
  font-size: 11px;
}
.upload-placeholder-sm .el-icon { font-size: 20px; }

/* ===== Records Dialog - Detail Bar ===== */
.records-detail-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 14px 16px;
  background: #f5f7fa;
  border-radius: 8px;
  margin-bottom: 12px;
}
.records-detail-item {
  font-size: 13px;
  color: #606266;
}
.records-detail-item .rd-label,
.rs-item .rd-label {
  color: #909399;
}

/* ===== Records Dialog - Supplier Section ===== */
.records-supplier-section {
  padding: 14px 16px;
  background: #fdf6ec;
  border: 1px solid #faecd8;
  border-radius: 8px;
  margin-bottom: 12px;
}
.records-supplier-title {
  font-size: 14px;
  font-weight: 600;
  color: #e6a23c;
  margin-bottom: 10px;
}
.records-supplier-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 24px;
}
.rs-item {
  font-size: 13px;
  color: #606266;
}

/* ===== Cascading Inventory (普通用户三级联动) ===== */
.cascading-inventory {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  min-height: 400px;
}
.cascade-column {
  flex: 1;
  min-width: 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cascade-column-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #303133;
  border-bottom: 1px solid #f0f0f0;
  background: #fafafa;
}
.cascade-column-header .el-icon {
  font-size: 16px;
  color: #409eff;
}
.cascade-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.cascade-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 4px;
}
.cascade-item:hover {
  background: #f5f9ff;
}
.cascade-item.active {
  background: #ecf5ff;
  border: 1px solid #b3d8ff;
}
.cascade-item-img {
  width: 40px; height: 40px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid #ebeef5;
  flex-shrink: 0;
}
.cascade-item-img-placeholder {
  width: 40px; height: 40px;
  border-radius: 6px;
  background: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #c0c4cc;
  flex-shrink: 0;
  border: 1px dashed #dcdfe6;
}
.cascade-item-name {
  font-size: 14px;
  color: #303133;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cascade-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cascade-item-stock {
  font-size: 12px;
  color: #909399;
}
.cascade-item-check {
  font-size: 14px;
  color: #409eff;
  flex-shrink: 0;
}
.cascade-empty {
  text-align: center;
  padding: 40px 20px;
  color: #c0c4cc;
  font-size: 13px;
}
.cascade-placeholder-col {
  display: flex;
  align-items: center;
  justify-content: center;
}
.cascade-placeholder {
  text-align: center;
  color: #c0c4cc;
}
.cascade-placeholder .el-icon {
  font-size: 36px;
  margin-bottom: 12px;
}
.cascade-placeholder p {
  font-size: 14px;
}

/* ===== Detail Panel (普通用户详情面板) ===== */
.detail-panel {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  overflow: hidden;
}
.detail-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid #f0f0f0;
}
.detail-panel-title {
  display: flex;
  align-items: center;
  gap: 16px;
}
.detail-panel-img {
  width: 64px; height: 64px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #ebeef5;
}
.detail-panel-img-placeholder {
  width: 64px; height: 64px;
  border-radius: 8px;
  background: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #c0c4cc;
  border: 1px dashed #dcdfe6;
}
.detail-panel-body {
  padding: 20px 24px;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.detail-grid-item {
  padding: 12px 16px;
  background: #f5f7fa;
  border-radius: 8px;
}
.dg-label {
  font-size: 12px;
  color: #909399;
  margin-bottom: 4px;
}
.dg-value {
  font-size: 15px;
  color: #303133;
  font-weight: 500;
}
.detail-payment-section {
  margin-top: 16px;
  padding: 16px;
  background: #f5f7fa;
  border-radius: 8px;
}

/* ===== Import Page ===== */
.import-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  max-width: 800px;
  margin: 0 auto;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c0c4cc; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #909399; }

/* ===== Mobile Responsive (< 768px) ===== */
@media (max-width: 767px) {
  /* Allow natural body scrolling on mobile — override fixed-height container */
  body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none;
  }
  .app-layout {
    height: auto !important;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .layout-main {
    overflow-y: visible !important;
    height: auto !important;
  }

  /* Layout */
  .layout-header {
    padding: 0 12px;
    height: 52px;
  }
  .header-title {
    font-size: 16px;
  }
  .header-right {
    gap: 4px;
  }
  .layout-main {
    padding: 12px;
  }
  .page-container {
    max-width: 100%;
  }

  /* Login */
  .login-card {
    padding: 28px 20px;
    width: 100%;
    max-width: 92vw;
    border-radius: 12px;
  }
  .login-title {
    font-size: 20px;
  }

  /* Dashboard */
  .dashboard-cards {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 16px;
  }
  .stat-card {
    padding: 16px;
    gap: 12px;
  }
  .stat-icon {
    width: 44px; height: 44px;
    font-size: 22px;
    border-radius: 10px;
  }
  .stat-info .stat-value {
    font-size: 22px;
  }
  .section-card {
    padding: 14px;
  }

  /* Cascading Inventory - Desktop hidden on mobile, mobile version below */
  .cascading-inventory {
    flex-direction: column;
    gap: 8px;
    min-height: auto;
  }

  /* Mobile Inventory Breadcrumb */
  .mobile-breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    margin-bottom: 10px;
  }
  .back-btn {
    padding: 4px !important;
    flex-shrink: 0;
  }
  .breadcrumb-path {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    font-size: 13px;
  }
  .breadcrumb-path::-webkit-scrollbar { display: none; }
  .breadcrumb-item {
    color: #409eff;
    cursor: pointer;
    flex-shrink: 0;
  }
  .breadcrumb-item.active {
    color: #303133;
    font-weight: 600;
    cursor: default;
  }
  .breadcrumb-sep {
    color: #c0c4cc;
    font-size: 12px;
    flex-shrink: 0;
  }

  /* Mobile Cascade Column */
  .mobile-cascade-column {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    overflow: hidden;
  }
  .mobile-cascade-column .cascade-list {
    padding: 6px;
  }
  .mobile-cascade-column .cascade-item {
    padding: 12px 10px;
  }
  .cascade-item-img,
  .cascade-item-img-placeholder {
    width: 44px; height: 44px;
  }

  /* Detail Panel */
  .detail-panel-header {
    padding: 14px 16px;
  }
  .detail-panel-img,
  .detail-panel-img-placeholder {
    width: 52px; height: 52px;
  }
  .detail-panel-body {
    padding: 14px 16px;
  }
  .detail-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Tables - horizontal scroll */
  .el-table {
    width: 100% !important;
    overflow-x: auto;
  }
  .el-table .el-table__inner-wrapper {
    min-width: 600px;
  }

  /* Forms */
  .el-form-item__label {
    font-size: 13px;
  }

  /* Product tree */
  .product-tree-card {
    padding: 12px;
  }
  .tree-node-img,
  .tree-node-img-placeholder {
    width: 32px; height: 32px;
  }

  /* Filter bar */
  .filter-bar {
    gap: 8px;
  }

  /* Import/Export cards */
  .import-card,
  .export-card {
    padding: 16px;
  }

  /* Records dialog supplier grid */
  .records-supplier-grid {
    grid-template-columns: 1fr;
  }

  /* Records detail bar */
  .records-detail-bar {
    gap: 10px;
    padding: 10px 12px;
  }

  /* Dialog full width on mobile */
  .el-dialog {
    width: 92vw !important;
    margin: 5vh auto !important;
  }

  /* Drawer menu */
  .layout-aside .el-menu-item {
    height: 48px;
    line-height: 48px;
  }
}
