/* ============================================================
   กลุ่มงานเภสัชกรรม — Global Stylesheet
   ============================================================ */

:root {
  --primary:       #1a7f5a;
  --primary-dark:  #145f44;
  --primary-light: #e8f5f0;
  --primary-mid:   #2da878;
  --sidebar-w:     260px;
  --navbar-h:      60px;
  --radius:        0.5rem;
  --shadow:        0 2px 8px rgba(0,0,0,0.08);
  --transition:    0.2s ease;
  /* Override Bootstrap's default blue primary with site green */
  --bs-primary:               #1a7f5a;
  --bs-primary-rgb:           26, 127, 90;
  --bs-primary-bg-subtle:     #e8f5f0;
  --bs-primary-border-subtle: #b3d9c8;
  --bs-primary-text-emphasis: #0d4f38;
  --bs-link-color:            #1a7f5a;
  --bs-link-hover-color:      #145f44;
}

/* ---- Base ---- */
* { font-family: 'Sarabun', sans-serif; }
body { font-size: 16px; background: #f4f6f9; color: #343a40; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #c1cdd6; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ============================================================
   NAVBAR
   ============================================================ */
.top-navbar {
  height: var(--navbar-h);
  background: var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1030;
}
.top-navbar .navbar-brand {
  color: #fff !important;
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.top-navbar .brand-icon-wrap {
  width: 36px; height: 36px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.top-navbar .nav-link { color: rgba(255,255,255,0.85) !important; transition: color var(--transition); }
.top-navbar .nav-link:hover { color: #fff !important; }
.top-navbar .navbar-toggler { border-color: rgba(255,255,255,0.4); }
.top-navbar .navbar-toggler-icon { filter: invert(1); }
.top-navbar .dropdown-menu { border: none; box-shadow: var(--shadow); border-radius: var(--radius); }
.user-avatar {
  width: 34px; height: 34px;
  background: rgba(255,255,255,0.25);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: #fff;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  min-height: calc(100vh - var(--navbar-h));
  background: #fff;
  border-right: 1px solid #e9ecef;
  box-shadow: 2px 0 8px rgba(0,0,0,0.04);
  position: fixed;
  top: var(--navbar-h);
  left: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition);
  z-index: 1020;
}


.sidebar-menu { padding: 0.5rem 0; list-style: none; margin: 0; }

.sidebar-menu .menu-section {
  padding: 0.6rem 1rem 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: #adb5bd;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-menu .menu-item > a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 1rem;
  color: #495057;
  font-size: 0.95rem;
  border-radius: 0;
  transition: all var(--transition);
  border-left: 3px solid transparent;
  white-space: nowrap;
}
.sidebar-menu .menu-item > a:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
}
.sidebar-menu .menu-item.active > a {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}
.sidebar-menu .menu-item > a .menu-icon {
  font-size: 1.05rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar-menu .menu-item > a .badge {
  margin-left: auto;
  font-size: 0.7rem;
}

/* Sidebar bottom user area */
.sidebar .sidebar-user-footer {
  position: sticky; bottom: 0;
  background: #fff;
  border-top: 1px solid #e9ecef;
  padding: 0.75rem 1rem;
}
.sidebar .sidebar-user-footer .user-name { color: #343a40; font-size: 0.85rem; font-weight: 600; }
.sidebar .sidebar-user-footer .user-role { color: #6c757d; font-size: 0.75rem; }

/* ============================================================
   MAIN CONTENT WRAPPER
   ============================================================ */
.page-wrapper {
  margin-top: var(--navbar-h);
  margin-left: var(--sidebar-w);
  min-height: calc(100vh - var(--navbar-h));
  padding: 1.5rem;
  transition: margin-left var(--transition);
}

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .page-wrapper { margin-left: 0; }
}

/* ============================================================
   PAGE HEADER (breadcrumb zone)
   ============================================================ */
.page-header {
  margin-bottom: 1.5rem;
}
.page-header h4 {
  font-weight: 700;
  color: #343a40;
  margin: 0;
  font-size: 1.25rem;
}
.page-header .breadcrumb { font-size: 0.85rem; margin: 0; }
.page-header .breadcrumb-item.active { color: #6c757d; }

/* ============================================================
   CARD
   ============================================================ */
.card {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  background: #fff;
  border-bottom: 1px solid #e9ecef;
  font-weight: 600;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius) var(--radius) 0 0 !important;
}
.card-header.bg-primary-soft {
  background: var(--primary-light);
  color: var(--primary);
}

/* ---- Stat Cards (legacy gradient) ---- */
.stat-card {
  border-radius: var(--radius);
  padding: 1.25rem;
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform var(--transition);
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card .stat-icon { font-size: 2.2rem; opacity: 0.85; }
.stat-card .stat-number { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { font-size: 0.9rem; opacity: 0.9; }

/* ---- Compact Stat Cards (icon-box style) ---- */
.stat-mini {
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  box-shadow: var(--shadow);
  transition: transform var(--transition);
  text-decoration: none;
  color: inherit;
}
.stat-mini:hover { transform: translateY(-2px); color: inherit; }
.stat-mini .smi-icon {
  width: 52px; height: 52px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  color: #fff;
  flex-shrink: 0;
}
.stat-mini .smi-num {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
  color: #1e293b;
}
.stat-mini .smi-label {
  font-size: 0.82rem;
  color: #64748b;
  margin-top: 3px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn { border-radius: var(--radius); transition: all var(--transition); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}
.badge-blue { background-color: #0d6efd !important; color: #fff; }
.btn-outline-primary {
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline-primary:hover {
  background: var(--primary);
  border-color: var(--primary);
}

/* ============================================================
   TABLE
   ============================================================ */
.table thead th {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  border-top: none;
  white-space: nowrap;
}
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: #f8fffe; }
.table-responsive { border-radius: var(--radius); }

/* ============================================================
   FORM
   ============================================================ */
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 0.2rem rgba(26,127,90,0.2);
}
.form-label { font-weight: 600; font-size: 0.9rem; }

/* ============================================================
   BADGE & STATUS
   ============================================================ */
.badge-active   { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #fee2e2; color: #991b1b; }
.badge-draft    { background: #fef9c3; color: #854d0e; }

/* Stock low highlight */
tr.stock-low td { background: #fff5f5 !important; }
tr.stock-critical td { background: #fee2e2 !important; }

/* Shift badges */
.shift-morning   { background: #fef3c7; color: #92400e; }
.shift-afternoon { background: #dbeafe; color: #1e40af; }
.shift-night     { background: #ede9fe; color: #5b21b6; }

/* Severity badges */
.severity-mild     { background: #d1fae5; color: #065f46; }
.severity-moderate { background: #fef3c7; color: #92400e; }
.severity-severe   { background: #fee2e2; color: #991b1b; }
.severity-death    { background: #1f2937; color: #f9fafb; }

/* Priority badges */
.priority-low    { background: #e5e7eb; color: #374151; }
.priority-normal { background: #dbeafe; color: #1e40af; }
.priority-high   { background: #fef3c7; color: #92400e; }
.priority-urgent { background: #fee2e2; color: #991b1b; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-header {
  background: var(--primary-light);
  border-bottom: 1px solid #bee3d4;
}
.modal-header .modal-title { color: var(--primary); font-weight: 700; }
.modal-content { border-radius: var(--radius); border: none; box-shadow: 0 8px 32px rgba(0,0,0,0.15); }

/* ============================================================
   SEARCH / FILTER BAR
   ============================================================ */
.filter-bar { background: #fff; border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }

/* ============================================================
   MAGAZINE CARD SYSTEM  (.mc)
   ============================================================ */
.mc {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  background: #0e1f17;
  box-shadow: 0 4px 20px rgba(0,0,0,.11);
  transition: transform .26s ease, box-shadow .28s ease;
}
.mc:hover { transform: translateY(-5px); box-shadow: 0 18px 46px rgba(0,0,0,.2); color: inherit; }
.mc-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; display: block;
  transition: transform .52s ease;
}
.mc:hover .mc-img { transform: scale(1.055); }
.mc-noimg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 3.5rem;
  background: linear-gradient(135deg,#1a7f5a 0%,#0d4f38 100%);
  color: rgba(255,255,255,.22);
}
.mc-grad {
  position: absolute; inset: 0;
  background: linear-gradient(
    to top,
    rgba(4,12,8,.9) 0%,
    rgba(4,12,8,.55) 40%,
    rgba(4,12,8,.08) 68%,
    transparent 100%
  );
}
.mc-body {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 1rem 1.2rem .95rem;
}
.mc-tag {
  display: inline-block;
  font-size: .62rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  border: 1.5px solid;
  border-radius: 20px;
  padding: .15em .65em;
  margin-bottom: .42rem;
}
.mc-title {
  font-size: .93rem; font-weight: 700; line-height: 1.38;
  color: #fff; margin-bottom: .28rem;
  text-shadow: 0 1px 8px rgba(0,0,0,.5);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.mc-meta {
  font-size: .71rem; color: rgba(255,255,255,.5);
  display: flex; align-items: center; gap: .4rem;
}

/* ============================================================
   AVATAR
   ============================================================ */
.avatar-circle {
  width: 48px; height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary-light);
}
.avatar-placeholder {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; font-weight: 700;
  border: 2px solid #bee3d4;
}

/* ============================================================
   OFFCANVAS SIDEBAR (mobile)
   ============================================================ */
.offcanvas-sidebar { width: var(--sidebar-w) !important; }
.offcanvas-sidebar .offcanvas-header {
  background: var(--primary);
  color: #fff;
  padding: 1rem;
}
.offcanvas-sidebar .btn-close { filter: invert(1); }

/* ============================================================
   FOOTER
   ============================================================ */
.main-footer {
  margin-top: 2rem;
  padding: 1rem 0;
  border-top: 1px solid #e9ecef;
  font-size: 0.82rem;
  color: #adb5bd;
  text-align: center;
}

/* ============================================================
   MISC
   ============================================================ */
.cursor-pointer { cursor: pointer; }
.text-primary-custom { color: var(--primary) !important; }
.bg-primary-custom  { background: var(--primary) !important; }
.bg-primary-light   { background: var(--primary-light) !important; }
.border-primary-custom { border-color: var(--primary) !important; }

.action-btn { width: 30px; height: 30px; padding: 0; display:inline-flex; align-items:center; justify-content:center; }

/* ---- Loading overlay ---- */
#pageLoader {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
#pageLoader .spinner-border { color: var(--primary); width:3rem; height:3rem; }

/* ---- Quill editor ---- */
.ql-toolbar { border-radius: var(--radius) var(--radius) 0 0 !important; }
.ql-container { border-radius: 0 0 var(--radius) var(--radius) !important; min-height: 200px; font-family: 'Sarabun', sans-serif; font-size: 16px; }

/* ============================================================
   RESPONSIVE — Mobile / Tablet
   ============================================================ */

/* xs — phones < 576px */
@media (max-width: 575.98px) {
  .page-wrapper { padding: 0.85rem 0.65rem; }
  .page-header { margin-bottom: 1rem; }
  .page-header h4 { font-size: 1.05rem; }
  .page-header .breadcrumb { font-size: 0.78rem; }

  .stat-mini { padding: 0.65rem 0.75rem; gap: 0.55rem; }
  .stat-mini .smi-icon { width: 38px; height: 38px; font-size: 1.1rem; border-radius: 8px; }
  .stat-mini .smi-num  { font-size: 1.15rem; }
  .stat-mini .smi-label { font-size: 0.7rem; }

  .filter-bar { padding: 0.65rem; }
  .card-header { padding: 0.65rem 0.9rem; font-size: 0.88rem; }
  .card-body   { padding: 0.85rem; }

  .modal .modal-dialog { margin: 0.4rem; }
  .modal .modal-header .modal-title { font-size: 1rem; }
  .modal .modal-body { padding: 0.85rem; }

  .table thead th { font-size: 0.78rem; padding: 0.5rem 0.6rem; }
  .table tbody td { font-size: 0.82rem; padding: 0.5rem 0.6rem; }
}

/* sm — 576–767px */
@media (max-width: 767.98px) {
  .page-wrapper { padding: 1rem 0.85rem; }
  .card-body { padding: 1rem; }
}

/* md — tablets 768–991px */
@media (min-width: 768px) and (max-width: 991.98px) {
  .page-wrapper { padding: 1.25rem 1rem; }
}

/* Prevent horizontal overflow globally */
body { overflow-x: hidden; }
.container, .container-fluid { overflow-x: hidden; }

/* ── RBAC: viewer role — hide all write-action UI ── */
body.role-viewer [data-write-only],
body.role-viewer .btn-write-only {
    display: none !important;
}
