/* =========================================================
   Nora Kingdom — หลังบ้านแอดมิน (ธีมห้องปราสาท / ดันเจี้ยน)
   ========================================================= */
body.admin {
  background-color: color-mix(in srgb, var(--lav) 50%, #8f8aab);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' shape-rendering='crispEdges'%3E%3Cg fill='%232f2153' fill-opacity='.2'%3E%3Crect y='29' width='64' height='3'/%3E%3Crect y='61' width='64' height='3'/%3E%3Crect x='61' width='3' height='32'/%3E%3Crect x='29' y='32' width='3' height='32'/%3E%3C/g%3E%3Cg fill='%23fff' fill-opacity='.18'%3E%3Crect width='61' height='3'/%3E%3Crect x='32' y='32' width='61' height='3'/%3E%3Crect y='32' width='29' height='3'/%3E%3C/g%3E%3C/svg%3E");
}
body.admin::after {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, .35), transparent 60%), linear-gradient(transparent 70%, rgba(47, 33, 83, .35));
}

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 60px 16px 40px; position: relative; }
.login { width: min(400px, 100%); }
.login .lock { display: block; width: 56px; margin: 0 auto 6px; animation: bob 1.4s steps(2) infinite; }
.input-ico { position: relative; }
.input-ico svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 22px; }
.input-ico .input { padding-left: 44px; }
.torch { position: absolute; top: 30px; width: 28px; }
.torch.l { left: 8%; } .torch.r { right: 8%; }
.torch i { display: block; width: 16px; height: 22px; margin: 0 auto; background: linear-gradient(#fff3a8, #ffb347 50%, #ff6f6f); border: 3px solid var(--ink); border-radius: 50% 50% 4px 4px; animation: flicker .3s steps(2) infinite; }
.torch b { display: block; width: 10px; height: 34px; margin: 0 auto; background: #8b5a3c; border: 3px solid var(--ink); }
@keyframes flicker { 50% { transform: scaleY(.85) translateY(2px); } }
.floor { position: fixed; left: 0; right: 0; bottom: 0; height: 26px; background: repeating-linear-gradient(90deg, #ffd88a 0 30px, #e8b664 30px 33px); border-top: 3px solid var(--ink); z-index: -1; }
.demo-cred { margin-top: 14px; padding: 10px; border: 2px dashed var(--lav-d); border-radius: 12px; background: var(--lav-xl); font-size: .86rem; text-align: center; }

/* ---------- Shell ---------- */
.a-top {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--ink); color: var(--white);
  border-bottom: 3px solid var(--lav-dd);
}
.a-top .crown { width: 30px; }
.a-top h1 { font-size: 1.05rem; font-family: var(--font-th); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.a-top h1 small { display: block; font-family: var(--font-px); font-size: .72rem; color: var(--lav-l); }
.a-top .grow { flex: 1; }
.a-top .btn { color: var(--ink); }
.a-nav {
  position: sticky; top: 56px; z-index: 40;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 10px 12px;
  background: var(--lav-l); border-bottom: 3px solid var(--ink);
}
.a-nav::-webkit-scrollbar { display: none; }
.a-nav button {
  flex: none; display: flex; align-items: center; gap: 6px;
  min-height: 42px; padding: 4px 14px;
  border: 3px solid var(--ink); border-radius: 12px; background: var(--white);
  box-shadow: 0 3px 0 var(--ink);
  font-family: var(--font-th); font-size: .92rem; cursor: pointer; white-space: nowrap;
}
.a-nav button svg { width: 20px; height: 20px; }
.a-nav button.active { background: var(--pink); }
.a-nav .cnt { font-family: var(--font-px); background: var(--gold); border: 2px solid var(--ink); border-radius: 8px; padding: 0 6px; font-size: .78rem; }
.a-main { width: min(100%, 1100px); margin: 0 auto; padding: 40px 12px 60px; }
.a-main > .win + .win { margin-top: 46px; }

/* ธงปักบนหน้าต่างแอดมิน (เหมือน wireframe) */
.win.flags::before, .win.flags::after {
  content: ''; position: absolute; top: -3px; width: 22px; height: 34px;
  background: var(--pink); border: 3px solid var(--ink); border-top: 0;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 75%, 0 100%);
}
.win.flags::before { left: 18px; } .win.flags::after { right: 18px; }

.page-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.page-title svg { width: 28px; }
.page-title h2 { font-size: 1.2rem; }

/* ---------- Dashboard ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile {
  display: grid; justify-items: center; gap: 4px; padding: 14px 8px;
  border: 3px solid var(--ink); border-radius: 14px; background: var(--white);
  box-shadow: inset 0 -4px 0 var(--lav-xl), 0 4px 0 var(--ink);
  font-family: var(--font-th); cursor: pointer; text-align: center;
}
.tile svg { width: 38px; height: 38px; }
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi { padding: 12px; border: 3px solid var(--ink); border-radius: 12px; background: var(--white); box-shadow: 0 4px 0 var(--ink); }
.kpi b { display: block; font-family: var(--font-px); font-size: 1.8rem; line-height: 1.1; }
.kpi span { font-family: var(--font-th); font-size: .85rem; color: var(--ink-soft); }
.kpi.k-pending { background: #fff4c4; }
.kpi.k-ok { background: #e3f7ea; }
.flow { display: grid; gap: 8px; counter-reset: f; margin: 0; padding: 0; list-style: none; }
.flow li { counter-increment: f; display: flex; gap: 10px; align-items: flex-start; }
.flow li::before { content: counter(f); flex: none; width: 26px; height: 26px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 8px; background: var(--gold); font-family: var(--font-px); }

/* ---------- จัดการรีวิว ---------- */
.a-tabs .tab { flex: 0 1 auto; }
.mod-list { display: grid; gap: 12px; }
.mod {
  display: grid; grid-template-columns: 48px 1fr; gap: 10px;
  padding: 12px; border: 3px solid var(--ink); border-radius: 14px; background: var(--white);
  box-shadow: inset 0 -4px 0 var(--lav-xl), 0 4px 0 var(--ink);
}
.mod .av-box { width: 48px; height: 48px; display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 10px; background: var(--sky-l); }
.mod .av-box svg { width: 36px; }
.mod-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.mod-head b { font-family: var(--font-th); font-weight: 500; }
.mod-text { margin: 6px 0; font-size: .93rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.mod-meta { font-size: .78rem; color: var(--ink-soft); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mod-body { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.mod-thumb { width: 72px; height: 72px; object-fit: cover; border: 3px solid var(--ink); border-radius: 10px; cursor: zoom-in; image-rendering: pixelated; background: var(--lav-xl); }
.mod-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; padding-top: 10px; border-top: 2px dashed var(--lav-l); }
.mod-actions .btn { flex: 1 1 auto; }
.stars .px-star { width: 16px; height: 16px; }

/* ---------- ฟอร์มตั้งค่า ---------- */
.form-grid { display: grid; gap: 0 16px; }
.save-bar {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; gap: 10px; justify-content: flex-end;
  margin: 18px -16px -18px; padding: 12px 16px;
  background: color-mix(in srgb, var(--lav-l) 92%, transparent); backdrop-filter: blur(4px);
  border-top: 3px solid var(--ink); border-radius: 0 0 12px 12px;
}
.asset-pick { display: grid; grid-template-columns: 110px 1fr; gap: 12px; align-items: center; padding: 12px; border: 3px solid var(--ink); border-radius: 12px; background: var(--white); margin-bottom: 14px; }
.asset-prev { width: 110px; height: 80px; display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 10px; background: var(--lav-xl); overflow: hidden; }
.asset-prev img { width: 100%; height: 100%; object-fit: contain; }
.asset-prev svg { width: 60%; }
.asset-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.hidden-file { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* ---------- ธีม ---------- */
.presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.preset { padding: 10px; border: 3px solid var(--ink); border-radius: 12px; background: var(--white); cursor: pointer; text-align: center; font-family: var(--font-th); font-size: .88rem; box-shadow: 0 3px 0 var(--ink); }
.preset.on { background: var(--pink-l); outline: 3px solid var(--pink-d); outline-offset: 2px; }
.swatches { display: flex; justify-content: center; gap: 3px; margin-bottom: 6px; }
.swatches i { width: 18px; height: 18px; border: 2px solid var(--ink); border-radius: 5px; }
.colors { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.color-field { display: flex; align-items: center; gap: 8px; padding: 8px; border: 3px solid var(--ink); border-radius: 12px; background: var(--white); font-family: var(--font-th); font-size: .88rem; }
.color-field input[type=color] { width: 40px; height: 36px; padding: 0; border: 2px solid var(--ink); border-radius: 8px; background: none; cursor: pointer; }
.preview-box { padding: 16px; border: 3px solid var(--ink); border-radius: 14px; background: linear-gradient(180deg, var(--lav-l), var(--pink-l)); display: grid; gap: 12px; justify-items: center; }

/* ---------- คลังสื่อ ---------- */
.media-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.media-item { border: 3px solid var(--ink); border-radius: 12px; background: var(--white); overflow: hidden; box-shadow: 0 4px 0 var(--ink); }
.media-item .mi-img { aspect-ratio: 4/3; background: var(--lav-xl) repeating-conic-gradient(var(--lav-l) 0 25%, transparent 0 50%) 0 0 / 16px 16px; display: grid; place-items: center; border-bottom: 3px solid var(--ink); }
.media-item img { max-width: 100%; max-height: 100%; object-fit: contain; }
.media-item .mi-body { padding: 8px; font-size: .8rem; }
.media-item .mi-name { font-family: var(--font-th); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-item .mi-actions { display: flex; gap: 6px; margin-top: 6px; }
.media-item .mi-actions .select { min-height: 36px; padding: 4px 30px 4px 8px; font-size: .82rem; background-position: calc(100% - 16px) 15px, calc(100% - 10px) 15px; }
.upload-zone { display: grid; place-items: center; gap: 6px; padding: 18px; text-align: center; border: 3px dashed var(--ink); border-radius: 12px; background: var(--lav-xl); cursor: pointer; position: relative; margin-bottom: 14px; }
.upload-zone svg { width: 40px; }
.upload-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.pick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pick-grid button { aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 10px; background: var(--lav-xl); padding: 4px; cursor: pointer; overflow: hidden; }
.pick-grid img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- ฟังก์ชันเสริม ---------- */
.feat { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 12px; border: 3px solid var(--ink); border-radius: 12px; background: var(--white); margin-bottom: 10px; }
.feat svg { width: 34px; }
.feat b { font-family: var(--font-th); font-weight: 500; }
.feat p { margin: 0; font-size: .85rem; color: var(--ink-soft); }

/* =========================================================
   Tablet / Desktop
   ========================================================= */
@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .full { grid-column: 1 / -1; }
  .presets { grid-template-columns: repeat(4, 1fr); }
  .media-grid { grid-template-columns: repeat(3, 1fr); }
  .mod-actions .btn { flex: 0 1 auto; }
  .a-main { padding: 44px 22px 60px; }
}
@media (min-width: 980px) {
  .a-shell { display: grid; grid-template-columns: 230px 1fr; align-items: start; }
  .a-nav {
    position: sticky; top: 56px; height: calc(100vh - 56px);
    flex-direction: column; overflow: visible; padding: 18px 14px;
    border-bottom: 0; border-right: 3px solid var(--ink);
  }
  .a-nav button { width: 100%; justify-content: flex-start; }
  .a-nav .cnt { margin-left: auto; }
  .media-grid { grid-template-columns: repeat(4, 1fr); }
  .dash-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 28px; align-items: start; margin-top: 46px; }
  .dash-grid > .win { margin-top: 0 !important; }
  .dash-grid > div > .win + .win { margin-top: 46px; }
}
@media (max-width: 479px) { .hide-xs { display: none; } .a-top .btn { padding: 4px 8px; } }
