/*
 * HANUMANIT UI kit (hn-*) — ชุด class กลางสำหรับหน้า backend ที่ออกแบบใหม่
 * รวมแพทเทิร์นที่เคยเขียนซ้ำในแต่ละหน้า (pv-, dv-, ep-, er-, pf-) ไว้ที่เดียว
 * ใช้ตัวแปรจาก theme-tokens.css / custom-theme.css จึงรองรับโหมดมืด/สว่างอัตโนมัติ
 * วิธีใช้และตัวอย่าง markup ดู backend/themes/mali/README-ui.md
 */

.hn { color: var(--text-main); }
.hn-ink { color: var(--text-main) !important; }
.hn-muted { color: var(--text-muted) !important; }
.hn-accent { color: var(--ci-accent-start, #c9a961) !important; }
.hn-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- Hero / หัวหน้า ---------- */
.hn-hero {
  position: relative; overflow: hidden; isolation: isolate;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1.25rem;
  padding: clamp(1.1rem, .8rem + 1.5vw, 1.75rem); margin-bottom: 1.5rem;
  border-radius: 1.25rem; background: var(--glass-03); border: 1px solid var(--line-08);
}
.hn-hero::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, var(--ci-accent-start, #c9a961), transparent); }
.hn-hero::after {
  content: ''; position: absolute; z-index: -1; right: -60px; top: -80px; width: 260px; height: 260px; border-radius: 50%;
  background: radial-gradient(circle, rgba(201, 169, 97, .16), transparent 70%); pointer-events: none;
}
.hn-hero-main { display: flex; align-items: center; gap: 1rem; min-width: 0; flex: 1 1 320px; }
.hn-hero-icon {
  flex-shrink: 0; width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  color: var(--ci-accent-start, #c9a961); background: rgba(201, 169, 97, .12); border: 1px solid rgba(201, 169, 97, .28);
}
.hn-hero-icon svg { width: 26px; height: 26px; }
.hn-kicker { display: inline-flex; align-items: center; gap: .4rem; font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ci-accent-start, #c9a961); }
.hn-kicker::before { content: ''; width: 16px; height: 2px; border-radius: 2px; background: currentColor; }
.hn-title { margin: .2rem 0 .25rem; font-size: clamp(1.25rem, 1.05rem + .8vw, 1.6rem); font-weight: 700; line-height: 1.3; color: var(--text-main); text-wrap: balance; }
.hn-sub { margin: 0; color: var(--text-muted); font-size: .9rem; max-width: 70ch; }
.hn-hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.hn-hero-actions .btn svg { width: 16px; height: 16px; }

/* ---------- ปุ่ม ---------- */
.hn-btn-gold, .btn.hn-btn-gold {
  display: inline-flex; align-items: center; gap: .45rem; border: 0; border-radius: 999px; padding: .5rem 1.15rem; font-weight: 600;
  background: linear-gradient(135deg, #e7d6a8, #c9a961); color: #1a1108 !important;
  box-shadow: 0 6px 18px -8px rgba(201, 169, 97, .7); transition: transform .15s ease, box-shadow .15s ease;
}
.hn-btn-gold:hover { transform: translateY(-1px); box-shadow: 0 10px 24px -10px rgba(201, 169, 97, .9); color: #1a1108 !important; }
.hn-btn-ghost, .btn.hn-btn-ghost {
  display: inline-flex; align-items: center; gap: .45rem; border-radius: 999px; padding: .5rem 1.05rem; font-weight: 500;
  background: transparent; border: 1px solid var(--line-15); color: var(--text-main) !important;
}
.hn-btn-ghost:hover { background: var(--glass-05); border-color: var(--line-25); }
.hn-btn-danger, .btn.hn-btn-danger { display: inline-flex; align-items: center; gap: .45rem; border-radius: 999px; padding: .5rem 1.05rem; font-weight: 500; background: rgba(239, 68, 68, .1); border: 1px solid rgba(239, 68, 68, .3); color: var(--tone-red, #ef4444) !important; }
.hn-btn-danger:hover { background: rgba(239, 68, 68, .18); }
.hn-btn-gold svg, .hn-btn-ghost svg, .hn-btn-danger svg { width: 16px; height: 16px; }

/* ปุ่มไอคอนกลม (ใช้ในตาราง / hero) */
.hn-icon-btn {
  width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-08); color: var(--text-muted); background: transparent; text-decoration: none; transition: all .15s ease;
}
.hn-icon-btn + .hn-icon-btn { margin-left: .25rem; }
.hn-icon-btn:hover { color: var(--ci-accent-start, #c9a961); border-color: rgba(201, 169, 97, .4); background: rgba(201, 169, 97, .08); }
.hn-icon-btn.danger:hover { color: var(--tone-red, #ef4444); border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .08); }
.hn-icon-btn svg { width: 15px; height: 15px; }

/* ---------- Stat tiles ---------- */
.hn-stats { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 1.5rem; }
.hn-stat {
  position: relative; display: flex; align-items: center; gap: .85rem; height: 100%; padding: 1rem 1.1rem; text-align: left; width: 100%;
  border-radius: 1rem; background: var(--glass-03); border: 1px solid var(--line-08); color: var(--text-main); text-decoration: none;
  transition: transform .18s ease, border-color .18s ease;
}
a.hn-stat:hover, button.hn-stat:hover { transform: translateY(-2px); border-color: rgba(201, 169, 97, .35); color: var(--text-main); }
button.hn-stat.is-active { border-color: var(--ci-accent-start, #c9a961); box-shadow: 0 0 0 1px var(--ci-accent-start, #c9a961) inset; }
.hn-stat-icon { flex-shrink: 0; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: rgba(201, 169, 97, .12); color: var(--ci-accent-start, #c9a961); }
.hn-stat-icon svg { width: 20px; height: 20px; }
.hn-stat-label { font-size: .74rem; font-weight: 600; letter-spacing: .03em; color: var(--text-muted); }
.hn-stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; color: var(--text-main); font-variant-numeric: tabular-nums; }
.hn-stat-unit { font-size: .8rem; font-weight: 500; color: var(--text-muted); margin-left: .2rem; }
.hn-stat-sub { font-size: .74rem; color: var(--text-muted); margin-top: .1rem; }
/* โทนสีของไอคอน stat / chip */
.tone-green .hn-stat-icon, .hn-chip.tone-green { background: rgba(16, 185, 129, .14); color: var(--tone-emerald, #10b981); }
.tone-blue .hn-stat-icon, .hn-chip.tone-blue { background: rgba(124, 131, 255, .14); color: var(--tone-indigo, #7c83ff); }
.tone-cyan .hn-stat-icon, .hn-chip.tone-cyan { background: rgba(13, 202, 240, .14); color: var(--tone-cyan, #0dcaf0); }
.tone-amber .hn-stat-icon, .hn-chip.tone-amber { background: rgba(245, 158, 11, .14); color: var(--tone-amber, #f59e0b); }
.tone-red .hn-stat-icon, .hn-chip.tone-red { background: rgba(239, 68, 68, .12); color: var(--tone-red, #ef4444); }
.tone-pink .hn-stat-icon, .hn-chip.tone-pink { background: rgba(255, 122, 184, .14); color: var(--tone-pink, #ff7ab8); }
.tone-gray .hn-stat-icon, .hn-chip.tone-gray { background: var(--line-08); color: var(--text-muted); }

/* แถบความคืบหน้า */
.hn-progress { height: 6px; border-radius: 4px; background: var(--line-10); overflow: hidden; margin-top: .4rem; }
.hn-progress > span { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, #c9a961, #e7d6a8); transition: width .6s ease; }

/* ---------- Card ---------- */
.hn-card { border-radius: 1rem; background: var(--glass-03); border: 1px solid var(--line-08); margin-bottom: 1.5rem; }
.hn-card-body { padding: 1.25rem 1.4rem; }
.hn-card-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .9rem 1.4rem; border-bottom: 1px solid var(--line-08);
}
.hn-card-title { display: flex; align-items: center; gap: .5rem; margin: 0; font-size: 1rem; font-weight: 700; color: var(--text-main); }
.hn-card-title svg { width: 16px; height: 16px; color: var(--ci-accent-start, #c9a961); }
.hn-card-title .hn-count { font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--line-08); color: var(--text-muted); }
.hn-card.danger { border-color: rgba(239, 68, 68, .25); }
.hn-card.danger .hn-card-title svg { color: var(--tone-red, #ef4444); }

/* ---------- Chip / สถานะ ---------- */
.hn-chip { display: inline-flex; align-items: center; gap: .35rem; padding: 2px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; background: var(--line-08); color: var(--text-muted); }
.hn-chip.tone-gold { background: rgba(201, 169, 97, .14); color: var(--ci-accent-start, #c9a961); }
.hn-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; flex-shrink: 0; }

/* ---------- Toolbar ค้นหา/กรอง ---------- */
.hn-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .9rem 1.4rem; border-bottom: 1px solid var(--line-08); }
.hn-toolbar .form-control, .hn-toolbar .form-select { max-width: 280px; border-radius: 999px; }
.hn-search { position: relative; flex: 1 1 220px; max-width: 320px; }
.hn-search svg { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-muted); pointer-events: none; }
.hn-search .form-control { padding-left: 2.3rem; max-width: none; }

/* ---------- GridView ใน hn-card ---------- */
.hn-grid .grid-view { margin: 0; }
.hn-grid .summary { padding: .7rem 1.4rem 0; font-size: .78rem; color: var(--text-muted); }
.hn-grid table.table { margin: 0; }
.hn-grid table.table > thead th {
  font-size: .74rem; font-weight: 600; letter-spacing: .03em; color: var(--text-muted); white-space: nowrap;
  border-bottom: 1px solid var(--line-08); background: transparent; padding-top: .85rem; padding-bottom: .85rem;
}
.hn-grid table.table > thead th a { color: inherit; text-decoration: none; }
.hn-grid table.table > thead th a:hover { color: var(--ci-accent-start, #c9a961); }
.hn-grid table.table > tbody td { vertical-align: middle; border-color: var(--line-05); padding-top: .8rem; padding-bottom: .8rem; }
.hn-grid table.table > tbody tr { transition: background-color .15s ease; }
.hn-grid table.table > tbody tr:hover { background: var(--glass-03); }
.hn-grid table.table th:first-child, .hn-grid table.table td:first-child { padding-left: 1.4rem; }
.hn-grid table.table th:last-child, .hn-grid table.table td:last-child { padding-right: 1.4rem; }
.hn-grid .filters input, .hn-grid .filters select { font-size: .8rem; border-radius: 8px; }
.hn-grid .pagination { padding: 1rem 1.4rem; margin: 0; }
.hn-grid .hn-actions { white-space: nowrap; text-align: right; width: 1%; }

/* ---------- รายละเอียด (แทน DetailView) ---------- */
.hn-dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.5rem; margin: 0; }
.hn-dl > div { min-width: 0; }
.hn-dl .span-2 { grid-column: 1 / -1; }
.hn-dl dt { font-size: .76rem; font-weight: 500; color: var(--text-muted); margin-bottom: .15rem; }
.hn-dl dd { margin: 0; color: var(--text-main); font-weight: 500; overflow-wrap: anywhere; }
.hn-dl dd:empty::before { content: '—'; color: var(--text-muted); font-weight: 400; }
/* DetailView เดิมที่ยังใช้อยู่ ให้หน้าตากลืนกับ card */
.hn-card table.detail-view { margin: 0; }
.hn-card table.detail-view th { width: 32%; font-size: .8rem; font-weight: 500; color: var(--text-muted); background: transparent; border-color: var(--line-05); }
.hn-card table.detail-view td { color: var(--text-main); border-color: var(--line-05); overflow-wrap: anywhere; }

/* ---------- ฟอร์ม ---------- */
.hn-form-section { padding: 1.25rem 1.4rem; border-bottom: 1px solid var(--line-08); }
.hn-form-section:last-of-type { border-bottom: 0; }
.hn-form-section-title { display: flex; align-items: center; gap: .55rem; margin: 0 0 1rem; font-size: .95rem; font-weight: 700; color: var(--text-main); }
.hn-form-section-title .hn-step { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; font-weight: 700; background: rgba(201, 169, 97, .14); color: var(--ci-accent-start, #c9a961); }
.hn-form-section-title small { font-weight: 400; color: var(--text-muted); }
.hn-form .form-label, .hn-form label.control-label, .hn-form .control-label { font-size: .82rem; font-weight: 600; color: var(--text-main); margin-bottom: .3rem; }
.hn-form .form-control, .hn-form .form-select { border-radius: 10px; }
.hn-form .hint-block, .hn-form .form-text { font-size: .76rem; color: var(--text-muted); }
.hn-form-actions {
  position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem;
  padding: .9rem 1.4rem; border-top: 1px solid var(--line-08); border-radius: 0 0 1rem 1rem;
  background: var(--surface-deep, rgba(13, 17, 48, .85)); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
[data-bs-theme="light"] .hn-form-actions { background: rgba(255, 255, 255, .92); }

/* ---------- Empty state ---------- */
.hn-empty { text-align: center; padding: 2.75rem 1.25rem; color: var(--text-muted); }
.hn-empty-icon {
  width: 64px; height: 64px; margin: 0 auto .9rem; border-radius: 50%; display: grid; place-items: center;
  background: rgba(201, 169, 97, .1); color: var(--ci-accent-start, #c9a961); animation: hn-bob 3s ease-in-out infinite;
}
.hn-empty-icon svg { width: 28px; height: 28px; }
.hn-empty h4 { font-size: 1rem; font-weight: 700; color: var(--text-main); margin-bottom: .25rem; }
.hn-empty p { font-size: .85rem; margin: 0 auto 1rem; max-width: 46ch; }
@keyframes hn-bob { 50% { transform: translateY(-4px); } }

/* ---------- Avatar ตัวอักษร ---------- */
.hn-avatar {
  flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; overflow: hidden;
  font-size: .8rem; font-weight: 700; background: linear-gradient(135deg, rgba(201, 169, 97, .35), rgba(124, 131, 255, .35)); color: var(--text-main);
}
.hn-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Timeline (ประวัติ/ติดตามงาน) ---------- */
.hn-timeline { list-style: none; margin: 0; padding: 0 0 0 1.25rem; position: relative; }
.hn-timeline::before { content: ''; position: absolute; left: .35rem; top: .3rem; bottom: .3rem; width: 2px; background: var(--line-10); border-radius: 2px; }
.hn-timeline > li { position: relative; padding: 0 0 1.1rem .75rem; }
.hn-timeline > li::before { content: ''; position: absolute; left: -1.2rem; top: .35rem; width: 12px; height: 12px; border-radius: 50%; background: var(--ci-accent-start, #c9a961); box-shadow: 0 0 0 4px rgba(201, 169, 97, .15); }

/* เข้าหน้าแบบนุ่ม ๆ ทีละส่วน */
.hn-rise > * { animation: hn-rise .45s ease both; }
.hn-rise > *:nth-child(2) { animation-delay: .05s; }
.hn-rise > *:nth-child(3) { animation-delay: .1s; }
.hn-rise > *:nth-child(4) { animation-delay: .15s; }
@keyframes hn-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (max-width: 575.98px) {
  .hn-hero-actions { width: 100%; }
  .hn-hero-actions > * { flex: 1; justify-content: center; }
  .hn-dl { grid-template-columns: 1fr; }
  .hn-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hn-stat { flex-direction: column; align-items: flex-start; gap: .5rem; }
}
@media (prefers-reduced-motion: reduce) {
  .hn-rise > *, .hn-empty-icon { animation: none; }
  .hn-stat, .hn-btn-gold { transition: none; }
}

/* โหมดสว่าง: ทองอ่อนบนพื้นขาวอ่านยาก (≈2:1) ใช้ทองเข้มกับตัวอักษร/ไอคอน */
[data-bs-theme="light"] .hn-kicker,
[data-bs-theme="light"] .hn-accent,
[data-bs-theme="light"] .hn-chip.tone-gold,
[data-bs-theme="light"] .hn-hero-icon,
[data-bs-theme="light"] .hn-stat-icon,
[data-bs-theme="light"] .hn-card-title svg,
[data-bs-theme="light"] .hn-form-section-title .hn-step,
[data-bs-theme="light"] .hn-empty-icon,
[data-bs-theme="light"] .hn-grid table.table > thead th a:hover { color: #8a6a1f !important; }
[data-bs-theme="light"] .tone-green .hn-stat-icon, [data-bs-theme="light"] .hn-chip.tone-green { color: #047857 !important; }
[data-bs-theme="light"] .tone-blue .hn-stat-icon, [data-bs-theme="light"] .hn-chip.tone-blue { color: #4338ca !important; }
[data-bs-theme="light"] .tone-cyan .hn-stat-icon, [data-bs-theme="light"] .hn-chip.tone-cyan { color: #0e7490 !important; }
[data-bs-theme="light"] .tone-amber .hn-stat-icon, [data-bs-theme="light"] .hn-chip.tone-amber { color: #b45309 !important; }
[data-bs-theme="light"] .tone-red .hn-stat-icon, [data-bs-theme="light"] .hn-chip.tone-red { color: #b91c1c !important; }
[data-bs-theme="light"] .tone-pink .hn-stat-icon, [data-bs-theme="light"] .hn-chip.tone-pink { color: #be185d !important; }
