/* ===== Fonts ===== */
@font-face { font-family: "Sao Chingcha"; font-weight: 300; src: url(fonts/SaoChingcha-Light.otf) format("opentype"); font-display: swap; }
@font-face { font-family: "Sao Chingcha"; font-weight: 400; src: url(fonts/SaoChingcha-Regular.otf) format("opentype"); font-display: swap; }
@font-face { font-family: "Sao Chingcha"; font-weight: 700; src: url(fonts/SaoChingcha-Bold.otf) format("opentype"); font-display: swap; }

/* ===== Tokens (อัตลักษณ์ กทม.) ===== */
:root {
  --green: #00744b;
  --green-dark: #004a31;
  --green-light: #0a9b68;
  --gold: #f4b400;

  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-2: #eaf3ee;
  --text: #15241d;
  --muted: #5a6b63;
  --line: #dce6e0;
  --link: #00744b;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 40, 25, .06), 0 4px 16px rgba(0, 40, 25, .06);
  --shadow-hover: 0 2px 4px rgba(0, 40, 25, .08), 0 12px 28px rgba(0, 40, 25, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1612;
    --surface: #16211c;
    --surface-2: #1c2c24;
    --text: #e7f0eb;
    --muted: #9fb3a9;
    --line: #26372f;
    --link: #4fcf97;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-hover: 0 8px 24px rgba(0, 0, 0, .45);
  }
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Sao Chingcha", "Sarabun", "Thonburi", system-ui, sans-serif;
  font-size: 17px; line-height: 1.65;
  display: flex; flex-direction: column; min-height: 100vh;
}
main { flex: 1; }
a { color: var(--link); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.35; font-weight: 700; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 24px; } }

/* ===== Top bar (ส่วนหัวเดียว) ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--line);
  box-shadow: inset 0 -3px 0 var(--gold);
}
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 68px; }
@media (max-width: 599px) { .topbar-in { min-height: 60px; } }
.brand { display: flex; align-items: center; }
.brand img { height: 44px; width: auto; display: block; }
.brand .logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .brand .logo-light { display: none; }
  .brand .logo-dark { display: block; }
}
.topnav { display: flex; gap: 4px; }
.topnav a {
  text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; font-size: .95rem; white-space: nowrap;
}
.topnav a.active { color: var(--green); background: var(--surface-2); font-weight: 700; }
@media (prefers-color-scheme: dark) { .topnav a.active { color: var(--link); } }
@media (max-width: 520px) { .brand img { height: 36px; } .topnav { display: none; } }

/* ===== Page intro ===== */
.intro { padding: 32px 0 20px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.eyebrow {
  margin: 0 0 4px; color: var(--green); font-weight: 700; font-size: .85rem; letter-spacing: .02em;
  display: flex; align-items: center; gap: 8px;
}
.eyebrow::before { content: ""; width: 24px; height: 3px; border-radius: 2px; background: var(--gold); }
@media (prefers-color-scheme: dark) { .eyebrow { color: var(--link); } }
.intro h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.2rem); }
.intro .lead { margin: 4px 0 0; color: var(--muted); }
.count { color: var(--muted); font-size: .92rem; }

/* ===== Toolbar ===== */
.toolbar {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
.toolrow { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 720px) { .toolrow { grid-template-columns: minmax(0, 1fr) minmax(0, 360px) auto; align-items: center; } }
.select { position: relative; }
.select svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.select::after {
  content: ""; position: absolute; right: 14px; top: 50%; width: 8px; height: 8px; pointer-events: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-70%) rotate(45deg);
}
.select select {
  width: 100%; appearance: none; -webkit-appearance: none; cursor: pointer;
  padding: 10px 36px 10px 40px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg);
  text-overflow: ellipsis;
}
.select select:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(0, 116, 75, .15); }
.select select.on { border-color: var(--green); background: var(--surface-2); font-weight: 700; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; padding: 10px 12px 10px 40px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg);
}
.search input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(0, 116, 75, .15); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: transparent;
  padding: 5px 14px; border-radius: 999px; cursor: pointer; font-size: .92rem; white-space: nowrap;
}
.chip:hover { border-color: var(--green); }
.chip[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; font-weight: 700; }

/* ===== Tag / meta ===== */
.meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.tag {
  display: inline-block; background: var(--gold); color: #3a2c00; font-weight: 700;
  border-radius: 6px; padding: 1px 8px; font-size: .78rem; line-height: 1.6;
}

/* ===== Featured ===== */
.featured {
  margin-top: 24px; display: grid; grid-template-columns: 1fr; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); transition: box-shadow .2s, transform .2s;
}
.featured:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.featured .media { aspect-ratio: 3 / 2; }
.featured .body { padding: 20px; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.featured h2 { margin: 0; font-size: clamp(1.25rem, 2.6vw, 1.6rem); }
.featured p { margin: 0; color: var(--muted); }
.featured .readmore { color: var(--link); font-weight: 700; font-size: .95rem; }
@media (min-width: 820px) {
  .featured { grid-template-columns: 1.35fr 1fr; }
  .featured .media { aspect-ratio: auto; min-height: 340px; }
  .featured .body { padding: 32px; }
}

/* ===== Cards grid ===== */
.section-title { margin: 32px 0 12px; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.section-title::before { content: ""; width: 4px; height: 18px; border-radius: 2px; background: var(--green); }
.grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.card {
  display: flex; flex-direction: column; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); transition: box-shadow .2s, transform .2s;
}
.card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.card .media { aspect-ratio: 3 / 2; }
.card .body { padding: 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card h3 {
  margin: 0; font-size: 1.05rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card p {
  margin: 0; color: var(--muted); font-size: .93rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.media { position: relative; background: var(--surface-2); overflow: hidden; }
.media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.media.empty { display: grid; place-items: center; }
.media.empty img { position: static; width: 38%; height: auto; max-width: 160px; opacity: .35; object-fit: contain; }

.more {
  display: block; margin: 28px auto 0; padding: 10px 28px; border: 1px solid var(--green); background: transparent;
  color: var(--link); border-radius: 999px; cursor: pointer; font-weight: 700;
}
.more:hover { background: var(--surface-2); }
.empty-state { text-align: center; color: var(--muted); padding: 56px 16px; grid-column: 1 / -1; }

/* ===== Detail ===== */
.crumb { margin: 24px 0 16px; font-size: .92rem; }
.crumb a { text-decoration: none; }
.crumb a:hover { text-decoration: underline; }
article.detail {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; max-width: 860px; margin: 0 auto;
}
.detail-head { padding: 24px 24px 0; }
.detail-head h1 { margin: 8px 0 0; font-size: clamp(1.4rem, 3.4vw, 2rem); }
.hero { margin: 20px 0 0; background: var(--surface-2); }
.hero img { width: 100%; height: auto; display: block; }
.detail-body { padding: 24px; }
.detail-body .text p { margin: 0 0 14px; }
.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 8px 0 24px; }
@media (min-width: 640px) { .gallery { grid-template-columns: repeat(3, 1fr); } }
.gallery a { display: block; aspect-ratio: 3 / 2; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.gallery a:hover img { transform: scale(1.03); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 16px; border-top: 1px solid var(--line); }
.fb-frame { width: 100%; max-width: 500px; height: 600px; border: 0; display: block; margin-top: 16px; border-radius: var(--radius-sm); }
.hint { font-size: .85rem; color: var(--muted); margin: 8px 0 0; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-sm); border: 1px solid var(--green);
  background: var(--green); color: #fff; text-decoration: none; cursor: pointer; font-size: .95rem; font-weight: 700;
}
.btn:hover { background: var(--green-dark); }
.btn.ghost { background: transparent; color: var(--link); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 12px; font-size: .85rem; }
.btn.danger { border-color: #c0392b; color: #c0392b; background: transparent; }
.btn.danger:hover { background: rgba(192, 57, 43, .08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== Footer ===== */
.foot { margin-top: 56px; background: var(--green-dark); color: rgba(255, 255, 255, .85); border-top: 4px solid var(--gold); }
.foot-in { padding: 28px 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-size: .9rem; }
.foot img { height: 40px; width: auto; display: block; }
.foot p { margin: 0; }

/* ===== Admin ===== */
.admin-grid { display: grid; gap: 24px; grid-template-columns: 1fr; padding-top: 24px; }
@media (min-width: 980px) { .admin-grid { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; } .admin-side { position: sticky; top: 92px; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 24px; }
.panel h2 { margin: 0 0 4px; font-size: 1.15rem; display: flex; align-items: center; gap: 10px; }
.step { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--green); color: #fff; font-size: .85rem; }
.panel .sub { margin: 0 0 12px; color: var(--muted); font-size: .9rem; }
.field { margin-top: 14px; }
.field label { display: block; font-size: .9rem; margin-bottom: 4px; font-weight: 700; }
.field small { display: block; color: var(--muted); font-size: .82rem; margin-top: 4px; }
.field input[type=text], .field input[type=url], .field input[type=date], .field input[type=password], .field select, .field textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(0, 116, 75, .15); }
.field textarea { min-height: 160px; resize: vertical; }
.row2 { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .row2 { grid-template-columns: 1fr 1fr; } }
.req { color: #c0392b; }
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 20px; text-align: center; cursor: pointer;
  color: var(--muted); background: var(--bg); transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--green); background: var(--surface-2); }
.drop strong { color: var(--text); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 12px; }
.thumb { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); font-size: .78rem; }
.thumb .ph { aspect-ratio: 3 / 2; background: var(--surface-2); position: relative; }
.thumb .ph img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .ph .badge { position: absolute; top: 6px; left: 6px; background: var(--gold); color: #3a2c00; border-radius: 4px; padding: 0 6px; font-weight: 700; }
.thumb .info { padding: 6px 8px; display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.thumb .size { color: var(--muted); line-height: 1.3; }
.thumb .size b { color: var(--green); }
@media (prefers-color-scheme: dark) { .thumb .size b { color: var(--link); } }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 2px 4px; border-radius: 4px; line-height: 1; }
.icon-btn:hover { color: #c0392b; background: rgba(192, 57, 43, .08); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.news-list { list-style: none; margin: 0; padding: 0; max-height: 460px; overflow: auto; }
.news-list li { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.news-list li:first-child { border-top: 0; }
.news-list .t { font-weight: 700; font-size: .95rem; line-height: 1.4; }
.news-list small { color: var(--muted); }
.news-list .acts { display: flex; gap: 6px; flex: none; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 0; }
.stats div { background: var(--bg); border-radius: var(--radius-sm); padding: 8px 10px; }
.stats b { display: block; font-size: 1.15rem; }
.stats span { font-size: .78rem; color: var(--muted); }
.notice { border-radius: var(--radius-sm); padding: 10px 14px; font-size: .9rem; margin-top: 12px; }
.notice.info { background: var(--surface-2); }
.notice.warn { background: #fff4d1; color: #5c4400; }
.progress { font-size: .88rem; color: var(--muted); margin-top: 8px; }
.notice.error { background: #fdecea; color: #8a1f14; }
@media (prefers-color-scheme: dark) { .notice.warn { background: #3a2f0c; color: #f6deA0; } .notice.error { background: #3d1a16; color: #f5b5ad; } }

/* ล็อกอิน / ผู้ใช้ */
.login { display: grid; place-items: center; padding: 48px 0; }
.login .panel { width: 100%; max-width: 420px; }
.login h1 { margin: 0 0 8px; font-size: 1.5rem; }
.btn.block { width: 100%; }
.userbar { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who { font-size: .9rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) { .who { display: none; } }
.news-list li.editing { background: var(--surface-2); border-radius: var(--radius-sm); padding-left: 8px; padding-right: 8px; }
.news-list .muted { color: var(--muted); justify-content: center; }
.thumb .ph .busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .45); color: #fff; font-size: .8rem; }
.thumb .ctl { display: flex; gap: 2px; }
.icon-btn:hover { color: var(--green); background: var(--surface-2); }
.icon-btn.del:hover { color: #c0392b; background: rgba(192, 57, 43, .08); }
details.panel summary { cursor: pointer; list-style-position: outside; }
details.panel[open] summary { margin-bottom: 4px; }
/* ===== หน้าเข้าสู่ระบบ ===== */
.login-page { background: var(--bg); }
.auth { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1fr; }
@media (min-width: 900px) { .auth { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

.auth-brand {
  position: relative; overflow: hidden; color: #fff;
  background: linear-gradient(150deg, #003a27 0%, #004a31 35%, #00744b 75%, #0a9b68 100%);
  display: none;
}
@media (min-width: 900px) { .auth-brand { display: flex; } }
/* วงกลมโปร่งตกแต่งพื้นหลัง */
.auth-brand::before, .auth-brand::after {
  content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .06); pointer-events: none;
}
.auth-brand::before { width: 520px; height: 520px; right: -180px; top: -160px; }
.auth-brand::after { width: 380px; height: 380px; left: -140px; bottom: -120px; background: rgba(244, 180, 0, .08); }
.auth-brand-in {
  position: relative; z-index: 1; display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
  padding: 48px clamp(32px, 5vw, 72px); width: 100%; max-width: 640px; margin-left: auto;
}
.auth-logo { height: 52px; width: auto; align-self: flex-start; }
.auth-brand h2 { margin: 0 0 12px; font-size: clamp(2rem, 3.4vw, 2.75rem); line-height: 1.25; }
.auth-brand h2 + p { margin: 0; font-size: 1.1rem; opacity: .88; max-width: 28em; }
.auth-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.auth-points li { display: flex; align-items: center; gap: 12px; opacity: .92; }
.auth-points li::before {
  content: ""; flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--gold) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233a2c00' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E") center / 14px no-repeat;
}
.auth-brand { border-right: 4px solid var(--gold); }

.auth-form {
  display: flex; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow-hover); padding: 32px 28px;
}
@media (min-width: 900px) { .auth-card { box-shadow: var(--shadow); padding: 40px 36px; } }
.auth-card h1 { margin: 0; font-size: 1.75rem; }
.auth-card .sub { margin: 4px 0 8px; color: var(--muted); }
.auth-logo-sm { height: 40px; width: auto; display: block; margin-bottom: 24px; }
.auth-logo-sm.logo-dark { display: none; }
@media (prefers-color-scheme: dark) { .auth-logo-sm.logo-light { display: none; } .auth-logo-sm.logo-dark { display: block; } }
@media (min-width: 900px) { .auth-logo-sm { display: none !important; } }
.auth-card .field select, .auth-card .field input { min-height: 48px; font-size: 1rem; }
.auth-card .select select { padding-left: 40px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px !important; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 40px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 6px;
  display: grid; place-items: center;
}
.pw-toggle:hover { color: var(--green); background: var(--surface-2); }
.pw-toggle[aria-pressed="true"] { color: var(--green); }
.pw-toggle svg { width: 20px; height: 20px; }
.caps { color: #8a5a00 !important; font-weight: 700; }
.btn.lg { min-height: 50px; font-size: 1.05rem; margin-top: 20px; border-radius: 10px; }
.center { text-align: center; }
.auth-card .hint { margin-top: 16px; }
.auth-card .back { margin: 12px 0 0; font-size: .92rem; }
.auth-card .back a { display: inline-flex; min-height: 44px; align-items: center; text-decoration: none; }
.auth-card .back a:hover { text-decoration: underline; }
/* มือถือ: แถบเขียวด้านบนให้มีอัตลักษณ์ */
@media (max-width: 899px) {
  .login-page { background: linear-gradient(180deg, #004a31 0, #00744b 220px, var(--bg) 220px); }
  .auth-form { align-items: flex-start; padding-top: max(48px, calc(env(safe-area-inset-top) + 32px)); }
}

.foot a { color: rgba(255, 255, 255, .85); }
.foot a:hover { color: #fff; }

/* ===================================================================
   Responsive: มือถือ (≤599) · แท็บเล็ต (600–979) · เดสก์ท็อป (≥980)
   =================================================================== */

/* รองรับจอมีรอยบาก (iPhone) */
.topbar-in, .foot-in { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.foot-in { padding-bottom: max(28px, env(safe-area-inset-bottom)); }

/* เอฟเฟกต์ลอยเฉพาะอุปกรณ์ที่มีเมาส์ (กันการ์ด "ค้าง" บนจอสัมผัส) */
@media (hover: none) {
  .card:hover, .featured:hover { transform: none; box-shadow: var(--shadow); }
  .gallery a:hover img { transform: none; }
}

/* ชื่อฝ่ายแยกบรรทัด อ่านง่ายทุกขนาดจอ */
.dept-line { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; line-height: 1.4; }
.dept-line::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--green); flex: none; }

/* แถบหมวด: เลื่อนแนวนอนได้ มีขอบจางบอกว่ายังมีต่อ */
.chips { scroll-snap-type: x proximity; padding-bottom: 2px; }
.chip { scroll-snap-align: start; min-height: 36px; }
.chips.fade-r { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
.chips.fade-l { -webkit-mask-image: linear-gradient(90deg, transparent, #000 15%); mask-image: linear-gradient(90deg, transparent, #000 15%); }
.chips.fade-l.fade-r { -webkit-mask-image: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent); mask-image: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent); }

.crumb a { display: inline-flex; align-items: center; min-height: 44px; padding-right: 8px; }

/* ปุ่มกลับขึ้นด้านบน */
.to-top {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 20;
  width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--green); color: #fff; box-shadow: var(--shadow-hover);
  display: grid; place-items: center; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .2s, transform .2s;
}
.to-top.show { opacity: 1; pointer-events: auto; transform: none; }
.to-top svg { width: 22px; height: 22px; }

/* ----- มือถือ ----- */
@media (max-width: 599px) {
  body { font-size: 16px; }
  .intro { padding: 20px 0 14px; gap: 4px; }
  .intro .lead { font-size: .95rem; }
  .toolbar { padding: 10px; gap: 10px; border-radius: 12px; }
  .featured { margin-top: 16px; }
  .featured .body { padding: 16px; gap: 6px; }
  .section-title { margin: 24px 0 10px; }

  /* การ์ดแบบแถว: รูปเล็กซ้าย ข้อความขวา เห็นได้หลายข่าวต่อหน้าจอ */
  .grid { gap: 10px; }
  .card { flex-direction: row; border-radius: 12px; }
  .card .media { flex: none; width: 116px; aspect-ratio: auto; min-height: 100%; }
  .card .body { padding: 10px 12px; gap: 4px; min-width: 0; }
  .card h3 { font-size: .98rem; -webkit-line-clamp: 3; }
  .card p { display: none; }
  .card .meta { gap: 6px; font-size: .8rem; }
  .card .dept-line { font-size: .8rem; }
  .media.empty img { width: 70%; }

  /* หน้าอ่านข่าวเต็มความกว้างจอ */
  #detail { margin: 0 -16px; }
  .crumb { margin: 4px 16px 4px; }
  article.detail { border-radius: 0; border-left: 0; border-right: 0; box-shadow: none; }
  .detail-head { padding: 16px 16px 0; }
  .detail-body { padding: 16px; }
  .detail-actions .btn { flex: 1 1 auto; }
  .fb-frame { height: 520px; }

  .foot-in { flex-direction: column; text-align: center; gap: 10px; }
  .foot img { height: 34px; }
}

/* ----- หลังบ้าน: แท็บบนจอเล็ก/กลาง ----- */
.tabs { display: none; }
@media (max-width: 979px) {
  .tabs {
    display: flex; gap: 4px; padding: 4px; margin-bottom: 16px; position: sticky; top: 72px; z-index: 5;
    background: var(--surface); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow);
  }
  .tabs button {
    flex: 1; min-height: 40px; border: 0; border-radius: 999px; background: transparent; cursor: pointer;
    font-weight: 700; font-size: .92rem; color: var(--muted); white-space: nowrap; padding: 0 8px;
  }
  .tabs button[aria-selected="true"] { background: var(--green); color: #fff; }
  .admin-grid { padding-top: 0; }
  .admin-grid[data-tab="form"] [data-pane]:not([data-pane="form"]),
  .admin-grid[data-tab="list"] [data-pane]:not([data-pane="list"]),
  .admin-grid[data-tab="account"] [data-pane]:not([data-pane="account"]) { display: none; }
  .admin-side { display: contents; }
  .panel + .panel { margin-top: 0; }
  .admin-grid { gap: 16px; }
  .news-list { max-height: none; }
  /* ปุ่มบันทึกติดด้านล่างจอ กดได้ตลอดโดยไม่ต้องเลื่อนลงสุด */
  .sticky-actions {
    position: sticky; bottom: 0; z-index: 4; margin: 20px -20px -20px; padding: 12px 20px max(12px, env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius);
  }
  .sticky-actions .btn { flex: 1; min-height: 44px; }
}
@media (max-width: 599px) {
  .tabs { top: 64px; }
  .panel { padding: 16px; }
  .sticky-actions { margin: 16px -16px -16px; padding-left: 16px; padding-right: 16px; }
  .news-list li { flex-direction: column; align-items: stretch; gap: 8px; }
  .news-list .acts { justify-content: flex-start; }
  .news-list .acts .btn { flex: 1; min-height: 38px; }
  .intro .btn { width: 100%; }
  .thumbs { grid-template-columns: repeat(2, 1fr); }
}
details.panel summary { min-height: 44px; display: flex; align-items: center; }
.icon-btn { min-width: 32px; min-height: 32px; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px)); transform: translateX(-50%); z-index: 50;
  background: var(--green-dark); color: #fff; padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow-hover); font-size: .95rem; max-width: calc(100% - 32px);
}
