/* NPS Photo — สีประจำโรงเรียน ฟ้า-แดง */
:root {
  --blue: #0b4f9c;
  --blue-2: #1677d2;
  --sky: #4fb3f6;
  --red: #d7263d;
  --red-2: #b51d31;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f9;
  --text: #13213a;
  --muted: #5a6b83;
  --line: #dfe6ef;
  --shadow: 0 1px 2px rgba(16, 38, 74, .06), 0 6px 20px rgba(16, 38, 74, .07);
  --radius: 14px;
  --rowh: 220px;
  --font: "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Prompt", var(--font);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue: #5fa8ff; --blue-2: #3d8ee6; --sky: #7cc6ff; --red: #ff5a6e; --red-2: #e8455a;
    --bg: #0c1320; --surface: #141e2f; --surface-2: #1b283d; --text: #e7eef8; --muted: #9aaac1; --line: #26354d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --blue: #5fa8ff; --blue-2: #3d8ee6; --sky: #7cc6ff; --red: #ff5a6e; --red-2: #e8455a;
  --bg: #0c1320; --surface: #141e2f; --surface-2: #1b283d; --text: #e7eef8; --muted: #9aaac1; --line: #26354d;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 16px/1.6 var(--font); min-height: 100vh; display: flex; flex-direction: column;
}
main { flex: 1; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.3; margin: 0; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 560px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.nowrap { white-space: nowrap; }
.link { color: var(--blue-2); font-weight: 500; }
.link:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; border-radius: 6px; }

/* แถบสีโรงเรียนด้านบน */
.ribbon { display: flex; height: 4px; }
.ribbon span:first-child { flex: 2; background: var(--blue); }
.ribbon span:last-child { flex: 1; background: var(--red); }

/* ---------- Header ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; object-fit: contain; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-text strong { font-family: var(--font-head); font-size: 1.15rem; color: var(--blue); letter-spacing: .2px; }
.brand-text small { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { display: flex; align-items: center; gap: 8px; flex: none; }
.nav-link { padding: 6px 10px; border-radius: 8px; font-weight: 500; color: var(--muted); }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary img, .avatar { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); }
.avatar { display: grid; place-items: center; background: var(--blue); color: #fff; font-weight: 600; }
.usermenu-pop {
  position: absolute; right: 0; top: 44px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 14px; min-width: 230px; display: flex; flex-direction: column; gap: 2px;
}
.usermenu-pop small { color: var(--muted); margin-bottom: 10px; word-break: break-all; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent;
  border-radius: 999px; padding: 10px 20px; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, transform .1s;
  line-height: 1.2; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 7px 14px; font-size: .92rem; }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { background: var(--red-2); }
.btn-blue { background: var(--blue-2); color: #fff; }
.btn-blue:hover { background: var(--blue); }
.btn-outline { border-color: var(--line); background: var(--surface); color: var(--text); }
.btn-outline:hover { border-color: var(--blue-2); color: var(--blue-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn[disabled] { opacity: .6; cursor: progress; }

/* ---------- Hero ---------- */
.hero {
  color: #fff; padding: 36px 0 30px;
  background:
    radial-gradient(1200px 300px at 85% -20%, rgba(79, 179, 246, .45), transparent 60%),
    radial-gradient(500px 200px at 0% 120%, rgba(215, 38, 61, .35), transparent 60%),
    linear-gradient(135deg, #0a3f80, #0b5cb5 60%, #1877d4);
}
.hero h1 { font-size: clamp(1.6rem, 4.5vw, 2.6rem); font-weight: 700; }
.hero-sub { margin: 8px 0 20px; opacity: .92; max-width: 640px; }
.br-sm { display: none; }
.search {
  display: flex; align-items: center; gap: 6px; background: #fff; border-radius: 999px; padding: 6px 6px 6px 16px;
  max-width: 680px; box-shadow: 0 10px 30px rgba(0, 20, 60, .25);
}
.search-ic { color: #7b8aa0; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: #13213a; padding: 8px 4px; font-size: 1.02rem; }
.search input::placeholder { color: #8a97aa; }
.page-home:not(:has(.hero h1)) .hero { padding: 22px 0; }

/* ---------- แท็บหมวดหมู่ ---------- */
.cat-tabs { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 64px; z-index: 30; }
.cat-scroll { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
.cat-scroll::-webkit-scrollbar { display: none; }
/* จอคอมพิวเตอร์: ขึ้นบรรทัดใหม่เมื่อแท็บยาวเกินจอ เพื่อให้เห็นครบทุกหมวด */
@media (min-width: 641px) {
  .cat-scroll { flex-wrap: wrap; overflow: visible; column-gap: 2px; }
  .cat-tab { padding: 14px 14px 11px; }
}
/* มือถือ: เลื่อนซ้าย-ขวา มีเงาจางที่ขอบขวาบอกว่ายังมีแท็บต่อ */
@media (max-width: 640px) {
  .cat-tabs .wrap { position: relative; }
  .cat-tabs .wrap::after {
    content: ""; position: absolute; top: 0; right: 0; bottom: 3px; width: 36px; pointer-events: none;
    background: linear-gradient(to right, transparent, var(--surface));
  }
}
.cat-tab {
  flex: none; display: inline-flex; align-items: center; padding: 14px 16px 11px; font-weight: 500; font-size: .98rem;
  color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; scroll-snap-align: start; transition: color .15s, border-color .15s;
}
.cat-tab:hover { color: var(--text); }
.cat-tab.on { color: var(--blue-2); border-bottom-color: var(--red); font-weight: 600; }
.cat-tab.empty { opacity: .45; }
.cat-n { font-size: .75rem; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 1px 7px; font-weight: 500; }

/* ---------- ปุ่มตัวกรอง (ปี / เดือน / แท็ก) ---------- */
.cat-bar { display: flex; align-items: center; gap: 10px; }
.cat-bar .cat-scroll { flex: 1; min-width: 0; }
.filter-pop { position: relative; flex: none; }
.filter-pop > summary { list-style: none; cursor: pointer; }
.filter-pop > summary::-webkit-details-marker { display: none; }
.filter-btn.has-active { border-color: var(--blue-2); color: var(--blue-2); }
.filter-count { background: var(--red); color: #fff; border-radius: 999px; font-size: .75rem; min-width: 18px; height: 18px; display: inline-grid; place-items: center; padding: 0 5px; }
.filter-sheet {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; width: 420px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(10, 30, 60, .18);
  padding: 14px 16px 16px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sheet-head strong { font-family: var(--font-head); font-size: 1.05rem; }
.sheet-label { margin: 12px 0 6px; font-size: .85rem; color: var(--muted); font-weight: 500; }
.chips.wrap-chips { flex-wrap: wrap; overflow: visible; }
.wrap-chips.months .chip { min-width: 58px; text-align: center; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 12px; }
.active-filters .chip { font-size: .88rem; }

/* ---------- Filters ---------- */
.filters { padding-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.filter-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.filter-label { flex: none; width: 74px; font-size: .88rem; color: var(--muted); font-weight: 500; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; flex-wrap: nowrap; }
.chips::-webkit-scrollbar { display: none; }
.album-head .chips { flex-wrap: wrap; }
.chip {
  flex: none; padding: 5px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  font-size: .92rem; color: var(--text); transition: all .15s;
}
.chip:hover { border-color: var(--blue-2); }
.chip.on { background: var(--blue-2); border-color: var(--blue-2); color: #fff; }
.chip-tag { color: var(--blue-2); }
.chip-tag.on { color: #fff; }

/* ---------- Album cards ---------- */
.results { padding-top: 20px; padding-bottom: 40px; }
.section-title { font-size: 1.25rem; margin: 6px 0 14px; display: flex; align-items: center; gap: 10px; }
.section-title::before { content: ""; width: 6px; height: 22px; border-radius: 3px; background: linear-gradient(var(--blue-2), var(--red)); }
.results-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.results-head p { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column; transition: transform .2s, box-shadow .2s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(16,38,74,.06), 0 14px 30px rgba(16,38,74,.12); }
.card-media { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; transition: transform .4s; }
.card:hover .card-media img { transform: scale(1.04); }
.card-count, .card-lock {
  position: absolute; bottom: 8px; right: 8px; display: inline-flex; align-items: center; gap: 4px;
  background: rgba(10, 20, 40, .72); color: #fff; font-size: .8rem; padding: 3px 9px; border-radius: 999px; backdrop-filter: blur(4px);
}
.card-lock { right: auto; left: 8px; top: 8px; bottom: auto; background: var(--red); }
.card-dl { position: absolute; left: 8px; bottom: 8px; display: inline-flex; align-items: center; gap: 4px; background: #178a3a; color: #fff;
  font-size: .75rem; padding: 2px 9px; border-radius: 999px; }
.badge-ok { background: #178a3a; color: #fff; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; }
.card-body time { font-size: .82rem; color: var(--red); font-weight: 600; }
.card-body h3 {
  font-size: 1rem; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-tags { display: flex; gap: 6px; flex-wrap: wrap; font-size: .8rem; color: var(--blue-2); }
.grid-sm { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.more { display: flex; justify-content: center; margin-top: 26px; }
.empty { text-align: center; padding: 60px 16px; }
.empty p { margin: 4px 0; }

/* ยอดชม / ยอดนิยม */
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.views { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: .8rem; }
.album-meta .views { font-size: inherit; }
.popular { padding-top: 22px; }
.pop-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 16px; overflow-x: auto; padding: 2px 2px 10px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.pop-row .card { scroll-snap-align: start; }
.sort-switch { float: right; display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin: 2px 0 10px 10px; }
.sort-switch a { padding: 4px 12px; border-radius: 999px; font-size: .88rem; color: var(--muted); }
.sort-switch a.on { background: var(--blue-2); color: #fff; }
.results .grid, .results .empty, .results .more { clear: both; }

/* รูปที่ซ่อน (แอดมินเห็นเท่านั้น) */
.jp.is-hidden img { opacity: .35; filter: grayscale(1); }
.hidden-tag { position: absolute; left: 6px; top: 6px; background: var(--red); color: #fff; font-size: .72rem; padding: 1px 8px; border-radius: 999px; }
.lb-btn.lb-on { background: var(--red); }

/* หน้าต่างรายงานภาพ */
.report-box .report-thumb { display: flex; justify-content: center; background: var(--surface-2); border-radius: 10px; padding: 6px; }
.report-box .report-thumb img { max-height: 140px; border-radius: 6px; }
.reasons { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.reasons legend { font-size: .92rem; color: var(--muted); margin-bottom: 4px; }
.reasons .check { color: var(--text); font-size: .95rem; }

/* ---------- Album page ---------- */
.album-head { padding-top: 22px; padding-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.crumbs { font-size: .9rem; color: var(--muted); display: flex; gap: 8px; }
.crumbs a:hover { color: var(--blue-2); }
.album-head h1 { font-size: clamp(1.35rem, 3.4vw, 2rem); }
.album-meta { margin: 0; color: var(--muted); }
.album-meta time { color: var(--red); font-weight: 600; }
.album-desc { margin: 0; max-width: 800px; }
.album-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.badge { display: inline-block; padding: 1px 10px; font-size: .8rem; border-radius: 999px; background: var(--red); color: #fff; vertical-align: middle; }
.badge-warn { background: #e6a700; color: #241a00; }

/* แสดงรูปแบบ justified (แถวเต็มกว้าง ตามสัดส่วนจริงของภาพ) */
.justified { display: flex; flex-wrap: wrap; gap: 6px; }
.justified::after { content: ""; flex-grow: 999999999; }
.jp {
  position: relative; flex-grow: calc(var(--r) * 100); flex-basis: calc(var(--r) * var(--rowh));
  background: var(--surface-2); border-radius: 6px; overflow: hidden; cursor: zoom-in;
}
.jp i { display: block; }
.jp img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: opacity .2s, transform .3s; }
.jp:hover img { transform: scale(1.03); }
.related { padding: 36px 16px 50px; }

/* ---------- Lightbox ---------- */
.lb {
  position: fixed; inset: 0; z-index: 100; background: #05080f; color: #fff;
  display: flex; flex-direction: column; touch-action: none; user-select: none; -webkit-user-select: none;
}
.lb[hidden] { display: none; }
.lb-bar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px; background: linear-gradient(rgba(0,0,0,.55), transparent);
}
.lb-count { font-variant-numeric: tabular-nums; opacity: .9; font-size: .95rem; padding-left: 4px; white-space: nowrap; flex: none; margin-right: 8px; }
.lb-tools { display: flex; gap: 4px; min-width: 0; }
.lb-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 0; background: transparent;
  color: #fff; cursor: pointer;
}
.lb-btn:hover { background: rgba(255,255,255,.12); }
.lb-btn[hidden] { display: none; }
/* จอสัมผัส: ซูมด้วยการถ่างนิ้ว/แตะสองครั้งได้อยู่แล้ว จึงซ่อนปุ่มซูมเพื่อให้ปุ่มปิดมีที่พอ */
@media (pointer: coarse) { .lb-btn[data-act="zoom"] { display: none; } }
/* มือถือจอแคบ: ปุ่มชิดขึ้น ตัวเลขเล็กลง ปุ่ม ✕ ต้องอยู่ในจอเสมอ */
@media (max-width: 440px) {
  .lb-bar { padding-left: 8px; padding-right: 4px; }
  .lb-tools { gap: 0; flex: 0 1 auto; justify-content: flex-end; }
  .lb-btn { width: 38px; height: 44px; flex: 0 1 38px; min-width: 30px; }
  .lb-count { font-size: .8rem; margin-right: 4px; padding-left: 2px; }
}
@media (max-width: 360px) { .lb-btn { width: 34px; flex-basis: 34px; } }
.lb-stage { flex: 1; position: relative; overflow: hidden; }
.lb-track { position: absolute; inset: 0; display: flex; will-change: transform; }
.lb-slide { flex: 0 0 100%; height: 100%; display: grid; place-items: center; overflow: hidden; position: relative; }
/* วางภาพแบบ absolute เพื่อให้ max-width/max-height อิงขนาดจอจริง (ภาพไม่ล้นจอ) */
.lb-slide img {
  position: absolute; inset: 0; margin: auto; width: auto; height: auto;
  max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center; will-change: transform;
  transition: opacity .2s;
}
.lb-slide .lb-thumb { max-width: none; max-height: none; }   /* ภาพย่อแสดงคมทันที แล้วภาพเต็มค่อยจางทับ */
/* จอคอมพิวเตอร์: เว้นที่ให้แถบเครื่องมือด้านบนและปุ่มลูกศร ภาพจะไม่ถูกบัง */
/* เว้นขอบเฉพาะจอคอมที่ใช้เมาส์ · มือถือ/แท็บเล็ต (รวมแนวนอน) แสดงภาพเต็มจอ ปุ่มลอยทับภาพ */
@media (min-width: 641px) and (min-height: 560px) and (hover: hover) and (pointer: fine) {
  .lb-slide img { top: 64px; bottom: 64px; left: 80px; right: 80px; max-width: calc(100% - 160px); max-height: calc(100% - 128px); }
}
/* แตะครั้งเดียวบนภาพ = ซ่อน/แสดงแถบปุ่ม (ดูภาพเต็มตา) */
.lb-bar, .lb-cap, .lb-nav { transition: opacity .2s; }
.lb.ui-off .lb-bar, .lb.ui-off .lb-cap, .lb.ui-off .lb-nav, .lb.ui-off .lb-like { opacity: 0; pointer-events: none; }
/* ปุ่มถูกใจ (อยู่ในแถบล่าง ด้านขวา) */
.lb-like {
  justify-self: end; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px 0 12px;
  border-radius: 999px; border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .12);
  color: #fff; cursor: pointer; font: 600 .95rem var(--font-head); opacity: 1; transition: background .15s, border-color .15s;
}
.lb-like:hover { background: rgba(255, 255, 255, .22); }
.lb-like[hidden] { display: none; }
.lb-like svg path { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.lb-like.on { color: #ff4d67; border-color: rgba(255, 77, 103, .6); background: rgba(255, 77, 103, .15); }
.lb-like.on svg path { fill: currentColor; }
.lb-like.pop svg { animation: heart-pop .4s ease; }
@keyframes heart-pop { 0% { transform: scale(1); } 35% { transform: scale(1.35); } 100% { transform: scale(1); } }
/* อุปกรณ์สัมผัส: ไม่ต้องมีลูกศร ใช้การปัดแทน */
@media (pointer: coarse), (max-height: 500px) { .lb .lb-nav { display: none; } }
/* มือถือแนวนอน: แถบบน/คำบรรยายเตี้ยลง */
@media (max-height: 500px) {
  .lb-bar { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: 4px;
            padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .lb-btn { width: 40px; height: 40px; }
  .lb-cap { padding: 8px max(12px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); font-size: .8rem; }
  .lb-like { height: 36px; }
}
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 52px; height: 52px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.12); color: #fff; cursor: pointer; display: grid; place-items: center;
}
.lb-nav:hover { background: rgba(255,255,255,.25); }
.lb-prev { left: 14px; } .lb-next { right: 14px; }
.lb-cap {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 3; font-size: .85rem;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 10px;
  padding: 16px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(transparent, rgba(0,0,0,.6));
}
.lb-cap-t { opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; text-align: center; }
@media (max-width: 640px) {
  /* มือถือ: ชื่อไฟล์ชิดซ้าย ปุ่มถูกใจชิดขวา */
  .lb-cap { grid-template-columns: minmax(0, 1fr) auto; }
  .lb-cap > span:first-child { display: none; }
  .lb-cap-t { text-align: left; max-width: none; }
}
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 200; background: #13213a; color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: .95rem; box-shadow: var(--shadow); animation: toast .25s ease;
}
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- Login ---------- */
.login { padding: 40px 16px 60px; }
.login-card { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); padding: 30px 26px; display: flex; flex-direction: column; gap: 12px; border-top: 5px solid var(--blue-2); }
.login-card h1 { font-size: 1.6rem; }
.login-card p { margin: 0; }
.perks { margin: 0; padding-left: 20px; color: var(--muted); }
#g-signin { min-height: 44px; margin: 8px 0; }
.login-error { color: var(--red); font-weight: 500; }

/* ---------- Error ---------- */
.error-page .err-code { font-family: var(--font-head); font-size: 4rem; font-weight: 700; color: var(--blue-2); margin: 0; line-height: 1; }
.error-page h1 { margin: 8px 0; }
.error-page .btn { margin-top: 18px; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--line); background: var(--surface); padding: 20px 0 calc(20px + env(safe-area-inset-bottom)); font-size: .9rem; }
.footer p { margin: 2px 0; }
.footer { color: var(--muted); }
.footer-credit { margin-top: 8px !important; font-size: .85rem; }
.footer-credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.footer-credit a:hover { color: var(--blue); }
.nowrap { white-space: nowrap; }

/* ---------- Admin ---------- */
.admin { padding-top: 24px; padding-bottom: 50px; display: flex; flex-direction: column; gap: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stats > div { background: var(--surface); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.stats strong { font-family: var(--font-head); font-size: 1.6rem; color: var(--blue-2); }
.stats .warn strong { color: #c98a00; }
.stats span { color: var(--muted); font-size: .88rem; }
.panel { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.panel-head h2 { font-size: 1.15rem; }
.row-gap { display: flex; gap: 8px; }
.sync-out { background: var(--surface-2); border-radius: 10px; padding: 12px; font-size: .85rem; white-space: pre-wrap; max-height: 220px; overflow: auto; }
.table-wrap { overflow-x: auto; margin-top: 8px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: .85rem; color: var(--muted); font-weight: 500; }
.table td a { font-weight: 500; }
.table td a:hover { color: var(--blue-2); }
.thumb-cell img { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; }
.st { padding: 1px 8px; border-radius: 999px; font-size: .8rem; background: var(--surface-2); }
.st-ok { background: #d8f2df; color: #1d6b32; } .st-error { background: #fde0e3; color: #a3172a; }
.input { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--surface); min-width: 0; }
.input-sm { padding: 5px 8px; font-size: .9rem; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
tr.saving { opacity: .55; }
.date-cell .input { width: 150px; }
/* แท็บหน้าผู้ดูแล */
.admin-head p { margin: 4px 0 0; }
.admin-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.admin-tabs button {
  flex: none; border: 0; background: none; padding: 10px 16px; font-weight: 600; color: var(--muted); cursor: pointer;
  border-bottom: 3px solid transparent; margin-bottom: -2px; font-family: var(--font-head);
}
.admin-tabs button.on { color: var(--blue-2); border-bottom-color: var(--red); }
.panel[hidden] { display: none; }
.panel .chips { flex-wrap: wrap; }
button.chip { cursor: pointer; font: inherit; font-size: .92rem; display: inline-flex; gap: 6px; align-items: center; }
.chip.on .cat-n { background: rgba(255,255,255,.25); color: #fff; }
.badge-muted { background: var(--surface-2); color: var(--muted); }
.cat-select { max-width: 210px; }
.cat-select.is-guess { border-style: dashed; border-color: #e6a700; }
.icon-input { width: 56px; text-align: center; font-size: 1.1rem; }
.kw-input { width: 100%; min-width: 280px; resize: vertical; }
#cat-table input[name=name] { min-width: 150px; }
.btn.danger:hover { color: var(--red); background: rgba(215, 38, 61, .08); }
.new-row td { background: var(--surface-2); }
#year-table { max-width: 560px; }
.row-off td { opacity: .5; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .2s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--blue-2); }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--sky); outline-offset: 2px; }
.field-note { color: var(--muted); font-size: .82rem; margin-top: -6px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--blue-2); cursor: pointer; font: inherit; text-decoration: underline; }
.modal-box .is-guess { border-style: dashed; border-color: #e6a700; background: rgba(230, 167, 0, .08); }
.cat-n.alert { background: var(--red); color: #fff; }
.sub-title { font-size: 1.02rem; margin: 22px 0 10px; display: flex; gap: 8px; align-items: center; }
.report-list { display: flex; flex-direction: column; gap: 12px; }
.report-card { display: flex; gap: 14px; border: 1px solid var(--line); border-left: 4px solid var(--red); border-radius: 12px; padding: 12px; }
.report-img { flex: none; width: 160px; }
.report-img img { width: 160px; height: 120px; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.report-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.report-reasons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.report-details { margin: 4px 0; padding-left: 18px; font-size: .9rem; }
.hidden-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.hidden-item { display: flex; flex-direction: column; gap: 4px; }
.hidden-item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; opacity: .6; background: var(--surface-2); }
.hidden-item small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) {
  .report-card { flex-direction: column; }
  .report-img, .report-img img { width: 100%; height: auto; }
}
.role-help { display: grid; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin: 6px 0 12px; font-size: .9rem; }
#admin-table input[name=email] { min-width: 220px; }
.qr-box { align-items: center; text-align: center; max-width: 420px; }
.qr-canvas { width: 280px; height: 280px; image-rendering: pixelated; border-radius: 8px; border: 1px solid var(--line); }
.qr-title { margin: 0; font-weight: 600; font-family: var(--font-head); }
.qr-url { margin: 0; word-break: break-all; }
.qr-actions { flex-wrap: wrap; justify-content: center; }
/* ---------- หน้าตั้งค่าสไลด์โชว์ ---------- */
.ss-setup { padding-top: 24px; padding-bottom: 50px; display: flex; flex-direction: column; gap: 16px; }
.ss-setup > p { margin: -6px 0 0; }
.ss-pane { padding-top: 14px; }
.ss-pick-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.ss-pick-head .input[type=search] { flex: 1 1 240px; }
.ss-list { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.ss-item { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ss-item:last-child { border-bottom: 0; }
.ss-item:hover { background: var(--surface-2); }
.ss-item.on { background: rgba(22, 119, 210, .08); }
.ss-item input { width: 18px; height: 18px; accent-color: var(--blue-2); }
.ss-t { font-weight: 500; }
.ss-m { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.ss-grid2, .ss-grid3 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
.ss-setup label:not(.ss-item) { display: flex; flex-direction: column; gap: 4px; font-size: .92rem; color: var(--muted); }
.ss-setup label.ss-inline { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 1rem; }
.ss-setup label.ss-check { flex-direction: row; color: var(--text); padding-bottom: 8px; }
.ss-options h2 { font-size: 1.1rem; margin-bottom: 10px; }
.ss-go { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.ss-start { font-size: 1.1rem; padding: 14px 34px; }
.ss-start.disabled { opacity: .45; cursor: not-allowed; }
.ss-link { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 320px; }
.ss-link code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: .82rem; }
@media (max-width: 640px) { .ss-item { grid-template-columns: auto 1fr; } .ss-m { grid-column: 2; } }
/* ---------- สถิติ ---------- */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 12px 0 16px; }
.stat-tile { background: var(--surface-2); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.stat-tile .lbl { font-size: .86rem; color: var(--muted); }
.stat-tile strong { font: 600 1.8rem/1.2 var(--font-head); color: var(--text); font-variant-numeric: tabular-nums; }
.stat-tile .sub { font-size: .82rem; color: var(--muted); }
.chart-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-top: 14px; min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head h3 { font-size: 1rem; }
.chart { position: relative; width: 100%; min-height: 260px; }
.lc { display: block; overflow: visible; }
.lc .grid { stroke: var(--line); stroke-width: 1; }
.lc .axis { stroke: var(--muted); stroke-opacity: .5; stroke-width: 1; }
.lc .tick { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.lc .line { fill: none; stroke: var(--blue-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.lc .area { fill: var(--blue-2); fill-opacity: .1; stroke: none; }
.lc .dot { fill: var(--blue-2); stroke: var(--surface); stroke-width: 2; }
.lc .cross { stroke: var(--muted); stroke-width: 1; }
.chart .tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  border-radius: 8px; padding: 6px 10px; display: flex; flex-direction: column; font-size: .82rem; white-space: nowrap; }
.chart .tip strong { font-size: .95rem; }
.chart .tip span { color: var(--muted); }
.chart-table summary { cursor: pointer; color: var(--blue-2); font-size: .88rem; margin-top: 4px; }
.chart-table .table { max-width: 360px; }
.stats-2col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 0 14px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.rank[hidden] { display: none; }
.rank li.muted { display: block; }
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rank li { display: grid; grid-template-columns: 22px minmax(0, 1fr) 90px 56px; align-items: center; gap: 8px; font-size: .92rem; }
.rk { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.rk-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-name:hover { color: var(--blue-2); }
.rk-bar, .hb-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.rk-bar i, .hb-track i { display: block; height: 100%; background: var(--blue-2); border-radius: 0 4px 4px 0; min-width: 2px; }
.rk-v, .hb-v { text-align: right; font-variant-numeric: tabular-nums; }
.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hbars li { display: grid; grid-template-columns: minmax(0, 170px) 1fr 64px; gap: 10px; align-items: center; font-size: .92rem; }
.hb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-photos[hidden] { display: none; }
.top-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.top-photos a { position: relative; border-radius: 8px; overflow: hidden; background: var(--surface-2); aspect-ratio: 4/3; }
.top-photos img { width: 100%; height: 100%; object-fit: cover; }
.tp-rank { position: absolute; top: 6px; left: 6px; background: rgba(10,20,40,.75); color: #fff; font-size: .75rem; border-radius: 999px; min-width: 22px; text-align: center; padding: 1px 6px; }
.tp-v { position: absolute; bottom: 6px; right: 6px; background: rgba(10,20,40,.75); color: #fff; font-size: .75rem; border-radius: 999px; padding: 1px 8px; }
@media (max-width: 640px) {
  .rank li { grid-template-columns: 20px minmax(0, 1fr) 50px; }
  .rk-bar { display: none; }
  .hbars li { grid-template-columns: minmax(0, 120px) 1fr 54px; }
}
.grid-more { height: 1px; }
kbd { font: inherit; font-size: .8rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface); }
.date-cell .is-guess { border-style: dashed; border-color: #e6a700; background: rgba(230, 167, 0, .08); }

/* Modal แก้ไขอัลบั้ม */
.modal { position: fixed; inset: 0; z-index: 150; background: rgba(6, 12, 24, .55); display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px; padding: 22px; display: flex; flex-direction: column; gap: 12px; max-height: 90vh; overflow: auto; }
.modal-box h2 { font-size: 1.2rem; }
.modal-box label { display: flex; flex-direction: column; gap: 4px; font-size: .92rem; color: var(--muted); }
.modal-box label.check { flex-direction: row; color: var(--text); }
.modal-box .input { width: 100%; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  :root { --rowh: 96px; }
  .brand-text small { display: none; }
  .hero { padding: 24px 0 22px; }
  .br-sm { display: inline; }
  .search { padding-left: 12px; }
  .search .btn { padding: 9px 14px; }
  .filter-label { width: auto; display: none; }
  .cat-tabs { top: 64px; }
  .cat-bar { gap: 6px; }
  .filter-btn { padding: 7px 10px; }
  .filter-btn-text { display: none; }
  /* แผ่นตัวกรองเลื่อนขึ้นจากล่างจอ */
  .filter-pop[open] > summary::before {
    content: ""; position: fixed; inset: 0; background: rgba(6, 12, 24, .45); z-index: 59; cursor: default;
  }
  .filter-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; max-width: none; max-height: 75vh; overflow: auto;
    border-radius: 18px 18px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); animation: sheet-up .22s ease;
  }
  .filter-sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
  .wrap-chips .chip { padding: 7px 14px; }
  /* หัวเว็บแบบกะทัดรัด เห็นรูปตั้งแต่หน้าจอแรก */
  .hero { padding: 14px 0 14px; }
  .hero h1 { font-size: 1.2rem; margin-bottom: 10px; }
  .hero-sub { display: none; }
  .br-sm { display: none; }
  .cat-tab { padding: 12px 12px 9px; font-size: .95rem; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { border-radius: 12px; }
  .card-body { padding: 8px 10px 10px; }
  .card-body h3 { font-size: .92rem; }
  .card-tags { display: none; }
  .pop-row { grid-auto-columns: 46%; gap: 10px; }
  .sort-switch { float: none; display: flex; width: max-content; margin: 0 0 10px; }
  .justified { gap: 3px; }
  .jp { border-radius: 3px; }
  .lb-nav { display: none; }
  .album-actions .btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
