:root {
  --admin-green: #174c3e;
  --admin-green-2: #2f735d;
  --admin-mint: #eaf3ed;
  --admin-lime: #dce8ad;
  --admin-canvas: #f4f7f4;
  --admin-ink: #1d332d;
  --admin-muted: #687a73;
  --admin-line: #dce5df;
}

.admin-ui {
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 0%, rgb(220 232 173 / 35%), transparent 24rem),
    var(--admin-canvas);
  color: var(--admin-ink);
}

.admin-ui a { color: var(--admin-green-2); }
.admin-ui input:not([type=checkbox]):not([type=radio]),
.admin-ui select,
.admin-ui textarea {
  border-color: #cbd8d0;
  border-radius: 11px;
  background: #fff;
}
.admin-ui input:focus,
.admin-ui select:focus,
.admin-ui textarea:focus {
  border-color: #49816d;
  box-shadow: 0 0 0 4px rgb(47 115 93 / 11%);
}
.admin-ui input[type=checkbox] { accent-color: var(--admin-green); }
.admin-ui .card {
  border-color: var(--admin-line);
  border-radius: 16px;
  box-shadow: 0 7px 26px rgb(28 56 46 / 5%);
}
.admin-ui .btn {
  min-height: 42px;
  border-color: #cbd8d0;
  border-radius: 10px;
  transition: transform .16s ease, box-shadow .2s ease, border-color .2s ease, background-color .2s ease;
}
.admin-ui .btn:hover { transform: translateY(-1px); border-color: #aebfb4; box-shadow: 0 6px 14px rgb(28 56 46 / 8%); }
.admin-ui .btn:active { transform: scale(.97); }
.admin-ui .btn-primary { border-color: var(--admin-green); background: var(--admin-green); box-shadow: 0 5px 14px rgb(23 76 62 / 15%); }
.admin-ui .btn-primary:hover { border-color: #246551; background: #246551; }
.admin-ui .btn-danger { border-color: #efd0cc; background: #fff; color: #a64238; }
.admin-ui .btn-danger:hover { background: #fff1ef; }

/* Header and navigation */
.admin-header {
  border-bottom: 1px solid rgb(216 226 219 / 88%);
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 5px 22px rgb(31 62 51 / 5%);
  backdrop-filter: blur(14px);
}
.admin-brand { color: var(--admin-ink) !important; }
.admin-logo {
  position: relative;
  display: inline-flex;
  min-width: 54px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: var(--admin-green);
  color: #fff;
  font: 700 14px/1 Prompt, sans-serif;
  letter-spacing: .08em;
  box-shadow: 0 7px 16px rgb(23 76 62 / 16%);
}
.admin-logo i { position: absolute; top: -7px; right: -6px; color: #b9d36f; font-size: 16px; font-style: normal; }
.admin-brand small,
.admin-login-brand small { display: block; margin-top: 3px; color: var(--admin-muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.admin-nav { display: flex; align-items: center; gap: 3px; }
.admin-nav-link {
  display: inline-flex;
  min-height: 39px;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border-radius: 9px;
  color: #4b6159 !important;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none !important;
  white-space: nowrap;
  transition: background-color .2s ease, color .2s ease, transform .16s ease;
}
.admin-nav-link > span { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center; border-radius: 6px; color: #668078; font-size: 14px; }
.admin-nav-link:hover { background: #f0f5f1; color: var(--admin-green) !important; transform: translateY(-1px); }
.admin-nav-link.active { background: var(--admin-mint); color: var(--admin-green) !important; }
.admin-nav-link.active > span { background: var(--admin-green); color: white; }
.admin-nav-link.logout { margin-left: 5px; border-left: 1px solid var(--admin-line); border-radius: 0 9px 9px 0; color: #7b6562 !important; }

/* Page structure */
.admin-main { width: 100%; }
.admin-page-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 2px; }
.admin-eyebrow { display: block; margin-bottom: 5px; color: #6d8666; font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.admin-page-title h1 { color: #1c332c; font-family: Prompt, Sarabun, sans-serif; font-size: clamp(23px, 2.3vw, 30px); font-weight: 600; letter-spacing: -.025em; }
.admin-page-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.admin-main > p.text-muted { max-width: 850px; margin-top: -7px; color: var(--admin-muted); font-size: 14px; line-height: 1.75; }
.admin-footer { color: #839089; font-size: 12px; }

/* Summary cards */
.admin-stat {
  position: relative;
  display: flex;
  min-height: 126px;
  overflow: hidden;
  flex-direction: column;
  padding: 20px;
  border: 1px solid var(--admin-line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 7px 24px rgb(28 56 46 / 5%);
}
.admin-stat::after { position: absolute; top: -30px; right: -25px; width: 88px; height: 88px; border-radius: 50%; background: #e5f0e8; content: ""; }
.admin-stat:nth-child(2)::after { background: #eef0d8; }
.admin-stat:nth-child(3)::after { background: #e8edf7; }
.admin-stat:nth-child(4)::after { background: #f4eade; }
.admin-stat > span { position: relative; z-index: 1; color: var(--admin-muted); font-size: 12px; font-weight: 700; }
.admin-stat > b { position: relative; z-index: 1; margin: 6px 0 3px; color: var(--admin-green); font: 600 30px/1.15 Prompt, sans-serif; }
.admin-stat > small { position: relative; z-index: 1; margin-top: auto; color: #788981; font-size: 12px; }

/* Filters, forms, messages */
.admin-filter { border-style: dashed; background: rgb(255 255 255 / 75%); box-shadow: none !important; }
.admin-filter::before { margin-right: 2px; color: #6b8177; content: "ตัวกรอง"; font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.admin-ui form.card > h2 { margin-bottom: 5px; color: var(--admin-green); font-family: Prompt, sans-serif; font-size: 18px; }
.admin-ui form.card label { color: #385149; font-size: 14px; }
.admin-ui form.card label .text-muted { font-weight: 400; }
.admin-flash { display: flex; align-items: center; gap: 10px; margin: 0; animation: admin-flash-in .35s ease both; }
.admin-flash > span { display: inline-flex; width: 25px; height: 25px; flex: none; align-items: center; justify-content: center; border-radius: 50%; color: white; font-weight: 800; }
.admin-flash.ok > span { background: #12805c; }
.admin-flash.err > span { background: #b44b42; }
.admin-flash.warn > span { background: #a66a16; }
.admin-ui .alert { border: 1px solid transparent; }
.admin-ui .alert.ok { border-color: #b9dece; }
.admin-ui .alert.warn { border-color: #edd5a7; }
.admin-ui .alert.err { border-color: #edc5c0; }

/* Tables */
.admin-ui .overflow-x-auto { scrollbar-color: #b5c6bb transparent; scrollbar-width: thin; }
.admin-ui .tbl { color: #2a4039; }
.admin-ui .tbl th,
.admin-ui .tbl td { padding: 11px 13px; border-color: #e5ebe7; }
.admin-ui .tbl th { position: sticky; top: 0; z-index: 1; background: #f3f6f3; color: #61746d; font-size: 11px; letter-spacing: .025em; }
.admin-ui .tbl tbody tr { transition: background-color .16s ease; }
.admin-ui .tbl tbody tr:nth-child(even) { background: #fbfcfb; }
.admin-ui .tbl tbody tr:hover { background: #f0f6f2; }
.admin-ui .tbl td a { font-weight: 600; text-decoration: none; }
.admin-ui .tbl td a:hover { text-decoration: underline; }
.admin-ui .tbl .btn { min-height: 34px; padding: 5px 10px; box-shadow: none; font-size: 12px; }
.admin-ui .tag { padding: 3px 9px; border: 1px solid #dce5df; background: #f3f6f4; }
.admin-ui .tag.green { border-color: #b7ddcd; background: #e9f5ef; }
.admin-ui .tag.red { border-color: #edc7c2; background: #fff0ee; }
.admin-ui .tag.amber { border-color: #ecd6a9; background: #fff7e6; }
.admin-ui .meter { background: #e6ece8; }

/* Individual response detail */
.admin-ui .response-answer-table td { vertical-align: top; }
.admin-ui .response-answer-table th:nth-child(2),
.admin-ui .response-answer-table td:nth-child(2) { min-width: 260px; }
.admin-ui .response-answer-table th:nth-child(3),
.admin-ui .response-answer-table td:nth-child(3),
.admin-ui .response-answer-table th:nth-child(4),
.admin-ui .response-answer-table td:nth-child(4) { min-width: 250px; }
.admin-ui .response-answer-table td:nth-child(3) { color: #174f3e; font-weight: 600; }

/* ความเชื่อมั่นทั้งฉบับ (หน้าวิเคราะห์ข้อสอบ) */
.rel-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 22px; }
.rel-main { display: flex; min-width: 170px; flex-direction: column; align-items: flex-start; gap: 6px; padding: 16px 20px; border: 1px solid #dfe8e2; border-radius: 14px; background: #f5f9f6; }
.rel-kicker { color: #61746d; font-size: 12px; font-weight: 700; }
.rel-value { color: var(--admin-green); font: 600 38px/1.1 Prompt, sans-serif; font-variant-numeric: tabular-nums; }
.rel-detail { min-width: 0; flex: 1 1 320px; }
.rel-formula { margin: 8px 0 6px; padding: 9px 12px; overflow-x: auto; border-radius: 10px; background: #f3f6f3; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rel-formula sup, .rel-formula sub { font-size: .78em; }

/* Website visits */
.visit-panel { padding: 22px; }
.visit-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.visit-heading h2 { color: var(--admin-green); font: 600 19px/1.4 Prompt, sans-serif; }
.visit-heading p { color: var(--admin-muted); font-size: 12px; }
.visit-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 22px; }
.visit-summary > div { display: flex; min-height: 98px; flex-direction: column; padding: 14px; border: 1px solid #e0e8e2; border-radius: 12px; background: #f8faf8; }
.visit-summary span { color: var(--admin-muted); font-size: 12px; font-weight: 700; }
.visit-summary b { margin-top: 4px; color: var(--admin-green); font: 600 25px/1.2 Prompt, sans-serif; }
.visit-summary small { margin-top: auto; color: #849189; font-size: 11px; }
.visit-chart { display: flex; height: 155px; align-items: flex-end; gap: 7px; padding: 12px 4px 0; border-top: 1px solid #e5ebe7; }
.visit-bar { display: flex; height: 100%; min-width: 0; flex: 1; flex-direction: column; align-items: center; justify-content: flex-end; }
.visit-bar span { min-height: 18px; color: #557168; font-size: 10px; font-weight: 700; }
.visit-bar i { display: block; width: min(100%, 28px); min-height: 3px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, #9ebf73, #347660); transition: height .5s cubic-bezier(.2,.8,.25,1); }
.visit-bar small { margin-top: 5px; color: #87958e; font-size: 9px; white-space: nowrap; }
.visit-bar:nth-child(even) small { opacity: .35; }

/* Modal */
.admin-ui #qrModal:not([hidden]) { animation: admin-fade .2s ease both; }
.admin-ui #qrModal:not([hidden]) > .card { animation: admin-modal-in .3s cubic-bezier(.2,.8,.25,1) both; }
.admin-ui #qrBox canvas,
.admin-ui #qrBox img { padding: 10px; border: 1px solid var(--admin-line); border-radius: 12px; background: white; }

/* Login */
.admin-login { position: relative; overflow: hidden; background: #edf3ee; }
.admin-login::before,
.admin-login::after { position: fixed; border-radius: 50%; content: ""; filter: blur(1px); }
.admin-login::before { top: -16vw; right: -10vw; width: 42vw; height: 42vw; background: rgb(206 224 157 / 48%); }
.admin-login::after { bottom: -18vw; left: -12vw; width: 38vw; height: 38vw; background: rgb(145 188 167 / 25%); }
.admin-login-card {
  position: relative;
  z-index: 1;
  width: min(100%, 400px) !important;
  max-width: 400px !important;
  margin: auto;
  padding: 30px;
  border: 1px solid rgb(255 255 255 / 70%) !important;
  box-shadow: 0 24px 65px rgb(26 62 49 / 13%) !important;
  animation: admin-login-in .55s cubic-bezier(.2,.8,.25,1) both;
}
.admin-login-brand { display: flex; align-items: center; gap: 13px; padding-bottom: 18px; border-bottom: 1px solid var(--admin-line); }
.admin-login-heading { padding: 7px 0 3px; }
.admin-login-heading h1 { font: 600 25px/1.4 Prompt, sans-serif; }
.admin-login-heading p { margin-top: 4px; color: var(--admin-muted); font-size: 14px; }
.admin-login-card label { color: #385149; font-size: 14px; }
.admin-login-card .btn-primary { margin-top: 5px; min-height: 49px; }
.admin-password { position: relative; display: block; }
.admin-password input { padding-right: 66px !important; }
.admin-password button { position: absolute; top: 50%; right: 8px; min-width: 50px; padding: 5px 8px; border-radius: 7px; color: var(--admin-green); font-size: 12px; font-weight: 700; transform: translateY(-50%); }
.admin-password button:hover { background: var(--admin-mint); }
.admin-login-back { display: block; color: var(--admin-muted) !important; text-align: center; font-size: 13px; text-decoration: none !important; }
.admin-login-back:hover { color: var(--admin-green) !important; }

/* Motion */
.admin-main > .admin-reveal { animation: admin-content-in .42s cubic-bezier(.2,.8,.25,1) both; }
@keyframes admin-content-in { from { opacity: 0; transform: translateY(12px) } to { opacity: 1; transform: none } }
@keyframes admin-login-in { from { opacity: 0; transform: translateY(18px) scale(.985) } to { opacity: 1; transform: none } }
@keyframes admin-flash-in { from { opacity: 0; transform: translateY(-8px) } to { opacity: 1; transform: none } }
@keyframes admin-fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes admin-modal-in { from { opacity: 0; transform: translateY(12px) scale(.96) } to { opacity: 1; transform: none } }

@media (max-width: 1120px) {
  .admin-header-inner { align-items: flex-start; }
  .admin-nav { width: 100%; overflow-x: auto; padding: 3px 0 1px; scrollbar-width: none; }
  .admin-nav::-webkit-scrollbar { display: none; }
  .admin-nav-link.logout { margin-left: 2px; }
}

@media (max-width: 700px) {
  .admin-header-inner { padding: 11px 14px 7px; }
  .admin-brand > span:last-child small { display: none; }
  .admin-logo { min-width: 50px; height: 37px; }
  .admin-nav { margin-right: -14px; margin-left: -14px; padding: 4px 14px 2px; }
  .admin-nav-link { min-height: 36px; padding: 6px 9px; font-size: 12px; }
  .admin-main { padding: 22px 12px 34px; }
  .admin-page-title { align-items: flex-start; flex-direction: column; gap: 12px; }
  .admin-page-actions { width: 100%; justify-content: flex-start; }
  .admin-page-actions .btn { flex: 1; }
  .admin-page-actions form { width: 100%; }
  .admin-page-actions select { width: 100% !important; }
  .admin-stat { min-height: 112px; padding: 16px; }
  .admin-stat > b { font-size: 25px; }
  .admin-filter { align-items: stretch; flex-direction: column; }
  .admin-filter::before { margin-bottom: 2px; }
  .admin-filter input,
  .admin-filter select,
  .admin-filter label,
  .admin-filter .btn { width: 100% !important; }
  .admin-filter label { align-items: flex-start; flex-direction: column; }
  .admin-ui .card.overflow-x-auto .tbl { min-width: 820px; }
  .admin-ui .card { padding: 17px; }
  .admin-ui .card.overflow-x-auto,
  .admin-ui section.card.p-0 { padding: 0; }
  .admin-login-card { padding: 24px 20px; }
  .visit-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
  .visit-summary { grid-template-columns: repeat(2, 1fr); }
  .visit-chart { gap: 4px; overflow: hidden; }
  .visit-bar small { font-size: 8px; transform: rotate(-45deg); transform-origin: top center; }
}

@media (max-width: 420px) {
  .admin-brand > span:last-child b { font-size: 14px; }
  .admin-nav-link > span { display: none; }
  .admin-nav-link { padding: 7px 10px; }
  .admin-login { padding: 12px; }
  .admin-login-brand > span:last-child b { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .admin-ui *, .admin-ui *::before, .admin-ui *::after { animation: none !important; transition: none !important; }
}
