// main: chatgpt.scss, messages.scss

@mixin file-upload-icon-sprites {
	$icon-size: 32px;

	&.mwai-idle-add {
		background-position: -1 * $icon-size -3 * $icon-size;
	}

	&.mwai-image-add {
		background-position: -1 * $icon-size -0 * $icon-size;
	}

	&.mwai-image-up {
		background-position: -2 * $icon-size -0 * $icon-size;
	}

	&.mwai-image-del {
		background-position: -3 * $icon-size -0 * $icon-size;
	}

	&.mwai-image-ok {
		background-position: -4 * $icon-size -0 * $icon-size;
	}

	&.mwai-document-add {
		background-position: -1 * $icon-size -2 * $icon-size;
	}

	&.mwai-document-up {
		background-position: -2 * $icon-size -2 * $icon-size;
	}

	&.mwai-document-del {
		background-position: -3 * $icon-size -2 * $icon-size;
	}

	&.mwai-document-ok {
		background-position: -4 * $icon-size -2 * $icon-size;
	}

	.mwai-file-upload-progress {
		position: absolute;
		font-size: 8px;
		width: 21px;
		top: 24px;
		left: 23px;
		overflow: hidden;
		text-align: center;
		font-weight: bold;
		color: white;
	}
}

@mixin microphone {

	display: flex;
	justify-content: center;
	align-items: center;

	svg {
		opacity: 0.5;
		filter: grayscale(100%);
		transition: opacity 0.3s ease-out;
		cursor: pointer;
	}

	&[active=true] svg {
		opacity: 1;
	}

	&[disabled] svg {
		opacity: 0;
		cursor: not-allowed;
	}
}

@mixin fullscreen-window {
  position: fixed;
  left: 0 !important;
  right: 0 !important; 
  bottom: 0 !important;
  top: 0 !important;
  width: 100%;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  margin: 0;
  z-index: 999999;
  background-color: var(--mwai-backgroundSecondaryColor);

	.mwai-header {
		border-radius: 0;
	} 

  .mwai-content {
    height: 100%;
    max-height: inherit;
		border-radius: 0;

    .mwai-conversation {
      flex: auto; 
      max-height: none;
    }
  }
}

@mixin common-styles {

	// Transitions

	&.mwai-transition, .mwai-transition {
		opacity: 0;
		transition: opacity 350ms ease-in-out;
	}

	&.mwai-transition-visible, .mwai-transition-visible {
		opacity: 1;
	}

	.mwai-text {
		overflow-wrap: anywhere;
		
		img {
			max-width: 100%;
		}

		div {
			p:first-child {
				margin-top: 0;
			}
			p:last-child {
				margin-bottom: 0;
			}
		}
	}

	// The icon when the chat window is closed.

	.mwai-trigger {
		position: absolute;
		right: 0;
		bottom: 0;
		transition: all 0.2s ease-out;
		z-index: 9999;
		display: flex;
		flex-direction: column;
		align-items: end;

		.mwai-icon-text-container {
			display: flex;
			flex-direction: column;
			align-items: flex-end;

			.mwai-icon-text {
				background: var(--mwai-iconTextBackgroundColor);
				color: var(--mwai-iconTextColor);
				box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.15);
				max-width: 200px;
				font-size: 13px;
				margin-bottom: 15px;
				padding: 10px 15px;
				border-radius: 8px;
			}

			.mwai-icon-text-close {
				color: var(--mwai-iconTextColor);
				background: var(--mwai-iconTextBackgroundColor);
				padding: 5px;
				width: 20px;
				height: 20px;
				border-radius: 100%;
				display: none;
				justify-content: center;
				align-items: center;
				margin-bottom: 3px;
			}

			&:hover {
				cursor: pointer;

				.mwai-icon-text-close {
					display: flex;
					font-size: 12px;

					&:hover {
						filter: brightness(1.2);
					}
				}
			}

			@media (max-width: 760px) {
				.mwai-icon-text-close {
					display: flex;
				}
			}

		}

		.mwai-icon-container {

			.mwai-icon {
				filter: drop-shadow(0px 0px 15px rgba(0, 0, 0, 0.15));
				transition: all 0.2s ease-out;

				&:hover {
					cursor: pointer;
					transform: scale(1.05);
				}
			}
		}
	}

	// Handle the chat window and fullscreen.
	// Let's keep this common for all themes.

	&.mwai-window {
		position: fixed;
		right: 30px;
		bottom: 30px;
		width: var(--mwai-width);
		z-index: 9999;

		.mwai-header {
			display: none;
			justify-content: flex-end;
			align-items: center;
			border-radius: var(--mwai-borderRadius) var(--mwai-borderRadius) 0 0;
			background: var(--mwai-backgroundHeaderColor);

			.mwai-buttons {
				display: flex;
				align-items: center;

				.mwai-resize-button {
					justify-content: center;
					height: 32px;
					width: 22px;
					cursor: pointer;
					display: flex;
					justify-content: center;
					align-items: center;

					&:before {
						transition: all 0.2s ease-out;
						content: ' ';
						cursor: pointer;
						position: absolute;
						height: 13px;
						width: 13px;
						border: 1px solid var(--mwai-headerButtonsColor);
					}

					&:hover:before {
						width: 16px;
						height: 16px;
					}
				}

				.mwai-close-button {
					justify-content: center;
					height: 32px;
					width: 33px;
					cursor: pointer;
					border-radius: var(--mwai-borderRadius);

					&:before {
						transition: all 0.2s ease-out;
						transform: translate(16px, 5px) rotate(45deg);
					}
					&:after {
						transition: all 0.2s ease-out;
						transform: translate(16px, 5px) rotate(-45deg);
					}
				}

				.mwai-close-button:before, .mwai-close-button:after {
					content: ' ';
					cursor: pointer;
					position: absolute;
					height: 22px;
					width: 1px;
					background-color: var(--mwai-headerButtonsColor);
				}

				.mwai-close-button:hover {
					&:before {
						opacity: 1;
						transform: translate(16px, 5px) rotate(135deg);
					}
					&:after {
						opacity: 1;
						transform: translate(16px, 5px) rotate(45deg);
					}
				}

			}
		}

		.mwai-content {
			display: none;
			opacity: 0;
			max-height: var(--mwai-maxHeight);
			border-radius: 0 0 var(--mwai-borderRadius) var(--mwai-borderRadius);
		}

		&.mwai-bottom-left {
			bottom: 30px;
			right: inherit;
			left: 30px;

			.mwai-trigger {
				right: inherit;
				left: 0;
			}
		}

		&.mwai-top-right {
			top: 30px;
			bottom: inherit;
			right: 30px;

			.mwai-trigger {
				top: 0;
				bottom: inherit;
			}
		}

		&.mwai-top-left {
			top: 30px;
			bottom: inherit;
			right: inherit;
			left: 30px;

			.mwai-trigger {
				top: 0;
				bottom: inherit;
				right: inherit;
				left: 0;
			}
		}

		&.mwai-top-left, &.mwai-bottom-left {
			
			.mwai-trigger {
				align-items: flex-start;
			}
		}

		&.mwai-top-right, &.mwai-top-left {

			.mwai-trigger {
				flex-direction: column-reverse;

				.mwai-icon-text {
					margin-bottom: 0;
					margin-top: 15px;
				}
			}
		}
	}

	// Popup chat is fullscreen

	&.mwai-window.mwai-fullscreen {

		.mwai-header  {

			.mwai-buttons  {
				margin-bottom: 0px;

				.mwai-resize-button {
					&:before {
						width: 16px;
						height: 16px;
					}
			
					&:hover:before {
						width: 13px;
						height: 13px;
					}
				}
			}
		}
	}

	// Standard chat is fullscreen

	&.mwai-fullscreen:not(.mwai-window), &.mwai-fullscreen.mwai-window.mwai-open {
		@include fullscreen-window;
	}

	// Popup chat is open

	&.mwai-window.mwai-open {

		.mwai-header {
			display: flex;
		}

		.mwai-content {
			display: flex;
			transition: opacity 200ms ease-in-out 0s;
			opacity: 1;
		}

		.mwai-trigger {
			display: none;
		}
	}

	.mwai-error {
		margin: var(--mwai-spacing);
		color: white;
		background: rgba(180, 55, 55, 0.55);
		padding: var(--mwai-spacing);
		border-radius: var(--mwai-borderRadius);

		&:hover {
			cursor: pointer;
			background: rgba(180, 44, 44, 0.85);
		}
	}

	&.mwai-bubble .mwai-icon-container {
		background: var(--mwai-bubbleColor);
		width: 60px;
		height: 60px;
		border-radius: 100%;
		transition: all 0.2s ease-out;
		display: flex;
		justify-content: center;
		align-items: center;

		.mwai-icon {
			max-width: 50%;
			max-height: 50%;
			filter: none;

			&:hover {
				transform: none;
			}
		}

		.mwai-emoji {
			font-size: 30px !important;
		}

		&:hover {
			cursor: pointer;
			filter: brightness(1.1);
		}
	}

	@media (max-width: 760px) {
		&.mwai-window.mwai-open {
			@include fullscreen-window;
		
			.mwai-input {
				flex-direction: column;

				button {
					font-size: 16px;
					margin-left: 0;
					width: 100%;
				}
				
				.mwai-input-text {
					//margin-bottom: var(--mwai-spacing);
					width: 100%;

					// This is to avoid iOS from zooming in when focusing on an input field.
					input, textarea {
						font-size: 16px;
					}
				}
			}
	
			.mwai-content {
				display: flex;
				transition: opacity 200ms ease-in-out 0s;
				opacity: 1;
				height: 100%;
				max-height: inherit;
	
				.mwai-conversation {
					flex: auto;
					max-height: none;
				}
			}

			.mwai-resize-button {
				display: none !important;
			}
	
			.mwai-trigger {
				display: none;
			}
		}
	}

	// Keyframes for buttons

	@keyframes mwai-button-spinner {

		from {
			transform: rotate(0turn);
		}
		to {
			transform: rotate(1turn);
		}
	}

	// WordPress Admin Bar

	.admin-bar .mwai-fullscreen:not(.mwai-window),
	.admin-bar .mwai-fullscreen.mwai-window.mwai-open {
		top: 32px;
	}
}

@mixin code-dark {

  pre code.hljs {
    display: block;
    overflow-x: auto;
    padding: 1em;
  }

  code.hljs {
    padding: 3px 5px;
  }

  .hljs {
    color: #fff;

    &-subst {
      color: #fff;
    }

    &-comment {
      color: #999;
    }

    &-attr,
    &-doctag,
    &-keyword,
    &-meta .hljs-keyword,
    &-section,
    &-selector-tag {
      color: #88aece;
    }

    &-attribute {
      color: #c59bc1;
    }

    &-name,
    &-number,
    &-quote,
    &-selector-id,
    &-template-tag,
    &-type {
      color: #f08d49;
    }

    &-selector-class {
      color: #88aece;
    }

    &-link,
    &-regexp,
    &-selector-attr,
    &-string,
    &-symbol,
    &-template-variable,
    &-variable {
      color: #b5bd68;
    }

    &-meta,
    &-selector-pseudo {
      color: #88aece;
    }

    &-built_in,
    &-literal,
    &-title {
      color: #f08d49;
    }

    &-bullet,
    &-code {
      color: #ccc;
    }

    &-meta .hljs-string {
      color: #b5bd68;
    }

    &-deletion {
      color: #de7176;
    }

    &-addition {
      color: #76c490;
    }

    &-emphasis {
      font-style: italic;
    }

    &-strong {
      font-weight: 700;
    }
  }
}

@mixin code-light {
  
  pre code.hljs {
    display: block;
    overflow-x: auto;
    padding: 1em;
  }

  code.hljs {
    padding: 3px 5px;
  }

  .hljs {
    color: #333;
    background: #f0f0f0;

    &-subst {
      color: #333;
    }

    &-comment {
      color: #888;
    }

    &-attr,
    &-doctag,
    &-keyword,
    &-meta .hljs-keyword,
    &-section,
    &-selector-tag {
      color: #0077cc;
    }

    &-attribute {
      color: #aa3377;
    }

    &-name,
    &-number,
    &-quote,
    &-selector-id,
    &-template-tag,
    &-type {
      color: #c18401;
    }

    &-selector-class {
      color: #0077cc;
    }

    &-link,
    &-regexp,
    &-selector-attr,
    &-string,
    &-symbol,
    &-template-variable,
    &-variable {
      color: #689700;
    }

    &-meta,
    &-selector-pseudo {
      color: #0077cc;
    }

    &-built_in,
    &-literal,
    &-title {
      color: #c18401;
    }

    &-bullet,
    &-code {
      color: #555;
    }

    &-meta .hljs-string {
      color: #689700;
    }

    &-deletion {
      color: #b71c1c;
    }

    &-addition {
      color: #1b5e20;
    }

    &-emphasis {
      font-style: italic;
    }

    &-strong {
      font-weight: 700;
    }
  }
}

@mixin reply-actions {
	.mwai-reply-actions {
		position: absolute;
		border-radius: 5px;
		top: 10px;
		right: 10px;
		display: flex;
		align-items: center;
		padding: 2px 2px;
		z-index: 100;
		background: var(--mwai-backgroundPrimaryColor);
		box-shadow: 0 0 8px rgba(0, 0, 0, 0.25);
		z-index: 100;

		.mwai-copy-button {
			fill: var(--mwai-fontColor);
			padding: 3px 5px;
			width: 24px;
			height: 24px;
			background: var(--mwai-backgroundPrimaryColor);
			cursor: pointer;
			border-radius: 5px;

			&:hover {
				filter: brightness(1.2);
			}
		}

		&.mwai-hidden {
			opacity: 0;
		}
	}
}

@mixin realtime {
	.mwai-realtime {
		padding: var(--mwai-spacing);

		.mwai-visualizer {
			display: flex;
			justify-content: center;
			align-items: center;

			hr {
				width: 100px;
				margin-right: var(--mwai-spacing);
				margin-left: var(--mwai-spacing);
				border: 1px solid var(--mwai-backgroundPrimaryColor);
			}

			.mwai-animation {
				background: var(--mwai-backgroundPrimaryColor);
			}
		}

		.mwai-controls {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-bottom: var(--mwai-spacing);

			> * + * {
				margin-left: 10px;
			}

			button {
				border-radius: 100%;
				width: 50px;
				height: 50px;
				margin: 5px;
				padding: 5px;
				display: flex;
				align-items: center;
				justify-content: center;
				color: var(--mwai-fontColor);
				border: 2px solid var(--mwai-backgroundPrimaryColor);
				background: none;
				cursor: pointer;
				transition: all 0.2s ease-out;
				min-width: inherit;
				max-width: inherit;

				&:hover:not(:disabled) {
					background: var(--mwai-backgroundPrimaryColor);
				}

				&:disabled {
					opacity: 0.5;
					cursor: not-allowed;
					background: none;
				}

				&.mwai-active {
					border: 2px solid var(--mwai-fontColor);
				}
			}
		}

		.mwai-last-transcript {
			margin: var(--mwai-spacing);
			margin-top: 0;
			border: 2px solid var(--mwai-backgroundPrimaryColor); 
			padding: calc(var(--mwai-spacing) / 2);
			border-radius: var(--mwai-borderRadius);
			display: flex;
			justify-content: center;
			font-size: 80%;
		}

		.mwai-statistics {
			display: grid;
			grid-template-columns: 1fr 1fr 1fr;
			grid-row-gap: 10px;
			font-size: 14px;

			div {
				display: flex;
    		flex-direction: column;
    		align-items: center;
			}

			label {
				font-size: 11px;
				opacity: 0.5;
				text-transform: uppercase;
			}
		}

		.mwai-options {
			margin-top: var(--mwai-spacing);
			display: flex;
			align-items: center;

			.mwai-option {
				cursor: pointer;
				opacity: 0.5;
				margin-right: 2px;

				&.mwai-active {
					opacity: 1;
				}
			}
		}
	}
}