/**
 * LiveSource Manager - Vercel Style CSS
 * 专为直播源管理界面设计的Vercel风格样式
 */

/* 统计卡片网格优化 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* 工具栏布局优化 - 将按钮和下拉菜单放在同一行 */
.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.search-group {
  display: flex;
  gap: 12px;
  align-items: center;
}

.page-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* 编辑器配置信息栏 - 严格单行布局，固定高度 */
.modal.large .modal-config-bar {
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  padding: 12px 24px !important;
  border-bottom: 1px solid #e5e7eb !important;
  background: #f9fafb !important;
  height: 60px !important; /* 固定高度确保计算准确 */
}

.config-inputs-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  align-items: center;
}

/* 编辑器工具栏 - 严格单行布局，左右分布，所有屏幕强制执行 */
.modal.large .modal-tools-bar {
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  padding: 12px 24px !important;
  border-bottom: 1px solid #e5e7eb !important;
  background: #f9fafb !important;
  display: flex !important;
  flex-direction: row !important; /* 强制水平布局 */
  height: 60px !important; /* 固定高度确保计算准确 */
  justify-content: space-between !important;
  align-items: center !important;
  gap: 16px !important;
  flex-wrap: nowrap !important; /* 禁止整个工具栏换行 */
}

/* 左侧工具区 - 下拉菜单区域 */
.tools-left {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  flex-shrink: 0 !important; /* 不允许收缩 */
  flex-wrap: nowrap !important; /* 强制单行 */
  white-space: nowrap !important;
}

/* 右侧工具区 - 按钮组区域 */
.tools-right {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex-shrink: 0 !important; /* 不允许收缩 */
  flex-wrap: nowrap !important; /* 强制单行，禁止换行 */
  white-space: nowrap !important;
}

/* Vercel风格的下拉菜单 */
.filter-select {
  height: 36px;
  padding: 8px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  min-width: 120px;
}

.filter-select:hover {
  border-color: #d1d5db;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.filter-select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Vercel风格的按钮 - 统一尺寸 */
.btn-primary, .btn-secondary, .tool-btn {
  height: 36px;
  padding: 0 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 100px;
  white-space: nowrap;
}

.btn-primary {
  background: #000000;
  color: #ffffff;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.btn-primary:hover {
  background: #1f2937;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.btn-secondary {
  background: #ffffff;
  color: #374151;
  border: 1px solid #d1d5db;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.btn-secondary:hover {
  background: #f9fafb;
  border-color: #9ca3af;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

/* 工具栏按钮特殊样式 */
.tool-btn {
  background: #ffffff;
  color: #374151;
  border: 1px solid #d1d5db;
  min-width: 80px;
}

.tool-btn:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.tool-btn.save {
  background: #059669;
  color: #ffffff;
  border-color: #059669;
}

.tool-btn.save:hover {
  background: #047857;
  border-color: #047857;
}

/* 表单输入框优化 - 适配新的单行布局 */
.form-input, .form-select {
  height: 36px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  font-size: 14px;
  transition: all 0.2s ease;
  width: 100%;
  box-sizing: border-box;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 配置输入框行特殊优化 */
.config-inputs-row .form-input {
  min-width: 150px;
}

/* ISP选择下拉菜单 */
.tools-left .form-select {
  width: auto;
  min-width: 120px;
}

/* 配置列表卡片宽度优化 */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.config-card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
  min-height: auto;
  cursor: pointer; /* 指示可点击 */
  user-select: none; /* 防止文本选择 */
}

.config-card:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  border-color: #d1d5db;
  transform: translateY(-1px); /* 微妙的悬停效果 */
  background: #fafafa; /* 微妙的背景变化 */
}

.config-card:active {
  transform: translateY(0); /* 点击时的按下效果 */
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

/* 卡片头部布局优化 - 标题和状态标签同一行 */
.card-header {
  display: flex !important;
  justify-content: space-between !important;
  align-items: flex-start !important;
  margin-bottom: 16px;
  gap: 16px;
}

.card-title {
  flex: 1;
  min-width: 0; /* 允许标题截断 */
}

.card-title h3 {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 600;
  color: #111827;
  line-height: 1.3;
}

.card-title p {
  margin: 0;
  font-size: 12px;
  color: #6b7280;
  line-height: 1.4;
}

.card-badges {
  display: flex !important;
  gap: 8px !important;
  flex-shrink: 0; /* 状态标签不收缩 */
  align-items: center;
}

/* 配置卡片内容布局优化 - 单行显示标签:值 */
.config-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 16px 0;
}

/* meta-item改为水平布局，标签:值在同一行 */
.meta-item {
  display: flex;
  flex-direction: row !important; /* 强制水平布局 */
  align-items: center !important;
  gap: 6px !important;
  white-space: nowrap;
}

.meta-label {
  font-size: 12px;
  color: #6b7280;
  font-weight: 500;
  flex-shrink: 0; /* 标签不收缩 */
}

.meta-value {
  font-size: 14px;
  color: #111827;
  font-weight: 500;
  flex: 1; /* 值可以伸缩 */
  min-width: 0; /* 允许文本截断 */
}

/* 配置时间戳布局优化 - 同一行显示最后更新和最后同步 */
.config-timestamps {
  display: flex !important;
  flex-direction: row !important;
  gap: 24px !important;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f3f4f6;
  flex-wrap: wrap; /* 允许小屏幕换行 */
}

.timestamp {
  display: flex !important;
  flex-direction: row !important; /* 标签:值在同一行 */
  align-items: center !important;
  gap: 6px !important;
  white-space: nowrap;
  font-size: 12px;
}

.timestamp span:first-child {
  color: #6b7280;
  font-weight: 500;
  flex-shrink: 0; /* 标签不收缩 */
}

.timestamp span:last-child {
  color: #111827;
  font-weight: 500;
}

/* 卡片按钮样式优化 */
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.btn-action {
  height: 32px;
  padding: 0 12px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  background: #ffffff;
  color: #374151;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-action:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.btn-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-edit:hover {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
}

.btn-sync:hover {
  background: #dcfce7;
  border-color: #16a34a;
  color: #15803d;
}

.btn-delete:hover {
  background: #fee2e2;
  border-color: #dc2626;
  color: #dc2626;
}

/* 编辑器模态框优化 - 全屏高度最大化M3U编辑区域 */
.modal.large .modal-content {
  width: 100% !important;
  max-width: 100% !important;
  height: 100vh !important;
  max-height: 100vh !important;
  margin: 0 !important;
  display: flex;
  flex-direction: column;
  border-radius: 0 !important;
  position: relative;
}

/* 模态框头部 - 固定高度确保计算准确 */
.modal.large .modal-header {
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  padding: 16px 24px !important;
  border-bottom: 1px solid #e5e7eb !important;
  height: 80px !important; /* 固定高度 */
  background: #ffffff;
  position: relative;
  z-index: 10;
}

/* 全屏编辑器关闭按钮优化 */
.modal.large .modal-header {
  padding: 12px 24px;
  background: #f9fafb;
  border-bottom: 2px solid #e5e7eb;
}

.modal.large .btn-close {
  position: absolute;
  top: 50%;
  right: 24px;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 20;
}

.modal.large .btn-close:hover {
  background: #fee2e2;
  border-color: #dc2626;
  color: #dc2626;
}

/* 覆盖redesign.css中的modal-body样式 */
.modal.large .modal-body {
  flex: 1 !important;
  padding: 0 !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important; /* 关键：允许flex子元素收缩 */
  height: auto !important;
}

/* 编辑器容器优化 - 简单静态布局 */
.modal.large .editor-container {
  display: block !important;
  overflow: hidden !important;
  /* 让M3U编辑器自己处理高度和滚动 */
}

.editor-header {
  flex-shrink: 0;
  padding: 8px 24px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: #6b7280;
  font-weight: 500;
  min-height: 40px;
}

/* M3U编辑器样式优化 - 精确计算可用高度 */
.modal.large .m3u-editor {
  margin: 0 !important;
  padding: 24px 32px !important;
  border: none !important;
  outline: none !important;
  resize: none !important;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace !important;
  font-size: 16px !important;
  line-height: 1.8 !important;
  background: #ffffff !important;
  color: #111827 !important;
  box-sizing: border-box !important;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  width: 100% !important;
  display: block !important;
  /* 精确计算高度：100vh减去所有固定元素的高度 */
  height: calc(100vh - 240px) !important; /* 头部80px + 配置栏60px + 工具栏60px + 状态栏40px */
  max-height: calc(100vh - 240px) !important;
  overflow-y: scroll !important; /* 强制显示滚动条 */
  overflow-x: hidden !important;
}

.modal.large .m3u-editor:focus {
  outline: none !important;
  box-shadow: inset 0 0 0 2px #3b82f6 !important;
}

/* 模态框底部状态栏 - 固定高度确保计算准确 */
.modal.large .modal-footer {
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  padding: 8px 24px !important;
  background: #f9fafb !important;
  border-top: 1px solid #e5e7eb !important;
  height: 40px !important; /* 固定高度 */
  position: relative !important;
  z-index: 10 !important;
}

/* 简化布局 - 移除复杂的flex嵌套 */
.modal.large .modal-content {
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

.modal.large .modal-body {
  overflow: hidden !important;
  padding: 0 !important;
}

.editor-status {
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: #6b7280;
  align-items: center;
}

.editor-status span {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

/* 状态指示器 */
.status-success {
  color: #059669;
}

.status-warning {
  color: #d97706;
}

.status-error {
  color: #dc2626;
}

/* 响应式优化 - 针对新的单行布局 */
@media (max-width: 768px) {
  .config-grid {
    grid-template-columns: 1fr;
  }
  
  .page-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-group, .page-actions {
    justify-content: center;
  }
  
  /* 配置输入框在小屏幕上垂直排列 */
  .config-inputs-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  /* 小屏幕也强制保持单行布局 - 压缩间距和按钮尺寸 */
  .modal.large .modal-tools-bar {
    flex-direction: row !important; /* 强制水平排列 */
    justify-content: space-between !important;
    align-items: center !important;
    gap: 4px !important; /* 进一步减小间距 */
    padding: 8px 16px !important; /* 减小padding节省空间 */
    flex-wrap: nowrap !important;
  }
  
  .tools-left, .tools-right {
    flex-wrap: nowrap !important; /* 禁止换行 */
    white-space: nowrap !important;
    gap: 4px !important; /* 减小间距 */
  }
  
  /* 小屏幕按钮尺寸优化 */
  .tools-right .tool-btn {
    padding: 6px 8px !important;
    font-size: 12px !important;
    min-width: auto !important;
  }
  
  /* 小屏幕下拉菜单优化 */
  .tools-left .form-select {
    min-width: 80px !important;
    font-size: 12px !important;
  }
  
  .config-meta {
    grid-template-columns: 1fr;
  }
  
  /* 小屏幕卡片头部保持水平布局 */
  .card-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }
  
  /* 小屏幕时间戳可以垂直排列节省空间 */
  .config-timestamps {
    flex-direction: column !important;
    gap: 8px !important;
  }
  
  /* 编辑器状态栏在小屏幕上换行 */
  .editor-status {
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* 全屏模态框背景 */
.modal.large {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  background: rgba(0, 0, 0, 0.5) !important;
  z-index: 9999 !important;
  display: flex !important;
  align-items: stretch !important;
  justify-content: stretch !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* 确保覆盖redesign.css中的所有textarea样式 - 精确高度计算 */
.modal.large textarea,
.modal.large .code-editor,
.modal.large #m3u-editor {
  resize: none !important;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  box-sizing: border-box !important;
  scrollbar-width: thin !important; /* Firefox滚动条 */
  scrollbar-color: #cbd5e1 #f1f5f9 !important;
  /* 使用精确的高度计算，不依赖flex */
  height: calc(100vh - 240px) !important;
  max-height: calc(100vh - 240px) !important;
  overflow-y: scroll !important;
  overflow-x: hidden !important;
}

/* 确保WebKit浏览器滚动条始终可见 */
.modal.large textarea::-webkit-scrollbar,
.modal.large .code-editor::-webkit-scrollbar,
.modal.large #m3u-editor::-webkit-scrollbar {
  width: 12px !important;
  display: block !important;
}

.modal.large textarea::-webkit-scrollbar-track,
.modal.large .code-editor::-webkit-scrollbar-track,
.modal.large #m3u-editor::-webkit-scrollbar-track {
  background: #f1f5f9 !important;
  border-radius: 6px !important;
}

.modal.large textarea::-webkit-scrollbar-thumb,
.modal.large .code-editor::-webkit-scrollbar-thumb,
.modal.large #m3u-editor::-webkit-scrollbar-thumb {
  background: #cbd5e1 !important;
  border-radius: 6px !important;
  border: 2px solid #f1f5f9 !important;
}

.modal.large textarea::-webkit-scrollbar-thumb:hover,
.modal.large .code-editor::-webkit-scrollbar-thumb:hover,
.modal.large #m3u-editor::-webkit-scrollbar-thumb:hover {
  background: #94a3b8 !important;
}

/* 中等屏幕优化 - 保持全屏和严格单行布局 */
@media (max-width: 1024px) {
  .modal.large .modal-content {
    width: 100%;
    height: 100vh;
    margin: 0;
  }
  
  .config-inputs-row {
    gap: 8px;
  }
  
  /* 中等屏幕也保持严格单行布局 */
  .modal.large .modal-tools-bar {
    flex-direction: row !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
  }
  
  .tools-left, .tools-right {
    flex-wrap: nowrap !important;
    white-space: nowrap !important;
  }
  
  .tools-right {
    gap: 6px !important;
  }
  
  /* 中等屏幕卡片布局优化 */
  .card-header {
    gap: 12px;
  }
  
  .config-timestamps {
    gap: 16px;
  }
}

/* 加载状态和空状态样式 */
.loading-card, .empty-state, .error-card {
  text-align: center;
  padding: 40px 20px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #6b7280;
}

.loading-icon, .empty-icon, .error-icon {
  font-size: 48px;
  margin-bottom: 16px;
  display: block;
}

/* 预览和历史模态框 */
.preview-content, .history-list {
  padding: 20px;
  max-height: 500px;
  overflow-y: auto;
}

.channel-item, .history-item {
  padding: 12px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  margin-bottom: 8px;
  background: #ffffff;
}

.channel-item:hover, .history-item:hover {
  background: #f9fafb;
}
