/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { background: #f5f5f2; } /* fallback: ไม่แว็บขาวบราวเซอร์เก่า */

/* ── Design tokens ───────────────────────────────────────── */
:root {
  --font:         'Inter', 'IBM Plex Sans Thai', system-ui, sans-serif;
  --brand-start:  #2a8a7a;
  --brand-mid:    #1f6e6a;
  --brand-end:    #2b7c93;
  --brand-grad:   linear-gradient(135deg, var(--brand-start) 0%, var(--brand-mid) 55%, var(--brand-end) 100%);
}

/* ── Base body ───────────────────────────────────────────── */

@keyframes page-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes tile-in  { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
body {
  font-family: var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
/* fade-in เฉพาะ content area — sidenav/logo ไม่ถูก animate ไม่กระตุก */
.main-body, .sa-body, .stage { animation: page-in .18s ease-out both; }
@supports (height: 100dvh) {
  body { min-height: 100dvh; }
}

/* ── Spinner ─────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.ring {
  width: 20px; height: 20px; flex-shrink: 0;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Accessibility ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}


/* ════════════════════════════════════════════════════════════
   Login page  (templates/index.html)
   ════════════════════════════════════════════════════════════ */

body.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 24px 72px;
  overflow-x: hidden;
  background: #fdf9fc;
}

/* ── Background ─────────────────────────────────── */
.bg { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.bg-base {
  position: absolute; inset: 0;
  background: linear-gradient(135deg,#fdeef4 0%,#fbe4ee 30%,#f8dce9 55%,#fde7f0 80%,#fcf0f5 100%);
}
.bg-blob {
  position: absolute; border-radius: 50%;
}
.bb1 {
  top:-180px; left:-120px; width:520px; height:520px;
  background: radial-gradient(circle at 35% 35%,#c7f0e6 0%,#9fdcce 40%,transparent 70%);
  filter: blur(30px); opacity: .6;
}
.bb2 {
  bottom:-160px; right:-140px; width:620px; height:620px;
  background: radial-gradient(circle at 60% 60%,#e9c6f0 0%,#d4a8e6 40%,transparent 70%);
  filter: blur(40px); opacity: .55;
}
.bb3 {
  top:30%; right:-80px; width:280px; height:280px;
  background: radial-gradient(circle at 40% 40%,#ffdcc0 0%,#f6c79f 50%,transparent 75%);
  filter: blur(30px); opacity: .5;
}
.bg-grid {
  position: absolute; inset: 0; perspective: 900px; overflow: hidden;
}
.bg-grid-inner {
  position: absolute; left:-10%; right:-10%; bottom:-50%; height:120%;
  transform: rotateX(68deg);
  background-image:
    linear-gradient(rgba(0,0,0,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,.05) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: linear-gradient(to top,#000 0%,transparent 80%);
  -webkit-mask-image: linear-gradient(to top,#000 0%,transparent 80%);
}
.bg-fade {
  position: absolute; inset: 0;
  background: linear-gradient(180deg,rgba(255,255,255,0) 0%,rgba(255,255,255,.15) 100%);
}

/* ── Stage ──────────────────────────────────────── */
.stage {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 340px;
  margin-top: -40px;
}

/* ── Drawer (behind card) ────────────────────────── */
.drawer {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 270px;
  margin-left: -135px;
  transform: translateY(-50%) translateX(0px);
  opacity: 0;
  visibility: hidden;
  transition: transform .55s cubic-bezier(.22,.9,.3,1), opacity .3s, visibility 0s .55s;
  z-index: 1;
  background: var(--brand-grad);
  color: #fff;
  border-radius: 22px;
  box-shadow: 0 20px 40px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}

.drawer-hdr {
  padding: 16px 18px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.drawer-hdr-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.65);
}

.drawer-close {
  background: transparent; border: 0;
  color: #fff; font-size: 18px; cursor: pointer;
  padding: 5px 9px; border-radius: 999px; line-height: 1;
  transition: background .15s;
}
.drawer-close:hover { background: rgba(255,255,255,.18); }

.drawer-list {
  padding: 10px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
}

.co-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.22);
  cursor: pointer;
  text-align: left; color: #fff;
  font-family: inherit;
  transition: background .15s, border-color .15s;
  width: 100%;
}
.co-row:hover { background: rgba(255,255,255,.22); border-color: rgba(255,255,255,.5); }
.co-row.active { border-color: #fff; background: rgba(255,255,255,.18); }

.co-logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  overflow: hidden;
}
.co-logo img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }

.co-info { flex: 1; min-width: 0; }
.co-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.co-status { font-size: 11px; color: rgba(255,255,255,.7); margin-top: 1px; }

.co-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 10px rgba(255,255,255,.9);
  flex-shrink: 0;
}

.drawer-spin {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 28px;
  font-size: 13px; color: rgba(255,255,255,.75);
}

/* ── Main card ──────────────────────────────────── */
.card {
  position: relative;
  z-index: 2;
  transform: translateX(0px);
  transition: transform .55s cubic-bezier(.22,.9,.3,1);
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 30px 70px rgba(0,0,0,.18);
  color: #17171c;
  overflow: hidden;
}

/* Open state */
.stage.open .card    { transform: translateX(-135px); }
.stage.open .drawer  {
  transform: translateY(-50%) translateX(182px);
  opacity: 1;
  visibility: visible;
  transition: transform .55s cubic-bezier(.22,.9,.3,1), opacity .3s;
}

/* ── Form ───────────────────────────────────────── */
.card-form {
  padding: 26px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* โลโก้ (LOGO_FILE ใน app.py — ไฟล์เดียวทุกหน้า) ย่อขยายตามความกว้างการ์ด */
.card-logo {
  width: min(200px, 62%);
  height: auto; display: block;
  margin: 6px auto 16px;
}

.field-label {
  display: block;
  font-size: 13px; font-weight: 600;
  color: #3f3f46;
  margin-bottom: 5px;
}

.inp-wrap { position: relative; }

.inp {
  width: 100%; height: 44px;
  padding: 0 14px;
  border: 1.5px solid #e4e4e7; border-radius: 10px;
  background: #fff;
  color: #17171c; font-family: inherit; font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.inp:focus       { border-color: var(--brand-mid); box-shadow: 0 0 0 3px rgba(31,110,106,.14); }
.inp::placeholder { color: #a1a1aa; }
.inp-pw          { padding-right: 42px; -webkit-text-security: disc; }
.inp-pw.pw-show  { -webkit-text-security: none; }
.inp-pw::placeholder { -webkit-text-security: none; }

.pw-eye {
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  background: transparent; border: 0;
  color: #71717a; cursor: pointer;
  padding: 5px; display: flex; align-items: center;
  border-radius: 6px; transition: color .15s;
}
.pw-eye:hover { color: #17171c; }

.remember-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: #52525b;
  cursor: pointer; user-select: none;
  margin-top: 1px;
}
.remember-row input { accent-color: var(--brand-mid); width: 14px; height: 14px; cursor: pointer; }

.err-box {
  display: none;
  font-size: 12.5px; color: #dc2626;
  padding: 2px 2px;
  line-height: 1.4;
}
.err-box.on { display: block; }

.lang-hint {
  display: none;
  align-items: center; gap: 5px;
  font-size: 12px; color: #b45309;
  margin-top: 5px;
  line-height: 1.3;
}
.lang-hint.on { display: flex; }
.lang-hint svg { flex-shrink: 0; }

.cta-row { margin-top: 4px; }

.btn-login {
  width: 100%; height: 46px; border-radius: 10px;
  background: var(--brand-mid); color: #fff; border: 0;
  font-family: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: background .15s;
}
.btn-login:hover:not(:disabled) { background: var(--brand-end); }
.btn-login:disabled { opacity: .6; cursor: not-allowed; }

.link-row {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 2px;
}

.btn-reg, .btn-forgot {
  background: none; border: none;
  color: #52525b; font-family: inherit; font-size: 12.5px;
  cursor: pointer; transition: color .15s;
}
.btn-reg { color: var(--brand-mid); font-weight: 600; }
.btn-reg:hover, .btn-forgot:hover { color: #17171c; }
.link-sep { color: #d4d4d8; font-size: 12.5px; }

/* ── Login responsive ─────────────────────────────── */
/* Below 780px the card and drawer no longer fit side by side: the drawer covers the card instead */
@media (max-width: 780px) {
  body.page-login { padding: 16px; }
  .card-form { padding: 22px 18px 24px; }
  .inp { font-size: 16px; }
  .drawer {
    left: 0; margin-left: 0; width: 100%;
    min-height: 100%;
    max-height: calc(100dvh - 32px);
    z-index: 3;
  }
  .stage.open .card   { transform: none; }
  .stage.open .drawer { transform: translateY(-50%) translateX(0); }
}

/* Phone: the card becomes the whole screen (edge-to-edge, no floating
   card look) instead of a small box centered over leftover background */
@media (max-width: 480px) {
  body.page-login { padding: 0; align-items: stretch; }
  .stage {
    margin-top: 0;
    max-width: none;
    min-height: 100dvh;
  }
  .card {
    width: 100%;
    min-height: 100dvh;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .card-form {
    gap: 14px;
    padding:
      calc(28px + env(safe-area-inset-top))
      calc(22px + env(safe-area-inset-right))
      calc(28px + env(safe-area-inset-bottom))
      calc(22px + env(safe-area-inset-left));
  }
  .inp { height: 46px; }
  .drawer { max-height: 100dvh; }
}


/* ════════════════════════════════════════════════════════════
   Main / menu page  (templates/main.html)
   ════════════════════════════════════════════════════════════ */

body.page-main {
  background: #fafaf8;
  color: #17171c;
  display: flex;                /* [เมนูสไลด์ด้านข้าง] [.main-body] */
}
.main-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ── Nav ─────────────────────────────────────────── */
.nav {
  position: sticky;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 32px;
  border-bottom: 1px solid #e9e8e4;
  top: 0;
  background: rgba(250,250,248,.92);
  backdrop-filter: blur(12px);
  z-index: 10;
  min-width: 0;
}

.nav-brand {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
  pointer-events: auto;
}
.nav-brand-logo {
  height: 26px;
  width: auto;
  display: block;
  object-fit: contain;
  /* วางบนแถบสีอ่อน → โลโก้ตัวเข้มอ่านชัดอยู่แล้ว ไม่ต้องมีพื้นหลัง */
}
/* แถบแคบ (≤800px): ซ่อนโลโก้กลาง กันซ้อนกับปุ่ม ☰ / ป้ายบริษัท */
@media (max-width: 800px) { .nav-brand { display: none; } }

.nav-company {
  display: flex; align-items: center; gap: 8px;
  background: #fff;
  border: 1px solid #e3e1dc;
  padding: 5px 10px 5px 7px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  font-family: inherit;
  transition: border-color .15s;
  min-width: 0;
  flex-shrink: 1;
}
.nav-company:hover { border-color: #17171c; }
a.nav-company { text-decoration: none; }

.nav-company-logo {
  height: 22px; width: auto;
  display: block; flex-shrink: 0;
}
.nav-divider { width: 1px; height: 16px; background: #e3e1dc; flex-shrink: 0; }
.nav-company-name {
  font-size: 13px; font-weight: 600;
  color: #17171c;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 200px;
}

.nav-page-title {
  font-size: 13px; font-weight: 500; color: #6b6b74;
  white-space: nowrap; flex-shrink: 0;
}
.nav-page-title::before { content: '/'; margin: 0 6px; color: #c8c6c0; }

.nav-spacer { flex: 1; min-width: 8px; }

.nav-user {
  font-size: 13px; color: #6b6b74;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 160px; flex-shrink: 1;
}

.btn-logout {
  background: none;
  border: 1px solid #e3e1dc;
  border-radius: 8px;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 13px;
  color: #53535c;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s, color .15s;
}
.btn-logout:hover { border-color: #ef4444; color: #ef4444; }

/* ── Main ────────────────────────────────────────── */
main {
  flex: 1;
  max-width: none;
  width: 100%;
  margin: 0 auto;
  /* เว้นที่ว่างซ้าย-ขวา ตามความกว้างจอ (จอ 1600px ≈ 96px ต่อข้าง) */
  padding: 28px clamp(32px, 6vw, 140px) 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-sizing: border-box;
}

/* ── App grid: ไอคอนเมนู (ใช้ร่วมกับหน้า Sysadmin) ─────────────
   ขนาดทุกอย่างคูณจาก --tile; static/app-grid.js ปรับ --tile อัตโนมัติ
   ให้ทุกปุ่มอยู่ในจอเดียวไม่มี scrollbar (เมนูเยอะ → กรอบเล็กลงเอง) */
.app-grid {
  --tile: 112px;
  /* เรียงจากซ้าย เต็มความกว้าง · จำนวนคอลัมน์ --cols ตั้งโดย app-grid.js (จอใหญ่ 5 → มือถือ 2) */
  --cols: 5;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  align-content: start;
  gap: clamp(8px, calc(var(--tile) * .09), 20px);
}

/* การ์ด (กรอบแบบเดิม): พื้นอ่อน + ขอบ ตามสีของเมนู (--h = hue 0–359)
   แถวบน [ไอคอน ชื่อ] · แถวล่าง คำอธิบาย (ชิดซ้าย) */
.app-tile {
  --h: 160;
  position: relative;
  min-width: 0;
  container-type: inline-size;          /* ให้ @container ด้านล่างรู้ความกว้างการ์ด */
  display: flex; flex-direction: column; align-items: flex-start;
  justify-content: center;                /* แถวถูกยืดให้เต็มจอ → เนื้อหาอยู่กลางการ์ด */
  gap: clamp(4px, calc(var(--tile) * .045), 14px);
  padding: clamp(8px, calc(var(--tile) * .065), 20px);
  border-radius: clamp(10px, calc(var(--tile) * .075), 14px);
  /* เปิดใช้งาน (มีลิงก์): พื้นขาวไล่สี ขอบเข้ม เงาสี — เด่น */
  background: linear-gradient(160deg, #fff 0%, hsl(var(--h), 62%, 95%) 100%);
  border: 1.5px solid hsl(var(--h), 55%, 66%);
  box-shadow: 0 1px 2px hsla(var(--h), 40%, 30%, .08), 0 8px 22px hsla(var(--h), 50%, 35%, .16);
  font-family: inherit; color: #111114;
  text-decoration: none; text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .22s, border-color .18s;
  animation: tile-in .16s .04s ease-out both;
}
.app-tile:focus-visible { outline: 2px solid var(--brand-mid); outline-offset: 2px; }

/* วงกลมรอบกรอบสี (เล็ก) */
.app-ring {
  width: clamp(42px, calc(var(--tile) * .32), 104px); height: clamp(42px, calc(var(--tile) * .32), 104px);
  border-radius: 50%;
  background: rgba(255,255,255,.8);
  display: grid; place-items: center;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .22s;
  flex-shrink: 0;
}
/* สี่เหลี่ยมมุมมนสีสด + ไอคอนขาว */
.app-sq {
  width: 66%; height: 66%;
  border-radius: 28%;
  background: linear-gradient(145deg, hsl(var(--h), 80%, 60%), hsl(var(--h), 72%, 45%));
  box-shadow: 0 2px 5px hsla(var(--h), 70%, 40%, .3);
  display: grid; place-items: center;
  color: #fff;
}
.app-glyph {
  width: 64%; height: 64%;
  background: currentColor;
  -webkit-mask: var(--ico) center / contain no-repeat;
          mask: var(--ico) center / contain no-repeat;
}
.app-sq svg { width: 60%; height: 60%; }        /* ไอคอนแบบเก่า (path data) */

/* แถวบน: ไอคอน + ชื่อ ต่อกัน */
.app-head {
  display: flex; align-items: center;
  gap: clamp(6px, calc(var(--tile) * .05), 18px);
  width: 100%; min-width: 0;
}
.app-head .app-label { flex: 1; min-width: 0; }
.app-label, .app-desc {
  overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  word-break: break-word;
}
.app-label {
  font-size: clamp(11.5px, calc(var(--tile) * .078), 22px);
  font-weight: 600;
  line-height: 1.3;
}
.app-desc {
  font-size: clamp(11px, calc(var(--tile) * .07), 16px);      /* ปุ่มใหญ่ → คำอธิบายใหญ่ตาม */
  color: #33333b;                 /* คำอธิบาย: เข้ม (เดิม #6b6b74 → #4b4b55 → #33333b) */
  line-height: 1.4;
}

/* การ์ดแคบ (เมนูเยอะ): ซ่อนคำอธิบาย + จัดกลาง ให้ทุกปุ่มยังอยู่ในจอเดียว */
/* หน้าจอเล็ก (มือถือ): ตัดคำอธิบายออก เหลือไอคอน + ชื่อ */
@media (max-width: 600px) {
  .app-desc { display: none; }
  /* ชื่อเมนูลงมาอีกบรรทัด ใต้ไอคอน */
  .app-head { flex-direction: column; align-items: flex-start; gap: 6px; }
  .app-head .app-label { flex: none; width: 100%; }
  /* มือถือ: ชื่อเมนูไม่ใหญ่เกิน (การ์ดยืดตามความสูงจอ แต่ตัวหนังสือไม่ต้องโตตาม) */
  .app-label { font-size: clamp(11.5px, 3.3vw, 13px); font-weight: 600; }
}
@container (max-width: 108px) {      /* การ์ดกว้าง < ~130px: ซ่อนคำอธิบาย → ชื่อลงมาใต้ไอคอน */
  .app-desc { display: none; }
  .app-head { flex-direction: column; align-items: flex-start; gap: 6px; }
  .app-head .app-label { flex: none; width: 100%; }
}
/* ชื่อยาว 2 บรรทัด (JS ใส่ .is-stacked) → ชื่อลงมาใต้ไอคอน */
.app-tile.is-stacked .app-head { flex-direction: column; align-items: flex-start; gap: 6px; }
.app-tile.is-stacked .app-head .app-label { flex: none; width: 100%; }
@container (max-width: 80px) {       /* การ์ดกว้าง < ~96px: ชื่อลงไปใต้ไอคอน จัดกลาง */
  .app-head { flex-direction: column; text-align: center; }
  .app-head .app-label { flex: none; width: 100%; }
}

/* ลูกศร ↗ มุมขวาบน = กดเข้าใช้งานได้ */
.app-tile::after {
  content: '';
  position: absolute;
  top: clamp(8px, calc(var(--tile) * .06), 14px);
  right: clamp(8px, calc(var(--tile) * .06), 14px);
  width: clamp(12px, calc(var(--tile) * .06), 24px); height: clamp(12px, calc(var(--tile) * .06), 24px);
  background: hsl(var(--h), 60%, 42%);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 17L17 7M8 7h9v9'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 17L17 7M8 7h9v9'/%3E%3C/svg%3E") center / contain no-repeat;
  opacity: .75;
  transition: opacity .18s, transform .18s;
}
.app-tile .app-head { padding-right: clamp(14px, calc(var(--tile) * .08), 22px); }
.app-tile .app-label { font-weight: 700; }

/* พื้นที่กดเปิดแท็บใหม่: ซ้อนบน ::after arrow มุมขวาบน (เฉพาะ main.html ที่ใส่ span.tile-newtab) */
.tile-newtab {
  position: absolute; top: 0; right: 0; z-index: 2;
  width:  clamp(28px, calc(var(--tile) * .2), 46px);
  height: clamp(28px, calc(var(--tile) * .2), 46px);
  border-radius: 0 clamp(10px, calc(var(--tile) * .075), 14px) 0 0;
  cursor: pointer;
}

@media (hover: hover) {
  .app-tile:hover {
    transform: translateY(-5px) scale(1.03);
    border-color: hsl(var(--h), 70%, 52%);
    /* เรืองแสง: ขอบคม + รัศมีสีฟุ้ง (glow) + เงาตกลึก */
    box-shadow:
      0 0 0 1px hsl(var(--h), 65%, 48%),
      0 0 18px 1px hsla(var(--h), 90%, 58%, .55),
      0 0 40px 6px hsla(var(--h), 85%, 55%, .32),
      0 20px 40px hsla(var(--h), 55%, 28%, .28);
  }
  .app-tile:hover .app-ring {
    transform: scale(1.14);
    box-shadow: 0 0 16px 2px hsla(var(--h), 90%, 60%, .5), 0 4px 14px hsla(var(--h), 60%, 40%, .35);
  }
  .app-tile:hover::after { opacity: 1; transform: translate(2px, -2px); }
}
.app-tile:active {
  transform: translateY(-1px) scale(.97);
  border-color: hsl(var(--h), 70%, 45%);
  box-shadow:
    0 0 0 1px hsl(var(--h), 60%, 42%),
    0 0 10px 1px hsla(var(--h), 85%, 55%, .28),
    0 4px 14px hsla(var(--h), 55%, 28%, .22);
  transition: transform .1s ease-out, box-shadow .1s ease-out, border-color .1s;
}

/* ยังไม่เปิดใช้งาน (ไม่มีลิงก์): จางลงชัดเจน ไม่มีเงา ไม่มีลูกศร ไม่มี hover */
.app-tile.is-disabled {
  cursor: default;
  background: hsl(var(--h), 18%, 97%);
  border: 1px solid hsl(var(--h), 14%, 89%);
  box-shadow: none;
}
.app-tile.is-disabled::after { display: none; }
.app-tile.is-disabled .app-head { padding-right: 0; }
.app-tile.is-disabled .app-ring { background: rgba(255,255,255,.6); }
.app-tile.is-disabled .app-sq { opacity: .5; filter: grayscale(.45); box-shadow: none; }
.app-tile.is-disabled .app-label { color: #8a8a93; font-weight: 600; }
.app-tile.is-disabled .app-desc { color: #6b6b74; }   /* เดิม #a8a8b0 → #85858f → #6b6b74 */
.app-tile.is-disabled:hover {
  transform: none;
  border-color: hsl(var(--h), 14%, 89%);
  box-shadow: none;
}

/* เมนูแม่ที่มีเมนูย่อย: ป้าย "N เมนู ›" แทนลูกศร ↗ */
.app-tile.is-folder::after { display: none; }
.app-tile.is-folder .app-head { padding-right: 0; }
.app-count {
  margin-top: 2px;
  font-size: clamp(10.5px, calc(var(--tile) * .045), 13.5px); font-weight: 600;
  color: hsl(var(--h), 60%, 32%);
  background: hsl(var(--h), 65%, 91%);
  padding: 2px 9px; border-radius: 999px; white-space: nowrap;
  transition: background .18s, color .18s;
}
@media (hover: hover) {
  .app-tile.is-folder:hover .app-count { background: hsl(var(--h), 60%, 42%); color: #fff; }
}

/* แถบนำทางในเมนูย่อย: ← เมนูหลัก / HR */
.app-crumb { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 36px; }
.app-crumb[hidden] { display: none; }
.app-crumb-back {
  display: inline-flex; align-items: center; gap: 4px;
  height: 34px; padding: 0 12px 0 8px; border-radius: 999px;
  background: #fff; border: 1px solid #e3e1dc;
  color: #3f3f46; font-size: 13.5px; font-weight: 600; text-decoration: none;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  transition: border-color .15s, color .15s, background .15s;
}
.app-crumb-back:hover { border-color: var(--brand-mid); color: var(--brand-mid); background: #f3faf8; }
.app-crumb-sep { color: #c8c6c0; }
.app-crumb-cur {
  --tile: 150px;
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 700; color: #17171c;
}

.menu-empty { grid-column: 1 / -1; text-align: center; font-size: 14px; color: #6b6b74; padding: 24px 0; }

/* ── หน้าเปลี่ยนรหัสผ่าน (templates/change_password.html) ── ใช้ .inp .field-label .err-box .btn-login ร่วมกับหน้า login */
.pw-card {
  width: 100%; max-width: 440px;
  background: #fff; border: 1px solid #ebeae6; border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 10px 30px rgba(0,0,0,.06);
  padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.pw-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.pw-ico {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, #34a38f, var(--brand-mid));
}
.pw-title { font-size: 18px; font-weight: 700; }
.pw-sub { font-size: 12.5px; color: #6b6b74; margin-top: 2px; }
.pw-field { display: flex; flex-direction: column; }
.pw-hint { font-size: 11.5px; color: #8a8a93; margin-top: 5px; }
.pw-show { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: #52525b; cursor: pointer; user-select: none; }
.pw-show input { accent-color: var(--brand-mid); width: 14px; height: 14px; }
.pw-ok {
  font-size: 13px; color: #166534; background: #ecfdf3; border: 1px solid #bbf7d0;
  padding: 10px 12px; border-radius: 10px;
}

/* ── ปุ่ม/หน้าต่าง ทดสอบ Cookie (หน้า /main) ── */
.btn-cookie {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #e3e1dc; border-radius: 8px;
  padding: 5px 11px; font: inherit; font-size: 12.5px; color: #53535c; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.btn-cookie:hover { border-color: var(--brand-mid); color: var(--brand-mid); }
.cookie-dlg {
  margin: auto; border: 0; border-radius: 14px; padding: 18px 20px;
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 40px);
  box-shadow: 0 30px 70px rgba(0,0,0,.25); font-family: var(--font); color: #17171c;
}
.cookie-dlg::backdrop { background: rgba(23,23,28,.45); }
.cookie-head { display: flex; align-items: center; justify-content: space-between; font-size: 15px; }
.cookie-x { background: none; border: 0; font-size: 16px; cursor: pointer; color: #6b6b74; padding: 4px 8px; border-radius: 6px; }
.cookie-x:hover { background: #f0efeb; }
.cookie-meta { font-size: 12.5px; color: #52525b; margin: 8px 0 10px; }
.cookie-meta .ok  { color: #15803d; font-weight: 600; }
.cookie-meta .bad { color: #dc2626; font-weight: 600; }
.cookie-json {
  background: #1e1e24; color: #e4e4e7; border-radius: 10px; padding: 12px 14px;
  font: 12.5px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all;
  max-height: 60vh; overflow: auto;
}
.cookie-foot { font-size: 11.5px; color: #8a8a93; margin-top: 8px; }
.cookie-dlg code { font-family: ui-monospace, Consolas, monospace; font-size: .95em; }
@media (max-width: 600px) { .btn-cookie span { display: none; } }

/* ── Main-page responsive ─────────────────────────── */
/* Tablet (700–1024px) */
@media (max-width: 1024px) {
  .nav { padding: 10px 20px; }
  main { padding: 20px 20px 16px; }
}

/* Mobile (<= 600px) */
@media (max-width: 600px) {
  .nav { padding: 8px 14px; gap: 8px; }
  .nav-brand-logo { height: 30px; }
  .nav-company-name { max-width: 110px; }
  .nav-user { display: none; }
  .btn-logout { padding: 5px 10px; font-size: 12px; }
  main { padding: 14px 10px 12px; gap: 14px; }
}
