:root {
  --bg-grad: linear-gradient(135deg, #e0e7ff 0%, #f3e8ff 48%, #e0f2fe 100%);
  --glass: rgba(255, 255, 255, 0.88);
  --card: #ffffff;
  --border: rgba(148, 163, 184, 0.25);
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-grad: linear-gradient(135deg, #3b82f6 0%, #7c3aed 100%);
  --success: #059669;
  --danger: #dc2626;
  --shadow: 0 8px 30px rgba(30, 41, 59, 0.06);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Sarabun', 'Tahoma', 'Segoe UI', sans-serif;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
}

/* App Shell — ProDeeMart v2.0 Frosted Sidebar Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
  padding: 12px;
  gap: 14px;
}
.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 12px;
  height: calc(100vh - 24px);
  overflow-y: auto;
}
.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.sb-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--primary-grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}
.sb-title { font-weight: 800; font-size: 1.05rem; line-height: 1.15; }
.sb-ver {
  display: inline-block; font-size: 0.68rem; font-weight: 800;
  padding: 2px 7px; border-radius: 999px; background: #dbeafe; color: #2563eb; margin-top: 2px;
}
.sb-section {
  font-size: 0.72rem; font-weight: 800; color: #3b82f6;
  padding: 10px 10px 4px; display: flex; align-items: center; gap: 6px;
}
.sb-section::before {
  content: ''; width: 5px; height: 5px; border-radius: 99px; background: #3b82f6;
}
.sb-nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  width: 100%; border: 0; background: transparent; color: #334155;
  padding: 9px 12px; border-radius: 12px; cursor: pointer;
  display: flex; align-items: center; gap: 9px;
  font-size: 0.88rem; font-weight: 600; text-align: left;
  transition: all 0.15s ease;
}
.nav-item:hover { background: rgba(99, 102, 241, 0.08); color: #1e293b; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.15), rgba(124, 58, 237, 0.12));
  color: #1d4ed8; font-weight: 800;
  box-shadow: inset 3px 0 0 #4f46e5;
}
.sb-footer {
  margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: 0.75rem; color: #059669; font-weight: 700;
  background: rgba(16, 185, 129, 0.08); border-radius: 12px; padding: 10px;
}

/* Main Workspace */
.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.topbar {
  background: var(--glass);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.page-heading { display: flex; align-items: center; gap: 10px; }
.page-heading h1 { margin: 0; font-size: 1.18rem; font-weight: 800; }
.mobile-menu-btn {
  display: none; border: 1px solid var(--border); background: #fff;
  border-radius: 10px; padding: 6px 10px; font-size: 1.1rem; cursor: pointer;
}
.badge-mode { font-size: 0.72rem; padding: 3px 9px; border-radius: 999px; background: #dbeafe; color: #1d4ed8; font-weight: 700; }

.card {
  background: var(--glass);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px;
}
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.input {
  padding: 8px 12px; border: 1px solid #cbd5e1; border-radius: 11px;
  font-size: 0.88rem; background: #fff; color: var(--text); outline: none;
}
.input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.14); }
.btn {
  padding: 8px 14px; border-radius: 11px; border: 1px solid #cbd5e1;
  background: #fff; color: #1e293b; font-weight: 700; cursor: pointer; font-size: 0.85rem;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.btn:hover:not(:disabled) { box-shadow: 0 3px 10px rgba(15, 23, 42, 0.08); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary-grad); color: #fff; border: 0; }
.btn-success { background: linear-gradient(135deg, #10b981, #059669); color: #fff; border: 0; }
.btn-danger { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }

.table-wrap { overflow-x: auto; background: #fff; border-radius: 14px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
th, td { padding: 10px 9px; border-bottom: 1px solid #f1f5f9; text-align: left; }
th { background: #f8fafc; font-weight: 800; color: #334155; white-space: nowrap; }
.thumb { width: 42px; height: 42px; border-radius: 10px; object-fit: cover; border: 1px solid #e2e8f0; background: #f8fafc; display: flex; align-items: center; justify-content: center; }

/* KPI & Packaging Cards (Exact ProDeeMart v2.0 Look) */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi-card {
  background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}
.kpi-label { font-size: 0.78rem; color: var(--muted); font-weight: 700; }
.kpi-val { font-size: 1.45rem; font-weight: 800; margin-top: 4px; }

.pkg-layout { display: grid; grid-template-columns: 1fr 330px; gap: 14px; align-items: start; }
.pkg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(195px, 1fr)); gap: 12px; }
.pkg-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 16px; padding: 11px;
  display: flex; flex-direction: column; gap: 7px; box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}
.pkg-card.selected { border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.22); }
.pkg-top { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.pill-sku { font-size: 0.7rem; font-weight: 800; padding: 2px 7px; border-radius: 99px; background: #e0e7ff; color: #3730a3; }
.pill-stock { font-size: 0.72rem; font-weight: 800; padding: 2px 7px; border-radius: 99px; background: #dcfce7; color: #166534; }
.pill-stock.low { background: #fee2e2; color: #b91c1c; }
.pkg-img-wrap { position: relative; height: 110px; background: #f8fafc; border-radius: 12px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pkg-img-wrap img { max-height: 100%; max-width: 100%; object-fit: contain; }
.pkg-dim { position: absolute; bottom: 5px; right: 5px; background: rgba(15, 23, 42, 0.78); color: #fff; font-size: 0.68rem; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.pkg-quick { display: flex; gap: 4px; flex-wrap: wrap; }
.pkg-qbtn { flex: 1; padding: 4px 2px; font-size: 0.74rem; font-weight: 800; border-radius: 8px; border: 1px solid #e2e8f0; background: #f8fafc; cursor: pointer; }
.pkg-qbtn:hover { background: #e0e7ff; border-color: #a5b4fc; }
.pkg-cart {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 18px; padding: 14px;
  position: sticky; top: 14px; box-shadow: var(--shadow);
}
.staff-pills { display: flex; gap: 6px; margin-bottom: 8px; }
.staff-pill {
  flex: 1; padding: 7px 6px; border-radius: 10px; border: 1px solid #cbd5e1;
  background: #f8fafc; font-weight: 700; cursor: pointer; font-size: 0.84rem;
}
.staff-pill.active { background: var(--primary-grad); color: #fff; border-color: transparent; }

/* Modal UX Rule: ห้ามปิดเมื่อแตะพื้นหลัง, ปิดได้เฉพาะปุ่ม ✕ แบบ sticky ที่เลื่อนตามการ scroll */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 23, 42, 0.55);
  display: none; align-items: center; justify-content: center; padding: 12px;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--card); border-radius: 18px; width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; border: 1px solid var(--border); position: relative;
}
.modal-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 14px 18px; display: flex; justify-content: space-between; align-items: center;
}
.modal-close-btn {
  width: 34px; height: 34px; border-radius: 999px; border: 1px solid var(--border);
  background: #f1f5f9; font-size: 1rem; font-weight: 800; cursor: pointer;
}
.modal-body { padding: 16px 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-full { grid-column: 1 / -1; }
.form-label { font-size: 0.8rem; font-weight: 700; margin-bottom: 4px; display: block; color: var(--muted); }
.toast {
  position: fixed; bottom: 18px; right: 18px; z-index: 300;
  background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 12px;
  font-size: 0.86rem; display: none; max-width: 360px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}

@media (max-width: 960px) {
  .pkg-layout { grid-template-columns: 1fr; }
  .pkg-cart { position: static; }
}
@media (max-width: 820px) {
  .app-shell { padding: 8px; }
  .mobile-menu-btn { display: inline-block; }
  .sidebar {
    position: fixed; left: -280px; top: 0; bottom: 0; height: 100vh;
    z-index: 150; border-radius: 0 20px 20px 0; transition: left 0.22s ease;
  }
  .sidebar.mobile-open { left: 0; }
  .form-grid { grid-template-columns: 1fr; }
}

/* Split-Screen Private Login Gate (ซ่อนโครงสร้างแอปทั้งหมดก่อนล็อกอิน) */
.login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 960px;
  min-height: 540px;
  background: #ffffff;
  border-radius: 26px;
  box-shadow: 0 24px 60px rgba(30, 41, 59, 0.14);
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1.05fr;
  border: 1px solid rgba(255, 255, 255, 0.9);
}
.login-left {
  padding: 44px 42px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.2rem;
}
.login-main { margin: 28px 0; }
.login-main h1 { margin: 0 0 8px; font-size: 1.75rem; font-weight: 800; color: #0f172a; }
.login-main p { margin: 0 0 26px; color: #64748b; font-size: 0.94rem; line-height: 1.5; }
.login-btn-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
}
.login-status {
  margin-top: 14px;
  font-size: 0.84rem;
  color: #4f46e5;
  font-weight: 700;
  min-height: 20px;
}
.login-sec-note {
  margin-top: 22px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: 0.8rem;
  color: #475569;
  line-height: 1.5;
}
.login-footer {
  font-size: 0.78rem;
  color: #94a3b8;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.login-right {
  position: relative;
  background: linear-gradient(145deg, #1e1b4b 0%, #312e81 42%, #4f46e5 82%, #0284c7 100%);
  color: #ffffff;
  padding: 42px 36px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.login-right::before {
  content: '';
  position: absolute;
  width: 320px; height: 320px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.35), transparent 70%);
  top: -80px; right: -80px;
}
.login-right::after {
  content: '';
  position: absolute;
  width: 280px; height: 280px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.35), transparent 70%);
  bottom: -70px; left: -60px;
}
.login-hero-badge {
  position: relative; z-index: 2;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
  font-size: 0.8rem; font-weight: 700; width: fit-content;
}
.login-hero-glass {
  position: relative; z-index: 2;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 20px;
  padding: 22px;
}
.login-hero-glass h2 { margin: 0 0 8px; font-size: 1.25rem; font-weight: 800; line-height: 1.35; }
.login-hero-list { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 8px; font-size: 0.86rem; color: rgba(255, 255, 255, 0.92); }
@media (max-width: 780px) {
  .login-card { grid-template-columns: 1fr; min-height: auto; }
  .login-left { padding: 30px 24px; }
  .login-right { padding: 26px 24px; }
}
