/* JNC-POS Super-Admin Console — สไตล์กลาง (vanilla CSS ไม่มี build step ให้ตรงกับแนวทางของ portal/) */
/* [สร้าง 2026-08-11] ก็อปมาจาก portal/assets/style.css เป็นฐาน แล้วปรับสีหลักเป็นโทนม่วงเข้ม
   เพื่อให้แยกออกจาก portal ของลูกค้าทันทีที่มองเห็น (กันทีมงานสับสนว่ากำลังอยู่หน้าไหน) */
:root {
  --brand: #6d28d9;
  --brand-dark: #5b21b6;
  --brand-soft: #f2ecfd;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #6b7684;
  --border: #e6eaf1;
  --ok: #1a7f37;
  --ok-soft: #e5f4e8;
  --warn: #9a6700;
  --warn-soft: #fdf3d7;
  --danger: #c1121f;
  --danger-soft: #fdeaea;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(20, 30, 55, .06), 0 1px 2px rgba(20, 30, 55, .04);
  --shadow-md: 0 8px 30px rgba(20, 30, 55, .09);
  --ease: 150ms ease;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", "Noto Sans Thai", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; transition: color var(--ease); }
a:hover { color: var(--brand-dark); text-decoration: underline; }

.topbar {
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.logo { font-weight: 800; font-size: 18px; letter-spacing: -.2px; }
.logo span { color: var(--brand); }
.logo .tag {
  font-size: 10.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
  background: var(--brand-soft); color: var(--brand-dark); padding: 2px 8px; border-radius: 999px;
  margin-left: 8px; vertical-align: middle;
}
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 7px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--muted);
}
.nav a:hover { background: var(--brand-soft); color: var(--brand-dark); text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a.active:hover { color: #fff; }

.wrap { max-width: 440px; margin: 64px auto; padding: 0 20px; }
.wrap-wide { max-width: 1100px; margin: 32px auto; padding: 0 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}
h1 { font-size: 21px; font-weight: 700; letter-spacing: -.2px; margin: 0 0 6px; }
h2 { font-size: 16px; font-weight: 700; margin: 26px 0 10px; }
.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

label { display: block; font-size: 13.5px; font-weight: 600; margin: 16px 0 6px; }
input, select {
  width: 100%; padding: 11px 13px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fbfcfe; color: var(--text);
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}
input:focus, select:focus {
  outline: none; border-color: var(--brand); background: #fff;
  box-shadow: 0 0 0 3px rgba(109, 40, 217, .12);
}
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.hint.ok { color: var(--ok); }
.hint.bad { color: var(--danger); }

button {
  width: auto; margin-top: 0; padding: 9px 15px;
  font-size: 14px; font-weight: 600; font-family: inherit;
  background: var(--brand); color: #fff; border: 0; border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--ease), transform var(--ease), box-shadow var(--ease);
}
button:hover { background: var(--brand-dark); box-shadow: 0 4px 14px rgba(109, 40, 217, .25); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; transform: none; }
button.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: #fafbfd; box-shadow: none; border-color: #c9d2e0; }
button.danger { background: var(--danger); }
button.danger:hover { background: #9e0e19; box-shadow: 0 4px 14px rgba(193, 18, 31, .25); }
button.block { width: 100%; margin-top: 24px; }

.msg { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; display: none; }
.msg.show { display: block; }
.msg.err { background: var(--danger-soft); color: var(--danger); border: 1px solid #f5c6cb; }
.msg.ok  { background: var(--ok-soft); color: var(--ok);    border: 1px solid #c7e6cb; }
.msg.info{ background: var(--brand-soft); color: var(--brand-dark); border: 1px solid #ded0fb; }

.foot { text-align: center; margin-top: 20px; font-size: 14px; color: var(--muted); }

/* --- dashboard --- */
.stat-grid { display: grid; gap: 16px; grid-template-columns: repeat(4, 1fr); margin-bottom: 20px; }
/* [แก้ 2026-08-12] ขยายจาก 900px → 1024px ให้ iPad แนวนอน (1024 CSS px) ได้ 2 คอลัมน์แทนที่จะบีบ 4
   คอลัมน์แน่นเกินไปบนจอ iPad — ดู responsive tablet/mobile block ท้ายไฟล์ */
@media (max-width: 1024px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .stat-grid { grid-template-columns: 1fr; } }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 6px; letter-spacing: -.5px; }
.stat .sub2 { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
/* [แก้ 2026-08-12] เดิม 900px ทำให้ iPad แนวตั้ง (768 CSS px) ตกในโซนนี้อยู่แล้วก็จริง แต่ขยับเป็น
   1024px ให้ iPad แนวนอนก็พับเป็นคอลัมน์เดียวด้วย — panel ฝั่งซ้าย/ขวาของหน้ารายละเอียดร้านแคบเกินไป
   ถ้าบีบ 2 คอลัมน์บนความกว้าง ~1024px (ปุ่ม/select ในแต่ละ panel ล้นได้) */
@media (max-width: 1024px) { .grid { grid-template-columns: 1fr; } }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14.5px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.neutral { background: var(--brand-soft); color: var(--brand-dark); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }
tr.clickable { cursor: pointer; transition: background var(--ease); }
tr.clickable:hover { background: var(--brand-soft); }
tr.sel { background: var(--brand-soft); }
.env-tag { background: var(--warn-soft); color: var(--warn); font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 700; }

.topbar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }

/* ปุ่มสลับภาษา TH/EN — [เพิ่ม 2026-08-11 Phase B] ก็อปจาก portal/assets/style.css
   (ปุ่มเดียวโชว์ "TH/EN" คู่กัน ไฮไลต์เฉพาะตัวที่ active ตาม feedback ของ Jeab วันที่ 2026-08-10) */
.lang-toggle-btn {
  padding: 3px 8px; font-size: 11px; font-weight: 700; font-family: inherit;
  border: 1px solid var(--border); background: #fff; color: var(--muted);
  border-radius: 999px; cursor: pointer; width: auto; margin: 0;
  white-space: nowrap; letter-spacing: .2px;
  transition: border-color var(--ease), background var(--ease), transform var(--ease);
}
.lang-toggle-btn:hover { border-color: var(--brand); background: var(--brand-soft); }
.lang-toggle-btn:active { transform: scale(.95); }
.lang-toggle-btn .lt-th, .lang-toggle-btn .lt-en { color: var(--muted); transition: color var(--ease); }
.lang-toggle-btn .lt-th.active, .lang-toggle-btn .lt-en.active { color: var(--brand); }
@media (pointer: coarse) {
  button.lang-toggle-btn { min-height: 32px; padding: 3px 8px; }
}

/* --- modal (users.html: สร้าง/reset password) --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,30,55,.45); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 28px; max-width: 420px; width: 100%; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* [เพิ่ม 2026-08-11] .panel — จัดกลุ่มข้อมูลในหน้ารายละเอียดร้าน (tenants.html) ให้แยกส่วนชัดเจน
   แทนการเรียง h2 ต่อกันเป็นพรืดยาวๆ แบบเดิม ตามที่ Jeab ขอให้ "จัดวางเรียงใหม่ให้สวยงาม" */
.panel {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px 18px; margin-top: 16px;
}
.panel:first-child { margin-top: 0; }
.panel h2 { margin: 0 0 4px; font-size: 14.5px; }
.panel .panel-desc { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; }
.panel-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.panel-row > div { flex: 1; min-width: 140px; }
.panel-row label { margin: 0 0 6px; }

/* [เพิ่ม 2026-08-11] mini bar chart แบบ CSS ล้วน (ไม่พึ่ง library ตาม convention vanilla ของโปรเจกต์)
   ใช้กับสถิติรายเดือนใน dashboard.html — เปิดใหม่/ปิด/ใกล้หมดอายุ/รายได้ */
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 56px 1fr 64px; align-items: center; gap: 10px; font-size: 12.5px; }
.bar-row .bar-month { color: var(--muted); white-space: nowrap; }
.bar-row .bar-track { position: relative; height: 18px; background: var(--bg); border-radius: 6px; overflow: hidden; display: flex; }
.bar-row .bar-fill { height: 100%; border-radius: 6px; transition: width var(--ease); }
.bar-row .bar-fill.c-open { background: var(--ok); }
.bar-row .bar-fill.c-closed { background: var(--danger); }
.bar-row .bar-fill.c-expiry { background: var(--warn); }
.bar-row .bar-fill.c-revenue { background: var(--brand); }
.bar-row .bar-value { text-align: right; font-weight: 700; white-space: nowrap; }
.bar-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.bar-legend span { display: inline-flex; align-items: center; gap: 5px; }
.bar-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.toolbar .spacer { flex: 1; }

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.mono { font-family: "SF Mono", "Consolas", monospace; font-size: 12.5px; }
.pre-wrap { white-space: pre-wrap; word-break: break-all; }

/* --- Responsive --- */
/* [แก้ 2026-08-12] ปรับ responsive เพิ่มสำหรับ iPad (portrait 768 / landscape 1024) และมือถือ
   ตามคำขอ Jeab — เดิมมีแค่ breakpoint เดียวที่ 780px ซึ่งพอใช้ได้แต่ toolbar/panel-row/table ยังบีบ
   แน่นเกินไปบนจอแคบจริง ๆ (มือถือ) และปุ่ม/select ที่ตั้ง width แบบ inline (เช่น statusSelect,
   planSelect) ยังล้นขอบจอได้ถ้าไม่บังคับ max-width ทับ */

/* Tablet (iPad portrait ~768px ถึง landscape ~1024px) */
@media (max-width: 1024px) {
  .wrap-wide { max-width: 100%; }
  .card { padding: 24px; }
}

@media (max-width: 780px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; padding: 12px 16px; }
  .wrap, .wrap-wide { margin: 20px auto; padding: 0 14px; }
  .card { padding: 20px; }
  h1 { font-size: 19px; }
  .nav { order: 3; width: 100%; }
  .nav a { flex: 1; text-align: center; }
}

/* มือถือ (≤640px) — toolbar/panel-row เปลี่ยนจากเรียงแนวนอนเป็นสแต็กเต็มความกว้าง, บังคับ
   max-width ทับ inline width เดิม (statusSelect/planSelect/extendMonths ฯลฯ) กันล้นขอบจอ */
@media (max-width: 640px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input, .toolbar select { width: 100%; min-width: 0; }
  .toolbar .spacer { display: none; }
  .toolbar #countHint { text-align: center; }

  .panel-row { flex-direction: column; align-items: stretch; }
  .panel-row > div { width: 100%; min-width: 0; max-width: none !important; }

  .actions-row { flex-direction: column; align-items: stretch; }
  .actions-row button, .actions-row select { width: 100%; margin: 0; }

  input, select, button { max-width: 100%; }

  table { font-size: 13px; }
  th, td { padding: 8px 5px; }
  .mono { font-size: 11.5px; }

  .modal { padding: 20px; max-height: 88vh; overflow-y: auto; }

  /* หัวการ์ดรายละเอียดร้าน (ชื่อร้าน + ปุ่มปิด) ให้ตกบรรทัดได้แทนที่จะบีบชื่อร้านยาว ๆ ให้แคบจนอ่านไม่ออก */
  #detailCard > div:first-child { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .card { padding: 16px; }
  .wrap, .wrap-wide { padding: 0 10px; }
  .topbar { padding: 10px 12px; }
  .logo { font-size: 16px; }
  .logo .tag { display: none; } /* ประหยัดพื้นที่แนวนอนบนจอเล็กมาก */
  .nav a { padding: 8px 8px; font-size: 12.5px; }
  h1 { font-size: 17px; }
  .stat .value { font-size: 22px; }
  .bar-row { grid-template-columns: 44px 1fr 52px; gap: 6px; font-size: 11.5px; }
}

@media (pointer: coarse) {
  input, select { font-size: 16px; min-height: 44px; }
  button { min-height: 40px; }
  .nav a { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
}

/* [เพิ่ม 2026-08-12] ปุ่มโชว์/ซ่อนรหัสผ่าน (visibility toggle) — สไตล์ icon-button วงกลมแบบ Material
   Design วางไว้ชิดขวาในช่อง (trailing icon) เพิ่มให้อัตโนมัติผ่าน assets/pw-toggle.js ไม่ต้องแก้ HTML
   ทีละช่อง — ดู business_rule.md ถ้ามี note เพิ่มเติมเรื่องนี้ */
.pw-field { position: relative; }
.pw-field input { padding-right: 42px; }
.pw-toggle-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; padding: 0; margin: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 50%; cursor: pointer;
  color: var(--muted); transition: background var(--ease), color var(--ease);
}
.pw-toggle-btn:hover { background: var(--brand-soft); color: var(--brand-dark); }
.pw-toggle-btn:active { transform: translateY(-50%) scale(.9); }
.pw-toggle-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.pw-toggle-btn svg { width: 19px; height: 19px; }
