/* ============================================================
   saraban-ui.css — Saraban e-Document Design System
   Theme: Navy Blue + Gold (ราชการ + ทันสมัย)
   ============================================================ */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

/* ---------- CSS Variables ---------- */
:root {
  --primary:        #1e3a5f;
  --primary-dark:   #152d4a;
  --primary-mid:    #2a4f7c;
  --primary-light:  #e8eef6;
  --accent:         #c9a84c;
  --accent-dark:    #a8892d;
  --accent-light:   #fdf6e3;

  --success:   #198754;
  --info:      #0dcaf0;
  --warning:   #ffc107;
  --danger:    #dc3545;

  --gray-50:  #f8f9fa;
  --gray-100: #f1f3f5;
  --gray-200: #e9ecef;
  --gray-300: #dee2e6;
  --gray-500: #adb5bd;
  --gray-600: #6c757d;
  --gray-700: #495057;
  --gray-800: #343a40;
  --gray-900: #212529;

  --body-bg:     #f0f3f8;
  --card-bg:     #ffffff;
  --sidebar-bg:  #1e3a5f;
  --topbar-bg:   #ffffff;

  --gradient:      linear-gradient(135deg, #1e3a5f 0%, #2a6496 100%);
  --gradient-gold: linear-gradient(135deg, #c9a84c 0%, #e0c97b 100%);
  --gradient-soft: linear-gradient(135deg, #e8eef6 0%, #fdf6e3 100%);
  --gradient-hero: linear-gradient(135deg, #1e3a5f 0%, #1a5276 60%, #c9a84c 100%);

  --shadow-xs:   0 1px 3px rgba(0,0,0,.07);
  --shadow-sm:   0 2px 8px rgba(0,0,0,.09);
  --shadow:      0 4px 16px rgba(0,0,0,.11);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.13);
  --shadow-navy: 0 4px 20px rgba(30,58,95,.30);
  --shadow-gold: 0 4px 16px rgba(201,168,76,.35);

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --sidebar-width:     260px;
  --sidebar-collapsed: 68px;
  --topbar-height:     64px;

  --transition: all .22s ease;
  --transition-slow: all .4s ease;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Sarabun', sans-serif;
  font-size: 15px;
  font-weight: 400;
  color: var(--gray-800);
  background: var(--body-bg);
  margin: 0;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-mid); }

h1,h2,h3,h4,h5,h6 { font-weight: 600; color: var(--gray-900); }

/* ---------- Layout Wrapper ---------- */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: var(--transition-slow);
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

/* Brand */
.sidebar-brand {
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  min-height: var(--topbar-height);
  text-decoration: none;
}

.sidebar-brand-icon {
  width: 38px; height: 38px;
  background: var(--gradient-gold);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-gold);
}

.sidebar-brand-text { overflow: hidden; }
.sidebar-brand-name {
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
  white-space: nowrap;
}
.sidebar-brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,.55);
  white-space: nowrap;
}

/* School logo in sidebar brand */
.sidebar-brand-logo {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
  padding: 14px 10px 4px;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar.collapsed .nav-section-label { opacity: 0; }

.nav-item { margin-bottom: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.75) !important;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}

.nav-link:hover {
  background: rgba(255,255,255,.1);
  color: #fff !important;
}

.nav-link.active {
  background: var(--gradient-gold);
  color: #fff !important;
  box-shadow: var(--shadow-gold);
}

.nav-link .nav-icon {
  font-size: 17px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.nav-link .nav-text { flex: 1; }

.nav-badge {
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

/* Collapsed sidebar tooltip */
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-badge { display: none; }

/* Sub-menu */
.nav-sub { display: none; padding-left: 8px; }
.nav-sub.show { display: block; }
.nav-sub .nav-link {
  font-size: 13px;
  padding: 7px 12px;
  color: rgba(255,255,255,.6) !important;
}
.nav-sub .nav-link::before {
  content: '';
  width: 4px; height: 4px;
  background: rgba(255,255,255,.4);
  border-radius: 50%;
  flex-shrink: 0;
}

/* Sidebar footer (user) */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.sidebar-user:hover { background: rgba(255,255,255,.08); }

.sidebar-user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--gradient-gold);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-info { overflow: hidden; flex: 1; }
.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11px;
  color: rgba(255,255,255,.5);
}
.sidebar.collapsed .sidebar-user-info { display: none; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: var(--transition-slow);
}

.main-content.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed);
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: var(--shadow-xs);
}

.topbar-toggle {
  width: 36px; height: 36px;
  border: none;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 16px;
  color: var(--gray-700);
  transition: var(--transition);
}
.topbar-toggle:hover { background: var(--primary-light); color: var(--primary); }

.topbar-breadcrumb { flex: 1; }
.topbar-breadcrumb .breadcrumb { margin: 0; font-size: 13px; }
.topbar-breadcrumb .breadcrumb-item + .breadcrumb-item::before { color: var(--gray-400); }
.topbar-breadcrumb .breadcrumb-item a { color: var(--primary); }
.topbar-breadcrumb .breadcrumb-item.active { color: var(--gray-600); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.topbar-btn {
  width: 36px; height: 36px;
  border: none;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 16px;
  color: var(--gray-700);
  transition: var(--transition);
  position: relative;
  text-decoration: none;
}
.topbar-btn:hover { background: var(--primary-light); color: var(--primary); }

.topbar-badge {
  position: absolute;
  top: 4px; right: 4px;
  width: 16px; height: 16px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}

/* ============================================================
   PAGE CONTENT
   ============================================================ */
.page-content {
  padding: 24px;
  flex: 1;
}

/* Page Header */
.page-header {
  background: var(--gradient);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-navy);
  position: relative;
  overflow: hidden;
}

.page-header::before {
  content: '';
  position: absolute;
  top: -30px; right: -30px;
  width: 180px; height: 180px;
  background: rgba(255,255,255,.05);
  border-radius: 50%;
}
.page-header::after {
  content: '';
  position: absolute;
  bottom: -50px; right: 80px;
  width: 120px; height: 120px;
  background: rgba(201,168,76,.12);
  border-radius: 50%;
}

.page-header-left { position: relative; z-index: 1; }
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 4px;
}
.page-subtitle { color: rgba(255,255,255,.75); font-size: 14px; margin: 0; }

.page-header-actions { position: relative; z-index: 1; display: flex; gap: 8px; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--card-bg);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow); }

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--gray-200);
  padding: 16px 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-body { padding: 20px; }

/* ============================================================
   KPI CARDS
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  cursor: default;
  border-left: 4px solid transparent;
}
.kpi-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }

.kpi-card::after {
  content: '';
  position: absolute;
  bottom: 0; right: 0;
  width: 80px; height: 80px;
  border-radius: 50% 0 0 0;
  opacity: .06;
}

.kpi-card.kpi-primary::after { background: var(--primary); }
.kpi-card.kpi-warning::after { background: var(--warning); }
.kpi-card.kpi-success::after { background: var(--success); }
.kpi-card.kpi-danger::after  { background: var(--danger); }
.kpi-card.kpi-gold::after    { background: var(--accent); }

.kpi-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.kpi-primary .kpi-icon { background: var(--primary-light); color: var(--primary); }
.kpi-warning .kpi-icon { background: #fff8e6; color: #d4811a; }
.kpi-success .kpi-icon { background: #e9f7ef; color: var(--success); }
.kpi-danger  .kpi-icon { background: #fdecea; color: var(--danger); }
.kpi-gold    .kpi-icon { background: var(--accent-light); color: var(--accent-dark); }
.kpi-info    .kpi-icon { background: #e8f6fd; color: #0a7cad; }

.kpi-body { flex: 1; min-width: 0; }
.kpi-value {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
  color: var(--gray-900);
  margin-bottom: 4px;
}
.kpi-label { font-size: 13px; color: var(--gray-600); font-weight: 500; }
.kpi-delta { font-size: 12px; margin-top: 4px; }
.kpi-delta.up   { color: var(--success); }
.kpi-delta.down { color: var(--danger); }

/* ============================================================
   TABLES
   ============================================================ */
.table-card { border-radius: var(--radius-lg); overflow-x: auto; -webkit-overflow-scrolling: touch; box-shadow: var(--shadow-sm); }

.table { margin: 0; font-size: 14px; }
.table thead th {
  background: var(--gray-50);
  color: var(--gray-700);
  font-weight: 600;
  font-size: 13px;
  border-top: none;
  padding: 12px 16px;
  white-space: nowrap;
}
.table tbody td { padding: 13px 16px; vertical-align: middle; }
.table tbody tr:hover { background: var(--gray-50); }

/* ============================================================
   BADGES
   ============================================================ */
.badge { font-weight: 600; letter-spacing: .02em; padding: 4px 10px; font-size: 12px; }
.badge-navy  { background: var(--primary); color: #fff; }
.badge-gold  { background: var(--accent); color: #fff; }
.badge-blue  { background: #1a6faa; color: #fff; }
.badge-teal  { background: #0d8a6f; color: #fff; }

/* ============================================================
   FORMS
   ============================================================ */
.form-label { font-weight: 600; font-size: 14px; color: var(--gray-700); margin-bottom: 6px; }
.form-control, .form-select {
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  transition: var(--transition);
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,58,95,.12);
  outline: none;
}
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--danger); }
.invalid-feedback { font-size: 12.5px; }

/* Required asterisk */
.form-label.required::after { content: ' *'; color: var(--danger); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  font-family: 'Sarabun', sans-serif;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-gold,
.btn-accent {
  background: var(--gradient-gold);
  border: none;
  color: #fff;
  box-shadow: var(--shadow-gold);
}
.btn-gold:hover,
.btn-accent:hover { opacity: .9; color: #fff; }

.btn-outline-primary {
  border-color: var(--primary);
  color: var(--primary);
}
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }

/* ============================================================
   MODALS
   ============================================================ */
.modal-content {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.modal-header {
  background: var(--gradient);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 18px 24px;
}
.modal-header .modal-title { color: #fff; font-weight: 700; }
.modal-header .btn-close { filter: brightness(0) invert(1); opacity: .8; }

/* ============================================================
   ALERTS & TOAST
   ============================================================ */
.toast-container { z-index: 9999; }

/* ============================================================
   STATUS TIMELINE
   ============================================================ */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 10px; top: 0; bottom: 0;
  width: 2px;
  background: var(--gray-200);
}
.timeline-item {
  position: relative;
  padding-bottom: 20px;
}
.timeline-dot {
  position: absolute;
  left: -22px; top: 4px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--primary);
}
.timeline-dot.success { background: var(--success); box-shadow: 0 0 0 2px var(--success); }
.timeline-dot.warning { background: var(--warning); box-shadow: 0 0 0 2px var(--warning); }
.timeline-dot.danger  { background: var(--danger);  box-shadow: 0 0 0 2px var(--danger);  }
.timeline-time { font-size: 12px; color: var(--gray-500); margin-bottom: 2px; }
.timeline-text { font-size: 14px; }
.timeline-user { font-size: 13px; color: var(--gray-600); }

/* ============================================================
   DOCUMENT STAMP PREVIEW
   ============================================================ */
.stamp-box {
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: rgba(30,58,95,.04);
  font-size: 13px;
  line-height: 1.7;
  font-weight: 500;
  color: var(--primary);
  display: inline-block;
}
.stamp-box strong { font-size: 14px; display: block; margin-bottom: 2px; }

/* ============================================================
   ANNOTATION BOX (เกษียณหนังสือ)
   ============================================================ */
.annotation-box {
  border: 1.5px dashed var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: var(--accent-light);
  position: relative;
}
.annotation-box-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-dark);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 8px;
}

/* ============================================================
   URGENCY BANNER
   ============================================================ */
.urgency-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
}
.urgency-banner.urgent      { background: #fff8e6; color: #d4811a; border: 1px solid #ffc107; }
.urgency-banner.very_urgent { background: #fdecea; color: #b71c1c; border: 1px solid #dc3545; }

/* ============================================================
   FILE DROP ZONE
   ============================================================ */
.dropzone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--gray-50);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.dropzone-icon { font-size: 40px; color: var(--gray-400); margin-bottom: 8px; }
.dropzone-text { font-size: 14px; color: var(--gray-600); }
.dropzone-hint { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-500);
}
.empty-state-icon { font-size: 56px; opacity: .35; margin-bottom: 12px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--gray-700); margin-bottom: 8px; }
.empty-state-text  { font-size: 14px; }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination .page-link {
  color: var(--primary);
  border-radius: var(--radius-xs) !important;
  margin: 0 2px;
  border-color: var(--gray-300);
  font-size: 13.5px;
}
.pagination .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
}
.pagination .page-link:hover { background: var(--primary-light); }

/* ============================================================
   NOTIFICATION DROPDOWN — class แทน inline style
   ============================================================ */
.notif-dropdown {
  width: 340px;
  max-height: 420px;
  overflow-y: auto;
}

/* ============================================================
   RESPONSIVE — Mobile-First (4 Breakpoints)
   ============================================================ */

/* ── ① Tablet landscape (≤991.98px) ── */
@media (max-width: 991.98px) {
  /* Sidebar → overlay */
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main-content { margin-left: 0 !important; }

  /* Page content */
  .page-content { padding: 16px; }

  /* Page header: stack title + actions */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 18px 20px;
    gap: 12px;
  }
  .page-header-actions { width: 100%; flex-wrap: wrap; }

  /* KPI: 2 columns */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }

  /* Cards: tighter padding */
  .card-header { padding: 14px 16px; }
  .card-body   { padding: 16px; }

  /* Notification */
  .notif-dropdown { width: 300px !important; max-height: 380px; }
}

/* ── ② Tablet portrait / large phone (≤767.98px) ── */
@media (max-width: 767.98px) {
  /* Topbar */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-actions { gap: 4px; }
  .topbar-btn { width: 34px; height: 34px; font-size: 15px; }

  /* Page header */
  .page-header  { padding: 14px 16px; }
  .page-title   { font-size: 1.15rem; }
  .page-subtitle { font-size: 13px; }

  /* KPI */
  .kpi-card  { padding: 14px; gap: 12px; }
  .kpi-icon  { width: 44px; height: 44px; font-size: 18px; }
  .kpi-value { font-size: 1.6rem; }
  .kpi-label { font-size: 12px; }

  /* Cards */
  .card-header { padding: 12px 14px; font-size: 13.5px; }
  .card-body   { padding: 14px; }

  /* Modals */
  .modal-dialog { margin: 8px auto; max-width: calc(100vw - 16px); }
  .modal-header { padding: 14px 18px; }
  .modal-body   { padding: 14px 16px; }
  .modal-footer { padding: 10px 16px; }
}

/* ── ③ Small mobile (≤575.98px) ── */
@media (max-width: 575.98px) {
  /* Layout */
  .page-content { padding: 10px; }

  /* Page header */
  .page-header   { padding: 12px 14px; }
  .page-title    { font-size: 1.05rem; gap: 6px; }
  .page-subtitle { font-size: 12px; }
  .page-header-actions .btn { font-size: 13px; }

  /* KPI: compact 2-column */
  .kpi-grid  { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-card  { padding: 12px 10px; gap: 8px; }
  .kpi-icon  { width: 38px; height: 38px; font-size: 15px; }
  .kpi-value { font-size: 1.35rem; }
  .kpi-label { font-size: 11.5px; }
  .kpi-delta { display: none; }   /* ซ่อน trend บนหน้าจอเล็ก */

  /* Table */
  .table          { font-size: 13px; }
  .table thead th { padding: 9px 11px; font-size: 12px; }
  .table tbody td { padding: 9px 11px; }

  /* Badges */
  .badge { font-size: 11px; padding: 3px 8px; }

  /* Pagination */
  .pagination .page-link { font-size: 12px; padding: 5px 9px; margin: 0 1px; }

  /* Timeline */
  .timeline { padding-left: 22px; }

  /* Forms */
  .form-label { font-size: 13px; }

  /* Modals: full-width on tiny screens */
  .modal-dialog  { margin: 4px; max-width: calc(100vw - 8px); }
  .modal-content { border-radius: var(--radius); }

  /* Notification: near-full-width */
  .notif-dropdown {
    width: min(320px, calc(100vw - 16px)) !important;
    right: 0 !important;
    left: auto !important;
  }
}

/* ── ④ Extra-small (≤380px) — จอเล็กมาก ── */
@media (max-width: 380px) {
  .topbar { padding: 0 8px; gap: 4px; }
  .topbar-btn { width: 30px; height: 30px; font-size: 14px; }
  .page-content { padding: 8px; }
  .kpi-card  { padding: 10px 8px; gap: 6px; }
  .kpi-icon  { width: 32px; height: 32px; font-size: 13px; }
  .kpi-value { font-size: 1.2rem; }
  .kpi-label { font-size: 11px; }
  .page-header { padding: 10px 12px; }
  .page-title  { font-size: 0.95rem; }
}

/* ============================================================
   SIDEBAR OVERLAY (mobile)
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 1039;
}
.sidebar-overlay.show { display: block; }

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.page-loader {
  position: fixed; inset: 0;
  background: #fff;
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  gap: 16px;
}
.page-loader .spinner-border { width: 3rem; height: 3rem; color: var(--primary); }
.page-loader-text { color: var(--gray-600); font-size: 14px; }

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

.fw-semibold { font-weight: 600 !important; }
.fs-13 { font-size: 13px !important; }
.fs-12 { font-size: 12px !important; }

.icon-circle {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.hover-lift { transition: var(--transition); }
.hover-lift:hover { transform: translateY(-3px); box-shadow: var(--shadow); }

.divider-text {
  display: flex; align-items: center; gap: 12px;
  color: var(--gray-500); font-size: 12px;
}
.divider-text::before, .divider-text::after {
  content: ''; flex: 1; height: 1px; background: var(--gray-200);
}

/* ============================================================
   UTILITY HELPERS
   ============================================================ */
.flex-1      { flex: 1 1 0%; }
.min-width-0 { min-width: 0; }

.req::after,
.required::after { content: ' *'; color: var(--bs-danger); }

.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================
   RESPONSIVE UTILITIES
   ============================================================ */

/* ── Table scroll wrapper (ครอบตารางที่ไม่ได้อยู่ใน .table-card) ── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
}
.table-scroll .table { min-width: 560px; }

/* ── Responsive padding helpers ── */
.p-page {
  padding: 24px;
}
@media (max-width: 991.98px) { .p-page { padding: 16px; } }
@media (max-width: 575.98px) { .p-page { padding: 10px; } }

/* ── Hide on mobile, show on desktop ── */
.d-mobile-none { display: block; }
@media (max-width: 575.98px) { .d-mobile-none { display: none !important; } }

/* ── Stack row → column on mobile ── */
.flex-mobile-col { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
@media (max-width: 575.98px) { .flex-mobile-col { flex-direction: column; align-items: stretch; } }

/* ── Full-width button on mobile ── */
@media (max-width: 575.98px) {
  .btn-mobile-block { width: 100%; justify-content: center; }
}

/* ── Truncate text (1 line) with tooltip ── */
.cell-truncate {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: middle;
}
@media (max-width: 767.98px) { .cell-truncate { max-width: 130px; } }
@media (max-width: 575.98px) { .cell-truncate { max-width: 90px; } }

/* ── Responsive filter bar ── */
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar .filter-item {
  flex: 1 1 160px;
  min-width: 120px;
}
@media (max-width: 575.98px) {
  .filter-bar .filter-item { flex: 1 1 100%; }
  .filter-bar .btn { width: 100%; justify-content: center; }
}

/* ── Responsive grid helpers ── */
.grid-2-1 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}
@media (max-width: 991.98px) {
  .grid-2-1 { grid-template-columns: 1fr; gap: 16px; }
}

/* ── Touch-friendly interactive elements ── */
@media (max-width: 991.98px) {
  .btn:not(.btn-sm) { min-height: 38px; }
  .form-control:not(.form-control-sm),
  .form-select:not(.form-select-sm) { min-height: 42px; }
}

/* ── Prevent text overflow in Thai ── */
.thai-wrap {
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: none;
}

/* ── Sticky bottom action bar (mobile) ── */
.action-bar-mobile {
  display: none;
}
@media (max-width: 767.98px) {
  .action-bar-mobile {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #fff;
    border-top: 1px solid var(--gray-200);
    padding: 10px 16px;
    gap: 8px;
    z-index: 1020;
    box-shadow: 0 -4px 16px rgba(0,0,0,.08);
  }
  .action-bar-mobile .btn { flex: 1; justify-content: center; }
  /* เพิ่ม padding-bottom ให้ page-content เพื่อไม่ให้ content ซ่อนใต้ action bar */
  .has-action-bar .page-content { padding-bottom: 72px; }
}
