/* ระบบจัดการข้อมูลหลังบ้าน */
body.admin { background: #eef4f7; min-height: 100vh; }
.admin-top {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 10px 20px; background: var(--brand-900); color: #fff;
}
.admin-top .brand { color: #fff; }
.admin-top .brand img { width: 44px; background: #fff; border-radius: 12px; padding: 3px; }
.admin-top .brand-title { color: #fff; }
.admin-top .brand-sub { color: rgba(255, 255, 255, .7); }
.admin-top-actions { display: flex; gap: 8px; flex: none; }
.btn-dark { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .25); }
.btn-dark:hover { background: rgba(255, 255, 255, .2); color: #fff; }
.btn-danger { background: #fff; color: var(--rose); border-color: #f0c9c5; }
.btn-danger:hover { background: #fdf0ee; color: #a32a21; }
.btn[disabled], .icon-btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

/* ---------- Login ---------- */
.login-wrap { display: grid; place-items: center; padding: 64px 16px; }
.login-card { width: min(400px, 100%); background: #fff; border-radius: 20px; padding: 32px; box-shadow: var(--shadow); display: grid; gap: 14px; text-align: center; }
.login-card img { width: 84px; margin: 0 auto; }
.login-card h1 { font-size: 1.4rem; margin: 0; }
.login-card p { margin: 0; color: var(--muted); font-size: .95rem; }
.login-card .f { text-align: left; }
.login-card .btn { justify-content: center; }

/* ---------- Layout ---------- */
.admin-shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 64px); }
.admin-nav { background: #fff; border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 64px; height: calc(100vh - 64px); overflow-y: auto; }
.admin-nav button {
  display: flex; align-items: center; gap: 10px; text-align: left; border: 0; background: transparent; cursor: pointer;
  padding: 10px 12px; border-radius: 10px; font: 500 .93rem var(--font-head); color: var(--ink-2);
}
.admin-nav button:hover { background: var(--sky-50); color: var(--brand-700); }
.admin-nav button[aria-current="page"] { background: var(--sky-100); color: var(--brand-700); }
.admin-nav .icon { color: var(--brand); }
.admin-main { padding: 28px 32px 80px; outline: none; max-width: 1200px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.admin-head h1 { font-size: 1.5rem; margin: 0 0 2px; }
.admin-head p { margin: 0; color: var(--muted); }
.admin-head-actions { display: flex; gap: 8px; }
.muted { color: var(--muted); font-size: .92rem; }
.hint { color: var(--muted); font-size: .88rem; margin: 6px 0 12px; }

/* ---------- รายการข่าว ---------- */
.row-list { display: grid; gap: 10px; }
.row { display: grid; grid-template-columns: 88px minmax(0, 1fr) auto; gap: 14px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px 10px 10px; }
.row-thumb { width: 88px; height: 64px; border-radius: 10px; overflow: hidden; background: var(--sky-100); display: grid; place-items: center; color: var(--muted); }
.row-thumb img { width: 100%; height: 100%; object-fit: cover; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-main b { font-family: var(--font-head); font-weight: 500; line-height: 1.45; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row-meta { color: var(--muted); font-size: .88rem; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink-2); cursor: pointer; display: inline-grid; place-items: center; font-size: .75rem; text-decoration: none; }
.icon-btn:hover:not([disabled]) { border-color: var(--brand); color: var(--brand); }
.icon-btn .icon { width: 16px; height: 16px; }

/* ---------- ตาราง ---------- */
.admin-filter { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.admin-filter select, .admin-filter input { font: inherit; font-size: .95rem; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-height: 42px; }
.admin-filter input { flex: 1 1 260px; }
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th { text-align: left; font: 500 .85rem var(--font-head); color: var(--muted); background: var(--sky-50); padding: 10px 14px; border-bottom: 1px solid var(--line); }
.admin-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tr:hover td { background: #fafdfe; }
.year-col { font-family: var(--font-head); font-weight: 600; color: var(--brand-700); white-space: nowrap; width: 64px; }
.actions-col { white-space: nowrap; width: 1%; text-align: right; }
.cell-title { font-weight: 500; line-height: 1.5; }
.cell-meta { color: var(--muted); font-size: .86rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }

/* ---------- ฟอร์ม ---------- */
.panel { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 22px; margin-bottom: 18px; }
.panel h2 { font-size: 1.1rem; margin: 0 0 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.f { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.f.full { grid-column: 1 / -1; }
.f > span { font: 500 .9rem var(--font-head); color: var(--ink-2); }
.f .req { color: var(--rose); font-style: normal; }
.f input, .f textarea, .f select {
  font: inherit; font-size: .96rem; color: var(--ink); background: #fff; width: 100%;
  border: 1px solid #c9dde6; border-radius: 10px; padding: 9px 12px; min-height: 42px;
}
.f input[type="color"] { padding: 4px; height: 42px; cursor: pointer; }
.f textarea { resize: vertical; line-height: 1.6; }
.f input:focus, .f textarea:focus, .f select:focus, .admin-filter :focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 136, 176, .15); }
.f small { color: var(--muted); font-size: .82rem; }
.form-error { color: var(--rose); font-size: .92rem; margin: 0; min-height: 1em; }
.save-bar { position: sticky; bottom: 0; display: flex; gap: 14px; align-items: center; padding: 14px 0; background: linear-gradient(transparent, #eef4f7 30%); }
.sub-head { font-size: 1.05rem; margin: 22px 0 10px; }

.rep-item { border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; background: var(--sky-50); }
.rep-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.rep-head span { display: flex; gap: 6px; }

/* ---------- แกลเลอรีในฟอร์มข่าว ---------- */
.gal { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; background: var(--sky-50); }
.gal-head { display: flex; gap: 10px; margin-bottom: 10px; }
.gal-head input { flex: 1; font: inherit; font-size: .95rem; padding: 8px 12px; border: 1px solid #c9dde6; border-radius: 10px; min-height: 40px; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.gal-item { position: relative; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; background: #dbeef4; }
.gal-item img { width: 100%; height: 100%; object-fit: cover; }
.gal-tools { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; gap: 4px; padding: 4px; background: linear-gradient(transparent, rgba(0, 0, 0, .55)); }
.gal-tools button { border: 0; border-radius: 6px; background: rgba(255, 255, 255, .92); width: 28px; height: 26px; cursor: pointer; font-size: .72rem; color: var(--ink); }
.gal-tools button.danger { margin-left: auto; color: var(--rose); font-weight: 700; }
.gal-tools button[disabled] { opacity: .35; cursor: default; }
.gal-upload { aspect-ratio: 4 / 3; border: 2px dashed #9fcfe0; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer; color: var(--brand-700); font: 500 .9rem var(--font-head); background: #fff; }
.gal-upload:hover { border-color: var(--brand); background: var(--sky-50); }
.gal-upload .icon { width: 26px; height: 26px; }
.gal-status { margin: 8px 0 0; font-size: .88rem; color: var(--brand-700); min-height: 1em; }

/* ---------- Dialog ---------- */
.admin-dialog { width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 30px 80px rgba(6, 30, 44, .35); }
.admin-dialog.wide { width: min(920px, calc(100vw - 24px)); }
.admin-dialog::backdrop { background: rgba(8, 30, 44, .55); }
.dialog-form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 1.2rem; }
.dialog-body { padding: 18px 20px; overflow-y: auto; }
.dialog-foot { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--sky-50); }
.dialog-foot .form-error { margin-right: auto; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 300; background: var(--brand-900); color: #fff; padding: 11px 20px; border-radius: 999px; font-weight: 500; box-shadow: var(--shadow); transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--rose); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-nav { position: sticky; top: 64px; z-index: 30; height: auto; flex-direction: row; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .admin-nav button { flex: none; white-space: nowrap; padding: 8px 12px; }
  .admin-main { padding: 20px 16px 80px; }
  .admin-top .brand-sub { display: none; }
}
@media (max-width: 640px) {
  .admin-top { padding: 8px 12px; }
  .admin-top .brand-title { font-size: .9rem; }
  .admin-top-actions .btn-ghost { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .row { grid-template-columns: 64px minmax(0, 1fr); }
  .row-thumb { width: 64px; height: 48px; }
  .row-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .admin-table thead { display: none; }
  .admin-table tr { display: grid; grid-template-columns: auto 1fr; border-bottom: 1px solid var(--line); }
  .admin-table td { border: 0; padding: 10px 12px; }
  .admin-table td.actions-col { grid-column: 1 / -1; text-align: left; padding-top: 0; }
  .admin-dialog, .admin-dialog.wide { width: 100vw; max-width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; }
  .dialog-form { max-height: 100vh; height: 100%; }
}

.img-prev { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 8px; }
.img-prev img { width: 200px; max-width: 60%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.img-pick { cursor: pointer; }
