/* ==========================================================================
   OFFICE KEY STORE - UI FEEDBACK DESIGN SYSTEM
   Toast Notifications, Top Loading Bar, Loading Overlay & Confirm Modal
   Matching Lexend Font, Light Theme, WCAG 2.2 AA Accessible
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. TOP LOADING PROGRESS BAR (Nano / YouTube / GitHub style)
   -------------------------------------------------------------------------- */
#top-loader {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3.5px;
  background: linear-gradient(90deg, #2563EB 0%, #3B82F6 50%, #60A5FA 100%);
  z-index: 999999;
  pointer-events: none;
  transition: width 0.22s ease-out, opacity 0.35s ease;
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.8), 0 0 5px rgba(59, 130, 246, 0.6);
  opacity: 0;
}

#top-loader.active {
  opacity: 1;
}

#top-loader-peg {
  position: absolute;
  right: 0;
  top: 0;
  width: 80px;
  height: 100%;
  box-shadow: 0 0 12px #3B82F6, 0 0 6px #60A5FA;
  opacity: 1;
  transform: rotate(3deg) translateY(-2px);
}

/* --------------------------------------------------------------------------
   2. PAGE LOADING OVERLAY (Modal / Form Submissions / Sync actions)
   -------------------------------------------------------------------------- */
#page-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(248, 250, 252, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 999990;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
  padding: 1.5rem;
}

#page-loading-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.loading-card {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 16px;
  padding: 2rem 2.25rem;
  box-shadow: 0 20px 25px -5px rgba(15, 23, 42, 0.12), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 380px;
  width: 100%;
  animation: loadingCardPop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.loading-spinner-wrapper {
  position: relative;
  width: 58px;
  height: 58px;
  margin-bottom: 1.25rem;
}

.loading-spinner-ring {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3.5px solid #EFF6FF;
  border-top-color: #2563EB;
  border-right-color: #3B82F6;
  animation: spinnerRotate 0.85s linear infinite;
}

.loading-spinner-logo {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.85rem;
  font-weight: 700;
  color: #2563EB;
  letter-spacing: -0.5px;
}

.loading-text {
  font-size: 1rem;
  font-weight: 600;
  color: #0F172A;
  margin-bottom: 0.35rem;
}

.loading-subtext {
  font-size: 0.85rem;
  color: #64748B;
}

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

@keyframes loadingCardPop {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* --------------------------------------------------------------------------
   3. TOAST NOTIFICATION CONTAINER & TOASTS
   -------------------------------------------------------------------------- */
#toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 1000000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
  max-width: 420px;
  width: calc(100vw - 2.5rem);
}

.app-toast {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 12px;
  padding: 0.875rem 1rem;
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.12), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  animation: toastSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.app-toast.toast-hiding {
  animation: toastSlideOut 0.28s cubic-bezier(0.4, 0, 1, 1) forwards;
}

.toast-icon-wrap {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-icon-wrap svg {
  width: 20px;
  height: 20px;
}

.toast-body {
  flex: 1;
  min-width: 0;
  padding-right: 0.25rem;
}

.toast-title {
  font-size: 0.925rem;
  font-weight: 600;
  color: #0F172A;
  margin-bottom: 0.2rem;
  line-height: 1.35;
}

.toast-message {
  font-size: 0.85rem;
  color: #475569;
  line-height: 1.45;
  word-break: break-word;
}

.toast-close-btn {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #94A3B8;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  padding: 0;
  margin: -2px -2px 0 0;
}

.toast-close-btn:hover {
  background: #F1F5F9;
  color: #0F172A;
}

.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  width: 100%;
  transform-origin: left;
  animation: toastProgress linear forwards;
}

.app-toast:hover .toast-progress {
  animation-play-state: paused;
}

/* Toast Variants */
.toast-success {
  border-color: #A7F3D0;
}
.toast-success .toast-icon-wrap {
  background: #ECFDF5;
  color: #059669;
}
.toast-success .toast-progress {
  background: #059669;
}

.toast-error {
  border-color: #FECACA;
}
.toast-error .toast-icon-wrap {
  background: #FEF2F2;
  color: #DC2626;
}
.toast-error .toast-progress {
  background: #DC2626;
}

.toast-warning {
  border-color: #FDE68A;
}
.toast-warning .toast-icon-wrap {
  background: #FFFBEB;
  color: #D97706;
}
.toast-warning .toast-progress {
  background: #D97706;
}

.toast-info {
  border-color: #BFDBFE;
}
.toast-info .toast-icon-wrap {
  background: #EFF6FF;
  color: #2563EB;
}
.toast-info .toast-progress {
  background: #2563EB;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(110%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes toastSlideOut {
  from {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateX(110%) scale(0.95);
  }
}

@keyframes toastProgress {
  from {
    width: 100%;
  }
  to {
    width: 0%;
  }
}

/* --------------------------------------------------------------------------
   4. CUSTOM CONFIRM MODAL (Modern alternative to native browser confirm)
   -------------------------------------------------------------------------- */
#app-confirm-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000005;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s;
  padding: 1.25rem;
}

#app-confirm-modal.visible {
  opacity: 1;
  visibility: visible;
}

.confirm-card {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.2);
  max-width: 440px;
  width: 100%;
  padding: 1.75rem;
  animation: confirmPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.confirm-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.confirm-icon-wrap {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.confirm-icon-wrap.danger {
  background: #FEF2F2;
  color: #DC2626;
  border: 1px solid #FECACA;
}

.confirm-icon-wrap.primary {
  background: #EFF6FF;
  color: #2563EB;
  border: 1px solid #BFDBFE;
}

.confirm-title-area {
  flex: 1;
}

.confirm-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: #0F172A;
  margin-bottom: 0.35rem;
  line-height: 1.35;
}

.confirm-message {
  font-size: 0.925rem;
  color: #475569;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.confirm-btn-cancel {
  background: #F1F5F9;
  color: #334155;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
  transition: all 0.15s ease;
  font-family: inherit;
}

.confirm-btn-cancel:hover {
  background: #E2E8F0;
  color: #0F172A;
}

.confirm-btn-ok {
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
  transition: all 0.15s ease;
  color: #FFFFFF;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.confirm-btn-ok.btn-danger-confirm {
  background: #DC2626;
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.2);
}

.confirm-btn-ok.btn-danger-confirm:hover {
  background: #B91C1C;
}

.confirm-btn-ok.btn-primary-confirm {
  background: #2563EB;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.confirm-btn-ok.btn-primary-confirm:hover {
  background: #1D4ED8;
}

@keyframes confirmPop {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* --------------------------------------------------------------------------
   5. MOBILE RESPONSIVENESS
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  #toast-container {
    top: 1rem;
    left: 1rem;
    right: 1rem;
    width: auto;
  }
  
  .confirm-card {
    padding: 1.35rem;
  }

  .confirm-actions {
    flex-direction: column-reverse;
  }

  .confirm-actions button {
    width: 100%;
  }
}
