/* Layer system for better cascade control */
@layer reset, base, components, utilities;

@layer reset {
  .explorer-row *,
  .modal *,
  .upload-progress-panel * {
    box-sizing: border-box;
  }
}

/* Error toast component */
@layer components {
.error-toast {
  position: fixed;
  top: calc(var(--header) + 20px);
  right: 20px;
  max-width: 400px;
  background: var(--card);
  border: 2px solid var(--danger);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
  z-index: 10000;
}

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

.error-toast-content {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.error-toast-content svg {
  flex-shrink: 0;
  color: var(--danger);
}

.error-toast-content > div {
  flex: 1;
  min-width: 0;
}

.error-toast-content strong {
  display: block;
  color: var(--danger);
  font-size: 15px;
  margin-bottom: 4px;
}

.error-toast-content p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.error-toast-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.error-toast-close:hover {
  background: var(--paper-deep);
  color: var(--ink);
}

/* Global loader */
.global-loader {
  position: fixed;
  inset: 0;
  background: rgba(244, 239, 230, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 9999;
}

.global-loader.show {
  opacity: 1;
  pointer-events: auto;
}

.loader-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.loader-spinner svg {
  flex-shrink: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Upload progress panel */
.upload-progress-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 360px;
  max-height: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 1000;
}

.upload-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-deep);
}

.upload-progress-header strong {
  font-size: 15px;
  color: var(--ink);
}

.upload-progress-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.upload-progress-close:hover {
  background: var(--line);
}

.upload-progress-list {
  max-height: 300px;
  overflow-y: auto;
  padding: 12px;
}

.upload-progress-item {
  padding: 12px;
  background: var(--paper);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.upload-progress-item:last-child {
  margin-bottom: 0;
}

.upload-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.upload-progress-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--ink);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-progress-stats {
  font-size: 12px;
  color: var(--muted);
  margin-left: 8px;
  white-space: nowrap;
}

.upload-progress-bar {
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  background: var(--teal);
  transition: width 0.3s ease;
}

/* Bulk actions bar */
.bulk-actions-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--teal-deep);
  color: white;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  z-index: 100;
}

.bulk-actions-info strong {
  font-size: 15px;
}

.bulk-actions-buttons {
  display: flex;
  gap: 12px;
}

.bulk-actions-buttons .btn {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.bulk-actions-buttons .btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.bulk-actions-buttons .btn-danger {
  background: var(--danger);
  border-color: var(--danger);
}

.bulk-actions-buttons .btn-danger:hover {
  background: #991b1b;
}

/* Modal improvements */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 10000;
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 38, 58, 0.6);
  backdrop-filter: blur(3px);
}

.modal-dialog {
  position: relative;
  width: 90%;
  max-width: 900px;
  max-height: 90vh;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
}

.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.modal-close:hover {
  background: var(--paper-deep);
  color: var(--ink);
}

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

.preview-content {
  min-height: 400px;
}

.preview-loading,
.preview-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  gap: 16px;
  text-align: center;
}

.preview-loading svg,
.preview-error svg {
  color: var(--teal);
}

.preview-error svg {
  color: var(--danger);
}

.preview-error p {
  margin: 0;
  color: var(--ink-soft);
}

.preview-error strong {
  color: var(--danger);
  font-size: 18px;
}

.docx-preview {
  font-family: var(--font);
  line-height: 1.6;
  color: var(--ink);
}

.docx-preview p {
  margin: 0 0 1em;
}

.docx-preview h1,
.docx-preview h2,
.docx-preview h3 {
  margin: 1.5em 0 0.5em;
  font-family: var(--serif);
  color: var(--ink);
}

.image-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}

.image-preview img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.pdf-preview iframe {
  width: 100%;
  height: 600px;
  border: none;
  border-radius: var(--radius-sm);
}

/* Drag and drop */
.drag-over {
  position: relative;
}

.drag-over::after {
  content: "Thả file vào đây để tải lên";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 92, 86, 0.05);
  border: 3px dashed var(--teal);
  border-radius: var(--radius);
  font-weight: 600;
  color: var(--teal);
  font-size: 18px;
  z-index: 10;
}

/* Responsive */
@media (max-width: 768px) {
  .error-toast {
    left: 12px;
    right: 12px;
    max-width: none;
  }
  
  .upload-progress-panel {
    left: 12px;
    right: 12px;
    width: auto;
  }
  
  .bulk-actions-bar {
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }
  
  .bulk-actions-buttons {
    width: 100%;
    justify-content: stretch;
  }
  
  .bulk-actions-buttons .btn {
    flex: 1;
  }
  
  .modal-dialog {
    width: 95%;
    max-height: 95vh;
  }
}

/* Container queries - responsive theo container thay vì viewport */
@container explorer (max-width: 600px) {
  .explorer-row {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .explorer-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast support */
@media (prefers-contrast: high) {
  .error-toast {
    border-width: 3px;
  }
  
  .btn {
    border: 2px solid currentColor;
  }
}

/* Focus visible improvements */
@layer utilities {
  *:focus-visible {
    outline: 3px solid var(--teal);
    outline-offset: 2px;
    border-radius: 4px;
  }
  
  .btn:focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
  }
  
  /* Skeleton loading */
  @keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: 200px 0; }
  }
  
  .skeleton {
    background: linear-gradient(
      90deg,
      var(--paper-deep) 0%,
      var(--paper) 50%,
      var(--paper-deep) 100%
    );
    background-size: 400px 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: 4px;
    height: 16px;
    margin-bottom: 8px;
  }
  
  .skeleton-line {
    height: 12px;
    background: linear-gradient(
      90deg,
      var(--paper-deep) 0%,
      var(--paper) 50%,
      var(--paper-deep) 100%
    );
    background-size: 400px 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: 4px;
    margin-bottom: 8px;
  }
  
  .skeleton-line.wide { width: 100%; }
  .skeleton-line.medium { width: 70%; }
  .skeleton-line.narrow { width: 40%; }
}

/* Update notification */
.update-notification {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--teal-deep);
  color: white;
  padding: 16px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  animation: slideUp 0.3s ease;
}

.update-notification-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.update-notification-content strong {
  font-size: 15px;
}

.update-notification-content .btn {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.update-notification-content .btn-primary {
  background: var(--gold);
  border-color: var(--gold);
}

.update-notification-content .btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

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

/* Print styles */
@media print {
  .upload-progress-panel,
  .bulk-actions-bar,
  .error-toast,
  .modal,
  .global-loader {
    display: none !important;
  }
  
  body {
    background: white;
  }
  
  .explorer-row {
    page-break-inside: avoid;
  }
}


} /* End @layer components */
