/* ============================================================
   园艺图鉴 — 月季与多肉
   设计系统：双主题（浅色/暗色）+ CSS 自定义属性驱动
   ============================================================ */

/* ===== 基础 Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== 主题变量：浅色模式（默认） ===== */
:root {
  /* 色彩 */
  --accent:        #b8382e;
  --accent-light:  #d94a3f;
  --accent-soft:   rgba(184, 56, 46, .08);
  --bg:            #f5f2ed;
  --surface:       #ffffff;
  --surface-hover: #faf8f5;
  --sidebar-bg:    #1e1010;
  --sidebar-text:  #c4b0b0;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(184, 56, 46, .28);
  --text:          #2c2c2c;
  --text-secondary:#6b6b6b;
  --text-muted:    #999999;
  --border:        #e8e3dc;
  --border-light:  rgba(0, 0, 0, .06);

  /* 阴影 */
  --shadow-sm:  0 1px 3px rgba(0, 0, 0, .06);
  --shadow-md:  0 4px 16px rgba(0, 0, 0, .08);
  --shadow-lg:  0 8px 32px rgba(0, 0, 0, .12);
  --shadow-card-hover: 0 8px 28px rgba(0, 0, 0, .14);

  /* 布局 */
  --sidebar-w:   220px;
  --header-h:    56px;
  --radius:      12px;
  --radius-sm:   8px;

  /* 过渡 */
  --theme-transition: background-color .3s ease, color .3s ease,
                       border-color .3s ease, box-shadow .3s ease;
}

/* ===== 暗色主题 ===== */
[data-theme="dark"] {
  --accent:        #e85d52;
  --accent-light:  #f07066;
  --accent-soft:   rgba(232, 93, 82, .12);
  --bg:            #131313;
  --surface:       #1e1e1e;
  --surface-hover: #242424;
  --sidebar-bg:    #0a0a0a;
  --sidebar-text:  #888888;
  --sidebar-hover: rgba(255, 255, 255, .04);
  --sidebar-active: rgba(232, 93, 82, .22);
  --text:          #e0e0e0;
  --text-secondary:#999999;
  --text-muted:    #666666;
  --border:        #2a2a2a;
  --border-light:  rgba(255, 255, 255, .06);

  --shadow-sm:  0 1px 3px rgba(0, 0, 0, .3);
  --shadow-md:  0 4px 16px rgba(0, 0, 0, .4);
  --shadow-lg:  0 8px 32px rgba(0, 0, 0, .5);
  --shadow-card-hover: 0 8px 28px rgba(0, 0, 0, .5);
}

/* ===== 全局 ===== */
html {
  /* 所有颜色属性平滑过渡 */
  transition: var(--theme-transition);
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ===== 桌面端顶栏 ===== */
header {
  height: var(--header-h);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .2);
  z-index: 100;
  transition: background .3s;
}
header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .04em;
}
header .search-wrap {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
header input[type=search] {
  padding: 7px 16px;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  width: 220px;
  outline: none;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  transition: background .2s;
}
header input[type=search]::placeholder { color: rgba(255, 255, 255, .6); }
header input[type=search]:focus {
  background: rgba(255, 255, 255, .28);
}

/* 主题切换按钮 */
#theme-toggle {
  background: rgba(255, 255, 255, .15);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .2s;
  flex-shrink: 0;
}
#theme-toggle:hover {
  background: rgba(255, 255, 255, .28);
  transform: scale(1.08);
}
#theme-toggle:active {
  transform: scale(.94);
}

/* ===== 移动端顶部导航条（默认隐藏）===== */
#mobile-nav { display: none; }

/* ===== 主布局 ===== */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - var(--header-h));
}

/* ===== 左侧分类（桌面端） ===== */
nav#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 12px 0 24px;
  transition: var(--theme-transition);
}
nav#sidebar h2 {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #777;
  padding: 16px 18px 8px;
}
nav#sidebar .cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  line-height: 1.3;
}
nav#sidebar .cat-item:hover {
  background: var(--sidebar-hover);
}
nav#sidebar .cat-item.active {
  background: var(--sidebar-active);
  border-left-color: var(--accent-light);
  color: #eee;
}
nav#sidebar .cat-item .label { flex: 1; }
nav#sidebar .cat-item .count {
  font-size: 11px;
  background: rgba(255, 255, 255, .1);
  padding: 1px 7px;
  border-radius: 10px;
  color: #aaa;
}
nav#sidebar .cat-item.active .count {
  background: rgba(255, 255, 255, .18);
  color: #eee;
}

/* 演化图谱入口 */
nav#sidebar .evo-link {
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  padding-top: 12px;
  text-decoration: none;
  color: #4fc3a7;
}
nav#sidebar .evo-link:hover { background: rgba(79, 195, 167, .12); }

/* ===== 树状分类结构 ===== */
.tree-group .parent-item {
  position: relative;
  font-weight: 600;
  color: #e0c8c8;
}
.tree-arrow {
  font-size: 10px;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  transition: transform .2s;
  color: #bbb;
}
.leaf-item .label { padding-left: 4px; font-size: 13.5px; }
.tree-indent { width: 20px; height: 1px; flex-shrink: 0; }

/* ===== 右侧主区域 ===== */
main#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  transition: var(--theme-transition);
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 10px;
}
.section-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}
.section-header .total {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== 卡片网格 ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  overflow: hidden;
  transition: transform .25s cubic-bezier(.16, 1, .3, 1),
              box-shadow .25s cubic-bezier(.16, 1, .3, 1),
              var(--theme-transition);
  display: flex;
  flex-direction: column;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-card-hover);
}
.card:active {
  transform: translateY(-1px);
}

.card .thumb {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .4s ease;
  background: var(--border);
}
.card .thumb.loaded { opacity: 1; }

/* 骨架屏 shimmer */
.card .thumb-skeleton {
  width: 100%;
  height: 140px;
  background: linear-gradient(
    90deg,
    var(--border) 25%,
    var(--surface-hover) 50%,
    var(--border) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.card .no-thumb {
  width: 100%;
  height: 140px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: var(--text-muted);
  opacity: 0;
  animation: fadeIn .3s .1s forwards;
}

.card .card-title {
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

/* 搜索结果的分类标签 */
.card .card-cat {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: .02em;
  opacity: .92;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

/* ===== 无匹配提示 ===== */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 0;
  color: var(--text-muted);
  font-size: 15px;
}

/* ===== 弹窗 ===== */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 9000;
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
#modal-overlay.open { display: flex; }

#modal-box {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border-light);
  box-shadow: 0 16px 64px rgba(0, 0, 0, .25);
  width: min(92vw, 1080px);
  height: min(90vh, 800px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  animation: modalEnter .25s cubic-bezier(.16, 1, .3, 1);
  transition: var(--theme-transition);
}
@keyframes modalEnter {
  from { opacity: 0; transform: scale(.94) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

#modal-header {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  background: var(--accent);
  color: #fff;
  gap: 12px;
  flex-shrink: 0;
}
#modal-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#modal-close {
  background: rgba(255, 255, 255, .18);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .15s;
}
#modal-close:hover {
  background: rgba(255, 255, 255, .32);
  transform: scale(1.08);
}

/* ===== 详情内联容器 ===== */
#detail-view {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  background: var(--surface);
  display: none;
  transition: var(--theme-transition);
}
#detail-view.active { display: block; }
#detail-view .detail-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  padding: 18px 24px 10px;
  border-bottom: 2px solid var(--accent);
  margin: 0;
}
#detail-view .detail-body {
  padding: 14px 24px 28px;
  line-height: 1.85;
  color: var(--text-secondary);
  font-size: 14.5px;
}
#detail-view .detail-body p {
  margin: 10px 0;
  text-indent: 2em;
}
#detail-view .detail-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin: 8px 0;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity .4s ease, transform .2s, box-shadow .2s;
}
#detail-view .detail-body img.loaded { opacity: 1; }
#detail-view .detail-body img:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
}
#detail-view .detail-error,
#detail-view .detail-loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* 图片灯箱 */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .88);
  backdrop-filter: blur(8px);
  z-index: 99999;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#lightbox.active { display: flex; }
#lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 4px 32px rgba(0, 0, 0, .4);
  opacity: 0;
  transition: opacity .3s ease;
}
#lightbox img.loaded { opacity: 1; }

/* ===== 加载状态 ===== */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  gap: 16px;
  transition: opacity .3s ease, visibility .3s ease;
  opacity: 1;
  visibility: visible;
}
#loading.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
#loading .spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading p { color: var(--text-muted); font-size: 14px; }

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
nav#sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); }

/* ============================================
   移动端响应式：≤768px
   ============================================ */
@media (max-width: 768px) {
  header { display: none; }
  nav#sidebar { display: none; }

  #mobile-nav {
    display: flex;
    flex-direction: column;
    width: 100%;
    background: var(--accent);
    color: #fff;
    flex-shrink: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
  }

  #mobile-nav .cat-scroll {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
    padding: 0 4px;
  }
  #mobile-nav .cat-scroll::-webkit-scrollbar { display: none; }

  #mobile-nav .cat-chip {
    flex-shrink: 0;
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    transition: background .15s, border-color .15s;
    color: rgba(255, 255, 255, .8);
    user-select: none;
    -webkit-user-select: none;
  }
  #mobile-nav .cat-chip:hover {
    background: rgba(255, 255, 255, .1);
    color: #fff;
  }
  #mobile-nav .cat-chip.active {
    border-bottom-color: #fff;
    color: #fff;
    font-weight: 600;
  }
  #mobile-nav .evo-chip {
    color: #4fc3a7;
    border-bottom: 2px solid transparent;
    text-decoration: none;
  }

  /* 移动端主题切换 + 搜索栏 */
  #mobile-nav .mobile-toolbar {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 8px;
  }
  #mobile-nav .mobile-toolbar input[type=search] {
    flex: 1;
    padding: 8px 14px;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    background: rgba(255, 255, 255, .2);
    color: #fff;
  }
  #mobile-nav .mobile-toolbar input[type=search]::placeholder {
    color: rgba(255, 255, 255, .65);
  }
  #mobile-nav .mobile-toolbar input[type=search]:focus {
    background: rgba(255, 255, 255, .35);
  }

  #mobile-theme-toggle {
    background: rgba(255, 255, 255, .15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
  }
  #mobile-theme-toggle:hover {
    background: rgba(255, 255, 255, .28);
  }

  /* 主内容区调整 */
  .layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  main#content {
    padding: 16px 12px;
    overflow-y: visible;
    height: auto;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }
  .section-header h2 { font-size: 17px; }
}

/* 超小屏幕 */
@media (max-width: 420px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .card .card-title { font-size: 11.5px; padding: 6px 8px; }
}

/* ===== 通用淡入动画 ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ===== 系统暗色模式自动检测（无用户手动选择时） ===== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --accent:        #e85d52;
    --accent-light:  #f07066;
    --accent-soft:   rgba(232, 93, 82, .12);
    --bg:            #131313;
    --surface:       #1e1e1e;
    --surface-hover: #242424;
    --sidebar-bg:    #0a0a0a;
    --sidebar-text:  #888888;
    --sidebar-hover: rgba(255, 255, 255, .04);
    --sidebar-active: rgba(232, 93, 82, .22);
    --text:          #e0e0e0;
    --text-secondary:#999999;
    --text-muted:    #666666;
    --border:        #2a2a2a;
    --border-light:  rgba(255, 255, 255, .06);
    --shadow-sm:  0 1px 3px rgba(0, 0, 0, .3);
    --shadow-md:  0 4px 16px rgba(0, 0, 0, .4);
    --shadow-lg:  0 8px 32px rgba(0, 0, 0, .5);
    --shadow-card-hover: 0 8px 28px rgba(0, 0, 0, .5);
  }
}
