/* ============================================
   EDAMA QMS — Animation System
   All animations respect prefers-reduced-motion
   ============================================ */

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

/* === Entrance Animations === */

@keyframes fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scale-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slide-right {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}

[dir="rtl"] .animate-slide-right {
  animation-name: slide-left;
}
@keyframes slide-left {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

/* === Loading === */

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* === Attention === */

@keyframes pulse-subtle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

/* === Utility Classes === */

.animate-fade-up { animation: fade-up 500ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1)) both; }
.animate-fade-in { animation: fade-in 400ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1)) both; }
.animate-scale-in { animation: scale-in 400ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1)) both; }
.animate-slide-right { animation: slide-right 500ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1)) both; }
.animate-float { animation: float 3s ease-in-out infinite; }
.shake { animation: shake 300ms ease; }

/* === Stagger System === */

.stagger > * { animation: fade-up 500ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1)) both; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 60ms; }
.stagger > *:nth-child(3) { animation-delay: 120ms; }
.stagger > *:nth-child(4) { animation-delay: 180ms; }
.stagger > *:nth-child(5) { animation-delay: 240ms; }
.stagger > *:nth-child(6) { animation-delay: 300ms; }
.stagger > *:nth-child(7) { animation-delay: 360ms; }
.stagger > *:nth-child(8) { animation-delay: 420ms; }
.stagger > *:nth-child(9) { animation-delay: 480ms; }
.stagger > *:nth-child(10) { animation-delay: 540ms; }
.stagger > *:nth-child(11) { animation-delay: 600ms; }
.stagger > *:nth-child(12) { animation-delay: 660ms; }

/* === Scroll-Reveal === */

.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 500ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1)), transform 500ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
}
.reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

.reveal-group > .reveal:nth-child(1) { transition-delay: 0ms; }
.reveal-group > .reveal:nth-child(2) { transition-delay: 60ms; }
.reveal-group > .reveal:nth-child(3) { transition-delay: 120ms; }
.reveal-group > .reveal:nth-child(4) { transition-delay: 180ms; }
.reveal-group > .reveal:nth-child(5) { transition-delay: 240ms; }
.reveal-group > .reveal:nth-child(6) { transition-delay: 300ms; }

/* === Loading Skeleton === */

.skeleton {
  background: linear-gradient(90deg, var(--bg-2, #e4edf5) 25%, var(--bg-1, #f0f4f8) 50%, var(--bg-2, #e4edf5) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm, 6px);
  color: transparent !important;
}
.skeleton * { visibility: hidden; }
.skeleton-text { height: 16px; width: 80%; margin-bottom: 8px; }
.skeleton-title { height: 24px; width: 60%; margin-bottom: 12px; }
.skeleton-card { height: 120px; width: 100%; }
.skeleton-row { height: 40px; width: 100%; margin-bottom: 4px; }
.skeleton-circle { height: 40px; width: 40px; border-radius: 50%; }

/* === Button Ripple === */

.btn {
  position: relative;
  overflow: hidden;
}
.btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: scale(0);
  animation: ripple 600ms linear;
  pointer-events: none;
}

/* === Toast Notifications === */

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
[dir="rtl"] .toast { animation-name: toast-in-rtl; }
@keyframes toast-in-rtl {
  from { transform: translateX(-100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-progress {
  from { width: 100%; }
  to { width: 0%; }
}

.toast-container {
  position: fixed;
  top: calc(var(--header-height, 56px) + 12px);
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}
[dir="rtl"] .toast-container {
  right: auto;
  left: 16px;
}

.toast {
  background: var(--glass-bg-heavy, rgba(255,255,255,0.88));
  backdrop-filter: blur(var(--glass-blur, 12px));
  -webkit-backdrop-filter: blur(var(--glass-blur, 12px));
  border: 1px solid var(--glass-border, rgba(255,255,255,0.25));
  border-radius: var(--radius-md, 10px);
  box-shadow: var(--glass-shadow-lg, 0 12px 32px rgba(0,0,0,0.08));
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toast-in 300ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1)) both;
  position: relative;
  overflow: hidden;
}
.toast-icon { flex-shrink: 0; width: 20px; height: 20px; line-height: 20px; text-align: center; }
.toast-body { flex: 1; font-size: var(--text-sm, 0.8125rem); line-height: 1.5; }
.toast-close {
  flex-shrink: 0; background: none; border: none;
  cursor: pointer; color: var(--ink-soft, #5a6270); padding: 0; font-size: 18px; line-height: 1;
}
.toast-close:hover { opacity: 0.7; }
.toast-progress {
  position: absolute; bottom: 0; left: 0; height: 3px;
  animation: toast-progress var(--toast-duration, 5s) linear both;
  border-radius: 0 0 0 var(--radius-md, 10px);
}

.toast--success { border-left: 3px solid var(--success, #0f8a4f); }
.toast--success .toast-icon { color: var(--success, #0f8a4f); }
.toast--success .toast-progress { background: var(--success, #0f8a4f); }

.toast--error { border-left: 3px solid var(--danger, #c4321c); }
.toast--error .toast-icon { color: var(--danger, #c4321c); }
.toast--error .toast-progress { background: var(--danger, #c4321c); }

.toast--warning { border-left: 3px solid var(--warning, #c47f17); }
.toast--warning .toast-icon { color: var(--warning, #c47f17); }
.toast--warning .toast-progress { background: var(--warning, #c47f17); }

.toast--info { border-left: 3px solid var(--primary, #0072BC); }
.toast--info .toast-icon { color: var(--primary, #0072BC); }
.toast--info .toast-progress { background: var(--primary, #0072BC); }

/* === Field Validation Animations === */

.field-error {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 300ms ease, opacity 200ms ease;
}
.field-error.visible {
  max-height: 60px;
  opacity: 1;
}

.field-check {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--success, #0f8a4f);
  pointer-events: none;
  font-size: 14px;
}
[dir="rtl"] .field-check { right: auto; left: 10px; }

.char-count {
  display: block;
  text-align: right;
  font-size: var(--text-xs, 0.75rem);
  color: var(--ink-soft, #5a6270);
  margin-top: 4px;
}
[dir="rtl"] .char-count { text-align: left; }
.char-count.char-warn { color: var(--warning, #c47f17); }
.char-count.char-danger { color: var(--danger, #c4321c); }

/* === Form Wizard === */

.wizard-progress {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: var(--sp-8, 32px);
  padding: var(--sp-4, 16px) 0;
  overflow-x: auto;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--sp-2, 8px) var(--sp-3, 12px);
  min-width: 80px;
  transition: opacity 200ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
}
.wizard-step:not(.active):not(.completed) { opacity: 0.5; cursor: default; }
.wizard-step.completed { cursor: pointer; }

.wizard-step-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-semibold, 600);
  font-size: var(--text-sm, 0.8125rem);
  border: 2px solid var(--line, rgba(0,0,0,0.12));
  background: var(--bg-1, #f0f4f8);
  color: var(--ink-soft, #5a6270);
  transition: all 200ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
}
.wizard-step.active .wizard-step-number {
  background: var(--primary, #0072BC);
  border-color: var(--primary, #0072BC);
  color: #fff;
  box-shadow: 0 0 12px rgba(0, 102, 255, 0.25);
}
.wizard-step.completed .wizard-step-number {
  background: var(--success, #0f8a4f);
  border-color: var(--success, #0f8a4f);
  color: #fff;
}

.wizard-step-label {
  font-size: var(--text-xs, 0.75rem);
  color: var(--ink-soft, #5a6270);
  text-align: center;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wizard-step.active .wizard-step-label { color: var(--ink, #1a1d21); font-weight: var(--weight-medium, 500); }

.wizard-connector {
  flex: 1;
  height: 2px;
  min-width: 20px;
  background: var(--line, rgba(0,0,0,0.12));
  transition: background 300ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
}
.wizard-connector.completed { background: var(--success, #0f8a4f); }

.wizard-nav {
  display: flex;
  align-items: center;
  padding-top: var(--sp-6, 24px);
  border-top: 1px solid var(--line, rgba(0,0,0,0.12));
  margin-top: var(--sp-6, 24px);
}

@media (max-width: 768px) {
  .wizard-step-label { display: none; }
  .wizard-step { min-width: 48px; }
}

/* === Table Pagination === */

.table-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4, 16px) 0;
  flex-wrap: wrap;
  gap: var(--sp-3, 12px);
}
.pager-info {
  font-size: var(--text-sm, 0.8125rem);
  color: var(--ink-soft, #5a6270);
}
.pager-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}
.pager-dots {
  padding: 0 4px;
  color: var(--ink-soft, #5a6270);
}

/* === Sort Arrow === */
.data-table th[aria-sort] { position: relative; }
.data-table th[aria-sort="ascending"],
.data-table th[aria-sort="descending"] { border-bottom-color: var(--primary, #0072BC); }

/* === Kanban Drag & Drop === */
.kanban-card[draggable="true"] { cursor: grab; }
.kanban-card[draggable="true"]:active { cursor: grabbing; }
.kanban-card.dragging {
  opacity: 0.6;
  transform: rotate(2deg);
  box-shadow: var(--glass-shadow-lg, 0 12px 32px rgba(0,0,0,0.08));
}
.kanban-column.drag-over {
  outline: 2px dashed var(--primary, #0072BC);
  outline-offset: -2px;
  background: rgba(var(--primary-rgb, 0, 102, 255), 0.04);
}

/* === Status Timeline === */

.status-timeline {
  display: flex;
  align-items: center;
  padding: var(--sp-4, 16px) var(--sp-6, 24px);
  overflow-x: auto;
  gap: 0;
}
.timeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}
.timeline-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs, 0.75rem);
  font-weight: var(--weight-semibold, 600);
  border: 2px solid var(--line, rgba(0,0,0,0.12));
  background: var(--bg-1, #f0f4f8);
  color: var(--ink-soft, #5a6270);
  transition: all 200ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
}
.timeline-step.completed .timeline-dot {
  background: var(--success, #0f8a4f); border-color: var(--success, #0f8a4f); color: #fff;
}
.timeline-step.current .timeline-dot {
  background: var(--primary, #0072BC); border-color: var(--primary, #0072BC); color: #fff;
  box-shadow: 0 0 10px rgba(0, 102, 255, 0.2);
}
.timeline-label { font-size: var(--text-xs, 0.75rem); color: var(--ink-soft, #5a6270); }
.timeline-step.current .timeline-label { color: var(--ink, #1a1d21); font-weight: var(--weight-medium, 500); }
.timeline-meta { font-size: 10px; color: var(--ink-soft, #5a6270); opacity: 0.7; }
.timeline-line {
  flex: 1; height: 2px; min-width: 16px;
  background: var(--line, rgba(0,0,0,0.12));
  transition: background 300ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
}
.timeline-line.completed { background: var(--success, #0f8a4f); }

/* === Breadcrumbs === */

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--sp-3, 12px) var(--sp-6, 24px);
  font-size: var(--text-sm, 0.8125rem);
  color: var(--ink-soft, #5a6270);
  flex-wrap: wrap;
}
.breadcrumbs a {
  color: var(--ink-soft, #5a6270);
  text-decoration: none;
  transition: color 150ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
}
.breadcrumbs a:hover { color: var(--primary, #0072BC); }
.breadcrumbs .separator { opacity: 0.4; }
[dir="rtl"] .breadcrumbs .separator { transform: scaleX(-1); }
.breadcrumbs .current {
  color: var(--ink, #1a1d21);
  font-weight: var(--weight-medium, 500);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === Card View === */

.card-view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--sp-6, 24px);
}
.card-view-item {
  background: var(--glass-bg, rgba(255,255,255,0.72));
  backdrop-filter: blur(var(--glass-blur, 12px));
  -webkit-backdrop-filter: blur(var(--glass-blur, 12px));
  border: 1px solid var(--glass-border, rgba(255,255,255,0.25));
  border-radius: var(--radius-lg, 14px);
  box-shadow: var(--glass-shadow-sm, 0 1px 3px rgba(0,0,0,0.04));
  padding: var(--sp-6, 24px);
  transition: transform 220ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1)), box-shadow 220ms var(--ease, cubic-bezier(0.4, 0, 0.2, 1));
}
.card-view-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--glass-shadow-md, 0 4px 12px rgba(0,0,0,0.06));
}
a.card-view-item {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
}
.card-view-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-3, 12px);
}
.card-view-item-code {
  font-size: var(--text-xs, 0.75rem);
  font-weight: var(--weight-semibold, 600);
  color: var(--clr-primary, #0C6E52);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.card-view-item-title {
  font-size: var(--text-base, 1rem);
  font-weight: var(--weight-semibold, 600);
  line-height: 1.4;
  margin: 0 0 var(--sp-3, 12px) 0;
  flex: 1;
}
.card-view-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3, 12px);
  font-size: var(--text-sm, 0.875rem);
  color: var(--clr-text-secondary, #6b7280);
  margin-bottom: var(--sp-3, 12px);
}
.card-view-item-meta span {
  display: flex;
  align-items: center;
  gap: var(--sp-1, 4px);
}
.card-view-item-footer {
  border-top: 1px solid var(--glass-border, rgba(0,0,0,0.08));
  padding-top: var(--sp-3, 12px);
  margin-top: auto;
}
.card-view-item-date {
  font-size: var(--text-xs, 0.75rem);
  color: var(--clr-text-tertiary, #9ca3af);
  display: flex;
  align-items: center;
  gap: var(--sp-1, 4px);
}

/* === Command Palette Enhancements === */

.cmd-category {
  font-size: var(--text-xs, 0.75rem);
  font-weight: var(--weight-semibold, 600);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft, #5a6270);
  padding: var(--sp-2, 8px) var(--sp-4, 16px);
  margin-top: var(--sp-2, 8px);
}
.cmd-result-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: var(--radius-full, 9999px);
  background: var(--bg-2, #e4edf5);
  color: var(--ink-soft, #5a6270);
  margin-inline-start: auto;
}
.cmd-match { font-weight: var(--weight-bold, 700); color: var(--primary, #0072BC); }

/* === Sticky Detail Actions === */

.detail-actions.sticky {
  position: sticky;
  top: var(--header-height, 56px);
  z-index: 100;
  background: var(--glass-bg-heavy, rgba(255,255,255,0.88));
  backdrop-filter: blur(var(--glass-blur, 12px));
  -webkit-backdrop-filter: blur(var(--glass-blur, 12px));
  border-bottom: 1px solid var(--glass-border, rgba(255,255,255,0.25));
  padding: var(--sp-3, 12px) var(--sp-6, 24px);
  margin: 0 calc(-1 * var(--sp-6, 24px));
  border-radius: 0;
}
