/*
  คลาสที่ใช้ร่วมกันทุกหน้าจอ — ชื่อคลาสตรงกับ design system ของ kku_supply
  หลักการ: คลาสคุมองค์ประกอบมาตรฐาน (ปุ่ม/การ์ด/ตาราง/สถานะ) ส่วน layout เฉพาะหน้าใช้ Tailwind ในไฟล์นั้น
  ห้ามตั้งกฎกับ element ทั่วไป (a, body, *) เพราะจะชนกับ Tailwind preflight
*/

[x-cloak] { display: none !important; }

.app {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* สเกลตัวอักษรแบบ kku_supply ไม่หนาเกิน 700 — กดน้ำหนักจาก utility เดิมลงทั้งระบบ */
.app .font-black,
.app .font-extrabold { font-weight: 700; }

/* การ์ดกระจกเดิมทั้งระบบ → การ์ดพื้นเรียบแบบ kku_supply */
.glass {
  background: var(--surface);
  border: 1px solid var(--border);
}

/* ---------------------------------------------------------------- โครงหน้า (desktop) */
.shell { display: flex; min-height: 100vh; }

.side {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  transition: width var(--dur) var(--ease);
}
.side--collapsed { width: 64px; }
.side--collapsed .brand { align-items: center; padding-left: 0; padding-right: 0; }
.side--collapsed .brand__txt,
.side--collapsed .nav__lbl,
.side--collapsed .nav__ext,
.side--collapsed .nav__sec span,
.side--collapsed .side__collapse span { display: none; }
.side--collapsed .nav__i { justify-content: center; padding-left: 0; padding-right: 0; }
.side--collapsed .nav__i--on::before { left: 0; }
.side--collapsed .nav__sec { height: 13px; padding: 12px 0 4px; }

.brand { display: flex; align-items: center; gap: 10px; padding: 14px 16px 12px; border-bottom: 1px solid var(--sidebar-border); }
.brand__logo { width: 36px; height: 36px; border-radius: var(--r-md); object-fit: cover; flex-shrink: 0; }
.brand__t { color: var(--sidebar-ink); font-weight: 700; font-size: 1rem; line-height: 1.2; letter-spacing: -0.01em; }
.brand__t em { font-style: normal; color: var(--accent); }
.brand__s { color: var(--sidebar-ink-muted); font-size: 0.66rem; line-height: 1.3; margin-top: 2px; }

.nav { flex: 1; padding: 8px 12px 16px; display: flex; flex-direction: column; gap: 1px; overflow-y: auto; }
.nav__sec {
  font-size: 0.63rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--sidebar-ink-muted); opacity: 0.6;
  padding: 14px 8px 4px; font-weight: 700;
}
.nav__i {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 8px 9px; border-radius: var(--r-md);
  color: var(--sidebar-ink-muted); font-size: 0.83rem; font-weight: 500;
  text-decoration: none; cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav__i svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav__i:hover { background: var(--sidebar-bg-active); color: var(--sidebar-ink); }
.nav__i--on { background: var(--sidebar-bg-active); color: var(--sidebar-ink); font-weight: 600; }
.nav__i--on::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav__ext { margin-left: auto; width: 12px !important; height: 12px !important; opacity: 0.7; }
.nav__b {
  margin-left: auto; background: var(--danger); color: var(--primary-ink);
  font-size: 0.65rem; font-weight: 700; border-radius: 999px; padding: 1px 6px;
}

.side__collapse {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 4px 12px 12px; padding: 8px 9px; border-radius: var(--r-md);
  background: transparent; border: 1px solid var(--sidebar-border);
  color: var(--sidebar-ink-muted); font-size: 0.78rem; font-family: inherit;
  cursor: pointer; flex-shrink: 0;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.side__collapse:hover { background: var(--sidebar-bg-active); color: var(--sidebar-ink); }
.side__backdrop { display: none; }

.content { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

.top {
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--surface);
  flex-shrink: 0; position: relative; z-index: 30;
}
.top__spacer { flex: 1; }
.top__div { width: 1px; height: 24px; background: var(--border); flex-shrink: 0; }
.brand__close { margin-left: auto; color: var(--sidebar-ink-muted); }
.brand__close:hover { background: var(--sidebar-bg-active); color: var(--sidebar-ink); }
.userbox__logout { margin-top: 8px; }
.dot--su { color: var(--success); }
.crumb { font-size: 0.78rem; color: var(--muted); display: flex; align-items: center; gap: 6px; min-width: 0; }
.crumb b { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb__sep { opacity: 0.5; }
.gfind {
  display: flex; align-items: center; gap: 8px; width: 300px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 7px 10px; color: var(--muted); font-size: 0.78rem;
}
.icnbtn {
  width: 34px; height: 34px; border-radius: var(--r-md); display: flex;
  align-items: center; justify-content: center; color: var(--muted); position: relative;
  cursor: pointer; background: none; border: none; font-family: inherit; flex-shrink: 0;
}
.icnbtn:hover { background: var(--bg); color: var(--ink); }
.icnbtn__dot {
  position: absolute; top: 7px; right: 8px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--danger); border: 1.5px solid var(--surface);
}
.icnbtn--menu { display: none; }
.av {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-subtle);
  color: var(--primary); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.78rem; overflow: hidden; flex-shrink: 0;
}
.av img { width: 100%; height: 100%; object-fit: cover; }

.userbox { position: relative; }
.userbox__trigger {
  display: flex; align-items: center; gap: 9px; background: transparent; border: none;
  padding: 4px 6px; border-radius: var(--r-md); cursor: pointer; color: var(--muted); font-family: inherit;
}
.userbox__trigger:hover { background: var(--bg); }
.userbox__name { font-size: 0.79rem; font-weight: 600; color: var(--ink); text-align: right; line-height: 1.3; }
.userbox__role { font-size: 0.69rem; color: var(--muted); text-align: right; line-height: 1.3; }
.userbox__menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
  width: 240px; padding: 10px; box-shadow: var(--shadow-pop);
}
.userbox__row { display: flex; align-items: center; gap: 8px; padding: 7px 4px; font-size: 0.8rem; }
.userbox__row + .userbox__row { border-top: 1px solid var(--border); }

.phead {
  padding: 14px 20px 12px; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
  position: relative; z-index: 10;
}
.phead__actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.ttl { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.005em; color: var(--ink); }
.sub { margin: 4px 0 0; font-size: 0.79rem; color: var(--muted); }
.body { flex: 1; min-height: 0; padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; overflow: auto; }

.app-main { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; }

/* ------------------------------------------------------------ ปุ่ม/ช่องกรอก */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--r-md); border: 1px solid transparent; font-weight: 600;
  font-size: 0.82rem; font-family: inherit; height: 36px; padding: 0 14px;
  white-space: nowrap; cursor: pointer; text-decoration: none; line-height: 1;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn--p { background: var(--primary); color: var(--primary-ink); box-shadow: var(--shadow-btn); }
.btn--p:hover { background: var(--primary-hover); color: var(--primary-ink); }
.btn--a { background: var(--accent); color: #FFFFFF; }
.btn--a:hover { background: var(--accent-hover); color: #FFFFFF; }
.btn--s { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn--s:hover { background: var(--bg); }
.btn--g { background: transparent; color: var(--muted); }
.btn--g:hover { background: var(--bg); color: var(--ink); }
.btn--d { background: var(--danger); color: #FFFFFF; }
.btn--d:hover { filter: brightness(0.92); }
.btn--sm { height: 30px; padding: 0 10px; font-size: 0.76rem; border-radius: var(--r-sm); }
.btn--lg { height: 42px; padding: 0 18px; font-size: 0.88rem; }
.btn--block { width: 100%; }
.btn--icon { width: 36px; padding: 0; }
.btn--sm.btn--icon { width: 30px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.inp {
  height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); font-size: 0.82rem; font-family: inherit; color: var(--ink); width: 100%;
}
.inp:focus, .inp:focus-visible { outline: 2px solid rgba(30, 58, 138, 0.35); outline-offset: 1px; border-color: var(--primary); }
.inp--ta { height: auto; padding: 8px 10px; line-height: 1.5; resize: vertical; }
.lbl { display: block; margin-bottom: 5px; font-size: 0.76rem; font-weight: 600; color: var(--ink-soft); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 11px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  font-size: 0.76rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.chip--on { background: var(--primary-subtle); border-color: rgba(30, 58, 138, 0.3); color: var(--primary); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--r-md); padding: 3px; gap: 2px; }
.seg__i { padding: 5px 12px; border-radius: 7px; font-size: 0.78rem; font-weight: 600; color: var(--muted); cursor: pointer; background: none; border: none; font-family: inherit; }
.seg__i:hover { color: var(--ink); }
.seg__i--on { background: var(--surface); color: var(--primary); box-shadow: 0 1px 2px rgba(17, 24, 39, 0.08); }

/* ---------------------------------------------------------------- การ์ด */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-card); }
.card__h { padding: 11px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card__hn { padding: 11px 14px; background: var(--primary); color: var(--primary-ink); display: flex; align-items: center; justify-content: space-between; gap: 10px; border-radius: var(--r-xl) var(--r-xl) 0 0; }
.card__t { margin: 0; font-size: 0.88rem; font-weight: 700; color: var(--ink); }
.card__hn .card__t { color: inherit; }
.card__b { padding: 14px; }
.card__f { padding: 11px 14px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tile__l { font-size: 0.73rem; color: var(--muted); font-weight: 600; }
.tile__v { font-size: 1.45rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; color: var(--ink); }
.tile__d { font-size: 0.72rem; color: var(--muted); }

/* --------------------------------------------------------------- ตาราง */
.tbl { width: 100%; border-collapse: collapse; font-size: 0.81rem; color: var(--ink); }
.tbl thead th {
  background: var(--bg); color: var(--muted); font-weight: 700; font-size: 0.69rem;
  text-transform: uppercase; letter-spacing: 0.04em; text-align: left;
  padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--bg); }
.tbl--sticky thead th { position: sticky; top: 0; z-index: 1; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mut { color: var(--muted); }
.strong { font-weight: 600; }
.sub2 { font-size: 0.72rem; color: var(--muted); font-weight: 400; }

/* --------------------------------------------------------------- สถานะ */
.bdg { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; line-height: 1.55; white-space: nowrap; }
.bdg--su { background: var(--success-subtle); color: var(--success-text); }
.bdg--wa { background: var(--warning-subtle); color: var(--warning-text); }
.bdg--da { background: var(--danger-subtle); color: var(--danger-text); }
.bdg--in { background: var(--info-subtle); color: var(--info-text); }
.bdg--ne { background: var(--surface-2); color: var(--muted); }
.bdg--ac { background: var(--accent-subtle); color: var(--accent-text); }
.bdg--pr { background: var(--primary-subtle); color: var(--primary); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ------------------------------------------------------ ขั้นตอน/ไทม์ไลน์ */
.stp { display: flex; align-items: center; gap: 8px; font-size: 0.76rem; color: var(--muted); }
.stp--on { color: var(--ink); font-weight: 600; }
.stp__n { width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.68rem; font-weight: 700; background: var(--surface-2); color: var(--muted); flex-shrink: 0; }
.stp__n--on { background: var(--primary); color: var(--primary-ink); }
.stp__n--dn { background: var(--success); color: #FFFFFF; }
.stp__l { flex: 1; height: 1px; background: var(--border); min-width: 18px; }

/* ---------------------------------------------------------------- อื่น ๆ */
.bar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar__f { height: 100%; border-radius: 999px; background: var(--primary); }
.note { border-radius: var(--r-lg); padding: 10px 12px; font-size: 0.78rem; line-height: 1.55; }
.note--wa { background: var(--warning-subtle); border: 1px solid rgba(245, 158, 11, 0.4); }
.note--in { background: var(--info-subtle); border: 1px solid rgba(37, 99, 235, 0.25); }
.note--su { background: var(--success-subtle); border: 1px solid rgba(22, 163, 74, 0.3); }
.note--da { background: var(--danger-subtle); border: 1px solid rgba(220, 38, 38, 0.3); }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 0.8rem; padding: 5px 0; }
.kv + .kv { border-top: 1px solid var(--border); }
.rowline { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }

/* หัวข้อย่อยในฟอร์ม/โมดัล */
.sec {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 0 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--border);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--primary);
}
.sec--mut { color: var(--muted); }

/* modal ที่ใช้ซ้ำ ๆ ในหน้า admin */
.modal__panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-pop); }
.modal__h { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal__t { margin: 0; font-size: 1rem; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.modal__b { padding: 18px; }
.modal__f { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--bg); display: flex; align-items: center; justify-content: flex-end; gap: 8px; border-radius: 0 0 var(--r-xl) var(--r-xl); }

/* --------------------------------------------------------- หน้าจอเล็ก */
@media (min-width: 1024px) {
  .shell { height: 100vh; overflow: hidden; }
  .shell .content { height: 100vh; }
  .app-main { overflow: auto; }
}

@media (max-width: 1023.98px) {
  .icnbtn--menu { display: flex; }
  .side {
    position: fixed; z-index: 50; inset: 0 auto 0 0; height: 100dvh;
    transform: translateX(-100%); transition: transform var(--dur) var(--ease);
    width: var(--sidebar-w) !important;
  }
  .side--open { transform: none; }
  .side--collapsed .brand__txt,
  .side--collapsed .nav__lbl,
  .side--collapsed .nav__ext,
  .side--collapsed .nav__sec span { display: revert; }
  .side--collapsed .nav__i { justify-content: flex-start; padding: 8px 9px; }
  .side__collapse { display: none; }
  .side__backdrop { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(15, 23, 42, 0.45); }
  .gfind { display: none; }
  .userbox__meta { display: none; }
  .top { padding: 0 12px; }
  .body { padding: 12px; }
  .phead { padding: 12px; flex-direction: column; align-items: stretch; }
  .phead__actions { justify-content: flex-start; }
}

@media print {
  .side, .top, .phead, .print-hide { display: none !important; }
  .body, .app-main { overflow: visible; padding: 0; }
}
