:root {
  --primary-color: #007bff;
  --hover-color: #0056b3;
  --active-color: #e6f0ff;
  --border-color: #ddd;
  --error-color: #ff3860;
  --success-color: #23d160;
  --text-color: #333;
  --light-text: #666;
  --bg-color: #f4f4f9;
  --card-bg: white;
  --shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  --radius: 10px;
  --transition: all 0.3s ease;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-color);
  margin: 0;
  padding: 0;
  color: var(--text-color);
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden; /* 防止整个页面滚动 */
}

h2 {
  text-align: center;
  color: var(--primary-color);
  margin-bottom: 10px;
}

/* 搜索容器 */
.search-container {
    width: 90%;
    max-width: 1200px;
    margin: 0 auto 20px;
    padding: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    flex-shrink: 0; /* 防止搜索容器被压缩 */
}

/* 搜索行布局 */
.search-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    flex-wrap: wrap;
}

/* 输入框容器 */
.input-wrapper {
    flex: 1;
    min-width: 250px;
    position: relative;
}

/* 输入框样式 */
#emailInput {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    box-sizing: border-box;
    transition: all 0.3s ease;
}

#emailInput:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
    outline: none;
}

/* 按钮基础样式 */
.search-btn, .import-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

/* 按钮组样式 */
.button-group {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

/* 搜索按钮 */
.search-btn {
    background: #007bff;
    color: white;
}

.search-btn:hover {
    background: #0056b3;
}

/* 导入按钮 */
.import-btn {
    background: #17a2b8;
    color: white;
}

.import-btn:hover {
    background: #138496;
}

/* 清空按钮 */
.clear-btn {
    background: #dc3545;
    color: white;
}

.clear-btn:hover {
    background: #c82333;
}

/* 文件输入隐藏 */
#fileInput {
    display: none;
}

/* 内容区域 */
.container {
  width: 90%;
  max-width: 1200px;
  margin: 0 auto 20px;
  padding: 20px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 15px;
  height: calc(100vh - 200px); /* 固定高度，减去搜索容器和边距 */
  min-height: 400px;
}

/* 左侧导入邮箱列表样式 - 默认隐藏 */
.imported-emails {
  width: 135px;
  border-right: 1px solid var(--border-color);
  padding-right: 15px;
  overflow-y: auto;
  display: none; /* 默认隐藏 */
  height: 100%; /* 占满容器高度 */
  flex-shrink: 0;
}

.imported-emails.show {
  display: block; /* 当有内容时显示 */
}

.imported-email-item {
  padding: 8px;
  margin-bottom: 5px;
  border-radius: 5px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}

.imported-email-item:hover {
  background-color: #f1f1f1;
}

.imported-email-item.active {
  background-color: var(--primary-color);
  color: white;
}

/* 中间邮件标题列表样式 */
.email-list {
  width: 200px;
  border-right: 1px solid var(--border-color);
  padding-right: 15px;
  overflow-y: auto;
  flex-shrink: 0;
  height: 100%; /* 占满容器高度 */
}

.email-item {
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 5px;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid #eee;
}

.email-item:hover {
  background-color: #f9f9f9;
  transform: translateX(3px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.email-item.active {
  background-color: var(--active-color);
  border-left: 3px solid var(--primary-color);
}

.email-subject {
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  white-space: normal;
  display: block;
  overflow: visible;
}

.email-time {
  font-size: 12px;
  color: var(--light-text);
}

/* 右侧邮件内容样式 */
.email-content {
  flex: 1;
  padding-left: 15px;
  display: flex;
  flex-direction: column;
  min-width: 0; /* 防止flex项目溢出 */
  height: 100%; /* 占满容器高度 */
}

.email-text {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  background-color: #f9f9f9;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  height: 100%; /* 占满父容器高度 */
  box-sizing: border-box;
}

/* 按钮样式 */
button {
  padding: 12px 20px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  min-width: 120px;
}

button:hover {
  background-color: var(--hover-color);
  transform: translateY(-2px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  background-color: #6c757d;
  cursor: not-allowed;
  transform: none;
  opacity: 0.6;
}

button:disabled:hover {
  background-color: #6c757d;
  transform: none;
}

button.import-btn {
  background-color: #17a2b8;
}

button.import-btn:hover {
  background-color: #138496;
}

#fileInput {
  display: none;
}

/* 加载动画 */
#loading {
  display: none;
  text-align: center;
  padding: 12px 20px;
  color: var(--primary-color);
  font-weight: bold;
  background-color: rgba(0, 123, 255, 0.1);
  border-radius: 5px;
  border: 1px solid rgba(0, 123, 255, 0.2);
  margin: 0 10px;
}

#loading::after {
  content: "";
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(0, 123, 255, 0.3);
  border-radius: 50%;
  border-top-color: var(--primary-color);
  animation: spin 1s linear infinite;
  margin-left: 10px;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 错误消息样式 */
.error-message {
  color: var(--error-color);
  font-size: 14px;
  margin-top: 5px;
  text-align: center;
  display: none;
}

/* 滚动条优化 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* 为不同区域设置不同的滚动条样式 */
.imported-emails::-webkit-scrollbar-thumb {
  background: #17a2b8;
}

.imported-emails::-webkit-scrollbar-thumb:hover {
  background: #138496;
}

.email-list::-webkit-scrollbar-thumb {
  background: #007bff;
}

.email-list::-webkit-scrollbar-thumb:hover {
  background: #0056b3;
}

.email-text::-webkit-scrollbar-thumb {
  background: #28a745;
}

.email-text::-webkit-scrollbar-thumb:hover {
  background: #218838;
}

/* 响应式设计 - 平板设备 */
@media (max-width: 1024px) {
  .search-container,
  .container {
    width: 95%;
    padding: 15px;
  }
  
  .container {
    height: calc(100vh - 190px); /* 调整平板高度 */
  }
  
  .search-row {
    gap: 8px;
  }
  
  .input-wrapper {
    min-width: 200px;
  }
  
  .button-group {
    gap: 8px; /* 平板设备减少按钮间距 */
  }
  
  .imported-emails {
    width: 120px;
  }
  
  .email-list {
    width: 180px;
  }
}

/* 响应式设计 - 移动设备 */
@media (max-width: 768px) {
  body {
    padding: 10px;
    height: 100vh;
    overflow: hidden;
  }
  
  .search-container,
  .container {
    width: 100%;
    padding: 15px;
    margin-bottom: 15px;
  }
  
  .container {
    flex-direction: column;
    gap: 15px;
    height: calc(100vh - 200px); /* 调整移动端高度，给emailContent更多空间 */
    min-height: 400px;
  }
  
  .search-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  
  .input-wrapper {
    min-width: unset;
  }
  
  /* 按钮容器，让Search和Import按钮在同一排 */
  .button-group {
    width: 100%;
    gap: 10px;
  }
  
  .search-btn, .import-btn {
    flex: 1; /* 两个按钮平均分配空间 */
    justify-content: center;
    margin-bottom: 5px;
  }
  
  /* 清空按钮单独一行 */
  .clear-btn {
    width: 100%;
    justify-content: center;
    margin-bottom: 5px;
  }
  
  #loading {
    width: 100%;
    margin: 10px 0;
    text-align: center;
  }
  
  .imported-emails {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 0 0 15px 0;
    height: 150px; /* 固定高度 */
    flex-shrink: 0;
  }
  
  .email-list {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 0 0 15px 0;
    height: 200px; /* 固定高度 */
    flex-shrink: 0;
  }
  
  .email-content {
    padding-left: 0;
    padding-top: 15px;
    flex: 1;
    height: auto;
    min-height: 250px; /* 增加最小高度 */
    overflow: hidden; /* 防止内容溢出 */
    display: flex;
    flex-direction: column;
  }
  
  .email-text {
    flex: 1; /* 让email-text占满剩余空间 */
    min-height: 200px;
    height: 100%;
    overflow-y: auto; /* 确保有垂直滚动条 */
    max-height: none; /* 移除最大高度限制 */
  }
}

/* 小屏幕优化 */
@media (max-width: 480px) {
  .search-container,
  .container {
    padding: 10px;
  }
  
  .container {
    height: calc(100vh - 180px); /* 调整小屏幕高度，给emailContent更多空间 */
  }
  
  h2 {
    font-size: 1.5rem;
    margin-bottom: 15px;
  }
  
  #emailInput {
    font-size: 14px;
    padding: 10px 12px;
  }
  
  .button-group {
    gap: 8px; /* 小屏幕减少按钮间距 */
  }
  
  .search-btn, .import-btn, .clear-btn {
    font-size: 14px;
    padding: 10px 15px;
  }
  
  .imported-emails {
    height: 120px; /* 调整小屏幕高度 */
  }
  
  .email-list {
    height: 150px; /* 调整小屏幕高度 */
  }
  
  .email-text {
    min-height: 150px;
    font-size: 14px;
    padding: 10px;
    overflow-y: auto; /* 确保有垂直滚动条 */
    flex: 1; /* 让email-text占满剩余空间 */
  }
  
  .email-item {
    padding: 10px;
  }
  
  .email-subject {
    font-size: 13px;
  }
  
  .email-time {
    font-size: 11px;
  }
}