/* ---------------- theme tokens ----------------
 * The active palette is chosen by <html data-theme="dark|light">, which the
 * inline script in <head> sets (from localStorage, else the OS preference)
 * BEFORE the page paints so there is no flash. Dark is the default. */
:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaee;
  --muted: #98a0b0;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);

  /* theme-independent tokens */
  --brand: #4f8cff;
  --brand-2: #7c5cff;
  --ok: #2ecc71;
  --warn: #f0b429;
  --danger: #ff5d5d;
  --radius: 14px;
  --wrap: 1500px;
}

/* Follow the OS preference unless the user has explicitly picked a theme. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e2e5ea;
    --text: #14171c;
    --muted: #626b7a;
    --shadow: 0 10px 30px rgba(16, 24, 40, .08);
  }
}

/* Manual override — force light (beats the media query via source order). */
:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #14171c;
  --muted: #626b7a;
  --shadow: 0 10px 30px rgba(16, 24, 40, .08);
}

/* Manual override — force dark. */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaee;
  --muted: #98a0b0;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans Thai", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip; /* prevent a horizontal scrollbar from full-bleed sections */
}

img { max-width: 100%; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2.1rem); }
code { background: var(--surface-2); padding: .1em .4em; border-radius: 6px; font-size: .9em; }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 18px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 99; }

/* ---------------- header ---------------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 16px; height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 800; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--brand); font-size: 1.1rem; }
.brand-name { font-size: 1.15rem; }
.brand-name small { font-weight: 500; color: var(--muted); font-size: .7rem; }

.search-form { margin-left: auto; display: flex; flex: 0 1 420px; }
.search-form input {
  flex: 1; min-width: 0; padding: 10px 14px; border: 1px solid var(--border);
  border-right: none; border-radius: 10px 0 0 10px; background: var(--surface);
  color: var(--text); font-size: .95rem; outline: none;
}
.search-form input:focus { border-color: var(--brand); }
.search-form button {
  padding: 10px 18px; border: none; border-radius: 0 10px 10px 0; cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 600;
}
.nav-toggle { display: none; margin-left: 0; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 1.1rem; cursor: pointer; }

/* right-side header actions: language (reserved) + theme toggle + mobile menu */
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.header-actions .nav-toggle { margin-left: 0; }

/* language switcher button — active, toggles TH/EN */
.lang-toggle {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  transition: color .18s ease, border-color .18s ease, background .18s ease;
}
.lang-toggle:hover { border-color: var(--brand); color: var(--brand); background: var(--surface-2); }
.lang-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.lang-toggle svg { display: block; }
/* admin sidebar: full-width labelled toggle */
.admin-sidebar-foot .lang-toggle { width: 100%; justify-content: flex-start; font-size: .86rem; font-weight: 600; }
.admin-sidebar-foot .theme-toggle { width: 100%; justify-content: flex-start; gap: 8px; font-size: .86rem; font-weight: 600; }
.admin-sidebar-foot .theme-toggle .theme-toggle-label { font-weight: 600; }

/* dark / light theme switch — right side of the header, same row as the brand */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  transition: color .18s ease, border-color .18s ease, background .18s ease;
}
.theme-toggle:hover { border-color: var(--brand); color: var(--brand); background: var(--surface-2); }
.theme-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.theme-toggle svg { display: none; }
/* dark (default) shows the sun icon — tapping switches to light */
.theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: block; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }

.cat-nav { border-top: 1px solid var(--border); background: var(--surface); }
.cat-nav-inner { display: flex; align-items: center; gap: 4px; padding: 6px 18px; overflow: visible; }
.cat-nav a {
  white-space: nowrap; padding: 7px 13px; border-radius: 999px; color: var(--muted);
  font-size: .88rem; font-weight: 500;
}
.cat-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.cat-nav a.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.caret { display: inline-block; margin-left: 3px; font-size: .7em; opacity: .7; }

/* dropdown for categories with subcategories — opened ONE at a time via .open */
.cat-item { position: relative; }
.cat-item .cat-sub {
  display: none;
  position: absolute; top: 100%; left: 0; z-index: 60;
  min-width: 235px; max-width: min(92vw, 340px); max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px;
  text-align: left;
}
.cat-sub.align-right { left: auto; right: 0; }
.cat-item.open > .cat-sub { display: block; }

.cat-sub .sub-link {
  display: block; white-space: nowrap; padding: 7px 12px; border-radius: 8px;
  color: var(--muted); font-size: .85rem; font-weight: 500;
}
.cat-sub .sub-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.cat-sub .sub-link.active { color: var(--brand); background: var(--surface-2); }
.cat-sub .sub-link--all {
  font-weight: 700; color: var(--text);
  border-bottom: 1px solid var(--border); border-radius: 8px 8px 0 0; margin-bottom: 4px;
}

/* subcategory chips on the category page */
.subcat-nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.subcat-nav .chip { font-size: .82rem; padding: 6px 13px; }
.chip-active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; }
.chip-active:hover { color: #fff; }

main { padding: 26px 18px 60px; }

/* ---------------- hero ---------------- */
.hero { margin: 6px 0 24px; max-width: 760px; }
.hero h1 { margin-bottom: .25em; }
.hero p { margin: 0; }

/* homepage hero: rotating background + tabs + search + tags */
.hero-bg { position: relative; overflow: hidden; min-height: 440px; display: flex; align-items: center; justify-content: center; border-radius: 0 0 22px 22px; margin-left: calc(50% - 50vw); margin-right: calc(50% - 50vw); }
.hero-bg .layer { position: absolute; inset: 0; background-size: cover; background-position: center; opacity: 0; transition: opacity .9s ease; transform: scale(1.05); }
.hero-bg .layer.show { opacity: 1; }
.hero-bg .layer-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-bg .tint { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,.5) 0%, rgba(0,0,0,.35) 45%, rgba(0,0,0,.62) 100%); }
.hero-content { position: relative; z-index: 2; text-align: center; max-width: 1160px; margin: 0 auto; padding: 60px 28px; color: #fff; }
.hero-content h1 { font-size: clamp(1.7rem, 1.3rem + 2vw, 2.8rem); margin: 0 0 24px; text-shadow: 0 2px 8px rgba(0,0,0,.45); }
.tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 24px; }
.tabs a { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22); backdrop-filter: blur(6px); padding: 8px 20px; border-radius: 999px; font-size: .95rem; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.tabs a:hover { background: rgba(255,255,255,.26); text-decoration: none; }
.tabs a.on { background: #fff; color: #10131a; font-weight: 700; border-color: #fff; text-decoration: none; }
.search-row { display: flex; gap: 10px; max-width: 780px; margin: 0 auto 20px; }
.search-row input { flex: 1; min-width: 0; padding: 15px 20px; border: none; border-radius: 999px; background: #fff; color: #10131a; font-size: 1.05rem; outline: none; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.search-row input::placeholder { color: #8b8f97; }
.search-row button { padding: 15px 32px; border: none; border-radius: 999px; cursor: pointer; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.tag { background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.2); backdrop-filter: blur(6px); padding: 7px 15px; border-radius: 999px; font-size: .88rem; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.tag:hover { background: rgba(255,255,255,.3); text-decoration: none; }
.arrow { position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; background: rgba(0,0,0,.35); color: #fff; border-radius: 999px; width: 42px; height: 42px; font-size: 1.1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; border: none; backdrop-filter: blur(4px); }
.arrow:hover { background: rgba(0,0,0,.55); }
.arrow.prev { left: 18px; }
.arrow.next { right: 18px; }
.dots { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; gap: 8px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,.4); cursor: pointer; transition: background .2s; box-sizing: content-box; padding: 8px; background-clip: content-box; }
.dots i.on { background-color: #fff; }
.credit { position: absolute; left: 20px; bottom: 14px; z-index: 3; display: flex; align-items: center; gap: 10px; color: #fff; font-size: .82rem; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.credit .avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; }
.credit-txt b { display: block; font-weight: 700; }
.credit-txt span { opacity: .85; font-size: .72rem; }

/* centered search bar (category / search / photo pages) */
.page-search { max-width: 720px; margin: 16px auto 6px; padding: 0 18px; }
.search-bar { display: flex; gap: 8px; max-width: 560px; margin: 0 auto; }
.search-bar input { flex: 1; min-width: 0; padding: 11px 16px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-size: .95rem; outline: none; }
.search-bar input:focus { border-color: var(--brand); }
.search-bar button { padding: 11px 20px; border: none; border-radius: 999px; cursor: pointer; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 600; }

/* homepage "Browse by category" tiles */
.section-title { font-size: 1.4rem; margin: 28px 0 14px; }
.section-head { margin: 28px 0 14px; }
.section-head .section-title { margin: 0; }
.section-sub { margin: 4px 0 0; font-size: .92rem; color: var(--muted); }
.cat-tiles { margin-top: 4px; }
.cat-tile-grid {
  display: grid; gap: 20px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: 1fr;
}
.cat-tile {
  position: relative; display: block; min-height: 230px; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--border);
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  color: var(--text); text-decoration: none;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.cat-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); }
.cat-tile-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.cat-tile:hover .cat-tile-img { transform: scale(1.06); }
.cat-tile::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.12) 20%, rgba(0,0,0,.72) 100%);
}
.cat-tile-body {
  position: absolute; left: 16px; right: 16px; bottom: 12px; z-index: 1;
  display: flex; flex-direction: column; gap: 3px;
}
.cat-tile-name { color: #fff; font-weight: 700; font-size: 1.15rem; text-shadow: 0 1px 3px rgba(0,0,0,.4); }
.cat-tile-count {
  font-size: .9rem;
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  width: fit-content;
  background: rgba(0,0,0,.45);
  padding: 3px 9px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
  text-shadow: none;
}

/* ยังไม่โชว์จำนวนรูปในหมวด — ดีไซน์ป้าย (ด้านบน) เก็บไว้แล้ว
   เมื่อต้องการแสดงจำนวน เพียงลบ/comment บรรทัดถัดไป */
.cat-tiles .cat-tile-count { display: none; }
.cat-tile .soon {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  background: rgba(0,0,0,.55); color: #fff; font-size: .7rem; font-weight: 600;
  padding: 4px 11px; border-radius: 999px; backdrop-filter: blur(4px);
}
/* decorative "image placeholder" icon on empty categories */
.cat-tile-art {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -62%);
  z-index: 1; color: color-mix(in srgb, var(--text) 18%, transparent); pointer-events: none;
}
.cat-tile-art svg { width: 46px; height: 46px; }
.cat-tile--empty {
  background:
    radial-gradient(120% 90% at 18% 0%, color-mix(in srgb, var(--brand) 22%, transparent), transparent 55%),
    radial-gradient(120% 90% at 100% 100%, color-mix(in srgb, var(--brand-2) 18%, transparent), transparent 55%),
    linear-gradient(135deg, var(--surface-2), var(--surface));
}
.cat-tile--empty::after { background: linear-gradient(180deg, rgba(0,0,0,0) 30%, rgba(0,0,0,.4) 100%); }
.cat-tile--empty .cat-tile-name { color: var(--text); text-shadow: none; }
.cat-tile--empty .cat-tile-count { color: var(--muted); text-shadow: none; }

.breadcrumb { font-size: .85rem; color: var(--muted); margin-bottom: 14px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- ads ---------------- */
.ad-box {
  margin: 22px 0; padding: 12px; border: 1px dashed var(--border);
  border-radius: var(--radius); background: var(--surface); text-align: center;
}
.ad-label { display: block; font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.ad-placeholder-inner { display: flex; flex-direction: column; gap: 4px; padding: 22px 12px; font-size: .9rem; }
.ad-header, .ad-footer { min-height: 96px; }
.ad-inarticle, .ad-sidebar { min-height: 250px; }

/* ---------------- grid ---------------- */
.photo-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}
/* "Trending now" grid — fixed 4 columns so top/bottom rows stay equal (4×2) */
.trending .photo-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  position: relative; aspect-ratio: 4 / 3;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); }
.card-link { display: block; position: absolute; inset: 0; color: inherit; }
.card-link:hover { text-decoration: none; }
.card-img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }

/* hover overlay — category + title at the bottom-left, hidden by default */
.card-overlay {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-start;
  gap: 4px; padding: 13px 74px 13px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,0) 45%, rgba(0,0,0,.82) 100%);
  opacity: 0; transition: opacity .2s ease;
}
.card-overlay .overlay-chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .68rem;
  background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.22);
}
.card-overlay .overlay-title {
  font-size: .95rem; font-weight: 600; color: #fff; margin: 0; line-height: 1.3;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* action buttons (like + download), icon only — bottom-right, revealed on hover */
.card-actions {
  position: absolute; right: 12px; bottom: 12px; z-index: 2;
  display: flex; align-items: center; gap: 8px; opacity: 0; transition: opacity .2s ease;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.5); color: #fff; border: 1px solid rgba(255,255,255,.25);
  cursor: pointer; backdrop-filter: blur(4px); text-decoration: none;
  transition: background .18s ease, transform .18s ease, border-color .18s ease;
}
.icon-btn:hover { background: rgba(0,0,0,.72); transform: translateY(-2px); text-decoration: none; }
.icon-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.like-btn svg { fill: none; stroke: currentColor; stroke-width: 2; }
.icon-btn.like-btn.liked svg { fill: currentColor; stroke: currentColor; }
.icon-btn.like-btn.liked { color: #ff5d5d; border-color: color-mix(in srgb, #ff5d5d 55%, transparent); background: rgba(255,93,93,.18); }
.icon-btn.dl-btn svg { stroke-width: 2; }

/* reveal on hover only where a real pointer can hover (no sticky hover on touch) */
@media (hover: hover) {
  .card:hover .card-overlay { opacity: 1; }
  .card:hover .card-actions { opacity: 1; }
  .card:hover .card-img { transform: scale(1.05); }
}
/* touch / no-hover devices can't hover, so the overlay would never appear —
   show the title (and the actions) permanently, with a lighter gradient. */
@media (hover: none) {
  .card-overlay { opacity: 1; padding: 12px 14px; background: linear-gradient(180deg, rgba(0,0,0,0) 55%, rgba(0,0,0,.72) 100%); }
  /* bigger tap targets; moved to the top-right so they never sit on the title
     (the desktop overlay only reserves 74px on the right for them) */
  .card-actions { opacity: 1; top: 10px; right: 10px; bottom: auto; }
  .icon-btn { width: 42px; height: 42px; }
}
/* keyboard users still see the info + actions */
.card:focus-within .card-overlay { opacity: 1; }
.card:focus-within .card-actions { opacity: 1; }

/* ---------------- masonry (Pinterest-style) photo listings ---------------- */
/* Columns are built by JS using balanced "shortest-column" placement, so the
   columns stay roughly equal height. Each card keeps its real aspect ratio
   (no stretch/crop). Used for the homepage "All photos", category + search.
   Defaults to `block` so cards stack cleanly before JS runs; JS switches it to
   a flex row of `.masonry-col` wrappers (no squished-row flash). */
.masonry { display: block; }
.masonry-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.masonry .card { aspect-ratio: auto; margin: 0; }
.masonry .card-link { position: static; }
.masonry .card-img { width: 100%; height: auto; }

/* ---------------- "All photos" grid — 3 uniform columns (responsive) ---------------- */
/* Uniform grid: every card is a clean 4:3 tile (no staggered masonry). */
.photo-grid.photo-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 980px) { .photo-grid.photo-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .photo-grid.photo-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 430px) { .photo-grid.photo-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
a.chip:hover { color: var(--text); text-decoration: none; border-color: var(--brand); }
.chip-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.chip-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------------- pagination ---------------- */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 32px 0 10px; }
.page-btn {
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: .88rem;
}
.page-btn:hover { border-color: var(--brand); text-decoration: none; }
.page-btn.current { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border-color: transparent; color: #fff; font-weight: 700; }

/* ---------------- photo page ---------------- */
.photo-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; }
.photo-figure { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.photo-figure img { width: 100%; height: auto; border-radius: 8px; }
.photo-figure figcaption { margin-top: 10px; font-size: .85rem; text-align: center; }
.photo-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 18px 0; }
.btn-download {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 13px 26px; border-radius: 12px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  font-size: 1rem; font-weight: 700; box-shadow: 0 6px 18px rgba(79, 140, 255, .3);
}
.btn-download:hover { text-decoration: none; filter: brightness(1.08); }
.photo-info { margin-top: 8px; }
.meta-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: .9rem; }
.meta-table th, .meta-table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.meta-table th { width: 160px; color: var(--muted); font-weight: 600; }
.tags { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.photo-side { position: sticky; top: 90px; }
.side-title { font-size: 1rem; margin-top: 22px; }
.side-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.side-grid img { aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

/* ---------------- prose ---------------- */
.prose { max-width: 820px; }
.prose h2 { margin-top: 1.6em; font-size: 1.2rem; }
.prose p, .prose li { color: color-mix(in srgb, var(--text) 88%, var(--muted)); }
.prose pre { background: var(--surface); border: 1px solid var(--border); padding: 14px; border-radius: 10px; overflow-x: auto; }
.prose-list { max-width: 820px; }
.contact-form { display: grid; gap: 12px; max-width: 520px; margin-top: 12px; }

/* ---------------- footer ---------------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 40px; padding: 40px 0 22px; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 32px; }
.footer-grid h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.footer-grid ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; font-size: .9rem; }
.footer-grid a { color: var(--text); }
.brand-footer { margin-bottom: 10px; }
.footer-bottom { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--border); font-size: .82rem; }

/* ---------------- forms ---------------- */
label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 14px; }
input[type="text"], input[type="password"], input[type="email"], input[type="search"], input[type="file"], textarea, select {
  width: 100%; margin-top: 6px; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 400; outline: none;
}
input:focus, textarea:focus { border-color: var(--brand); }
label.checkbox { display: flex; align-items: center; gap: 10px; font-weight: 500; }
label.checkbox input { width: auto; margin: 0; }
.inline-form { display: inline; }
.link-btn { background: none; border: none; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
.link-btn.danger { color: var(--danger); }
.alert { padding: 12px 16px; border-radius: 10px; margin: 14px 0; font-size: .92rem; }
.alert-ok { background: color-mix(in srgb, var(--ok) 16%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent); }
.alert-error { background: color-mix(in srgb, var(--danger) 16%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); }

/* ---------------- admin: sidebar shell ---------------- */
.admin-body { background: var(--bg); }

.admin-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.admin-shell--standalone { grid-template-columns: minmax(0, 1fr); }
.admin-shell--standalone .admin-sidebar,
.admin-shell--standalone .sidebar-toggle { display: none; }
.admin-shell--standalone .admin-content { max-width: 720px; margin: 0 auto; }

.admin-sidebar {
  position: sticky; top: 0; height: 100vh; padding: 18px 12px 16px;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px; overflow-y: auto;
}
.admin-sidebar .brand { padding: 4px 10px 18px; }
.admin-sidebar .brand-name { line-height: 1.2; }
.admin-sidebar .brand-name small { display: block; margin-top: 2px; }

.admin-nav { display: flex; flex-direction: column; gap: 2px; }
.admin-nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); font-size: .92rem; font-weight: 600;
}
.admin-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.admin-nav a.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }

.admin-sidebar-foot {
  margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px; font-size: .86rem; align-items: flex-start;
}

.sidebar-toggle {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 60;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-size: 1.1rem; cursor: pointer;
}

.admin-content { padding: 26px 22px 60px; min-width: 0; }
.admin-footer { border-top: 1px solid var(--border); padding: 18px 0; font-size: .82rem; }
.brand-logo { height: 26px; width: auto; border-radius: 6px; }

.admin-form { max-width: 620px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 18px 0 26px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; }
.stat-num { font-size: 1.7rem; font-weight: 800; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .88rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.admin-table th, .admin-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.admin-table th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.thumb-xs { width: 54px; height: 40px; object-fit: cover; border-radius: 6px; }
.login-card { max-width: 380px; margin: 60px auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.login-card .btn-download { width: 100%; justify-content: center; margin-top: 6px; }
.login-brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 4px; }

/* admin login — soft brand gradient (no dependency on a media file) */
.admin-body--login {
  min-height: 100vh;
  background:
    radial-gradient(1100px 600px at 18% 0%, rgba(79, 140, 255, .24), transparent 62%),
    radial-gradient(900px 520px at 82% 100%, rgba(124, 92, 255, .22), transparent 60%),
    linear-gradient(180deg, #0b0f17 0%, #111827 100%);
  background-attachment: fixed;
}
.admin-body--login .admin-shell { min-height: 100vh; }
.admin-body--login .admin-content {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; max-width: none; padding: 24px;
}
.admin-body--login .login-card {
  width: 100%; max-width: 400px; margin: 0;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(14px) saturate(150%);
  border: 1px solid rgba(255,255,255,.2);
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.admin-body--login .admin-footer { display: none; }

/* ---------------- admin dashboard ---------------- */
.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 12px; border: 1px solid var(--border); cursor: pointer;
  background: var(--surface); color: var(--text); font-size: .95rem; font-weight: 600;
}
.btn-secondary:hover { text-decoration: none; border-color: var(--brand); color: var(--brand); }

.admin-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 22px; }
.admin-actions .btn-download { padding: 11px 20px; font-size: .95rem; }

.card-block {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin: 16px 0;
}
.card-block .section-title { margin-top: 0; }
.admin-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; align-items: start; }
.admin-cols .card-block { margin: 0 0 18px; }

/* bar chart */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding: 8px 4px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar { width: 100%; max-width: 34px; background: linear-gradient(180deg, var(--brand), var(--brand-2)); border-radius: 6px 6px 0 0; min-height: 4px; }
.bar-count { font-size: .68rem; color: var(--muted); margin-top: 4px; }
.bar-label { font-size: .62rem; color: var(--muted); transform: rotate(-35deg); white-space: nowrap; margin-top: 2px; }

/* mini lists */
.mini-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.mini-list li { display: flex; align-items: center; gap: 10px; }
.mini-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }
.mini-title a { color: var(--text); }
.mini-title a:hover { color: var(--brand); }

/* admin page head + filters */
.admin-page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.admin-page-head h1 { margin: 0; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 14px 0 16px; }
.filter-bar input[type="search"] { max-width: 360px; margin: 0; }
.filter-bar select { width: auto; margin: 0; min-width: 200px; }
.filter-bar .btn-secondary { padding: 10px 16px; }
.filter-count { margin-left: auto; }

/* bulk bar */
.bulk-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 6px 0 12px; }
.bulk-bar select { width: auto; margin: 0; }
.bulk-bar .btn-secondary { padding: 9px 16px; }
.bulk-all { font-weight: 500; margin: 0; display: flex; align-items: center; gap: 8px; }
.bulk-all input { width: auto; margin: 0; }

/* table helpers */
.table-scroll { overflow-x: auto; }
.admin-table { min-width: 760px; }
.col-check { width: 34px; }
.col-check input { width: auto; margin: 0; }
.col-actions { white-space: nowrap; width: 1%; }
.row-title { color: var(--text); font-weight: 600; }
.row-title:hover { color: var(--brand); }
.row-actions { display: flex; align-items: center; gap: 12px; }
.chip-on { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.admin-pagination { justify-content: flex-start; margin: 18px 0 0; }

/* edit page */
.edit-layout { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 18px; align-items: start; }
.edit-photo { width: 100%; border-radius: 10px; border: 1px solid var(--border); }
.kv { display: flex; gap: 10px; padding: 7px 2px; border-bottom: 1px solid var(--border); font-size: .86rem; }
.kv dt { color: var(--muted); min-width: 90px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.edit-form .btn-download { margin-top: 6px; }
.form-actions { display: flex; align-items: center; gap: 12px; }

/* categories */
.tree-indent { padding-left: calc(var(--depth, 0) * 18px); font-weight: 500; }

/* category tree (categories + homepage) */
.cat-tree { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cat-tree-item { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.cat-tree-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cat-tree-row .tree-indent { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-tree-actions { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.cat-cover-thumb { width: 30px; height: 22px; object-fit: cover; border-radius: 4px; vertical-align: middle; margin-right: 6px; }
.cover-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cover-form input[type="file"] { width: auto; margin: 0; max-width: 180px; }
.small-btn { padding: 6px 12px; font-size: .82rem; }

/* upload preview */
.upload-preview { margin: 4px 0 16px; }
.upload-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.upload-item { display: flex; flex-direction: column; gap: 4px; font-size: .72rem; color: var(--muted); position: relative; }
.upload-item img { aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); width: 100%; }
.upload-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* remove (X) button on each upload preview tile */
.upload-remove {
  position: absolute; top: 5px; right: 5px; z-index: 2;
  width: 22px; height: 22px; padding: 0; border-radius: 999px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; line-height: 1;
  font-size: 15px; font-weight: 700;
  color: #fff; background: rgba(0, 0, 0, .62); border: 1px solid rgba(255, 255, 255, .32);
  backdrop-filter: blur(4px); transition: background .15s ease, transform .15s ease;
}
.upload-remove:hover { background: var(--danger); transform: scale(1.1); }
.upload-remove:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* confirm dialog overlay (remove upload) */
.confirm-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px);
}
.confirm-overlay[hidden] { display: none; }
.confirm-modal {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow);
}
.confirm-title { font-weight: 700; font-size: 1.05rem; margin: 0 0 8px; }
.confirm-text { color: var(--muted); font-size: .92rem; margin: 0 0 18px; overflow-wrap: anywhere; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--danger); color: #fff; font-size: .95rem; font-weight: 600;
}
.btn-danger:hover { text-decoration: none; filter: brightness(1.08); }

/* logo preview */
.logo-preview { max-height: 44px; width: auto; border-radius: 6px; margin-bottom: 8px; }
.add-featured { display: flex; gap: 10px; margin-top: 14px; }
.add-featured select { width: auto; flex: 1; margin: 0; }
.add-featured .btn-secondary { white-space: nowrap; }



/* admin homepage: category card cover tiles (เฉพาะหมวดหมู่หลัก) */
.cat-cover-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.cat-cover-tile { display: flex; flex-direction: column; gap: 8px; }
.cat-cover-card {
  position: relative; aspect-ratio: 4/3; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); background: linear-gradient(135deg, var(--surface-2), var(--surface));
}
.cat-cover-card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cat-cover-card .cover-ph {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: color-mix(in srgb, var(--text) 18%, transparent);
  background: radial-gradient(120% 90% at 18% 0%, color-mix(in srgb, var(--brand) 14%, transparent), transparent 55%);
}
.cat-cover-card .cover-ph svg { width: 40px; height: 40px; }
.cat-cover-card .cover-name {
  position: absolute; left: 12px; right: 12px; bottom: 10px; z-index: 2;
  color: #fff; font-weight: 700; font-size: .95rem; text-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.cat-cover-card::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,.72) 100%); }

/* admin homepage: "กำลังเป็นที่นิยม" (Trending) config */
.trending-form { display: grid; gap: 14px; margin-top: 6px; }
.trending-mode { display: flex; gap: 18px; flex-wrap: wrap; }
.trending-mode label {
  display: inline-flex; align-items: center; gap: 8px; margin: 0;
  font-weight: 600; font-size: .95rem; cursor: pointer;
}
.trending-mode input[type="radio"] { width: auto; margin: 0; accent-color: var(--brand); }
.trending-auto, .trending-manual { display: flex; flex-direction: column; gap: 12px; }
.trending-field {
  display: inline-flex; align-items: center; gap: 10px; margin: 0;
  font-weight: 600; font-size: .92rem;
}
.trending-field select, .trending-field input[type="number"] { width: auto; margin: 0; min-width: 160px; }
.trending-manual .mini-list { margin: 0; }
.reorder { display: inline-flex; align-items: center; gap: 6px; }
.reorder .link-btn[disabled] { opacity: .35; cursor: not-allowed; }
.trending-save { margin-top: 4px; }
.trending-save .btn-download { padding: 11px 22px; font-size: .95rem; }



/* ---------------- responsive ---------------- */
@media (max-width: 980px) {
  .photo-layout { grid-template-columns: 1fr; }
  .photo-side { position: static; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .trending .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .admin-cols { grid-template-columns: 1fr; }
  .edit-layout { grid-template-columns: 1fr; }

  /* compact mobile menu: hidden behind the toggle, accordion sections */
  .search-form { display: none; }
  .nav-toggle { display: block; }
  .cat-nav { display: none; }

  body.nav-open .search-form {
    display: flex; position: absolute; left: 18px; right: 18px; top: 66px; z-index: 45;
  }
  body.nav-open .cat-nav {
    display: block; position: absolute; left: 0; right: 0; top: 116px; z-index: 44;
    border-top: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .cat-nav-inner {
    display: block; padding: 8px 18px 14px;
    max-height: calc(100vh - 130px); overflow-y: auto; scrollbar-width: thin;
  }
  .cat-nav-inner > a { display: block; padding: 10px 6px; border-radius: 10px; }
  .cat-item { display: block; }
  .cat-item .cat-link {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    padding: 10px 6px; border-radius: 10px;
  }
  .cat-item.open > .cat-link { background: var(--surface-2); }

  /* only the chosen section expands, as an in-flow accordion (no wide layout) */
  .cat-item .cat-sub,
  .cat-item.open > .cat-sub,
  .cat-item.open > .cat-sub--cols {
    display: none; position: static; box-shadow: none; border: 0; border-radius: 0;
    min-width: 0; max-width: none; max-height: none; margin: 0; padding: 0 0 8px;
  }
  .cat-item.open > .cat-sub,
  .cat-item.open > .cat-sub--cols { display: block; }
  .cat-item .cat-sub .sub-link { padding: 8px 6px 8px 22px; }
  .cat-item .cat-sub .sub-link--all { margin-top: 4px; }
}
@media (max-width: 720px) {
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .footer-grid { grid-template-columns: 1fr; }
  .meta-table th { width: 120px; }

  .arrow { display: none; }
  .hero-bg { min-height: 400px; }
  .hero-content { padding: 40px 18px; }
  .search-row { flex-direction: column; gap: 8px; }
  .search-row button { width: 100%; }
  .cat-tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; grid-auto-rows: auto; }
  .cat-tile { min-height: 150px; }
  .search-bar { flex-direction: column; gap: 8px; }
  .search-bar button { width: 100%; }
}
@media (max-width: 430px) {
  .cat-tile-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------- admin: mobile sidebar drawer ---------------- */
@media (max-width: 900px) {
  .admin-shell { grid-template-columns: minmax(0, 1fr); }
  .admin-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 250px; z-index: 50;
    transform: translateX(-100%); transition: transform .2s ease; height: 100vh;
  }
  .admin-body.admin-nav-open .admin-sidebar { transform: translateX(0); box-shadow: var(--shadow); }
  .sidebar-toggle { display: block; }
  .admin-content { padding-top: 60px; }
}

/* ---------------- feature picker modal (เลือกภาพเด่น) ---------------- */
.picker-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 18px;
  background: rgba(0, 0, 0, .58); backdrop-filter: blur(2px);
}
.picker-overlay[hidden] { display: none; }
.picker-modal {
  width: 100%; max-width: 920px; height: min(86vh, 760px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.picker-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.picker-head h3 { margin: 0; }
.picker-toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.picker-toolbar input[type="search"] { flex: 1 1 220px; max-width: 340px; margin: 0; }
.picker-toolbar select { width: auto; margin: 0; min-width: 160px; }
.picker-toolbar label.picker-all {
  display: inline-flex; align-items: center; gap: 8px; margin: 0;
  font-size: .85rem; font-weight: 500;
}
.picker-toolbar label.picker-all input { width: auto; margin: 0; }
.picker-count {
  margin-left: auto; padding: 5px 12px; border-radius: 999px; white-space: nowrap;
  background: color-mix(in srgb, var(--brand) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
  color: var(--brand); font-size: .82rem; font-weight: 700;
}
.picker-grid {
  flex: 1; overflow-y: auto; padding: 14px; align-content: start;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
}
.picker-cell {
  position: relative; display: block; margin: 0; cursor: pointer;
  aspect-ratio: 4/3; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); background: var(--surface-2);
}
.picker-cell img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  transition: transform .25s ease;
}
.picker-cell:hover img { transform: scale(1.05); }
.picker-cell input[type="checkbox"] {
  position: absolute; top: 8px; left: 8px; z-index: 3;
  width: 20px; height: 20px; margin: 0; accent-color: var(--brand); cursor: pointer;
}
.picker-cell::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0) 42%, rgba(0,0,0,.78) 100%);
}
.picker-cell .picker-name {
  position: absolute; left: 10px; right: 10px; bottom: 26px; z-index: 2;
  color: #fff; font-size: .82rem; font-weight: 600; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.picker-cell .picker-meta {
  position: absolute; left: 10px; right: 10px; bottom: 9px; z-index: 2;
  color: rgba(255,255,255,.82); font-size: .7rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.picker-cell:has(input:checked) {
  border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 55%, transparent);
}
.picker-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; border-top: 1px solid var(--border);
}
.picker-pages { display: flex; align-items: center; gap: 8px; }
.picker-pages .page-btn:disabled { opacity: .45; cursor: not-allowed; }
.picker-actions { display: flex; gap: 10px; }
.picker-actions .btn-download:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 620px) {
  .picker-toolbar input[type="search"], .picker-toolbar select { flex: 1 1 100%; max-width: none; }
  .picker-count { margin-left: 0; }
  .picker-foot { flex-direction: column; align-items: stretch; }
  .picker-pages { justify-content: center; }
}

/* ---------------- admin: bulk upload ---------------- */
.bulk-upload { position: relative; }
.bulk-upload [hidden] { display: none !important; }
.upload-sub { margin: 6px 0 0; }

/* drop zone */
.upload-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 30px 22px; margin: 14px 0 8px;
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  text-align: center; cursor: pointer;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.upload-drop:hover { border-color: color-mix(in srgb, var(--brand) 60%, var(--border)); }
.upload-drop.is-drag {
  border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--surface));
  transform: scale(1.005);
}
.upload-drop:focus-within { outline: 2px solid var(--brand); outline-offset: 3px; }
.upload-drop-icon {
  display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 2px;
  border-radius: 50%; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 24px color-mix(in srgb, var(--brand) 35%, transparent);
}
.upload-drop-title { font-size: 1.08rem; font-weight: 700; }
.upload-drop-sub { color: var(--muted); font-size: .88rem; }
.upload-kbd {
  display: inline-block; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .76rem;
}
.upload-drop-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 8px 0 2px; }
.upload-drop-actions .btn-download { padding: 10px 20px; font-size: .92rem; }
.upload-drop-actions .btn-secondary { padding: 10px 18px; font-size: .92rem; }
.upload-drop-hint { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.upload-queue-hint { margin: 8px 0 2px; }

/* batch defaults */
.upload-batch { padding: 0; overflow: hidden; }
.upload-batch summary {
  display: flex; align-items: baseline; gap: 10px; padding: 14px 18px;
  cursor: pointer; font-weight: 700; list-style: none;
}
.upload-batch summary::-webkit-details-marker { display: none; }
.upload-batch summary::before {
  content: '▸'; color: var(--muted); font-size: .9em; transition: transform .15s ease;
}
.upload-batch[open] summary::before { content: '▾'; }
.upload-batch-head .muted { font-weight: 400; }
.upload-batch-body {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px; padding: 0 18px 18px; border-top: 1px solid var(--border);
}
.upload-batch-body > .upload-field { margin: 10px 0 0; }
.upload-batch-actions {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; padding-top: 12px; margin-top: 2px; border-top: 1px dashed var(--border);
}
.upload-batch-actions .btn-secondary { padding: 8px 14px; font-size: .85rem; }
.upload-batch-actions .checkbox { margin: 0; font-size: .86rem; }

/* queue header */
.upload-queue-head { display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; }
.upload-queue-head h2 { margin: 0; font-size: 1.05rem; }
.upload-spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 38%, transparent);
  color: var(--brand); font-size: .78rem; font-weight: 700; white-space: nowrap;
}
.upload-empty {
  margin: 0; padding: 26px 18px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 12px; font-size: .9rem;
}

/* queue rows */
.upload-queue { display: grid; gap: 10px; }
.upload-row {
  display: grid; align-items: center; gap: 12px; padding: 10px;
  grid-template-columns: 72px minmax(0, 1.4fr) minmax(140px, 1fr) minmax(150px, .9fr) minmax(190px, 1.1fr);
  grid-template-areas:
    'thumb file title cat state'
    'detail detail detail detail detail';
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  transition: border-color .15s ease, background .15s ease;
}
.upload-row[data-state="uploading"],
.upload-row[data-state="processing"] { border-color: color-mix(in srgb, var(--brand) 55%, var(--border)); }
.upload-row[data-state="done"] { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.upload-row[data-state="error"] { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.upload-row.is-open { background: var(--surface-2); }
.upload-thumb {
  grid-area: thumb; width: 72px; aspect-ratio: 4 / 3; border-radius: 8px;
  overflow: hidden; background: var(--surface-2); border: 1px solid var(--border);
}
.upload-thumb img { width: 100%; height: 100%; object-fit: cover; }
.upload-file { grid-area: file; min-width: 0; }
.upload-fname {
  font-weight: 600; font-size: .86rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.upload-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  color: var(--muted); font-size: .74rem; margin-top: 2px;
}
.upload-badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: .7rem; font-weight: 700; white-space: nowrap;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface-2);
}
.upload-badge.is-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.upload-badge.is-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.upload-badge.is-bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.upload-badge.is-busy { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 40%, var(--border)); background: color-mix(in srgb, var(--brand) 12%, transparent); }

.upload-field { margin: 0; font-size: .78rem; font-weight: 600; color: var(--muted); min-width: 0; }
.upload-field > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-field em { font-style: normal; font-weight: 400; opacity: .8; }
.upload-field input[type="text"],
.upload-field select,
.upload-field textarea {
  width: 100%; margin-top: 3px; padding: 7px 9px; border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: .84rem;
}
.upload-field textarea { resize: vertical; min-height: 38px; }
.upload-field-title { grid-area: title; }
.upload-field-cat { grid-area: cat; }
.upload-field-wide { grid-column: span 2; }

.upload-state { grid-area: state; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.upload-progress {
  height: 6px; border-radius: 999px; overflow: hidden; background: var(--surface-2);
}
.upload-progress i {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  transition: width .15s linear;
}
.upload-progress.is-indeterminate i {
  width: 40% !important; animation: upload-slide 1.1s ease-in-out infinite;
}
@keyframes upload-slide {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}
.upload-status {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: .76rem; color: var(--muted); min-height: 1.2em; line-height: 1.35;
}
.upload-status.is-ok { color: var(--ok); }
.upload-status.is-error { color: var(--danger); }
.upload-status.is-busy { color: var(--brand); }
.upload-status a { color: inherit; text-decoration: underline; }
.upload-sep { opacity: .5; }
.upload-actions { display: flex; align-items: center; gap: 4px; }
.upload-icon-btn {
  width: 28px; height: 28px; padding: 0; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: .82rem; line-height: 1; display: inline-grid; place-items: center;
}
.upload-icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.upload-icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.upload-icon-danger:hover { border-color: var(--danger); color: var(--danger); }
.upload-detail {
  grid-area: detail; grid-column: 1 / -1; display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px;
  margin-top: 8px; padding-top: 12px; border-top: 1px dashed var(--border);
}
.upload-detail .upload-field { margin: 0; }

/* sticky action bar */
.upload-bar {
  position: sticky; bottom: 12px; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 16px; padding: 12px 16px;
  border: 1px solid var(--border); border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px) saturate(140%);
  box-shadow: var(--shadow);
}
.upload-summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .82rem; }
.upload-summary [data-summary="done"] { font-weight: 700; }
.upload-summary [data-summary="active"] { color: var(--brand); }
.upload-summary [data-summary="failed"] { color: var(--danger); }
.upload-total {
  flex: 1 1 160px; min-width: 100px; height: 7px; border-radius: 999px;
  overflow: hidden; background: var(--surface-2);
}
.upload-total i {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  transition: width .2s ease;
}
.upload-bar .btn-download { padding: 9px 18px; font-size: .88rem; }
.upload-bar .btn-secondary { padding: 9px 14px; font-size: .86rem; }
.upload-bar .btn-download:disabled,
.upload-bar .btn-secondary:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.35); }
.upload-queue-head .link-btn:disabled { opacity: .45; cursor: not-allowed; }

@media (max-width: 1000px) {
  .upload-row {
    grid-template-columns: 64px minmax(0, 1fr) minmax(140px, 1fr);
    grid-template-areas:
      'thumb file file'
      'title title cat'
      'state state state'
      'detail detail detail';
  }
  .upload-thumb { width: 64px; }
}
@media (max-width: 760px) {
  .upload-batch-body { grid-template-columns: minmax(0, 1fr); }
  .upload-field-wide { grid-column: auto; }
  .upload-batch-actions { grid-column: auto; }
  .upload-drop { padding: 22px 14px; }
}
@media (max-width: 640px) {
  .upload-row {
    grid-template-columns: 56px minmax(0, 1fr);
    grid-template-areas:
      'thumb file'
      'title title'
      'cat cat'
      'state state'
      'detail detail';
  }
  .upload-thumb { width: 56px; }
  .upload-detail { grid-template-columns: minmax(0, 1fr); }
  .upload-field-wide { grid-column: auto; }
  .upload-bar { bottom: 6px; padding: 10px 12px; }
  .upload-summary { width: 100%; }
  .upload-bar .btn-download, .upload-bar .btn-secondary { flex: 1 1 auto; justify-content: center; }
}
