/* 全局样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #f0f4f8 0%, #d9e2ec 100%);
  color: #333;
  line-height: 1.6;
  overflow: hidden; /* 防止出现滚动条 */
}

/* 容器和整体布局 */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.8rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  height: 100vh; /* 固定高度为视窗高度 */
}

.header {
  text-align: center;
  padding: 0.8rem 0;
  margin-bottom: 0.8rem;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.header h1 {
  color: #2b3e50;
  font-size: 1.6rem;
  font-weight: 700;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

/* 主要内容区域 */
.main-content {
  display: flex;
  gap: 0.8rem;
  flex: 1;
  min-height: 0; /* 允许flex子项收缩小于内容大小 */
}

/* 左侧面板 - 上传区域和已上传列表 */
.left-panel {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 50%;
}

/* 右侧面板 - 设置区域 */
.right-panel {
  width: 50%;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

/* 上传区域 */
.upload-section {
  background: white;
  border-radius: 10px;
  padding: 0.8rem;
  box-shadow: 0 4px 12px rgba(50, 88, 148, 0.12);
  border: 1px solid #e0e8f0;
  display: flex;
  flex-direction: column;
  height: calc(50% - 0.4rem); /* 使两个左侧框高度一致 */
}

.upload-area {
  border: 2px dashed #5fa8e5;
  border-radius: 6px;
  padding: 1rem;
  text-align: center;
  background: #f9fcff;
  transition: all 0.3s ease;
  cursor: pointer;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.upload-area:hover {
  border-color: #2b6cb0;
  background: #edf7ff;
}

.upload-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 0.8rem;
  opacity: 0.7;
}

.upload-area p {
  font-size: 0.9rem;
  color: #4a90e2;
  margin-bottom: 0.4rem;
}

.upload-area button {
  background: linear-gradient(135deg, #4a90e2 0%, #2b6cb0 100%);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.3s ease;
  margin-top: 0.4rem;
  box-shadow: 0 2px 6px rgba(74, 144, 226, 0.4);
}

.upload-area button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(74, 144, 226, 0.6);
}

.help-text {
  margin-top: 0.6rem;
  color: #6c7a89;
  font-size: 0.75rem;
  text-align: center;
}

/* 操作按钮放在页面底部 */
.action-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 0.8rem;
  justify-content: center;
}

.btn-primary, .btn-secondary {
  padding: 0.8rem 2rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 160px;
}

.btn-primary {
  background: linear-gradient(135deg, #4a90e2 0%, #2b6cb0 100%);
  color: white;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #2b6cb0 0%, #4a90e2 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(74, 144, 226, 0.4);
}

.btn-secondary {
  background: linear-gradient(135deg, #50c878 0%, #2e7d32 100%);
  color: white;
}

.btn-secondary:hover {
  background: linear-gradient(135deg, #2e7d32 0%, #50c878 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(80, 200, 120, 0.4);
}

/* 已上传发票列表 */
.uploaded-list-section {
  background: white;
  border-radius: 10px;
  padding: 1rem;
  box-shadow: 0 4px 12px rgba(50, 88, 148, 0.12);
  border: 1px solid #e0e8f0;
  height: calc(50% - 0.4rem); /* 使两个左侧框高度一致 */
  display: flex;
  flex-direction: column;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.list-header h3 {
  margin: 0;
  color: #2b3e50;
  font-size: 1rem;
  font-weight: 600;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #4a90e2;
  flex-shrink: 0;
}

.invoices-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0;
  border-radius: 5px;
  background: #fafdff;
  border: 1px solid #e0e8f0;
}

/* 发票列表项 */
.invoice-item {
  display: flex;
  align-items: center;
  padding: 0.4rem;
  border-bottom: 1px solid #e0e8f0;
  transition: background-color 0.2s ease;
  cursor: move; /* 表示可以拖拽 */
  user-select: none; /* 防止文字被选中 */
  position: relative;
}

.invoice-item.dragging {
  opacity: 0.6;
  background: #d1e7ff;
  z-index: 10;
}

.invoice-item:last-child {
  border-bottom: none;
}

.invoice-item:hover {
  background: #f0f7ff;
}

.info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.info p {
  margin: 0.05rem 0;
  font-size: 0.8rem;
  color: #262626;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info p:first-child {
  font-weight: 600;
  color: #2b3e50;
}

.remove-btn {
  background: #e67e7e;
  color: white;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  margin-left: 0.4rem;
}

.remove-btn:hover {
  background: #d32f2f;
  transform: scale(1.1);
}

/* 设置卡片 */
.setting-card {
  background: white;
  border-radius: 10px;
  padding: 1rem;
  box-shadow: 0 4px 12px rgba(50, 88, 148, 0.12);
  border: 1px solid #e0e8f0;
  height: calc(50% - 0.4rem); /* 使两个右侧框高度一致 */
  display: flex;
  flex-direction: column;
}

.setting-card:last-child {
  margin-bottom: 0;
}

.setting-card h3 {
  margin: 0 0 0.8rem 0;
  color: #2b3e50;
  font-size: 1rem;
  font-weight: 600;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #4a90e2;
}

/* 输入组 */
.input-group {
  margin-bottom: 0.8rem;
}

.input-group:last-child {
  margin-bottom: 0;
}

.input-group label {
  display: block;
  margin-bottom: 0.3rem;
  color: #2b3e50;
  font-weight: 500;
  font-size: 0.85rem;
}

.input-group input,
.input-group select {
  width: 100%;
  padding: 0.45rem;
  border: 1px solid #c5d4e3;
  border-radius: 5px;
  font-size: 0.85rem;
  background: #fafdff;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.input-group input:focus,
.input-group select:focus {
  outline: none;
  border-color: #4a90e2;
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

/* 日期范围输入 */
.date-range-inputs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.date-range-inputs input {
  flex: 1;
}

.date-separator {
  color: #4a90e2;
  font-weight: 600;
  font-size: 0.9rem;
  align-self: center;
}

/* 自定义尺寸输入 */
.size-inputs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.size-inputs input {
  flex: 1;
}

.size-separator {
  color: #4a90e2;
  font-weight: 600;
}

/* 全屏预览样式 */
.fullscreen-preview {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10000;
  display: none;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.Preview-content-wrapper {
  position: relative;
  width: 90%;
  max-width: 1200px;
  height: 85vh;
  z-index: 2;
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.Preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, #2b3e50 0%, #3a506b 100%);
  color: white;
  flex-shrink: 0;
}

.Preview-controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex: 1;
  justify-content: space-between;
}

.Preview-header h2 {
  color: white;
  font-size: 1.1rem;
  margin: 0;
  font-weight: 500;
  text-align: center;
  flex: 1;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

.nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.close-btn {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  margin-left: 1rem;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

.Preview-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  padding: 1.5rem;
  overflow: auto;
}

.Preview-body canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  background: white;
  border: 1px solid #e0e6ed;
}

/* 加载遮罩 */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10001;
}

.loading-spinner {
  width: 45px;
  height: 45px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 0.8rem;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-overlay p {
  color: white;
  font-size: 1rem;
  font-weight: 600;
}

/* 隐藏自定义尺寸部分 */
#customSize {
  display: none;
}

/* 响应式设计 - 移动端适配 */
@media screen and (max-width: 768px) {
  html, body {
    height: auto;
    overflow-x: hidden; /* 防止水平滚动条 */
  }
  
  body {
    margin: 0;
    padding: 0.5rem 0.3rem; /* 减少左右padding */
    background: linear-gradient(135deg, #2b3e50 0%, #3a506b 100%);
  }
  
  .container {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    padding: 0.5rem;
    gap: 0.8rem;
    max-width: 100vw;
    overflow-x: hidden;
  }
  
  .header h1 {
    font-size: 1.4rem;
    margin: 0.3rem 0;
    text-align: center;
  }
  
  .main-content {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    width: 100%;
  }
  
  .left-panel, .right-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
  }
  
  .upload-section {
    min-height: 120px;
    padding: 0.8rem;
    width: 100%;
  }
  
  .upload-area {
    padding: 0.8rem;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    width: 100%;
  }
  
  .upload-area p {
    font-size: 0.85rem;
    margin: 0.3rem 0;
    text-align: center;
  }
  
  .upload-icon {
    width: 30px;
    height: 30px;
  }
  
  .uploaded-list-section {
    height: 220px; /* 固定高度以便滚动 */
    min-height: 220px;
    width: 100%;
    display: flex;
    flex-direction: column;
  }
  
  .list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
  }
  
  .invoices-list {
    padding: 0.4rem 0;
    flex: 1;
    width: 100%;
    overflow-y: auto;
    border: 1px solid #e0e8f0;
    border-radius: 5px;
    background: #fafdff;
  }
  
  .invoice-item {
    padding: 0.4rem;
    display: flex;
    align-items: center;
    width: 100%;
    border-bottom: 1px solid #e0e8f0;
  }
  
  .info {
    flex: 1;
    min-width: 0;
  }
  
  .info p {
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0.1rem 0;
  }
  
  .remove-btn {
    width: 24px;
    height: 24px;
    font-size: 1rem;
    margin-left: 0.5rem;
    flex-shrink: 0;
  }
  
  .setting-card {
    padding: 0.8rem;
    width: 100%;
  }
  
  .setting-card h3 {
    font-size: 1.1rem;
    margin: 0 0 0.6rem 0;
  }
  
  .input-group {
    margin-bottom: 0.8rem;
  }
  
  .input-group label {
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
    display: block;
  }
  
  .input-group input,
  .input-group select {
    font-size: 0.9rem;
    padding: 0.5rem 0.6rem;
    width: 100%;
    box-sizing: border-box; /* 确保padding不影响宽度 */
  }
  
  .date-range-inputs {
    display: flex;
    gap: 0.3rem;
    align-items: center;
  }
  
  .date-separator {
    margin: 0 0.3rem;
  }
  
  .size-inputs {
    display: flex;
    align-items: center;
    gap: 0.3rem;
  }
  
  .size-separator {
    align-self: center;
    margin: 0 0.3rem;
  }
  
  .size-inputs input {
    flex: 1;
    width: auto;
  }
  
  .action-buttons {
    display: flex;
    flex-direction: row;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 0.5rem;
  }
  
  .btn-primary, .btn-secondary {
    flex: 1;
    min-width: 120px;
    padding: 0.7rem 1rem;
    font-size: 0.95rem;
    white-space: nowrap;
  }
  
  /* 全屏预览移动端优化 */
  .fullscreen-preview {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: none;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  
  .Preview-content-wrapper {
    position: relative;
    width: 95%;
    max-width: 100%;
    height: 80vh;
    z-index: 2;
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  }
  
  .Preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    background: linear-gradient(135deg, #2b3e50 0%, #3a506b 100%);
    color: white;
    flex-shrink: 0;
  }
  
  .Preview-controls {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex: 1;
    justify-content: space-between;
  }
  
  .Preview-header h2 {
    color: white;
    font-size: 0.9rem;
    margin: 0;
    font-weight: 500;
    text-align: center;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  .nav-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 0.2rem;
  }
  
  .close-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    margin-left: 0.5rem;
  }
  
  .Preview-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    padding: 0.8rem;
    overflow: auto;
  }
  
  .Preview-body canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    background: white;
    border: 1px solid #e0e6ed;
  }
  
  /* 特别针对更小屏幕的优化 */
  @media screen and (max-width: 480px) {
    body {
      padding: 0.3rem 0.2rem;
    }
    
    .container {
      padding: 0.3rem;
      gap: 0.5rem;
    }
    
    .upload-area {
      padding: 0.6rem;
    }
    
    .upload-area p {
      font-size: 0.75rem;
      line-height: 1.3;
    }
    
    .header h1 {
      font-size: 1.1rem;
    }
    
    .setting-card {
      padding: 0.5rem;
    }
    
    .setting-card > div:first-child {
      margin-top: 0.3rem;
    }
    
    .setting-card h3 {
      font-size: 1rem;
    }
    
    .input-group {
      margin-bottom: 0.6rem;
    }
    
    .input-group label {
      font-size: 0.85rem;
      margin-bottom: 0.2rem;
    }
    
    .input-group input,
    .input-group select {
      font-size: 0.85rem;
      padding: 0.4rem 0.5rem;
    }
    
    .date-range-inputs {
      flex-direction: column;
    }
    
    .date-separator {
      display: none;
    }
    
    .size-inputs {
      flex-direction: column;
    }
    
    .size-separator {
      display: none; /* 隐藏×符号，因为是垂直排列 */
    }
    
    .size-inputs input {
      width: 100%;
    }
    
    .action-buttons {
      flex-direction: column; /* 小屏幕上按钮竖排 */
      padding: 0.2rem;
    }
    
    .btn-primary, .btn-secondary {
      width: 100%;
      min-width: auto;
      padding: 0.8rem;
      margin: 0.2rem 0;
    }
    
    .invoice-item {
      padding: 0.3rem;
    }
    
    .info p {
      font-size: 0.65rem; /* 减小字体以适应更小屏幕 */
    }
    
    .remove-btn {
      width: 22px;
      height: 22px;
      font-size: 0.9rem;
    }
    
    .list-header h3 {
      font-size: 0.9rem;
    }
    
    .list-header small {
      font-size: 0.6rem;
    }
    
    .Preview-content-wrapper {
      width: 98%;
      height: 85vh;
    }
    
    .Preview-header {
      padding: 0.5rem;
    }
    
    .Preview-header h2 {
      font-size: 0.75rem;
    }
    
    .nav-btn {
      padding: 0.3rem 0.5rem;
      font-size: 0.75rem;
    }
    
    .close-btn {
      width: 26px;
      height: 26px;
      font-size: 1rem;
    }
    
    .Preview-body {
      padding: 0.4rem;
    }
  }
}
