/* Modal component styles - shared across app */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 39, 0.5);
  z-index: 100;
  animation: modalFadeIn 0.2s ease;
  padding: 16px;
}

.modal {
  @apply rounded-lg shadow-xl w-full box-border;
  font-family: var(--app-font);
  /* Đồng bộ font với hệ thống */
  background: #ffffff;
  width: 100%;
  margin: auto;
  /* Đảm bảo modal centered */
  position: relative;
  /* Để các phần tử con có thể positioned */
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15), 0 8px 16px rgba(0, 0, 0, 0.1);
  animation: modalSlideUp 0.3s ease;
  max-height: 98vh;
  overflow-y: auto;
}

.modal-sm {
  max-width: 480px;
}

.modal-md {
  max-width: 800px;
}

.modal-lg {
  max-width: 1100px;
}

.modal-xl {
  max-width: 1400px;
}

.modal-header {
  @apply flex items-center justify-between px-5 py-3 border-b border-gray-200;
  gap: 16px;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.modal-body {
  @apply px-5 py-4 overflow-y-auto;
  max-height: calc(98vh - 120px);
}

.modal-footer {
  @apply px-5 py-3 border-t border-gray-200 flex items-center justify-end gap-3 bg-white;
  position: sticky;
  bottom: 0;
}

.modal-close {
  @apply cursor-pointer text-2xl leading-none;
  color: var(--gray-400);
  background: transparent;
  border: none;
  padding: 0;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.modal-close:hover {
  color: var(--primary-500);
  background-color: var(--primary-50);
}

/* Animations */
@keyframes modalFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modalSlideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* small accessibility helpers */
.modal[role="dialog"] {
  outline: none;
}

.modal-overlay.show {
  display: flex;
}

/* Modal variants - Compact cho confirmation dialogs */
.modal.compact {
  max-width: 420px;
}

.modal.compact .modal-header {
  padding: 16px 20px;
}

.modal.compact .modal-body {
  padding: 16px 20px;
}

.modal.compact .modal-footer {
  padding: 12px 20px 16px 20px;
}

/* Modal Icon Styles - cho alert/confirmation modals */
.modal-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 18px;
  margin-right: 12px;
  flex-shrink: 0;
}

.modal-icon.info {
  background: var(--primary-50);
  color: var(--primary-600);
  border: 1px solid var(--primary-200);
}

.modal-icon.success {
  background: var(--success-50);
  color: var(--success-600);
  border: 1px solid var(--success-100);
}

.modal-icon.warning {
  background: var(--warning-50);
  color: var(--warning-600);
  border: 1px solid var(--warning-100);
}

.modal-icon.error {
  background: var(--error-50);
  color: var(--error-600);
  border: 1px solid var(--error-100);
}

/* Modal Header với icon alignment */
.modal-header.with-icon {
  align-items: center;
}

.modal-header.with-icon h3 {
  display: flex;
  align-items: center;
}

/* Form Validation Styles */
.input-invalid {
  border-color: var(--error-500) !important;
  box-shadow: 0 0 0 3px var(--error-100) !important;
}

.field-error {
  color: var(--error-600);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 4px;
}

.form-error {
  background: var(--error-50);
  border: 1px solid var(--error-100);
  color: var(--error-600);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 16px;
}

/* ============================================
   NOTIFICATION / TOAST CONTAINER
   ============================================ */
.notification-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  max-width: 400px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.notification {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  border-left: 4px solid;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: notificationSlideIn 0.3s ease-out forwards;
  pointer-events: auto;
  font-size: 14px;
  line-height: 1.5;
  max-width: 400px;
  word-wrap: break-word;
}

@keyframes notificationSlideIn {
  from {
    opacity: 0;
    transform: translateX(400px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes notificationSlideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }

  to {
    opacity: 0;
    transform: translateX(400px);
  }
}

.notification.closing {
  animation: notificationSlideOut 0.3s ease-in forwards;
}

/* Notification variants */
.notification.success {
  border-left-color: var(--success-500);
  background: var(--success-50);
  color: var(--success-700);
}

.notification.error {
  border-left-color: var(--error-500);
  background: var(--error-50);
  color: var(--error-700);
}

.notification.warning {
  border-left-color: var(--warning-500);
  background: var(--warning-50);
  color: var(--warning-700);
}

.notification.info {
  border-left-color: var(--primary-500);
  background: var(--primary-50);
  color: var(--primary-700);
}

.notification-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: bold;
}

.notification.success .notification-icon::before {
  content: '✓';
  color: var(--success-500);
  font-size: 16px;
}

.notification.error .notification-icon::before {
  content: '✕';
  color: var(--error-500);
  font-size: 14px;
}

.notification.warning .notification-icon::before {
  content: '⚠';
  color: var(--warning-500);
  font-size: 14px;
}

.notification.info .notification-icon::before {
  content: 'ℹ';
  color: var(--primary-500);
  font-size: 14px;
}

.notification-content {
  flex: 1;
  word-break: break-word;
}

.notification-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.notification-message {
  font-size: 13px;
  opacity: 0.9;
}

.notification-close {
  background: none;
  border: none;
  padding: 0;
  margin-left: 8px;
  cursor: pointer;
  font-size: 18px;
  color: currentColor;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.notification-close:hover {
  opacity: 1;
}

/* Sync modal - flex column layout with scrollable table */
.sync-modal {
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  overflow: hidden;
  max-height: 90vh;
}

.sync-modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0 24px;
}

/* ============================================
   SYNC PROGRESS MODAL
   ============================================ */
.sync-spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border: 4px solid var(--primary-100);
  border-top: 4px solid var(--primary-500);
  border-radius: 50%;
  animation: syncSpin 0.8s linear infinite;
}

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

.sync-spinner-sm {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 2.5px solid var(--primary-100);
  border-top: 2.5px solid var(--primary-500);
  border-radius: 50%;
  animation: syncSpin 0.8s linear infinite;
}

.sync-progress-bar {
  width: 100%;
  height: 8px;
  background: var(--primary-100);
  border-radius: 4px;
  overflow: hidden;
}

.sync-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-400), var(--primary-600));
  border-radius: 4px;
  transition: width 0.5s ease;
}

.sync-done-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--success-50);
  color: var(--success-600);
  border-radius: 50%;
  font-size: 28px;
  font-weight: bold;
}

/* Responsive notifications */
@media (max-width: 640px) {
  .notification-container {
    left: 10px;
    right: 10px;
    max-width: none;
  }

  .notification {
    max-width: 100%;
  }
}

/* Loại bỏ margin-bottom của form-group cuối trong modal task */
#addTaskForm .modal-form-grid .form-group:last-child,
#editTaskForm .modal-form-grid .form-group:last-child {
  margin-bottom: 0 !important;
}