:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #dfe5ee;
  --text: #18212f;
  --muted: #6b7788;
  --primary: #0f6fff;
  --danger: #d92d20;
  --success: #067647;
  --shadow: 0 10px 30px rgba(22, 31, 52, 0.08);
}
html[data-theme="dark"] {
  --bg: #0f141c;
  --card: #171e29;
  --line: #273245;
  --text: #edf2fb;
  --muted: #9aa7bb;
  --primary: #6ea8ff;
  --danger: #ff6b5f;
  --success: #38c793;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
.wrap { width: min(1240px, calc(100% - 32px)); margin: 0 auto; }
.site-header { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 70px; }
.brand { font-size: 20px; font-weight: 700; white-space: nowrap; flex: 0 0 auto; }
.header-tools { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex: 1 1 auto; min-width: 0; }
.site-search { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-left: auto; flex: 0 1 460px; }
.site-search input {
  width: min(360px, 100%); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--card); color: var(--text);
}
.top-nav { display: flex; gap: 10px; color: var(--muted); align-items: center; flex-wrap: wrap; justify-content: flex-end; flex: 0 0 auto; }
.lang-toggle, .theme-toggle {
  border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 999px; padding: 8px 12px; cursor: pointer;
}
.lang-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.main-content { padding: 28px 0 48px; }
.hero, .page-header, .panel, .auth-card, .empty-state { background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.hero, .page-header, .panel, .auth-card, .empty-state { padding: 24px; }
.hero h1, .page-header h1, .auth-card h1 { margin: 0 0 8px; font-size: 30px; }
.compact-header h2, .panel h2 { margin: 0; }
.hero p, .page-header p, .muted, .card-body p, .empty-state p, .gallery-subtext { color: var(--muted); margin: 0; }
.small-text { font-size: 13px; }
.page-header.split, .toolbar-inline, .header-row, .panel-header { display: flex; gap: 12px; align-items: center; }
.page-header.split, .panel-header { justify-content: space-between; }
.toolbar-inline { flex-wrap: wrap; }
.toolbar-inline.grow { justify-content: center; }
.panel { margin-top: 20px; }
.page-header + .section-block { margin-top: 20px; }
.panel h2 { margin-bottom: 16px; font-size: 20px; }
.flash-stack {
  position: fixed;
  top: 84px;
  right: 18px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(420px, calc(100vw - 24px));
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .22s ease, transform .22s ease;
}
.flash { padding: 12px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.flash.success { border-color: rgba(6, 118, 71, 0.35); color: var(--success); }
.flash.error { border-color: rgba(217, 45, 32, 0.35); color: var(--danger); }
.stack-form { display: grid; gap: 14px; }
.stack-form.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack-form label { display: grid; gap: 8px; }
.stack-form span { color: var(--muted); font-size: 14px; }
.stack-form input[type="text"], .stack-form input[type="password"], .stack-form input[type="file"], .stack-form select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--card); color: var(--text);
}
.checkbox-line { display: inline-flex !important; gap: 10px; align-items: center; }
.btn {
  display: inline-flex; justify-content: center; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: var(--card); color: var(--text); cursor: pointer;
}
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn:disabled { opacity: 0.65; cursor: not-allowed; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.card-grid.compact { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.album-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.cover-frame { aspect-ratio: 4 / 3; background: color-mix(in srgb, var(--card) 72%, #d9e3f2 28%); overflow: hidden; }
.cover-frame.small { aspect-ratio: 1.1 / 1; }
.cover-frame img { width: 100%; height: 100%; object-fit: cover; }
.cover-empty { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.card-body { padding: 14px; }
.card-body h3 { margin: 0 0 6px; font-size: 18px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.gallery-item { position: relative; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--card); }
.gallery-item img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; background: color-mix(in srgb, var(--card) 72%, #d9e3f2 28%); }
.gallery-item span, .gallery-subtext { display: block; padding: 10px 12px 0; font-size: 14px; }
.gallery-subtext { padding: 0 12px 12px; }
.admin-item { padding-bottom: 12px; cursor: pointer; transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease; }
.admin-item:hover { transform: translateY(-1px); }
.admin-item.selected { border-color: color-mix(in srgb, var(--primary) 55%, var(--line) 45%); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent); }
.admin-item .toolbar-inline { padding: 0 10px; }
.admin-item .toolbar-inline, .admin-item .image-check { cursor: auto; }
.image-meta-box strong { display:block; overflow-wrap:anywhere; }
.image-check { position:absolute; top:10px; left:10px; background:rgba(255,255,255,0.9); padding:6px; border-radius:10px; z-index:2; }
.auth-card { width: min(420px, 100%); margin: 48px auto 0; }
.empty-state { text-align: center; padding: 36px 24px; }
.breadcrumbs { margin-bottom: 18px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.section-block + .section-block { margin-top: 24px; }
.admin-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 20px; }
.tree-list { display: grid; gap: 12px; }
.tree-item { border: 1px solid var(--line); border-radius: 14px; background: var(--card); padding: 12px 14px; }
.tree-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tree-actions { display: flex; gap: 8px; }
.tree-open .tree-item { box-shadow: none; }
.depth-1 { margin-left: 20px; }
.depth-2 { margin-left: 40px; }
.depth-3 { margin-left: 60px; }
.depth-4 { margin-left: 80px; }
.upload-progress { width: 100%; height: 12px; background: color-mix(in srgb, var(--card) 65%, #c7d3e6 35%); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.upload-progress-bar { width: 0; height: 100%; background: linear-gradient(90deg, var(--primary), #7db2ff); transition: width 0.2s ease; }
.upload-meta { color: var(--muted); font-size: 14px; }
.drop-zone { border: 2px dashed var(--line); border-radius: 16px; padding: 20px; text-align:center; color:var(--muted); cursor:pointer; }
.drop-zone.dragover { border-color: var(--primary); color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--card) 92%); }
.list-toolbar { margin-bottom: 14px; }
.viewer-layout { display:grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; }
.viewer-stage { position:relative; min-height: 70vh; display:flex; align-items:center; justify-content:center; background: color-mix(in srgb, var(--card) 70%, #c7d3e6 30%); border-radius: 18px; overflow:hidden; }
.viewer-image { max-height: 78vh; width:auto; object-fit: contain; }
.viewer-arrow { position:absolute; top:50%; transform:translateY(-50%); background: rgba(18,25,38,0.55); color:#fff; padding:12px 14px; border-radius:999px; }
.viewer-arrow.left { left:16px; }
.viewer-arrow.right { right:16px; }
.meta-list { display:grid; gap: 12px; margin: 14px 0 18px; }
.meta-list div { display:grid; gap: 4px; padding-bottom:12px; border-bottom:1px solid var(--line); }
@media (max-width: 1100px) {
  .header-row { flex-direction: column; align-items: stretch; padding: 10px 0; }
  .header-tools { width: 100%; flex-direction: column; align-items: stretch; }
  .site-search { width: 100%; max-width: none; flex: 1 1 auto; }
  .site-search input { width: 100%; }
  .top-nav { justify-content: flex-end; }
  .viewer-layout { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
  .stack-form.two-col { grid-template-columns: 1fr; }
  .page-header.split, .tree-row { flex-direction: column; align-items: flex-start; }
}

.tree-toolbar { margin-bottom: 16px; }
.tree-collapsible { gap: 10px; }
.tree-node { border: 1px solid var(--line); border-radius: 14px; background: var(--card); overflow: hidden; }
.tree-summary { list-style: none; cursor: pointer; padding: 12px 14px; }
.tree-summary::-webkit-details-marker { display: none; }
.tree-main { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.tree-caret { width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform 0.18s ease; margin-left: 2px; flex: 0 0 auto; }
.tree-node[open] > .tree-summary .tree-caret { transform: rotate(45deg); }
.tree-meta-inline { display: inline-block; margin-left: 8px; }
.tree-children { padding: 0 10px 10px; display: grid; gap: 10px; }
.tree-leaf-self { background: color-mix(in srgb, var(--card) 96%, var(--primary) 4%); }
.tree-leaf, .tree-leaf-self { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tree-summary .tree-actions { margin-left: auto; }
@media (max-width: 900px) {
  .tree-meta-inline { display: block; margin: 4px 0 0; }
}

.header-actions-wrap { justify-content: flex-end; }
.category-jump { display: grid; gap: 6px; min-width: 220px; }
.category-jump select { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--card); color: var(--text); }
.tree-main { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.tree-thumb-wrap { flex: 0 0 auto; }
.tree-thumb { width: 42px; height: 42px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); background: color-mix(in srgb, var(--card) 72%, #d9e3f2 28%); }
.tree-thumb-empty { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; font-weight: 700; }
.tree-spacer { width: 14px; flex: 0 0 14px; }
.tree-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tree-actions { margin-left: auto; }
.tree-summary::-webkit-details-marker { display: none; }
.tree-summary { list-style: none; }
@media (max-width: 760px) {
  .header-actions-wrap { width: 100%; justify-content: stretch; }
  .category-jump { min-width: 100%; }
  .tree-row { align-items: flex-start; }
  .tree-actions { width: 100%; display: flex; justify-content: flex-end; }
}


.viewer-side h2, .meta-list span {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.viewer-side h2 {
  line-height: 1.35;
  margin: 0 0 14px;
}
.category-jump {
  min-width: 260px;
}
.category-jump select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 11px 42px 11px 14px;
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) calc(50% - 3px), calc(100% - 14px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
@media (max-width: 760px) {
  .category-jump {
    min-width: 100%;
  }
}


.viewer-main.panel { display: grid; gap: 16px; }
.viewer-filmstrip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 86px;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 2px;
  scrollbar-width: thin;
  scroll-behavior: smooth;
  scroll-padding-inline: 30%;
}

.film-thumb {
  display: block;
  border: 2px solid transparent;
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.film-thumb img {
  width: 100%;
  height: 72px;
  object-fit: cover;
}
.film-thumb:hover { transform: translateY(-1px); }
.film-thumb.active { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent); }
@media (max-width: 1100px) {
  .top-nav { justify-content: flex-end; }
}
@media (max-width: 760px) {
  .top-nav { width: 100%; justify-content: flex-end; }
  .viewer-filmstrip { grid-auto-columns: 74px; }
  .film-thumb img { height: 64px; }
}


.admin-tree-header { align-items: flex-end; gap: 16px; }
.admin-tree-toolbar { margin-top: 14px; }
.admin-category-jump { min-width: 280px; }
.admin-tree-list .tree-summary .tree-actions,
.admin-tree-list .tree-actions { flex-wrap: wrap; }
@media (max-width: 760px) {
  .admin-tree-header { align-items: stretch; }
  .admin-category-jump { min-width: 100%; }
}

.current-album {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--line) 45%) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent), var(--shadow);
  background: color-mix(in srgb, var(--primary) 5%, var(--card) 95%);
}
.current-badge {
  color: var(--primary);
  font-weight: 700;
}
.tree-drag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  cursor: grab;
  user-select: none;
  flex: 0 0 auto;
  background: color-mix(in srgb, var(--card) 92%, var(--primary) 8%);
}
.tree-drag:active { cursor: grabbing; }
.sortable-node.dragging {
  opacity: 0.68;
}
[data-sort-container="1"].drag-target {
  background: color-mix(in srgb, var(--primary) 5%, transparent);
  border-radius: 14px;
}
.admin-tree-list .sortable-node {
  transition: box-shadow .16s ease, transform .16s ease, border-color .16s ease;
}
.admin-tree-list .sortable-node:hover {
  transform: translateY(-1px);
}
.admin-tree-list .tree-summary .tree-main,
.admin-tree-list .tree-row .tree-main {
  min-width: 0;
}


.admin-gallery { align-items: stretch; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.admin-gallery.manual-sort-mode { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.admin-item { display: flex; flex-direction: column; min-height: 100%; padding-bottom: 0; }
.admin-item img { flex: 0 0 auto; }
.admin-item .image-meta-box { flex: 1 1 auto; display: grid; align-content: start; gap: 6px; padding-bottom: 10px; }
.admin-item .image-meta-box p { margin: 0; color: var(--muted); overflow-wrap: anywhere; word-break: break-word; }
.admin-item .image-meta-box strong { line-height: 1.35; max-height: 3.2em; overflow: hidden; }
.admin-item .image-meta-box p { min-height: 2.8em; }
.image-actions { margin-top: auto; padding: 10px 10px 12px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; align-items: stretch; }
.image-actions > a, .image-actions > form { width: 100%; }
.image-actions .btn { width: 100%; min-height: 36px; }
.image-actions form { margin: 0; }
.image-sort-form { margin: 0; }
.image-sort-label { display: inline-flex; align-items: center; margin: 0; }
.image-sort-label select { border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; background: var(--card); color: var(--text); min-width: 170px; height: 38px; }
.panel-header .toolbar-inline { align-items: center; }
.panel-header #bulkDeleteForm { margin: 0; }
.image-drag { position: absolute; top: 10px; right: 10px; z-index: 2; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 10px; border: 1px dashed var(--line); background: rgba(255,255,255,0.92); color: var(--muted); cursor: grab; user-select: none; }
html[data-theme="dark"] .image-drag { background: rgba(23,30,41,0.94); }
.image-drag:active { cursor: grabbing; }
#adminImageGrid .admin-item.dragging { opacity: .65; transform: scale(.985); }
#adminImageGrid.manual-sort-mode { position: relative; }
@media (max-width: 1280px) { .admin-gallery, .admin-gallery.manual-sort-mode { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 980px) { .admin-gallery, .admin-gallery.manual-sort-mode { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) { .admin-gallery, .admin-gallery.manual-sort-mode { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

@media (max-width: 760px) { .image-actions { grid-template-columns: 1fr; } .image-sort-label select { min-width: 100%; } }


.flash-stack {
  position: fixed;
  top: 84px;
  right: 18px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(420px, calc(100vw - 24px));
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .22s ease, transform .22s ease;
}
.flash-stack.show { opacity: 1; transform: translateY(0); }
.flash-stack.hide { opacity: 0; transform: translateY(-8px); }
.flash { box-shadow: 0 14px 36px rgba(0,0,0,.14); }

.gallery-grid.admin-gallery {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 1200px) {
  .gallery-grid.admin-gallery { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .gallery-grid.admin-gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .gallery-grid.admin-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) {
  .gallery-grid.admin-gallery { grid-template-columns: 1fr; }
}
