/**
 * Telegram Restricted Media Downloader - WebUI 自定义样式
 * 
 * 基于 Tailwind CSS 的扩展样式
 * 深色主题，Telegram 风格
 */

/* ==================== 全局样式 ==================== */
:root {
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --error-color: #ef4444;
  --info-color: #06b6d4;
  
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --border-color: #475569;
  --shadow-color: rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

/* ==================== FOUC 防护 ==================== */
/* Alpine.js 初始化前隐藏所有带 x-cloak 的元素，防止弹框/遮罩层
   在页面加载瞬间闪现（生产环境静态资源加载慢时尤为明显）。
   Alpine 初始化完成后会自动移除 x-cloak 属性，由 x-show 无缝接管。 */
[x-cloak] {
  display: none !important;
}

/* ==================== 滚动条样式 ==================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-color);
}

/* ==================== 侧边栏样式 ==================== */
.sidebar {
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  transition: transform 0.3s ease;
}

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
}

.sidebar-link:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.sidebar-link.active {
  background-color: var(--primary-color);
  color: white;
}

.sidebar-link svg {
  width: 1.25rem;
  height: 1.25rem;
  margin-right: 0.75rem;
}

/* ==================== 卡片样式 ==================== */
.card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: 0 4px 6px var(--shadow-color);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ==================== 按钮样式 ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  gap: 0.5rem;
}

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

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
}

.btn-success {
  background-color: var(--success-color);
  color: white;
}

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

.btn-warning {
  background-color: var(--warning-color);
  color: white;
}

.btn-warning:hover:not(:disabled) {
  background-color: #d97706;
}

.btn-error {
  background-color: var(--error-color);
  color: white;
}

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

.btn-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--border-color);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

/* ==================== 表单样式 ==================== */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: border-color 0.2s ease;
}

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

.form-input::placeholder {
  color: var(--text-muted);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
}

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

.form-error {
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--error-color);
}

/* ==================== 表格样式 ==================== */
.table-container {
  overflow-x: auto;
  border-radius: 0.75rem;
  border: 1px solid var(--border-color);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  background-color: var(--bg-tertiary);
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.875rem;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover td {
  background-color: var(--bg-tertiary);
}

/* ==================== 状态徽章 ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
}

.badge-pending {
  background-color: rgba(100, 116, 139, 0.2);
  color: var(--text-secondary);
}

.badge-running {
  background-color: rgba(59, 130, 246, 0.2);
  color: var(--primary-color);
}

.badge-completed {
  background-color: rgba(16, 185, 129, 0.2);
  color: var(--success-color);
}

.badge-failed {
  background-color: rgba(239, 68, 68, 0.2);
  color: var(--error-color);
}

.badge-cancelled {
  background-color: rgba(245, 158, 11, 0.2);
  color: var(--warning-color);
}

.badge-queued {
  background-color: rgba(6, 182, 212, 0.2);
  color: var(--info-color);
}

/* ==================== 进度条 ==================== */
.progress-bar {
  width: 100%;
  height: 0.5rem;
  background-color: var(--bg-tertiary);
  border-radius: 9999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--primary-color);
  border-radius: 9999px;
  transition: width 0.3s ease;
}

.progress-bar-fill.success {
  background-color: var(--success-color);
}

.progress-bar-fill.warning {
  background-color: var(--warning-color);
}

.progress-bar-fill.error {
  background-color: var(--error-color);
}

/* ==================== 通知样式 ==================== */
.notification {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  max-width: 24rem;
  padding: 1rem;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px var(--shadow-color);
  animation: slideIn 0.3s ease;
}

.notification-info {
  background-color: var(--bg-secondary);
  border-left: 4px solid var(--info-color);
}

.notification-success {
  background-color: var(--bg-secondary);
  border-left: 4px solid var(--success-color);
}

.notification-warning {
  background-color: var(--bg-secondary);
  border-left: 4px solid var(--warning-color);
}

.notification-error {
  background-color: var(--bg-secondary);
  border-left: 4px solid var(--error-color);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ==================== 加载动画 ==================== */
.spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--bg-tertiary);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 1rem;
  height: 1rem;
  border-width: 2px;
}

.spinner-lg {
  width: 2.5rem;
  height: 2.5rem;
  border-width: 3px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==================== 模态框 ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.modal {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  width: 100%;
  max-width: 32rem;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px var(--shadow-color);
  animation: scaleIn 0.2s ease;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ==================== 抽屉样式 ==================== */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 28rem;
  background-color: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  box-shadow: -4px 0 10px var(--shadow-color);
  z-index: 1001;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-body {
  padding: 1.5rem;
  overflow-y: auto;
  height: calc(100% - 4.5rem);
}

/* ==================== 标签页样式 ==================== */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  gap: 0;
}

.tab {
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

/* ==================== 面包屑导航 ==================== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.breadcrumb-item {
  color: var(--text-secondary);
  text-decoration: none;
}

.breadcrumb-item:hover {
  color: var(--primary-color);
}

.breadcrumb-item.active {
  color: var(--text-primary);
  font-weight: 500;
}

.breadcrumb-separator {
  color: var(--text-muted);
}

/* ==================== 工具提示 ==================== */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.375rem 0.75rem;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.75rem;
  border-radius: 0.375rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 100;
}

.tooltip:hover::after {
  opacity: 1;
  visibility: visible;
  bottom: calc(100% + 0.5rem);
}

/* ==================== 响应式调整 ==================== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 16rem;
    z-index: 100;
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0 !important;
  }
  
  .card {
    padding: 1rem;
  }
  
  .table th,
  .table td {
    padding: 0.5rem 0.75rem;
  }
  
  .notification {
    left: 1rem;
    right: 1rem;
    max-width: none;
  }
  
  .drawer {
    max-width: 100%;
  }
}

@media (min-width: 769px) {
  .main-content {
    margin-left: 16rem;
  }
}

/* ==================== 辅助类 ==================== */
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: transform 0.3s ease;
}

.slide-enter-from {
  transform: translateY(-1rem);
}

.slide-leave-to {
  transform: translateY(-1rem);
}

/* ==================== 动画辅助类 ==================== */
.animate-spin {
  animation: spin 1s linear infinite;
}
