/* =====================================================================
 * หน้าหลังบ้าน — ใช้ร่วมกับ ../styles.css (สี ตัวอักษร ปุ่ม ช่องกรอก)
 * ===================================================================== */
.page-admin { min-height: 100vh; min-height: 100dvh; }

/* ----- แถบบน ----- */
.atop {
  color: #f3efe4;
  background:
    radial-gradient(80% 160% at 100% 0%, rgba(98, 186, 150, .35) 0%, transparent 60%),
    linear-gradient(165deg, var(--jade-800), var(--jade-950));
  border-bottom: 1px solid rgba(217, 191, 134, .35);
}
.atop__inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px clamp(16px, 3vw, 32px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 18px;
  flex-wrap: wrap;
}
.atop__tag {
  margin-left: 2px;
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  letter-spacing: .06em;
  color: var(--jade-900);
  background: var(--gold-300);
}
.atop__actions { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.atop .link-btn { color: rgba(243, 239, 228, .85); }
.atop .btn--soft {
  min-height: 40px;
  color: #f3efe4;
  background: rgba(255, 255, 255, .08);
  box-shadow: inset 0 0 0 1px rgba(217, 191, 134, .35);
}
.atop .btn--soft svg { width: 17px; height: 17px; }

.amain { max-width: 1240px; margin: 0 auto; padding: 22px clamp(16px, 3vw, 32px) 48px; }

input[type="password"] {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.field.is-invalid input[type="password"] { border-color: var(--error); background-color: var(--error-bg); }
code { padding: 0 4px; border-radius: 4px; background: rgba(0, 0, 0, .06); font-size: .92em; }

/* ----- เข้าสู่ระบบ ----- */
.login { max-width: 420px; margin: 7vh auto 0; padding: 30px 28px 26px; }
.login h1 { margin: 0 0 4px; font-family: var(--font-display); font-size: 25px; font-weight: 600; line-height: 1.35; }
.login__lead { margin: 0 0 20px; color: var(--muted); font-size: 14.5px; }
.login .notice { margin-bottom: 18px; }
.login .btn { margin-top: 16px; }
.login__demo { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); text-align: center; }
.login__demo p { margin: 0 0 8px; font-size: 13.5px; color: var(--muted); }
.login .login__demo .btn { margin-top: 0; }
.remember { margin-top: 14px; }
.remember__hint { display: block; font-size: 12.5px; color: var(--muted); }

/* ----- ข้อมูลตัวอย่าง ----- */
.demo-banner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px 16px;
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  color: var(--warn-ink);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
}
.demo-banner .link-btn { color: var(--warn-ink); }

/* ----- แท็บ ----- */
.tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs__btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 12px;
  border: 0;
  border-radius: 10px 10px 0 0;
  font: inherit;
  font-size: 15.5px;
  color: var(--muted);
  white-space: nowrap;
  background: none;
  cursor: pointer;
}
.tabs__btn[aria-selected="true"] { color: var(--jade-900); font-weight: 600; }
.tabs__btn[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--jade-600);
}
.tabs__btn:focus-visible { outline: 2px solid var(--jade-600); outline-offset: -2px; }
.tabs__badge {
  min-width: 22px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.7;
  text-align: center;
  color: var(--warn-ink);
  background: var(--gold-100);
}

/* ----- ตัวเลขสรุป ----- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi {
  padding: 15px 18px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
.kpi__label { margin: 0; font-size: 13.5px; color: var(--muted); }
.kpi__value {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.kpi__sub { margin: 2px 0 0; min-height: 1.45em; font-size: 12.5px; color: var(--muted); }
.kpis--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ----- ค้นหาและตัวกรอง ----- */
.tools { display: grid; gap: 10px; padding: 14px; margin-bottom: 8px; border-radius: 14px; }
.tools__filters { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.tools input[type="search"], .tools select { min-height: 44px; font-size: 15px; }
.tools__search { display: flex; flex-wrap: wrap; gap: 8px; }
.tools__search input { flex: 1 1 260px; min-width: 0; }
.tools__search select { flex: 0 1 220px; width: auto; }
.tools__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.tools__actions .btn svg { width: 17px; height: 17px; }
.result-meta { margin: 8px 2px 10px; font-size: 13.5px; color: var(--muted); }

/* ----- ตารางลูกค้า ----- */
.table-card { overflow-x: auto; border-radius: 14px; }
.ctable { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.ctable th {
  padding: 10px 14px;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  background: var(--jade-50);
  border-bottom: 1px solid var(--line);
}
.ctable td { padding: 11px 14px; vertical-align: top; border-bottom: 1px solid var(--line); }
.ctable tbody tr { cursor: pointer; transition: background-color .12s; }
.ctable tbody tr:last-child td { border-bottom: 0; }
.ctable tbody tr:focus-visible { outline: 2px solid var(--jade-600); outline-offset: -2px; }
.cell__main { display: block; color: var(--ink); }
.cell__sub { display: block; font-size: 12.5px; color: var(--muted); }
.cell--date { white-space: nowrap; }
.cell--email .cell__main { overflow-wrap: anywhere; }
.ctable .tag { white-space: nowrap; }
.tag--ok { color: var(--jade-800); background: var(--jade-100); }
.tag--partial { color: var(--warn-ink); background: var(--gold-100); }
.empty { margin: 0; padding: 36px 16px; text-align: center; color: var(--muted); }
.more { display: flex; justify-content: center; margin-top: 14px; }

/* ----- ภาพรวมลูกค้า ----- */
.ins-note { margin: -4px 2px 16px; font-size: 13px; color: var(--muted); }
.ins { margin-bottom: 14px; padding: 18px 20px 20px; border-radius: 14px; }
.ins--plain { padding: 8px 0 0; }
.ins__head { margin-bottom: 12px; }
.ins__head h2 { margin: 0; font-family: var(--font-display); font-size: 19px; font-weight: 600; line-height: 1.45; }
.ins__head p { max-width: 72ch; margin: 2px 0 0; font-size: 13.5px; color: var(--muted); }
.ins__sub { margin: 18px 0 6px; font-size: 14px; font-weight: 600; color: var(--jade-800); }
.ins__foot { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); }
.ins__more { margin-top: 8px; font-size: 14px; }
.ins-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.ins-grid > .ins { margin-bottom: 0; min-width: 0; }

/* แถบแนวนอน */
.bars { display: grid; gap: 2px; }
.bar {
  display: grid;
  grid-template-columns: minmax(110px, 34%) minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 12px;
  width: calc(100% + 12px);
  margin: 0 -6px;
  padding: 6px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  text-align: left;
  color: inherit;
  background: none;
}
button.bar { cursor: pointer; }
button.bar:focus-visible { outline: 2px solid var(--jade-600); outline-offset: -2px; }
.bar__label { min-width: 0; font-size: 14px; line-height: 1.35; }
.bar__sub { display: block; font-size: 12px; color: var(--muted); }
.bar__track { height: 10px; overflow: hidden; border-radius: 4px; background: #edf1ee; }
.bar__fill { display: block; height: 100%; border-radius: 4px; background: var(--jade-600); }
.bar--muted .bar__fill { background: var(--faint); }
.bar--muted .bar__label { color: var(--muted); }
.bar__value { min-width: 4.8em; font-size: 14px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar__pct { margin-left: 6px; font-size: 12.5px; color: var(--muted); }

/* ระดับลูกค้า */
.tiers { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tier {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 14px 16px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.tier--vip { border-color: var(--gold-300); background: linear-gradient(180deg, var(--gold-100), var(--surface) 75%); }
.tier__top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tier__pct { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tier__count { margin: 4px 0 0; font-family: var(--font-display); font-size: 28px; font-weight: 600; line-height: 1.25; font-variant-numeric: tabular-nums; }
.tier__count span { font-family: var(--font-body); font-size: 14px; font-weight: 400; color: var(--muted); }
.tier__rule, .tier__meta { margin: 0; font-size: 13px; color: var(--muted); }
.tier__use { flex: 1; margin: 6px 0 0; font-size: 13.5px; color: var(--ink-2); }
.tier .link-btn { align-self: flex-start; margin-top: 6px; }
.tier-tag {
  display: inline-block;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .03em;
  line-height: 1.75;
  white-space: nowrap;
  vertical-align: 1px;
}
.tier-tag--vip { color: var(--gold-300); background: var(--jade-900); }
.tier-tag--gold { color: var(--warn-ink); background: var(--gold-100); box-shadow: inset 0 0 0 1px var(--gold-300); }
.tier-tag--silver { color: var(--ink-2); background: #eef1ef; box-shadow: inset 0 0 0 1px var(--line-strong); }
.tier-tag--member { color: var(--jade-800); background: var(--jade-50); box-shadow: inset 0 0 0 1px var(--jade-100); }
.cell--name .tag { vertical-align: 1px; }

/* ตาราง (เจน กฎ รายการที่พบ) */
.table-scroll { overflow-x: auto; }
.gtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.gtable th, .gtable td { padding: 9px 14px 9px 0; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.gtable thead th { font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; border-bottom-color: var(--line-strong); }
.gtable tbody th { font-weight: 600; }
.gtable .num { padding-right: 0; text-align: right; font-variant-numeric: tabular-nums; }
.gtable tbody tr:last-child > * { border-bottom: 0; }
.rtable tr.is-zero { color: var(--faint); }
.rtable tr.is-zero .kind { opacity: .55; }
.rtable th .link-btn { font-weight: 600; text-align: left; }
.itable tbody tr { cursor: pointer; transition: background-color .12s; }
.itable tbody tr:focus-visible { outline: 2px solid var(--jade-600); outline-offset: -2px; }
.itable .cell--before { color: var(--ink-2); overflow-wrap: anywhere; white-space: pre-wrap; }
.kind { display: inline-block; padding: 0 8px; border-radius: 999px; font-size: 12px; line-height: 1.75; white-space: nowrap; }
.kind--review { color: var(--warn-ink); background: var(--gold-100); }
.kind--fix { color: var(--jade-800); background: var(--jade-100); }
.kind--exclude { color: var(--muted); background: #eef1ef; }

/* กลุ่มลูกค้า */
.segs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.seg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 16px 18px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.seg__top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.seg__name { margin: 0; font-size: 15.5px; font-weight: 600; line-height: 1.45; }
.seg__kind { flex: none; padding: 0 8px; border-radius: 999px; font-size: 11.5px; line-height: 1.8; }
.seg__kind--market { color: var(--jade-800); background: var(--jade-50); box-shadow: inset 0 0 0 1px var(--jade-100); }
.seg__kind--service { color: var(--warn-ink); background: var(--gold-100); }
.seg__count { margin: 2px 0 0; font-family: var(--font-display); font-size: 26px; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; }
.seg__count span { font-family: var(--font-body); font-size: 13.5px; font-weight: 400; color: var(--muted); }
.seg__rule { margin: 0; font-size: 13px; color: var(--muted); }
.seg__use { flex: 1; margin: 6px 0 0; font-size: 13.5px; color: var(--ink-2); }
.seg__use strong { font-weight: 600; color: var(--ink); }
.seg__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 10px; }
.seg__actions .link-btn[disabled], .seg__actions .btn[disabled] { opacity: .45; cursor: default; }

/* ตรวจข้อมูล */
.notice--info { color: var(--ink-2); background: var(--jade-50); border: 1px solid var(--jade-100); }
.q-note { margin: 0 0 14px; font-size: 14px; }
.q-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.q-tools select { flex: 0 1 230px; width: auto; min-height: 42px; font-size: 14.5px; }
.q-tools .btn svg { width: 17px; height: 17px; }

/* ----- รายละเอียดลูกค้า ----- */
.detail {
  width: min(720px, calc(100% - 24px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .45);
}
.detail::backdrop { background: rgba(10, 42, 34, .55); }
.detail[open] { display: flex; flex-direction: column; }
.detail__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--line);
}
.detail__code { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .06em; color: var(--gold-500); }
.detail h2 { margin: 2px 0 0; font-family: var(--font-display); font-size: 22px; font-weight: 600; line-height: 1.35; }
.detail__close {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  color: var(--ink-2);
  background: #eef2ef;
  cursor: pointer;
}
.detail__close svg { width: 18px; height: 18px; }
.detail__close:focus-visible { outline: 2px solid var(--jade-600); outline-offset: 2px; }
.detail__body { overflow-y: auto; padding: 4px 22px 22px; }
.dgroup h3 { margin: 18px 0 4px; font-size: 14px; font-weight: 600; color: var(--jade-800); }
.dgroup dl { margin: 0; display: grid; grid-template-columns: minmax(150px, 34%) 1fr; }
.dgroup dt, .dgroup dd { margin: 0; padding: 7px 0; font-size: 14.5px; border-bottom: 1px solid var(--line); }
.dgroup dt { padding-right: 12px; color: var(--muted); }
.dgroup dd { overflow-wrap: anywhere; white-space: pre-wrap; }

@media (hover: hover) {
  .ctable tbody tr:hover, .itable tbody tr:hover, button.bar:hover { background: var(--jade-50); }
  .tabs__btn:hover { color: var(--ink); background: var(--jade-50); }
  .atop .link-btn:hover { color: #fff; }
  .atop .btn--soft:hover { background: rgba(255, 255, 255, .16); }
  .detail__close:hover { background: #e2e8e4; }
}

/* ----- จอแคบ ----- */
@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tools__filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tiers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .segs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .ins-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .amain { padding-top: 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px 14px; }
  .kpi:first-child { grid-column: 1 / -1; }
  .kpi__value { font-size: 24px; }
  .tools__filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis--4 .kpi:first-child { grid-column: auto; }
  .ins { padding: 16px 14px 16px; }
  .segs { grid-template-columns: minmax(0, 1fr); }
  .tabs__btn { padding: 10px 11px 12px; font-size: 15px; }

  /* ตาราง -> การ์ด */
  .gtable thead { display: none; }
  .gtable, .gtable tbody, .gtable tr, .gtable th, .gtable td { display: block; }
  .gtable tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .gtable tbody tr:last-child { border-bottom: 0; }
  .gtable th, .gtable td { padding: 2px 0; border: 0; }
  .gtable .num { text-align: left; }
  .gtable td[data-label]::before { content: attr(data-label) " · "; font-size: 12.5px; color: var(--faint); }
  .itable td[data-label="ประเภท"]::before, .rtable td[data-label="ประเภท"]::before { content: none; }
  .q-tools select, .q-tools .btn { flex: 1 1 100%; }
  .tools__actions .btn { flex: 1 1 100%; }

  /* ตาราง -> การ์ดทีละคน */
  .table-card { overflow: visible; background: transparent; border: 0; box-shadow: none; }
  .ctable, .ctable tbody { display: block; }
  .ctable thead { display: none; }
  .ctable tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 12px;
    margin-bottom: 10px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
  }
  .ctable td { display: block; min-width: 0; padding: 0; border: 0; }
  .ctable td::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--faint); }
  .ctable td.cell--name { grid-column: 1 / -1; order: -1; }
  .ctable td.cell--name::before { display: none; }
  .ctable td.cell--name .cell__main { font-size: 16px; font-weight: 600; }
  .ctable td.cell--email { grid-column: 1 / -1; }
  .cell--date { white-space: normal; }

  .detail { width: calc(100% - 16px); }
  .detail__head { padding: 16px 16px 12px; }
  .detail__body { padding: 0 16px 18px; }
  .dgroup dl { grid-template-columns: 1fr; }
  .dgroup dt { padding: 8px 0 0; border-bottom: 0; font-size: 13px; }
  .dgroup dd { padding: 0 0 8px; }
}
@media (max-width: 520px) {
  .bar { grid-template-columns: minmax(0, 1fr) auto; }
  .bar__label { grid-column: 1 / -1; }
}
@media (max-width: 420px) {
  .tiers { grid-template-columns: minmax(0, 1fr); }
}
