/* ====== 移动端适配强化 & 主题切换样式 ====== */

/* ====== 导航栏图标按钮（统一风格） ====== */
.nav-links { display: none !important; }

.nav-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.nav-icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.nav-icon-btn:hover {
  color: var(--text);
  background: var(--card);
}

.nav-icon-btn:active {
  transform: scale(0.92);
}

.nav-search-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1100;
  background: rgba(10, 14, 26, 0.97);
  border-bottom: 1px solid var(--card-border);
  padding: 12px 5%;
  display: none;
  align-items: flex-start;
  justify-content: center;
  animation: navSlideDown 0.2s ease;
}

.nav-search-overlay.active {
  display: flex;
}

@keyframes navSlideDown {
  from { opacity: 0; transform: translateY(-100%); }
  to { opacity: 1; transform: translateY(0); }
}

.search-overlay-box {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--dark3);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 10px 20px;
  width: 100%;
  max-width: 500px;
}

.search-overlay-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.2);
}

.search-overlay-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-overlay-box input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 1rem;
  width: 100%;
}

.search-overlay-box input::placeholder {
  color: var(--text-muted);
}

.search-overlay-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.search-overlay-close:hover {
  color: var(--text);
  background: var(--card);
}

/* 搜索结果下拉 */
.search-results-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: -20px;
  right: -20px;
  background: var(--dark2);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  max-height: 360px;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 1200;
}
.search-results-dropdown.active {
  display: block;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover,
.search-result-item.selected {
  background: var(--dark3);
}
.search-result-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(108,99,255,0.15);
}
.search-result-info { flex: 1; min-width: 0; }
.search-result-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-name em {
  font-style: normal;
  color: var(--primary);
}
.search-result-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-enter {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.search-result-item:hover .search-result-enter { opacity: 1; }
.search-results-empty {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* 收藏面板 */
.fav-panel-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.5);
  justify-content: center;
  align-items: flex-start;
  padding-top: 80px;
}
.fav-panel-overlay.active { display: flex; }
.fav-panel {
  background: var(--dark2);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  width: 90%;
  max-width: 420px;
  max-height: 70vh;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  animation: favSlideIn 0.2s ease;
}
@keyframes favSlideIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
.fav-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}
.fav-panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.fav-panel-close:hover { color: var(--text); background: var(--card); }
.fav-panel-addbtn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.fav-panel-addbtn:hover { opacity: 0.85; }
.fav-panel-list {
  overflow-y: auto;
  max-height: calc(70vh - 120px);
}
.fav-panel-item {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background 0.15s;
}
.fav-panel-item:hover { background: var(--dark3); }
.fav-panel-item.current { background: rgba(108,99,255,0.1); }
.fav-panel-link {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
}
.fav-panel-icon { font-size: 1.2rem; flex-shrink: 0; }
.fav-panel-name {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fav-panel-item.current .fav-panel-name { color: var(--primary); font-weight: 600; }
.fav-panel-del {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 12px 16px;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
}
.fav-panel-del:hover { color: #ff6b6b; }
.fav-panel-empty {
  padding: 48px 20px;
  text-align: center;
  font-size: 1rem;
  color: var(--text-muted);
}
.fav-panel-hint {
  display: block;
  margin-top: 8px;
  font-size: 0.8rem;
  opacity: 0.6;
}
.fav-panel-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--card-border);
  text-align: center;
}
.fav-panel-clearbtn {
  background: none;
  border: 1px solid rgba(255,107,107,0.3);
  color: #ff6b6b;
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.fav-panel-clearbtn:hover {
  background: rgba(255,107,107,0.1);
  border-color: #ff6b6b;
}

/* 页面内收藏按钮（工具子页面） */
.page-fav-btn {
  position: fixed;
  right: 24px;
  bottom: 100px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--dark2);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  backdrop-filter: blur(10px);
}
.page-fav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.page-fav-btn.favorited {
  color: #ffd93d;
  border-color: rgba(255,217,61,0.3);
  background: rgba(255,217,61,0.08);
}
.page-fav-btn svg {
  flex-shrink: 0;
}
[data-theme="light"] .page-fav-btn {
  background: #fff;
  border-color: #dee2e6;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
[data-theme="light"] .page-fav-btn:hover {
  border-color: var(--primary);
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

/* Toast 提示 */
.fav-toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.fav-toast.show { opacity: 1; }

/* 浅色主题 */
[data-theme="light"] .fav-panel-overlay { background: rgba(0,0,0,0.25); }
[data-theme="light"] .fav-panel { background: #fff; border-color: #dee2e6; box-shadow: 0 16px 48px rgba(0,0,0,0.15); }
[data-theme="light"] .fav-panel-item { border-bottom-color: #f1f3f5; }
[data-theme="light"] .fav-panel-item:hover { background: #f8f9fa; }
[data-theme="light"] .fav-panel-item.current { background: rgba(108,99,255,0.06); }

[data-theme="light"] .nav-search-overlay {
  background: rgba(255, 255, 255, 0.97);
}

/* 搜索建议下拉 */
.search-results-dropdown {
  position: absolute;
  top: calc(100% + 12px);
  left: 5%;
  right: 5%;
  max-width: 500px;
  margin: 0 auto;
  background: var(--dark3);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  overflow: hidden;
  display: none;
  max-height: 420px;
  overflow-y: auto;
}

.search-results-dropdown.active {
  display: block;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--card-border);
  text-decoration: none;
  color: inherit;
}

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

.search-result-item:hover,
.search-result-item:focus {
  background: var(--card);
}

.search-result-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  background: var(--card);
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.search-result-name mark {
  background: linear-gradient(135deg, rgba(108,99,255,0.3), rgba(0,212,255,0.3));
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.search-result-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-enter {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.search-result-item:hover .search-result-enter {
  opacity: 1;
}

.search-no-result {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

[data-theme="light"] .search-results-dropdown {
  background: var(--bg-primary);
  box-shadow: 0 8px 30px rgba(0,0,0,0.1);
}

[data-theme="light"] .search-result-item:hover,
[data-theme="light"] .search-result-item:focus {
  background: var(--bg-secondary);
}

[data-theme="light"] .search-result-icon {
  background: var(--bg-secondary);
}

/* ====== 移动端适配强化 ====== */

/* 确保所有按钮点击区域 ≥ 44px */
button, 
.btn,
input[type="submit"],
input[type="button"],
.tool-card,
.popular-card,
a.btn {
  min-height: 44px;
  min-width: 44px;
}

/* 字体大小 ≥ 16px（防止iOS自动缩放） */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="tel"],
textarea,
select {
  font-size: 16px !important;
}

/* 移动端适配 - 小屏手机 */
@media (max-width: 480px) {
  .tool-container {
    padding: 80px 12px 40px;
  }
  
  .tool-header h1 {
    font-size: 1.5rem;
  }
  
  .tool-header p {
    font-size: 0.85rem;
  }
  
  .tool-card {
    padding: 16px;
  }
  
  .tool-icon {
    width: 48px;
    height: 48px;
    font-size: 1.5rem;
  }
  
  .tool-name {
    font-size: 0.95rem;
  }
  
  .tool-desc {
    font-size: 0.8rem;
  }
  
  /* 导航栏移动端优化 */
  nav {
    padding: 0 12px;
    height: 56px;
  }
  
  .logo {
    font-size: 1.1rem;
  }
  
  .logo-icon {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }
  
  /* 工具网格移动端优化 */
  .tools-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  /* 按钮移动端优化 */
  .btn {
    padding: 12px 20px;
    font-size: 0.9rem;
  }
  
  /* 表单元素移动端优化 */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="url"],
  input[type="tel"],
  textarea,
  select {
    padding: 12px;
    font-size: 16px !important;
  }
}

/* 移动端适配 - 中等屏幕手机 */
@media (min-width: 481px) and (max-width: 768px) {
  .tool-container {
    padding: 90px 16px 50px;
  }
  
  .tools-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  
  nav {
    padding: 0 16px;
  }
}

/* 移动端适配 - 平板 */
@media (min-width: 769px) and (max-width: 1024px) {
  .tools-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ====== 主题切换功能 ====== */

/* 浅色主题变量 */
[data-theme="light"] {
  --primary: #6c63ff;
  --secondary: #00d4ff;
  --accent: #ff6b6b;
  --accent2: #ffd93d;
  --dark: #ffffff;
  --dark2: #f8f9fa;
  --dark3: #e9ecef;
  --card: rgba(0, 0, 0, 0.04);
  --card-border: rgba(0, 0, 0, 0.08);
  --text: #212529;
  --text-muted: #6c757d;
  --gradient1: linear-gradient(135deg, #6c63ff, #00d4ff);
  --gradient2: linear-gradient(135deg, #ff6b6b, #ffd93d);
  --gradient3: linear-gradient(135deg, #00d4ff, #06ffa5);
  --gradient4: linear-gradient(135deg, #a78bfa, #ec4899);
  --gradient5: linear-gradient(135deg, #fb923c, #f97316);
  --gradient6: linear-gradient(135deg, #06ffa5, #00d4ff);
  --gradient7: linear-gradient(135deg, #f97316, #ffd93d);
  --gradient8: linear-gradient(135deg, #ec4899, #a78bfa);
  --bg-primary: #e9ecef;
  --bg-secondary: #f1f3f5;
}

/* 主题切换按钮 */
.theme-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--gradient1);
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(108, 99, 255, 0.4);
  transition: all 0.3s ease;
  z-index: 1000;
}

.theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(108, 99, 255, 0.6);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* 浅色主题下的样式调整 */
[data-theme="light"] body {
  background: var(--dark);
  color: var(--text);
}

[data-theme="light"] nav {
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--card-border);
}

[data-theme="light"] nav.scrolled {
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 4px 30px rgba(108, 99, 255, 0.15);
}

[data-theme="light"] .tool-card {
  background: var(--card);
  border: 1px solid var(--card-border);
}

[data-theme="light"] .tool-card:hover {
  background: var(--dark3);
  border-color: var(--primary);
}

[data-theme="light"] input[type="text"],
[data-theme="light"] input[type="email"],
[data-theme="light"] input[type="password"],
[data-theme="light"] input[type="search"],
[data-theme="light"] input[type="url"],
[data-theme="light"] input[type="tel"],
[data-theme="light"] textarea,
[data-theme="light"] select {
  background: var(--dark2);
  border: 1px solid var(--card-border);
  color: var(--text);
}

[data-theme="light"] .btn-primary,
[data-theme="light"] .btn:not(.btn-secondary):not(.btn-success):not(.btn-danger):not(.btn-copy) {
  background: var(--gradient1);
  color: white;
}

[data-theme="light"] .btn-primary:hover,
[data-theme="light"] .btn:not(.btn-secondary):not(.btn-success):not(.btn-danger):not(.btn-copy):hover {
  opacity: 0.9;
}

[data-theme="light"] .btn-secondary {
  background: #e9ecef;
  color: #212529;
  border: 1px solid #ced4da;
}

[data-theme="light"] .btn-secondary:hover {
  background: #dee2e6;
}

[data-theme="light"] .btn-success {
  background: #28a745;
  color: white;
}

[data-theme="light"] .btn-success:hover {
  background: #218838;
}

/* 浅色主题：页脚适配 */
[data-theme="light"] footer {
  background: #f1f3f5;
  border-top: 1px solid var(--card-border);
}

[data-theme="light"] .footer-brand-desc,
[data-theme="light"] .footer-links a,
[data-theme="light"] .footer-icp,
[data-theme="light"] .footer-icp a,
[data-theme="light"] .footer-copyright {
  color: var(--text-muted);
}

[data-theme="light"] .footer-icp a:hover {
  color: var(--text);
}

[data-theme="light"] .footer-links a {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.1);
}

[data-theme="light"] .footer-links a:hover {
  background: rgba(108,99,255,0.1);
  border-color: var(--primary);
}

[data-theme="light"] .footer-divider {
  background: rgba(0,0,0,0.1);
}

/* 浅色主题：特色功能卡片 */
[data-theme="light"] .feature-card {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
}

[data-theme="light"] .feature-card:hover {
  border-color: rgba(108,99,255,0.3);
  box-shadow: 0 8px 30px rgba(0,0,0,0.08);
}

/* 浅色主题：快速工具条 */
[data-theme="light"] .quick-tool-item {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
}

[data-theme="light"] .quick-tool-item:hover {
  background: rgba(108,99,255,0.06);
  border-color: rgba(108,99,255,0.3);
}

/* 浅色主题：分类按钮 */
[data-theme="light"] .cat-btn {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.08);
  color: var(--text-muted);
}

[data-theme="light"] .cat-btn:hover,
[data-theme="light"] .cat-btn.active {
  background: rgba(108,99,255,0.1);
  border-color: rgba(108,99,255,0.3);
  color: var(--text);
}

/* 浅色主题：section-tag 标签 */
[data-theme="light"] .section-tag {
  background: rgba(108,99,255,0.08);
  border-color: rgba(108,99,255,0.2);
}

/* 浅色主题：特性标签 */
[data-theme="light"] .feature-tag {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.1);
  color: var(--text-muted);
}

/* 浅色主题：条幅 */
[data-theme="light"] .showcase-section {
  background: #f1f3f5;
}

[data-theme="light"] .marquee-item {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.08);
  color: var(--text-muted);
}

[data-theme="light"] .marquee-item:hover {
  color: var(--text);
  border-color: rgba(108,99,255,0.3);
}

/* 浅色主题：搜索浮层 */
[data-theme="light"] .search-overlay-box {
  background: var(--dark3);
}
[data-theme="light"] .search-results-dropdown {
  background: #fff;
  border-color: #dee2e6;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
[data-theme="light"] .search-result-item {
  border-bottom-color: #e9ecef;
}
[data-theme="light"] .search-result-item:hover,
[data-theme="light"] .search-result-item.selected {
  background: #f1f3f5;
}

[data-theme="light"] .rainbow-line {
  opacity: 0.4;
}

/* ====== 触摸设备优化 ====== */

/* 移除触摸设备上的hover效果 */
@media (hover: none) {
  .tool-card:hover {
    transform: none;
    box-shadow: none;
  }
  
  .btn:hover {
    transform: none;
  }
}

/* 优化触摸滚动 */
* {
  -webkit-overflow-scrolling: touch;
}

/* 防止移动端长按选中文本 */
.user-select-none {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* 优化移动端点击反馈 */
@media (max-width: 768px) {
  .tool-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
  
  .btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }
}

/* ====== 性能优化 ====== */

/* 使用will-change优化动画性能 */
.tool-card {
  will-change: transform;
}

.btn {
  will-change: transform;
}

/* 使用contain优化渲染性能 */
.tools-grid {
  contain: layout style;
}

.tool-container {
  contain: layout style;
}

/* ====== 打印样式优化 ====== */
@media print {
  nav,
  footer,
  .theme-toggle,
  .btn,
  .tool-badge {
    display: none !important;
  }
  
  body {
    background: white;
    color: black;
  }
  
  .tool-container {
    padding: 20px;
  }
}
