/* ============================================================
   ระบบสต็อกโรงงาน — Modern UI Theme
   ============================================================ */
:root {
  --sidebar-w: 264px;
  --brand-1: #4f46e5;
  --brand-2: #7c3aed;
  --brand-grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --bg: #f3f5fb;
  --card-radius: 18px;
  --shadow-sm: 0 1px 3px rgba(30, 27, 75, .06), 0 4px 16px rgba(30, 27, 75, .06);
}

* { font-family: 'Prompt', system-ui, sans-serif; }

body { background: var(--bg); min-height: 100vh; }

.app-wrap { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #181433 0%, #241b4d 60%, #2b1e5e 100%);
  color: #cbd0e8;
  position: fixed; inset: 0 auto 0 0;
  z-index: 1040;
  display: flex; flex-direction: column;
  transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px 18px; }
.brand-icon {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--brand-grad);
  display: grid; place-items: center;
  color: #fff; font-size: 1.3rem;
  box-shadow: 0 4px 14px rgba(124, 58, 237, .45);
}
.brand-name { color: #fff; font-weight: 600; font-size: .98rem; line-height: 1.2; }
.brand-sub { font-size: .72rem; color: #8b87b8; letter-spacing: .12em; text-transform: uppercase; }

.side-nav { flex: 1; overflow-y: auto; padding: 6px 14px 20px; }
.nav-section {
  font-size: .68rem; letter-spacing: .14em; text-transform: uppercase;
  color: #716c9e; margin: 18px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; margin-bottom: 2px;
  border-radius: 12px;
  color: #b9bedd; text-decoration: none;
  font-size: .92rem; font-weight: 400;
  transition: all .18s;
}
.nav-item i { font-size: 1.05rem; width: 22px; text-align: center; }
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active {
  background: var(--brand-grad); color: #fff; font-weight: 500;
  box-shadow: 0 4px 14px rgba(99, 82, 230, .4);
}
.side-foot { padding: 14px 20px; font-size: .72rem; color: #6d689a; border-top: 1px solid rgba(255,255,255,.06); }

.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(15, 12, 41, .5); z-index: 1035;
}

/* ---------- Main / Topbar ---------- */
.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 26px;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #e8eaf4;
  position: sticky; top: 0; z-index: 1020;
}
.page-title { font-size: 1.15rem; font-weight: 600; margin: 0; color: #1e1b4b; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 1px solid #e8eaf4; border-radius: 50rem;
  padding: 5px 14px 5px 6px; text-align: left;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-weight: 600;
}
.content { padding: 24px 26px 40px; }

/* ---------- Cards / Tables ---------- */
.card { border: 0; border-radius: var(--card-radius); box-shadow: var(--shadow-sm); }
.card-header { background: transparent; border-bottom: 1px solid #eef0f8; font-weight: 600; padding: 16px 20px; }

.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center; font-size: 1.5rem; color: #fff;
}
.stat-card .stat-value { font-size: 1.55rem; font-weight: 700; color: #1e1b4b; line-height: 1.1; }
.stat-card .stat-label { font-size: .82rem; color: #8a8fb0; }

.table { --bs-table-hover-bg: #f6f7fe; }
.table thead th {
  background: #f6f7fc; color: #5c6086;
  font-weight: 600; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 0; padding: 12px 16px; white-space: nowrap;
}
.table tbody td { padding: 11px 16px; vertical-align: middle; }
.table > :not(caption) > * > * { border-bottom-color: #eef0f8; }

.btn-primary {
  background: var(--brand-grad); border: 0;
  box-shadow: 0 3px 10px rgba(99, 82, 230, .35);
}
.btn-primary:hover { filter: brightness(1.08); background: var(--brand-grad); }
.btn { border-radius: 10px; }
.form-control, .form-select { border-radius: 10px; border-color: #e2e5f1; }
.form-control:focus, .form-select:focus { border-color: var(--brand-1); box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .12); }
.modal-content { border: 0; border-radius: var(--card-radius); }
.badge { font-weight: 500; }

.ts-control { border-radius: 10px !important; border-color: #e2e5f1 !important; padding: 7px 12px; }

/* แถวสินค้าในฟอร์มเอกสาร */
.item-table td { vertical-align: top; }
.qty-input { max-width: 110px; }

/* tree สถานที่จัดเก็บ */
.loc-zone { border-left: 4px solid var(--brand-1); }
.bin-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid #e2e5f1; border-radius: 10px;
  padding: 5px 10px; margin: 3px; font-size: .82rem; background: #fff;
}
.bin-chip.has-stock { border-color: #4f46e5; background: #f4f3ff; }
.bin-chip.inactive { opacity: .45; text-decoration: line-through; }

/* ---------- Login ---------- */
.login-bg {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 10% -10%, #4f46e5cc, transparent),
              radial-gradient(1000px 600px at 110% 110%, #7c3aedbb, transparent),
              #14102e;
}
.login-card {
  width: min(420px, 92vw);
  background: rgba(255, 255, 255, .97);
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
  padding: 40px 36px;
}

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .main { margin-left: 0; }
  .content { padding: 16px 14px 32px; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .no-print, .sidebar-backdrop { display: none !important; }
  .main { margin-left: 0; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  body { background: #fff; }
}

/* ---------- Tom Select ที่ส่งรายการไปวางที่ body (ใช้ใน modal) ต้องลอยเหนือ modal ---------- */
body > .ts-dropdown { z-index: 1070; }
