/* Tajawal font - applied system-wide */
* {
  font-family: 'Tajawal', sans-serif !important;
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem var(--app-primary, #258cfb);
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

/* Card styling - visual distinction */
.card {
  border-radius: 0.5rem;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.08) !important;
}

/* Primary color - يستخدم متغيرات الهوية البصرية */
.bg-primary {
  background: linear-gradient(135deg, var(--app-primary, #0d6efd) 0%, var(--app-primary-dark, #0a58ca) 100%) !important;
}

/* أزرار الحفظ والإضافة - تستخدم لون الأزرار من الهوية البصرية */
.btn-primary {
  --bs-btn-bg: var(--app-button-color, var(--app-primary, #0d6efd)) !important;
  --bs-btn-border-color: var(--app-button-color, var(--app-primary, #0d6efd)) !important;
  --bs-btn-hover-bg: var(--app-button-color-dark, var(--app-primary-dark, #0a58ca)) !important;
  --bs-btn-hover-border-color: var(--app-button-color-dark, var(--app-primary-dark, #0a58ca)) !important;
  --bs-btn-active-bg: var(--app-button-color-dark, var(--app-primary-dark, #0a58ca)) !important;
  --bs-btn-active-border-color: var(--app-button-color-dark, var(--app-primary-dark, #0a58ca)) !important;
  background-color: var(--app-button-color, var(--app-primary, #0d6efd)) !important;
  border-color: var(--app-button-color, var(--app-primary, #0d6efd)) !important;
}
.btn-primary:hover {
  background-color: var(--app-button-color-dark, var(--app-primary-dark, #0a58ca)) !important;
  border-color: var(--app-button-color-dark, var(--app-primary-dark, #0a58ca)) !important;
}

.navbar-brand {
  font-weight: 700;
}

/* Badge styling */
.badge {
  font-weight: 500;
}

/* Table improvements */
.table-hover tbody tr:hover {
  background-color: rgba(var(--app-primary-rgb, 13, 110, 253), 0.05);
}

/* Form placeholder RTL */
.form-control::placeholder {
  text-align: right;
}

.form-select {
  text-align: right;
}

/* Dropdown RTL fix */
.dropdown-menu {
  text-align: right;
}

/* ===== Modals - Mobile ===== */
@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }
  .modal-dialog.modal-lg {
    max-width: calc(100% - 1rem);
  }
  .modal-content {
    border-radius: 0.5rem;
  }
  .modal-body {
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-footer .btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
  }
}

/* ===== Forms - Mobile ===== */
@media (max-width: 575.98px) {
  .form-control, .form-select {
    font-size: 16px;
  }
  .form-control:focus, .form-select:focus {
    font-size: 16px;
  }
  .btn-primary, .btn-secondary, .btn-outline-primary, .btn-outline-secondary {
    min-height: 44px;
    padding: 0.5rem 1rem;
  }
}

/* ===== Org Structure Tree Dropdown ===== */
.org-tree-dropdown .org-tree-toggle {
  cursor: pointer;
}

.org-tree-dropdown .org-tree-display.text-muted {
  color: #6c757d !important;
}

.org-tree-dropdown .org-tree-node-row {
  cursor: default;
}

.org-tree-dropdown .org-tree-expand {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #6c757d;
}

.org-tree-dropdown .org-tree-expand:hover {
  color: var(--app-primary, #0d6efd);
}

.org-tree-dropdown .org-tree-selectable {
  cursor: pointer;
}

.org-tree-dropdown .org-tree-selectable:hover {
  color: var(--app-primary, #0d6efd);
}

.org-tree-dropdown .org-tree-node-row:hover .org-tree-selectable {
  text-decoration: underline;
}

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

.sidebar {
  width: 260px;
  min-width: 260px;
  background: #f8f9fa;
  border-left: 1px solid #dee2e6;
  transition: margin 0.3s ease, min-width 0.3s ease;
  display: flex;
  flex-direction: column;
}

.sidebar.collapsed {
  margin-right: -260px;
  min-width: 0;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid #dee2e6;
  background: white;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: var(--app-primary, #0d6efd);
  font-weight: 700;
  font-size: 1.1rem;
}

.sidebar-brand:hover {
  color: var(--app-primary-dark, #0a58ca);
}

.sidebar-brand-text {
  white-space: nowrap;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

/* تباعد خفيف بين عناصر القائمة الجانبية */
.sidebar-nav .nav-item {
  margin-bottom: 0.35rem;
}

.sidebar-nav .nav-item:last-child {
  margin-bottom: 0;
}

.sidebar-nav .submenu .nav-item {
  margin-bottom: 0.25rem;
}

.sidebar-nav .submenu .nav-item:last-child {
  margin-bottom: 0;
}

.sidebar-nav .nav-link {
  color: #212529;
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  margin: 0 0.5rem;
  display: flex;
  align-items: center;
  position: relative;
  transition: all 0.25s ease;
}

.sidebar-nav .nav-link:hover {
  background: rgba(var(--app-primary-rgb, 13, 110, 253), 0.08);
  color: var(--app-primary, #0d6efd);
}

/* تمييز بصري إبداعي للعنصر المحدد في القائمة الجانبية */
.sidebar-nav .nav-link.active {
  background: linear-gradient(270deg, rgba(var(--app-primary-rgb, 13, 110, 253), 0.18) 0%, rgba(var(--app-primary-rgb, 13, 110, 253), 0.08) 100%);
  color: var(--app-primary, #0d6efd);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(var(--app-primary-rgb, 13, 110, 253), 0.15);
}

/* شريط تأشير عمودي مميز على الحافة المواجهة للمحتوى (RTL) */
.sidebar-nav .nav-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 70%;
  min-height: 24px;
  background: linear-gradient(180deg, var(--app-primary, #0d6efd) 0%, var(--app-primary-dark, #0a58ca) 100%);
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 12px rgba(var(--app-primary-rgb, 13, 110, 253), 0.4);
}

/* تمييز الأيقونة في العنصر النشط */
.sidebar-nav .nav-link.active i {
  color: var(--app-primary, #0d6efd);
  background: rgba(var(--app-primary-rgb, 13, 110, 253), 0.12);
  padding: 0.35rem;
  border-radius: 0.4rem;
  transition: all 0.25s ease;
}

.sidebar-nav .submenu .nav-link {
  padding: 0.5rem 1rem 0.5rem 2rem;
  font-size: 0.9rem;
}

/* شريط أرفع للعناصر الفرعية النشطة */
.sidebar-nav .submenu .nav-link.active::before {
  height: 60%;
  width: 3px;
}

.sidebar-nav .collapse-icon {
  transition: transform 0.2s;
}

.sidebar-nav .nav-link[aria-expanded="true"] .collapse-icon {
  transform: rotate(180deg);
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: white;
  border-bottom: 1px solid #dee2e6;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.sidebar-toggle {
  color: #495057;
  padding: 0.25rem 0.5rem;
}

.sidebar-toggle:hover {
  color: var(--app-primary, #0d6efd);
}

.topbar-spacer {
  flex: 1;
}

.main-content {
  flex: 1;
  padding: 1rem;
}

@media (min-width: 768px) {
  .main-content {
    padding: 1.25rem;
  }
}

@media (min-width: 992px) {
  .main-content {
    padding: 1.5rem;
  }
}

.main-footer {
  padding: 0.75rem 1.5rem;
  background: #f8f9fa;
  border-top: 1px solid #dee2e6;
  text-align: center;
  font-size: 0.875rem;
  color: #6c757d;
}

/* Sidebar backdrop - للجوال والتابلت */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1049;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.show {
  display: block;
  opacity: 1;
}

@media (max-width: 991.98px) {
  .sidebar-backdrop.show {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    z-index: 1050;
    margin-right: 0;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    width: 260px;
  }

  .sidebar.collapsed {
    margin-right: -260px;
  }

  .sidebar-toggle {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ===== Tasks List - Mobile Card Layout ===== */
.tasks-list-mobile .task-card-mobile {
  transition: background-color 0.2s ease;
}
.tasks-list-mobile .task-card-mobile:active {
  background-color: rgba(var(--app-primary-rgb, 13, 110, 253), 0.05);
}
.tasks-list-mobile .btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===== Topbar - Mobile ===== */
@media (max-width: 575.98px) {
  .topbar { padding: 0.5rem 0.75rem; }
  .topbar-user-link { min-height: 44px; padding: 0.5rem; }
}

@media (min-width: 576px) {
  .topbar-username { max-width: 150px; }
}

@media (min-width: 768px) {
  .topbar-username { max-width: 200px; }
}

/* ===== Tasks View Tabs - Mobile ===== */
.tasks-view-tabs {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.tasks-view-tabs .nav-item { flex-shrink: 0; }
.tasks-view-tabs .nav-link { white-space: nowrap; }

/* ===== Kanban Board ===== */
.kanban-board { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.kanban-column { min-width: 180px; }
@media (max-width: 767.98px) {
  .kanban-board .row { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -0.5rem; padding: 0 0.5rem; }
  .kanban-board .col-12 { flex: 0 0 85%; max-width: 85%; min-width: 260px; }
}
.kanban-card.dragging { opacity: 0.5; }
.kanban-cards { min-height: 60px; }
.kanban-cards.drag-over { background: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.15); border-radius: 0.5rem; border: 2px dashed var(--bs-primary, #0d6efd); }
.kanban-card { cursor: grab; }
.kanban-card:active { cursor: grabbing; }
.kanban-card[draggable="false"] { cursor: default; }
.kanban-mobile-move .btn { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }

/* ===== Print - إخفاء عناصر الواجهة عند الطباعة ===== */
@media print {
  .sidebar, .sidebar-backdrop, .topbar, .main-footer { display: none !important; }
  .app-wrapper { display: block !important; }
  .main-wrapper { flex: none !important; }
  .main-content { padding: 0 !important; }
  body { margin-bottom: 0 !important; background: #fff !important; }
}
