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

:root {
  --primary: #7C3AED;
  --primary-dark: #5B21B6;
  --primary-darker: #4C1D95;
  --primary-light: #EDE9FE;
  --primary-lighter: #F5F3FF;
  --secondary: #A78BFA;
  --accent: #DDD6FE;
  --text-primary: #1E1B4B;
  --text-secondary: #4B5563;
  --text-muted: #9CA3AF;
  --bg: #F8F7FF;
  --bg-white: #FFFFFF;
  --border: #E5E7EB;
  --border-light: #F3F4F6;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow: 0 4px 6px rgba(124,58,237,.1), 0 1px 3px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px rgba(124,58,237,.15), 0 4px 6px rgba(0,0,0,.05);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --transition: .2s ease;
}

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  font-size: 15px;
}

/* ===== LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 260px;
  background: linear-gradient(180deg, var(--primary-darker) 0%, var(--primary-dark) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 200;
  transition: transform var(--transition);
  overflow: hidden;
}

.sidebar-brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand-icon {
  width: 42px; height: 42px;
  background: rgba(255,255,255,.15);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.sidebar-logo {
  width: 48px; height: 48px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 50%;
  background: #fff;
  padding: 2px;
}

.sidebar-brand-text h1 { font-size: .95rem; font-weight: 700; line-height: 1.3; }
.sidebar-brand-text p { font-size: .7rem; color: rgba(255,255,255,.55); margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 14px 10px; overflow-y: auto; }

.nav-section { margin-bottom: 6px; }
.nav-section + .nav-section {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.nav-section-label {
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: rgba(255,255,255,.38);
  padding: 0 12px;
  margin-bottom: 6px;
  font-weight: 700;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.62);
  cursor: pointer;
  transition: all var(--transition);
  font-size: .875rem;
  margin-bottom: 1px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  text-decoration: none;
  position: relative;
}

.nav-item:hover { background: rgba(255,255,255,.09); color: rgba(255,255,255,.92); }
.nav-item.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 18%; bottom: 18%;
  width: 3px;
  background: rgba(255,255,255,.75);
  border-radius: 0 3px 3px 0;
}
.nav-item .ni {
  font-size: .92rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: .7;
}
.nav-item:hover .ni, .nav-item.active .ni { opacity: 1; }

.sidebar-footer {
  padding: 12px 10px 14px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.08);
}

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

.user-info-text { flex: 1; min-width: 0; }
.user-name { font-weight: 600; color: #fff; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role-text { font-size: .68rem; color: rgba(255,255,255,.45); }

.logout-btn {
  width: 28px; height: 28px;
  background: rgba(255,255,255,.1);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: rgba(255,255,255,.6);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.logout-btn:hover { background: rgba(255,0,0,.25); color: #fff; }

.settings-btn {
  width: 28px; height: 28px;
  background: rgba(255,255,255,.1);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: rgba(255,255,255,.6);
  font-size: .95rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
  text-decoration: none;
}
.settings-btn:hover { background: rgba(255,255,255,.22); color: #fff; }
.user-card-btns { display: flex; gap: 4px; flex-shrink: 0; }

/* ===== MAIN CONTENT ===== */
.main-content { margin-left: 260px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.topbar-subtitle { font-size: .8rem; color: var(--text-muted); }

.hamburger {
  display: none;
  width: 38px; height: 38px;
  background: none; border: none; cursor: pointer;
  flex-direction: column; gap: 5px;
  align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  padding: 8px;
}
.hamburger span { display: block; width: 18px; height: 2px; background: var(--text-secondary); border-radius: 2px; }

.page-content { flex: 1; padding: 24px; }

.site-footer {
  margin-top: 32px;
  padding: 16px 0 4px;
  border-top: 1px solid var(--border-light);
  text-align: center;
  font-size: .75rem;
  color: var(--text-muted);
  line-height: 1.8;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-white);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
}

.card-title { font-size: .95rem; font-weight: 700; }
.card-body { padding: 20px 22px; }

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

.stat-card {
  background: var(--bg-white);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: box-shadow var(--transition), transform var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

.stat-icon {
  width: 50px; height: 50px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; flex-shrink: 0;
}
.stat-icon.purple { background: var(--primary-light); }
.stat-icon.green { background: #D1FAE5; }
.stat-icon.orange { background: #FEF3C7; }
.stat-icon.blue { background: #DBEAFE; }

.stat-value { font-size: 1.7rem; font-weight: 800; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: 3px; }

/* ===== TABLE ===== */
.table-container { overflow-x: auto; border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; font-size: .855rem; }

thead th {
  background: var(--primary-lighter);
  color: var(--primary-dark);
  font-weight: 700;
  padding: 11px 14px;
  text-align: left;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border-light); transition: background var(--transition); }
tbody tr:hover { background: var(--primary-lighter); }
tbody tr:last-child { border-bottom: none; }

td { padding: 11px 14px; color: var(--text-secondary); vertical-align: middle; }
td.td-name { color: var(--text-primary); font-weight: 500; }
td.td-id { font-family: monospace; font-size: .82rem; color: var(--text-muted); }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: .83rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 5px;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .88rem;
  color: var(--text-primary);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,.1);
}

select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236B7280' d='M6 8L.804 0h10.392z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  appearance: none;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: 4px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .855rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(124,58,237,.3); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(124,58,237,.4); }

.btn-secondary { background: var(--primary-light); color: var(--primary); }
.btn-secondary:hover { background: var(--accent); }

.btn-danger { background: #FEE2E2; color: var(--danger); }
.btn-danger:hover { background: #FECACA; }

.btn-success { background: #D1FAE5; color: #059669; }
.btn-success:hover { background: #A7F3D0; }

.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-lighter); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--border-light); color: var(--text-primary); }

.btn-sm { padding: 5px 12px; font-size: .78rem; border-radius: 6px; }
.btn-lg { padding: 12px 28px; font-size: .95rem; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: .7rem; font-weight: 600; white-space: nowrap;
}
.badge-purple { background: var(--primary-light); color: var(--primary); }
.badge-green { background: #D1FAE5; color: #059669; }
.badge-orange { background: #FFEDD5; color: #EA580C; }
.badge-red { background: #FEE2E2; color: #DC2626; }
.badge-gray { background: #F3F4F6; color: #6B7280; }
.badge-yellow { background: #FEF3C7; color: #D97706; }

/* ===== ALERTS ===== */
.alert {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: .855rem;
  margin-bottom: 14px;
  display: flex; align-items: flex-start; gap: 9px;
  line-height: 1.5;
}
.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-info { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }
.alert-warning { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(17,24,39,.6);
  z-index: 1000;
  align-items: center; justify-content: center;
  padding: 16px;
  backdrop-filter: blur(3px);
}
.modal-overlay.active { display: flex; animation: fadeIn .2s ease; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}

.modal-title { font-size: .95rem; font-weight: 700; }

.modal-close {
  width: 30px; height: 30px;
  border-radius: 6px;
  background: var(--border-light);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); font-size: .95rem;
  transition: background var(--transition);
}
.modal-close:hover { background: #E5E7EB; color: var(--text-primary); }

.modal-body { padding: 18px 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border-light);
  display: flex; gap: 10px; justify-content: flex-end;
  flex-shrink: 0;
}

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.toolbar-left { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; min-width: 0; }
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.search-wrap::before {
  content: '🔍'; position: absolute;
  left: 11px; top: 50%; transform: translateY(-50%);
  font-size: .78rem; pointer-events: none;
}
.search-wrap input { padding-left: 34px; }

/* ===== PAGINATION ===== */
.pagination {
  display: flex; align-items: center; gap: 5px;
  justify-content: center; padding: 14px 0;
}
.page-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .83rem; color: var(--text-secondary);
  transition: all var(--transition);
  font-family: inherit;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ===== TOAST ===== */
#toast-container {
  position: fixed; bottom: 22px; right: 22px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: .855rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease;
  pointer-events: auto;
  max-width: 320px;
  line-height: 1.5;
}
.toast-success { background: #065F46; color: #fff; }
.toast-error { background: #991B1B; color: #fff; }
.toast-info { background: var(--primary-dark); color: #fff; }
.toast-warning { background: #92400E; color: #fff; }
@keyframes toastIn { from { opacity:0; transform: translateX(14px); } to { opacity:1; transform: translateX(0); } }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-darker) 0%, var(--primary) 55%, #9333EA 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}

.login-box {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px rgba(0,0,0,.22);
  width: 100%; max-width: 400px;
  overflow: hidden;
}

.login-header {
  background: linear-gradient(135deg, var(--primary-darker), var(--primary));
  padding: 30px 28px 24px;
  text-align: center; color: #fff;
}

.login-logo {
  width: 60px; height: 60px;
  background: rgba(255,255,255,.15);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.65rem; margin: 0 auto 14px;
}

.login-header h1 { font-size: 1.15rem; font-weight: 800; margin-bottom: 3px; }
.login-header p { font-size: .78rem; opacity: .7; }

.login-body { padding: 26px 28px 22px; }
.login-footer { padding: 12px 28px 18px; border-top: 1px solid var(--border-light); text-align: center; font-size: .72rem; color: var(--text-muted); }

/* ===== PROFILE CARD (user page) ===== */
.profile-card {
  background: linear-gradient(135deg, var(--primary-darker), var(--primary));
  color: #fff; border-radius: var(--radius-lg);
  padding: 26px; margin-bottom: 20px;
  position: relative; overflow: hidden;
}
.profile-card::before {
  content: ''; position: absolute; top: -40px; right: -40px;
  width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255,255,255,.07);
}
.profile-card::after {
  content: ''; position: absolute; bottom: -50px; left: -20px;
  width: 130px; height: 130px; border-radius: 50%;
  background: rgba(255,255,255,.05);
}
.profile-avatar-lg {
  width: 60px; height: 60px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 800;
  margin-bottom: 12px; position: relative; z-index: 1;
}
.profile-name { font-size: 1.2rem; font-weight: 800; margin-bottom: 2px; position: relative; z-index: 1; }
.profile-meta { font-size: .82rem; opacity: .75; position: relative; z-index: 1; display: flex; flex-direction: column; gap: 2px; }

/* ===== TABS ===== */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--border-light); margin-bottom: 20px; }
.tab-btn {
  padding: 9px 20px; background: none; border: none;
  cursor: pointer; font-family: inherit; font-size: .88rem;
  color: var(--text-muted); border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all var(--transition); font-weight: 500;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== MISC ===== */
.loading { text-align: center; padding: 40px; color: var(--text-muted); }
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--primary-light); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty-state .es-icon { font-size: 2.8rem; margin-bottom: 10px; opacity: .5; }
.empty-state h3 { font-size: .95rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 3px; }
.empty-state p { font-size: .82rem; }

.divider { height: 1px; background: var(--border-light); margin: 18px 0; }

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 14px; } .mt-3 { margin-top: 22px; }
.mb-2 { margin-bottom: 14px; } .mb-3 { margin-bottom: 22px; }
.text-muted { color: var(--text-muted); font-size: .83rem; }
.text-right { text-align: right; }
.w-full { width: 100%; }
.font-bold { font-weight: 700; }

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

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  /* Sidebar */
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .hamburger { display: flex; }

  /* Layout */
  .page-content { padding: 12px; }
  .hide-mobile { display: none !important; }

  /* Topbar */
  .topbar { padding: 0 14px; gap: 8px; }
  .topbar-title { font-size: .9rem; max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Stats */
  .stats-grid { grid-template-columns: repeat(2,1fr); gap: 10px; }
  .stat-card { padding: 14px 12px; gap: 10px; }
  .stat-icon { width: 40px; height: 40px; font-size: 1.1rem; }
  .stat-value { font-size: 1.45rem; }

  /* Cards */
  .card-header { flex-wrap: wrap; gap: 10px; padding: 14px 16px 12px; }
  .card-body { padding: 14px 16px; }

  /* Tables */
  td { padding: 9px 10px; font-size: .82rem; }
  td.td-id { font-size: .75rem; }
  thead th { padding: 9px 10px; font-size: .7rem; }

  /* Toolbar */
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar-left { flex-direction: column; align-items: stretch; }
  .toolbar-right { justify-content: flex-end; }
  .search-wrap { max-width: 100%; min-width: 0; }
  .search-wrap input { width: 100%; }
  .toolbar select, .toolbar .filter-select { width: 100%; min-width: 0; }

  /* Forms */
  .form-row { grid-template-columns: 1fr; }

  /* Buttons — larger touch targets */
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; padding: 6px 12px; }

  /* Modal — slide up from bottom on mobile */
  .modal {
    max-width: 100%; border-radius: var(--radius) var(--radius) 0 0;
    position: fixed; bottom: 0; left: 0; right: 0;
    max-height: 92vh;
  }
  .modal-overlay.active { align-items: flex-end; padding: 0; }

  /* Toast */
  #toast-container { right: 10px; bottom: 10px; left: 10px; }
  .toast { max-width: 100%; }

  /* iOS font-size zoom fix — inputs < 16px trigger zoom on Safari */
  input[type="text"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="email"],
  input[type="number"],
  input[type="date"],
  input[type="url"],
  select,
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .page-content { padding: 10px; }
  .stats-grid { grid-template-columns: repeat(2,1fr); gap: 8px; }
  .stat-value { font-size: 1.3rem; }
  .card-header { padding: 12px 14px 10px; }
  .card-body { padding: 12px 14px; }
  .topbar-title { max-width: 45vw; }
  .login-body { padding: 20px; }
  .login-header { padding: 22px 20px 18px; }

  /* Full-width modals on very small screens */
  .modal { max-height: 95vh; }

  /* Pagination — compact on small screens */
  .page-btn { width: 30px; height: 30px; font-size: .78rem; }
}

/* ===== LINE LIFF / in-app browser ===== */

/* ป้องกัน element ใดๆ ยื่นออกนอก viewport โดยไม่ซ่อนเนื้อหา */
* { max-width: 100%; }
img, video, iframe { max-width: 100%; height: auto; }

/* ตาราง: scroll แนวนอนได้ภายใน container ไม่โดนตัด */
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { min-width: 520px; } /* ตารางยังดูได้ครบ ใน container ที่ scroll ได้ */

/* ป้องกัน text ล้นบนจอแคบ */
td, th { word-break: break-word; white-space: normal; }
td.td-id, thead th { white-space: nowrap; } /* แต่ยังคง nowrap สำหรับ ID / header */

/* ป้องกัน text เล็กเกินบน Android WebView */
@media screen and (max-width: 420px) {
  body { font-size: 14px; }
  .topbar { height: 52px; }
  .page-content { padding: 8px; }
  .stats-grid { gap: 8px; }
  .stat-card { padding: 12px 10px; gap: 8px; }
  .stat-icon { width: 36px; height: 36px; font-size: 1rem; }
  .stat-value { font-size: 1.2rem; }
  .stat-label { font-size: .72rem; }
  .card-header { padding: 10px 12px; }
  .card-body { padding: 10px 12px; }
  .sidebar-brand { padding: 16px 14px 12px; }
}
