/* ระบบหลังบ้านจำลอง — โหลดหลัง style.css (ใช้ตัวแปรสีชุดเดียวกัน) */
.admin { background: var(--c-bg); }
.admin-container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 var(--gutter); }
.admin-header { background: var(--c-surface); border-bottom: 1px solid var(--c-line); }
.admin-header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.admin-header .brand img { width: 36px; height: 36px; }
.admin-notice { background: #e6f0fb; border-bottom: 1px solid #c9ddf2; color: var(--c-text); font-size: .9rem; }
.admin-notice-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding-top: 10px; padding-bottom: 10px; }
.admin-notice p { margin: 0; }
.admin-main { padding-top: 20px; padding-bottom: 80px; }
.admin-title { font-size: 1.5rem; margin-bottom: 12px; }
.muted { color: var(--c-muted); }
.small { font-size: .85rem; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--c-line); margin-bottom: 20px; }
.tab { font: inherit; font-weight: 600; color: var(--c-muted); background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 16px; cursor: pointer; margin-bottom: -1px; }
.tab:hover { color: var(--c-primary); }
.tab[aria-selected="true"] { color: var(--c-primary); border-bottom-color: var(--c-primary); }

.tiles { list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; }
.tile span { color: var(--c-muted); font-size: .88rem; }
.tile strong { font-size: 1.6rem; color: var(--c-heading); line-height: 1.3; }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.admin-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.admin-toolbar .search-box { flex: 1 1 240px; }
.field-inline { margin: 0; flex: 0 1 220px; }
.admin-toolbar .btn-primary { margin-left: auto; }

.table-wrap { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--c-line); vertical-align: middle; }
.admin-table thead th { background: var(--c-tint); font-size: .88rem; color: var(--c-muted); font-weight: 600; }
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table tr.is-hidden .cell-product { opacity: .55; }
.cell-product { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-product img { width: 48px; height: 36px; flex: none; background: var(--c-tint); border-radius: 6px; }
.cell-product strong { display: block; font-weight: 600; line-height: 1.4; }
.cell-product small { color: var(--c-muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.admin-empty { padding: 24px; text-align: center; color: var(--c-muted); margin: 0; }
.badge { display: inline-block; font-size: .8rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.badge-ok { background: #e3f4ec; color: var(--c-success); }
.badge-warn { background: #fff1d6; color: #8a5a00; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; background: #c3d1e1; border-radius: 999px; transition: background .2s; pointer-events: none; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .2s; }
.switch input:checked + span { background: var(--c-primary); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--c-primary-soft); outline-offset: 2px; }

/* ตาราง ≤ 720px แสดงเป็นการ์ด */
@media (max-width: 720px) {
  .table-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  .admin-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .admin-table, .admin-table tbody, .admin-table tr, .admin-table td { display: block; width: 100%; }
  .admin-table tr { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 6px 14px; margin-bottom: 12px; }
  .admin-table td { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
  .admin-table td::before { content: attr(data-label); color: var(--c-muted); font-size: .85rem; flex: none; }
  .admin-table td:first-child { display: block; }
  .admin-table td:first-child::before, .admin-table td:last-child::before { display: none; }
  .admin-table td:last-child { border-bottom: 0; }
  .admin-table td:last-child .row-actions { width: 100%; }
  .row-actions .btn { flex: 1; }
  .admin-toolbar .btn-primary { margin-left: 0; width: 100%; }
  .field-inline { flex: 1 1 100%; }
}
@media (max-width: 420px) { .hide-sm { display: none; } }

.panel-card { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); max-width: 860px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 14px; }
.field-full { grid-column: 1 / -1; }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.field small { font-weight: 400; }

/* dialog */
.a-dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100% - 24px); padding: 0; border: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); color: var(--c-text); overflow: hidden; }
.a-dialog[open] { display: flex; }
.a-dialog::backdrop { background: rgba(23, 48, 79, .45); }
.a-dialog-form { display: flex; flex-direction: column; width: 100%; max-height: calc(100vh - 24px); }
.a-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--c-line); }
.a-dialog-head h2 { margin: 0; font-size: 1.2rem; }
.a-dialog-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.a-dialog-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--c-line); background: var(--c-bg); }
.spacer { flex: 1; }
.a-confirm { width: min(440px, calc(100% - 24px)); }
.a-confirm h2 { font-size: 1.15rem; }
.a-confirm p { color: var(--c-muted); margin: 0; }
fieldset { border: 1px solid var(--c-line); border-radius: var(--radius); padding: 12px 16px 16px; margin: 0 0 16px; min-width: 0; }
legend { font-weight: 700; color: var(--c-heading); padding: 0 6px; }
.icon-btn { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--c-line); background: var(--c-surface); color: var(--c-muted); cursor: pointer; font-size: 1.1rem; }
.icon-btn:hover { color: var(--c-danger); border-color: #f0c4c0; }
.spec-rows { display: grid; gap: 8px; margin-bottom: 10px; }
.spec-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; }
.spec-row input { width: 100%; min-width: 0; font: inherit; color: var(--c-text); border: 1px solid #c3d6eb; border-radius: 10px; padding: 8px 10px; min-height: 40px; }
.spec-row input:focus { outline: 3px solid var(--c-primary-tint); border-color: var(--c-primary); }
.upload { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.upload-preview { width: 120px; height: 90px; flex: none; border: 1px dashed #b9d3ec; border-radius: var(--radius-sm); display: grid; place-items: center; text-align: center; font-size: .8rem; color: var(--c-muted); background: var(--c-tint); overflow: hidden; }
.upload-preview img { width: 100%; height: 100%; object-fit: cover; }
.upload > div { flex: 1 1 200px; }
.upload-btn { cursor: pointer; }
#p-image:focus-visible + p, #p-image:focus + p { outline: none; }
.upload-btn:focus-within { outline: 3px solid var(--c-primary-soft); }
.slug-input { display: flex; align-items: stretch; border: 1px solid #c3d6eb; border-radius: 10px; overflow: hidden; }
.slug-input span { background: var(--c-tint); color: var(--c-muted); padding: 10px; font-size: .9rem; display: flex; align-items: center; }
.slug-input input { border: 0 !important; border-radius: 0 !important; flex: 1; min-width: 0; }
.slug-input:focus-within { outline: 3px solid var(--c-primary-tint); border-color: var(--c-primary); }
.counter { font-size: .82rem; }
.counter.is-ok { color: var(--c-success); }
.counter.is-warn { color: #8a5a00; }
.serp { border: 1px solid var(--c-line); border-radius: var(--radius); padding: 14px 16px; background: #fff; font-family: Arial, var(--font); }
.serp-label { font-size: .8rem; color: var(--c-muted); margin: 0 0 8px; font-family: var(--font); }
.serp-site { display: flex; align-items: center; gap: 10px; }
.serp-site img { border-radius: 50%; }
.serp-site span { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.serp-site strong { font-size: .88rem; font-weight: 400; color: #202124; }
.serp-site small { font-size: .78rem; color: #4d5156; overflow-wrap: anywhere; }
.serp-title { color: #1a0dab; font-size: 1.15rem; margin: 6px 0 2px; line-height: 1.35; }
.serp-desc { color: #4d5156; font-size: .9rem; margin: 0; line-height: 1.55; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--c-primary); }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #912018; color: #fff; }
.btn-danger-outline { background: #fff; color: var(--c-danger); border-color: #f0c4c0; }
.btn-danger-outline:hover { background: #fdf0ef; color: var(--c-danger); }

.toast-area { position: fixed; right: 16px; bottom: 60px; left: 16px; z-index: 1000; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.toast { max-width: 360px; padding: 10px 16px; border-radius: 12px; color: #fff; font-weight: 500; box-shadow: var(--shadow-lg); transition: opacity .3s, transform .3s; }
.toast.is-out { opacity: 0; transform: translateY(8px); }
.toast-success { background: var(--c-success); }
.toast-info { background: var(--c-primary); }
.toast-warning { background: #8a5a00; }
@media (max-width: 560px) {
  .a-dialog { width: 100%; max-width: 100%; max-height: 100%; height: 100%; border-radius: 0; }
  .a-dialog-form { max-height: 100vh; height: 100%; }
  .a-confirm { height: auto; border-radius: var(--radius-lg); width: calc(100% - 24px); margin: auto; }
  .a-confirm .a-dialog-form { height: auto; }
}
