/**
 * بوابة رفق | Welfare Gateway  
 * Component Styles
 * ===============
 */

/* ==================== Top Bar ==================== */
.topbar {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-sticky);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--white);
  padding: var(--space-4) 0;
  box-shadow: var(--shadow-md);
}

.topbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.brand {
  flex: 1;
}

.brand-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.5px;
}

.brand-sub {
  font-size: var(--text-sm);
  opacity: 0.9;
  margin-top: var(--space-1);
}

.topbar .actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar .btn {
  background-color: rgba(255, 255, 255, 0.2);
  color: var(--white);
  border-color: rgba(255, 255, 255, 0.3);
}

.topbar .btn:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

/* ==================== Tabs ==================== */
.tabs {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-4) 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--space-6);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.tab:hover {
  color: var(--primary);
  background-color: var(--primary-lightest);
  border-radius: var(--radius) var(--radius) 0 0;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ==================== Dashboard Cards ==================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-6);
  margin-bottom: var(--space-8);
}

.dashboard-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.dashboard-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.card-icon {
  font-size: 3rem;
  margin-bottom: var(--space-3);
}

.card-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--primary);
  margin: var(--space-2) 0;
}

.card-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-change {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-sm);
}

.card-change.positive {
  color: var(--success);
  background-color: var(--success-bg);
}

.card-change.negative {
  color: var(--error);
  background-color: var(--error-bg);
}

/* ==================== Progress Bar ==================== */
.progress-bar {
  width: 100%;
  height: 8px;
  background-color: var(--gray-200);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

/* ==================== Badge ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-primary {
  color: var(--primary);
  background-color: var(--primary-lightest);
}

.badge-success {
  color: var(--success);
  background-color: var(--success-bg);
}

.badge-warning {
  color: var(--warning);
  background-color: var(--warning-bg);
}

.badge-error {
  color: var(--error);
  background-color: var(--error-bg);
}

.badge-info {
  color: var(--info);
  background-color: var(--info-bg);
}

/* ==================== Toast Notifications ==================== */
.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 400px;
}

html[dir="rtl"] .toast-container {
  right: auto;
  left: var(--space-6);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateX(120%);
  opacity: 0;
  transition: all var(--transition-base);
}

html[dir="rtl"] .toast {
  transform: translateX(-120%);
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast.hide {
  transform: translateX(120%);
  opacity: 0;
}

html[dir="rtl"] .toast.hide {
  transform: translateX(-120%);
}

.toast-success {
  border-left: 4px solid var(--success);
}

html[dir="rtl"] .toast-success {
  border-left: none;
  border-right: 4px solid var(--success);
}

.toast-error {
  border-left: 4px solid var(--error);
}

html[dir="rtl"] .toast-error {
  border-left: none;
  border-right: 4px solid var(--error);
}

.toast-warning {
  border-left: 4px solid var(--warning);
}

html[dir="rtl"] .toast-warning {
  border-left: none;
  border-right: 4px solid var(--warning);
}

.toast-info {
  border-left: 4px solid var(--info);
}

html[dir="rtl"] .toast-info {
  border-left: none;
  border-right: 4px solid var(--info);
}

.toast-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  color: currentColor;
}

.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--error); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--info); }

.toast-message {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.toast-close {
  flex-shrink: 0;
  padding: var(--space-1);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.toast-close:hover {
  color: var(--text-primary);
}

/* ==================== Modal ==================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.modal-overlay.show {
  opacity: 1;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9);
  transition: transform var(--transition-base);
}

.modal-overlay.show .modal {
  transform: scale(1);
}

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

.modal-title {
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0;
}

.modal-close {
  padding: var(--space-2);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background-color: var(--gray-100);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-6);
}

.modal-footer {
  padding: var(--space-6);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ==================== Loading Spinner ==================== */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray-300);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner-lg {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

/* ==================== Empty State ==================== */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.empty-state-text {
  font-size: var(--text-base);
  margin-bottom: var(--space-6);
}

/* ==================== Footer ==================== */
.footer {
  background-color: var(--surface);
  border-top: 1px solid var(--border);
  padding: var(--space-8) 0;
  margin-top: var(--space-12);
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  text-align: center;
}

.footer-links {
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
  justify-content: center;
}

.footer-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-link:hover {
  color: var(--primary);
  text-decoration: none;
}

/* ==================== Profile Dropdown ==================== */
.profile-menu-container {
  position: relative;
}

.profile-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 300px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-4);
  z-index: var(--z-dropdown);
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: all var(--transition-base);
}

html[dir="rtl"] .profile-dropdown {
  right: auto;
  left: 0;
}

.profile-dropdown.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.profile-header {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.profile-avatar {
  width: 48px;
  height: 48px;
  background-color: var(--primary-lightest);
  color: var(--primary);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-info {
  flex: 1;
}

.profile-name {
  font-weight: 600;
  color: var(--text-primary);
}

.profile-contact {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.profile-divider {
  height: 1px;
  background-color: var(--border);
  margin: var(--space-3) 0;
}

.profile-detail-item {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) 0;
}

.profile-detail-item svg {
  flex-shrink: 0;
  color: var(--text-secondary);
}

.profile-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
}

.profile-value {
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-weight: 500;
}

.profile-action-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  text-align: start;
}

.profile-action-btn:hover {
  background-color: var(--gray-100);
}

.profile-action-btn.logout-btn {
  color: var(--error);
}

.profile-action-btn.logout-btn:hover {
  background-color: var(--error-bg);
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
  .topbar {
    padding: var(--space-3) 0;
  }

  .brand-title {
    font-size: var(--text-xl);
  }

  .brand-sub {
    display: none;
  }

  .tabs {
    gap: var(--space-1);
  }

  .tab {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
  }

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

  .toast-container {
    top: var(--space-3);
    right: var(--space-3);
    left: var(--space-3);
    max-width: none;
  }

  .profile-dropdown {
    right: auto;
    left: 0;
    width: calc(100vw - var(--space-6));
  }
}

/* ==================== Skeleton Loaders ==================== */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--gray-200) 0%,
    var(--gray-100) 50%,
    var(--gray-200) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

.skeleton-text {
  height: 16px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-sm);
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: var(--space-4);
  border-radius: var(--radius-sm);
}

.skeleton-card {
  height: 200px;
  border-radius: var(--radius-lg);
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==================== Error State ==================== */
.error-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--text-secondary);
}

.error-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.error-state p {
  font-size: var(--text-lg);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

/* ==================== Modal Overlay ==================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-4);
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  position: relative;
  padding: var(--space-8);
  width: 100%;
  animation: slideInUp 0.3s ease-out;
}

.modal-close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  background: rgba(0, 0, 0, 0.1);
  border: none;
  border-radius: var(--radius-full);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* RTL Support for modal close button */
html[dir="rtl"] .modal-close {
  right: auto;
  left: var(--space-4);
}

/* ==================== Microlearning Styles ==================== */
.microlearning-type-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--primary-lightest);
  color: var(--primary-dark);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-4);
}

.scenario-situation {
  background: var(--info-bg);
  border-left: 4px solid var(--info);
  padding: var(--space-4);
  border-radius: var(--radius);
  margin: var(--space-4) 0;
}

html[dir="rtl"] .scenario-situation {
  border-left: none;
  border-right: 4px solid var(--info);
}

.scenario-choices {
  margin: var(--space-6) 0;
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: start;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-lightest);
  transform: translateX(-4px);
}

html[dir="rtl"] .choice-btn:hover:not(:disabled) {
  transform: translateX(4px);
}

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

.choice-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-full);
  font-weight: 600;
  flex-shrink: 0;
}

.choice-text {
  flex: 1;
}

.scenario-feedback {
  padding: var(--space-4);
  border-radius: var(--radius);
  margin: var(--space-4) 0;
}

.scenario-feedback.correct {
  background: var(--success-bg);
  border: 2px solid var(--success);
}

.scenario-feedback.incorrect {
  background: var(--error-bg);
  border: 2px solid var(--error);
}

.feedback-text {
  font-size: var(--text-lg);
  margin-bottom: var(--space-3);
}

.points-earned {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--success);
}

.checklist-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition-base);
}

.checklist-item:hover {
  border-color: var(--primary);
  background: var(--primary-lightest);
}

.checklist-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.check-text {
  flex: 1;
}

.quick-tips {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.tip-item {
  padding: var(--space-3);
  background: var(--gray-100);
  border-radius: var(--radius);
  font-size: var(--text-base);
}

.quick-quiz {
  background: var(--gray-100);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
}

.quiz-question {
  margin: var(--space-4) 0;
}

.quiz-option-btn {
  display: block;
  width: 100%;
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: start;
  transition: all var(--transition-base);
}

.quiz-option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-lightest);
}

.quiz-option-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.infographic-grid {
  margin-top: var(--space-6);
}

.infographic-section {
  text-align: center;
}

.matching-challenge {
  margin: var(--space-4) 0;
}

.match-row {
  transition: all var(--transition-base);
}

.match-row select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  cursor: pointer;
}

.points-award {
  text-align: center;
}

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

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