/* =========================================================
   HRMS Modern Arabic Design System (نظام إدارة الموارد البشرية)
   ========================================================= */

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

:root {
  /* Color Palette */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: rgba(79, 70, 229, 0.12);
  --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  
  --success: #10b981;
  --success-hover: #059669;
  --success-light: rgba(16, 185, 129, 0.12);
  --success-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);

  --warning: #f59e0b;
  --warning-hover: #d97706;
  --warning-light: rgba(245, 158, 11, 0.12);

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: rgba(239, 68, 68, 0.12);

  --info: #06b6d4;
  --info-light: rgba(6, 182, 212, 0.12);

  --purple: #8b5cf6;
  --purple-light: rgba(139, 92, 246, 0.12);

  /* Light Theme Defaults */
  --bg-app: #f8fafc;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #ffffff;
  --bg-modal: #ffffff;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --border-color: #e2e8f0;
  --border-light: #f1f5f9;
  --border-focus: #6366f1;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.25);

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

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* LTR Support for English */
html[dir="ltr"] body {
  direction: ltr;
  text-align: left;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html[dir="ltr"] .main-wrapper {
  margin-right: 0;
  margin-left: 280px;
}

html[dir="ltr"] .sidebar {
  right: auto;
  left: 0;
  border-left: none;
  border-right: 1px solid var(--border-color);
}

html[dir="ltr"] .stat-card::before {
  right: auto;
  left: 0;
  border-radius: 4px 0 0 4px;
}

html[dir="ltr"] .search-box input {
  padding-right: 14px;
  padding-left: 38px;
}

html[dir="ltr"] .search-box .search-icon {
  right: auto;
  left: 12px;
}

html[dir="ltr"] .toast.toast-success { border-right: none; border-left: 4px solid var(--success); }
html[dir="ltr"] .toast.toast-danger { border-right: none; border-left: 4px solid var(--danger); }
html[dir="ltr"] .toast.toast-warning { border-right: none; border-left: 4px solid var(--warning); }
html[dir="ltr"] .toast-container { left: auto; right: 24px; }

html[dir="ltr"] .drawer-content {
  right: auto;
  left: 0;
  border-left: none;
  border-right: 1px solid var(--border-color);
  animation: slideLeft 0.3s ease-out;
}

@keyframes slideLeft {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

@media (max-width: 1024px) {
  html[dir="ltr"] .main-wrapper {
    margin-left: 0;
  }
}

[data-theme='dark'] {
  --bg-app: #090d16;
  --bg-sidebar: #0f172a;
  --bg-card: #131d31;
  --bg-card-hover: #1e293b;
  --bg-input: #1a243a;
  --bg-modal: #131d31;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  
  --border-color: #1e293b;
  --border-light: #182235;
  --border-focus: #818cf8;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 30px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.35);
}

/* Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Cairo', 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  direction: rtl;
  text-align: right;
  min-height: 100vh;
  overflow-x: hidden;
  font-size: 14.5px;
  line-height: 1.6;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-right: 280px;
  transition: margin-right var(--transition-normal);
}

@media (max-width: 1024px) {
  .main-wrapper {
    margin-right: 0;
  }
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-color);
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border-color);
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.brand-info h2 {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.3px;
}

.brand-info p {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.sidebar-nav {
  padding: 18px 14px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-light);
  padding: 12px 14px 6px;
  letter-spacing: 0.5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
}

.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(79, 70, 229, 0.2);
}

.nav-item .nav-badge {
  margin-right: auto;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: var(--bg-card-hover);
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #6366f1, #ec4899);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

/* Navbar */
.navbar {
  height: 70px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title h1 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
}

.page-title p {
  font-size: 12.5px;
  color: var(--text-muted);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  outline: none;
  user-select: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-secondary {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border-color);
}

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
  border-radius: var(--radius-md);
}

/* Cards & Widgets */
.content-body {
  padding: 28px;
  flex: 1;
}

.grid {
  display: grid;
  gap: 20px;
}

.grid-cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid-cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-cols-1 {
  grid-template-columns: 1fr;
}

@media (max-width: 1200px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .grid-cols-4, .grid-cols-3, .grid-cols-2 { grid-template-columns: 1fr; }
  .content-body { padding: 16px; }
  .navbar { padding: 0 16px; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
}

.card-hover:hover {
  box-shadow: var(--shadow-md);
  border-color: rgba(99, 102, 241, 0.3);
  transform: translateY(-2px);
}

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

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Stat Cards */
.stat-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
}

.stat-card.stat-success::before { background: var(--success); }
.stat-card.stat-warning::before { background: var(--warning); }
.stat-card.stat-danger::before { background: var(--danger); }
.stat-card.stat-info::before { background: var(--info); }
.stat-card.stat-purple::before { background: var(--purple); }

.stat-icon-wrapper {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  color: var(--primary);
}

.stat-card.stat-success .stat-icon-wrapper { background: var(--success-light); color: var(--success); }
.stat-card.stat-warning .stat-icon-wrapper { background: var(--warning-light); color: var(--warning); }
.stat-card.stat-danger .stat-icon-wrapper { background: var(--danger-light); color: var(--danger); }
.stat-card.stat-info .stat-icon-wrapper { background: var(--info-light); color: var(--info); }
.stat-card.stat-purple .stat-icon-wrapper { background: var(--purple-light); color: var(--purple); }

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-main);
  margin-top: 6px;
  letter-spacing: -0.5px;
}

.stat-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-sub {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-purple { background: var(--purple-light); color: var(--purple); }
.badge-gray { background: var(--bg-card-hover); color: var(--text-muted); border: 1px solid var(--border-color); }

/* Tables */
.table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 13.5px;
}

.table th {
  background: var(--bg-card-hover);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 12.5px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
  vertical-align: middle;
}

.table tbody tr:hover {
  background-color: rgba(99, 102, 241, 0.03);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* Forms & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-textarea {
  min-height: 85px;
  resize: vertical;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box input {
  padding-right: 38px;
}

.search-box .search-icon {
  position: absolute;
  right: 12px;
  color: var(--text-light);
  pointer-events: none;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: zoomIn 0.25s ease-out;
  overflow: hidden;
}

.modal-content.modal-lg {
  max-width: 880px;
}

.modal-content.modal-xl {
  max-width: 1100px;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: var(--bg-card-hover);
}

/* Drawers */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

.drawer-content {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  width: 100%;
  max-width: 580px;
  background: var(--bg-modal);
  border-left: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
  z-index: 101;
  display: flex;
  flex-direction: column;
  animation: slideRight 0.3s ease-out;
}

/* Tabs & Filter Pills */
.tabs-header {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab-btn {
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

.tab-btn.active {
  color: var(--primary);
  background: var(--primary-light);
}

/* Alerts / Notification Banners */
.alert-box {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13.5px;
  margin-bottom: 18px;
  border: 1px solid transparent;
}

.alert-warning {
  background: var(--warning-light);
  color: #92400e;
  border-color: rgba(245, 158, 11, 0.3);
}

[data-theme='dark'] .alert-warning {
  color: #fde68a;
}

.alert-info {
  background: var(--info-light);
  color: #0e7490;
  border-color: rgba(6, 182, 212, 0.3);
}

[data-theme='dark'] .alert-info {
  color: #a5f3fc;
}

.alert-success {
  background: var(--success-light);
  color: #065f46;
  border-color: rgba(16, 185, 129, 0.3);
}

[data-theme='dark'] .alert-success {
  color: #a7f3d0;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--radius-md);
  background: #0f172a;
  color: #ffffff;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.3s ease-out;
  border: 1px solid rgba(255, 255, 255, 0.1);
  min-width: 280px;
}

.toast.toast-success { border-right: 4px solid var(--success); }
.toast.toast-danger { border-right: 4px solid var(--danger); }
.toast.toast-warning { border-right: 4px solid var(--warning); }

/* Quick Action floating buttons */
.quick-action-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

@keyframes zoomIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Official Print Templates */
@media print {
  body, html {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
  }

  @page {
    margin-bottom: 20mm;
  }

  body::after {
    content: "صادر من برنامج بينو سوفت لإدارة الموارد البشرية";
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 10px;
    color: #64748b;
    padding: 10px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    z-index: 9999;
  }

  html[lang="en"] body::after, html[dir="ltr"] body::after {
    content: "Issued from HRMS Enterprise";
  }

  tr, td, th, .item-row {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .sidebar, .navbar, .btn, .modal-footer, .no-print, .toast-container, .tabs-header {
    display: none !important;
  }

  .main-wrapper {
    margin-right: 0 !important;
    margin-left: 0 !important;
  }

  .content-body, .modal-content, .modal-overlay {
    padding: 0 !important;
    background: #ffffff !important;
    border: none !important;
    box-shadow: none !important;
    position: static !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  .receipt-slip-page {
    page-break-after: always !important;
    break-after: page !important;
    border: 1px solid #cbd5e1 !important;
    margin-bottom: 20px !important;
    padding: 24px !important;
    background: #ffffff !important;
    color: #0f172a !important;
    box-sizing: border-box !important;
  }

  .print-page {
    page-break-after: always !important;
    padding: 20px !important;
  }
}

/* === Permission management === */
.perms-section {
  margin-top: 8px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface, #f8fafc);
}

.perms-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-secondary, #f1f5f9);
  border-bottom: 1px solid var(--border, #e2e8f0);
  flex-wrap: wrap;
}

.perm-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.perm-summary-count {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary, #4f46e5);
  background: color-mix(in srgb, var(--primary, #4f46e5) 12%, #fff);
  border: 1px solid color-mix(in srgb, var(--primary, #4f46e5) 30%, #fff);
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.perms-groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
  padding: 14px 16px;
}

.perm-card {
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  transition: box-shadow 0.15s ease;
}

.perm-card:hover {
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

.perm-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border, #eef2f7);
  background: #fbfcfe;
  flex-wrap: wrap;
}

.perm-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.perm-module-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 800;
  border: 1px solid transparent;
  flex-shrink: 0;
}

.perm-module-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main, #0f172a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.perm-count {
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
}

.perm-card-actions {
  display: flex;
  gap: 6px;
}

.perm-card-actions .btn-xs {
  padding: 3px 8px;
  font-size: 11px;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 2px;
  padding: 8px 10px 10px;
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 7px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease;
}

.perm-item:hover {
  background: #f1f5f9;
}

.perm-item input[name="perm"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.perm-checkbox {
  width: 17px;
  height: 17px;
  border: 2px solid #cbd5e1;
  border-radius: 5px;
  background: #fff;
  position: relative;
  flex-shrink: 0;
  transition: all 0.12s ease;
}

.perm-item input[name="perm"]:checked + .perm-checkbox {
  background: var(--primary, #4f46e5);
  border-color: var(--primary, #4f46e5);
}

.perm-item input[name="perm"]:checked + .perm-checkbox::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.perm-item input[name="perm"]:focus-visible + .perm-checkbox {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary, #4f46e5) 25%, transparent);
}

.perm-label {
  font-size: 12.5px;
  color: var(--text-main, #334155);
  line-height: 1.35;
}

/* ===== Interface polish layer ===== */
.toast-container, .toast { pointer-events: none; }
[data-bino-lab-legacy-blocked]:disabled { opacity: .45; cursor: not-allowed; }
.main-wrapper, .content-body { min-width: 0; max-width: 100vw; }
@media (max-width: 768px) {
  .navbar { height: auto; min-height: 60px; flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .navbar-right { flex: 1 1 100%; min-width: 0; }
  .page-title { min-width: 0; }
  .page-title h1 { font-size: 17px; }
  .page-title p { display: none; }
  .navbar-actions { flex: 1 1 100%; flex-wrap: wrap; min-width: 0; }
  .navbar-actions select, .navbar-actions .form-select { max-width: 100%; min-width: 0; }
  .toast-container { left: 12px; right: 12px; bottom: 12px; }
}

/* ===== Responsive shell: the sidebar becomes an off-canvas drawer on tablets and phones ===== */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-xl); }
  html[dir="ltr"] .sidebar { transform: translateX(-100%); }
  html[dir="ltr"] .sidebar.open { transform: translateX(0); }
  #btn-sidebar-toggle { display: inline-flex !important; }
}
@media (max-width: 768px) {
  .main-wrapper { overflow-x: clip; }
  .content-body div[style*="display:flex"], .content-body div[style*="display: flex"] { flex-wrap: wrap; }
  .content-body select, .content-body input:not([type="checkbox"]):not([type="radio"]) { min-width: 0; max-width: 100%; }
}
@media (max-width: 768px) {
  .content-body div:has(> select.form-select) { flex-wrap: wrap; }
  .content-body select.form-select { min-width: 140px; flex: 1 1 140px; }
}
