/**
 * IT Agent Chat Widget Styles
 * Primaris Employee Portal
 *
 * Follows Primaris Brand Guidelines:
 * - Primary Red: #E12727
 * - Dark Gray: #4B4F55
 * - Medium Gray: #787A80
 * - Light Gray: #EDEDED
 * - Primaris Blue: #6B91BA
 */

/* ==================== */
/* LAUNCHER BUTTON      */
/* ==================== */

.agent-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  background: #E12727; /* Primaris Red */
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(225, 39, 39, 0.4);
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.agent-launcher:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(225, 39, 39, 0.5);
}

.agent-launcher:active {
  transform: scale(1.05);
}

.agent-launcher .agent-icon {
  width: 28px;
  height: 28px;
  fill: #FFFFFF;
}

.agent-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #E5A64A; /* Primaris Gold */
  color: #FFFFFF;
  font-size: 0.75rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* ==================== */
/* BACKDROP OVERLAY     */
/* ==================== */

.agent-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1001;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.agent-backdrop.show {
  opacity: 1;
}

/* ==================== */
/* CHAT PANEL           */
/* ==================== */

.agent-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 630px;
  height: 100vh;
  background: #FFFFFF;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.2);
  z-index: 1002;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.agent-panel.show {
  transform: translateX(0);
}

/* Legacy animation removed - using transform-based slide-in instead */

/* ==================== */
/* HEADER               */
/* ==================== */

.agent-header {
  background: #4B4F55; /* Dark Gray */
  color: #FFFFFF;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 3px solid #E12727; /* Primaris Red accent */
  flex-shrink: 0;
}

.agent-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
}

.agent-header-icon {
  width: 24px;
  height: 24px;
  fill: #FFFFFF;
}

.agent-header h3 {
  color: #FFFFFF;
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

.agent-minimize,
.agent-close {
  background: transparent;
  border: none;
  color: #FFFFFF;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.agent-minimize:hover,
.agent-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.agent-minimize:active,
.agent-close:active {
  background: rgba(255, 255, 255, 0.25);
}

/* ==================== */
/* MESSAGES CONTAINER   */
/* ==================== */

.agent-messages {
  flex: 1;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 1rem;
  display: flex;
  flex-direction: column-reverse;
  gap: 1rem;
  background: #EDEDED; /* Light Gray */
  min-height: 0;
}

/* Custom scrollbar */
.agent-messages::-webkit-scrollbar {
  width: 8px;
}

.agent-messages::-webkit-scrollbar-track {
  background: transparent;
}

.agent-messages::-webkit-scrollbar-thumb {
  background: #C9C9CC;
  border-radius: 4px;
}

.agent-messages::-webkit-scrollbar-thumb:hover {
  background: #787A80;
}

/* ==================== */
/* MESSAGE BUBBLES      */
/* ==================== */

.agent-message {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.agent-message-assistant {
  align-self: flex-start;
  max-width: 95%;
}

.agent-message-user {
  align-self: flex-end;
  max-width: 85%;
}

.agent-message-bubble {
  padding: 0.4rem 0.6rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.25;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.agent-message-assistant .agent-message-bubble {
  background: #FFFFFF;
  color: #4B4F55; /* Dark Gray */
  border: 1px solid #C9C9CC;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Rich text formatting in agent messages */
.agent-message-assistant .agent-message-bubble p {
  margin: 0;
  line-height: 1.25;
}

.agent-message-assistant .agent-message-bubble p + p {
  margin-top: 0.1rem;
}

.agent-message-assistant .agent-message-bubble strong {
  font-weight: 600;
  color: #4B4F55;
}

.agent-message-assistant .agent-message-bubble em {
  font-style: italic;
}

.agent-message-assistant .agent-message-bubble a {
  color: #6B91BA;
  text-decoration: underline;
}

.agent-message-assistant .agent-message-bubble a:hover {
  color: #4B4F55;
}

.agent-message-assistant .agent-message-bubble ul,
.agent-message-assistant .agent-message-bubble ol {
  margin: 0.1rem 0 0.15rem 0;
  padding-left: 0;
  list-style-position: inside;
}

.agent-message-assistant .agent-message-bubble ul {
  list-style-type: disc;
}

.agent-message-assistant .agent-message-bubble ol {
  list-style-type: decimal;
}

.agent-message-assistant .agent-message-bubble li {
  margin: 0;
  padding: 0;
  line-height: 1.25;
  text-indent: 0;
}

.agent-message-assistant .agent-message-bubble li + li {
  margin-top: 0;
}

/* Remove line height spacing for tighter list rendering */
.agent-message-assistant .agent-message-bubble ul,
.agent-message-assistant .agent-message-bubble ol {
  line-height: 1;
}

.agent-message-assistant .agent-message-bubble hr {
  border: none;
  border-top: 1px solid #C9C9CC;
  margin: 0.25rem 0;
}

/* Inline code */
.agent-message-assistant .agent-message-bubble code {
  background: #F3F3F3;
  border: 1px solid #E1E1E1;
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.85em;
  color: #292929;
  font-weight: 400;
}

/* Code block container - with relative positioning for copy button */
.agent-message-assistant .agent-message-bubble pre {
  position: relative;
  background: #F8F8F8;
  border: 1px solid #E5E5E5;
  border-radius: 6px;
  padding: 0.75rem 0.85rem;
  padding-top: 2.2rem;
  margin: 0.35rem 0;
  overflow-x: auto;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.85em;
  line-height: 1.4;
  transition: background 0.2s ease;
}

.agent-message-assistant .agent-message-bubble pre:hover {
  background: #F3F3F3;
}

/* Code inside pre blocks */
.agent-message-assistant .agent-message-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 1em;
  color: #292929;
  display: block;
  white-space: pre;
}

/* Copy button container */
.code-copy-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: #FFFFFF;
  border: 1px solid #D1D1D1;
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
  color: #4B4F55;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.2s ease;
  z-index: 10;
  font-family: 'Segoe UI', 'Nunito Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 500;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  -webkit-user-select: none;
  user-select: none;
}

.code-copy-button:hover {
  background: #F5F5F5;
  border-color: #C1C1C1;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.code-copy-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.code-copy-button:focus-visible {
  outline: 2px solid #E12727;
  outline-offset: 2px;
}

/* Copy button icon */
.code-copy-button-icon {
  width: 14px;
  height: 14px;
  display: inline-block;
  flex-shrink: 0;
}

/* Copied state */
.code-copy-button.copied {
  background: #E8F5E9;
  border-color: #4CAF50;
  color: #2E7D32;
}

.agent-message-user .agent-message-bubble {
  background: #6B91BA; /* Primaris Blue */
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 3px rgba(107, 145, 186, 0.3);
}

.agent-message-timestamp {
  font-size: 0.75rem;
  color: #787A80; /* Medium Gray */
  margin-top: 0.25rem;
  padding: 0 0.5rem;
}

/* ==================== */
/* ERROR DISPLAY        */
/* ==================== */

.agent-error {
  background: #FEE;
  border-top: 3px solid #E12727; /* Primaris Red */
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-shrink: 0;
}

.agent-error-text {
  flex: 1;
  color: #C00;
  font-size: 0.9rem;
}

.agent-error-retry {
  background: #E12727;
  color: #FFFFFF;
  border: none;
  padding: 0.375rem 0.875rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.agent-error-retry:hover {
  background: #c11f1f;
}

.agent-error-retry:active {
  background: #a11818;
}

/* ==================== */
/* INPUT AREA           */
/* ==================== */

.agent-input-container {
  border-top: 1px solid #C9C9CC;
  padding: 1rem;
  display: flex;
  gap: 0.75rem;
  background: #FFFFFF;
  flex-shrink: 0;
}

.agent-input {
  flex: 1;
  border: 1px solid #C9C9CC;
  border-radius: 20px;
  padding: 0.625rem 1rem;
  font-size: 0.95rem;
  font-family: 'Segoe UI', 'Nunito Sans', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  resize: none;
  max-height: 100px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  line-height: 1.5;
}

.agent-input:focus {
  outline: none;
  border-color: #E12727; /* Primaris Red */
  box-shadow: 0 0 0 3px rgba(225, 39, 39, 0.1);
}

.agent-input:disabled {
  background: #F5F5F5;
  color: #787A80;
  cursor: not-allowed;
}

.agent-input::placeholder {
  color: #787A80;
}

.agent-send {
  background: #E12727; /* Primaris Red */
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.agent-send:hover:not(:disabled) {
  background: #c11f1f;
  transform: scale(1.05);
}

.agent-send:active:not(:disabled) {
  background: #a11818;
  transform: scale(1);
}

.agent-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.agent-send-icon {
  width: 20px;
  height: 20px;
  fill: #FFFFFF;
}

/* ==================== */
/* LOADING INDICATOR    */
/* ==================== */

.agent-loading {
  padding: 0.75rem 1rem;
  background: #FFFFFF;
  border-top: 1px solid #C9C9CC;
  flex-shrink: 0;
}

.agent-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.5rem;
}

.agent-typing-indicator span {
  width: 8px;
  height: 8px;
  background: #787A80; /* Medium Gray */
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.agent-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.agent-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-8px);
  }
}

/* ==================== */
/* RESPONSIVE DESIGN    */
/* ==================== */

@media (max-width: 480px) {
  /* Mobile: Full-screen takeover (no backdrop, no slide animation) */
  .agent-panel {
    width: 100vw;
    height: 100vh;
    transform: none;
    transition: none;
  }

  .agent-panel.show {
    transform: none;
  }

  .agent-backdrop {
    display: none !important;
  }

  .agent-launcher {
    bottom: 16px;
    right: 16px;
  }

  .agent-message {
    max-width: 90%;
  }
}

@media (max-width: 768px) and (min-width: 481px) {
  /* Tablet: Slightly narrower slide-out panel */
  .agent-panel {
    width: 480px;
  }
}

/* ==================== */
/* SIGN-IN CARD         */
/* ==================== */

.agent-signin-card {
  text-align: center;
  padding: 1rem;
}

.agent-signin-text {
  margin: 0 0 0.75rem 0;
  color: #4B4F55;
  font-size: 0.9rem;
  line-height: 1.4;
}

.agent-signin-button {
  display: inline-block;
  background: #E12727;
  color: #FFFFFF;
  border: none;
  padding: 0.625rem 1.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: 'Segoe UI', 'Nunito Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.agent-signin-button:hover:not(:disabled) {
  background: #c11f1f;
  transform: translateY(-1px);
}

.agent-signin-button:active:not(:disabled) {
  background: #a11818;
  transform: translateY(0);
}

.agent-signin-button:disabled {
  background: #C9C9CC;
  color: #787A80;
  cursor: not-allowed;
}

.agent-signin-button:focus-visible {
  outline: 2px solid #E12727;
  outline-offset: 2px;
}

/* ==================== */
/* MAGIC CODE INPUT     */
/* ==================== */

.agent-magic-code-card {
  padding: 1rem;
}

.agent-magic-code-text {
  margin: 0 0 0.75rem 0;
  color: #4B4F55;
  font-size: 0.9rem;
  line-height: 1.4;
}

.agent-magic-code-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.agent-magic-code-input {
  flex: 1;
  border: 1px solid #C9C9CC;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  letter-spacing: 0.2em;
  text-align: center;
  max-width: 160px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.agent-magic-code-input:focus {
  outline: none;
  border-color: #E12727;
  box-shadow: 0 0 0 3px rgba(225, 39, 39, 0.1);
}

.agent-magic-code-input::placeholder {
  color: #787A80;
  letter-spacing: normal;
}

.agent-magic-code-submit {
  background: #E12727;
  color: #FFFFFF;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: 'Segoe UI', 'Nunito Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.agent-magic-code-submit:hover {
  background: #c11f1f;
}

.agent-magic-code-submit:active {
  background: #a11818;
}

.agent-magic-code-submit:focus-visible {
  outline: 2px solid #E12727;
  outline-offset: 2px;
}

/* ==================== */
/* ACCESSIBILITY        */
/* ==================== */

.agent-launcher:focus-visible,
.agent-send:focus-visible,
.agent-close:focus-visible,
.agent-minimize:focus-visible,
.agent-error-retry:focus-visible {
  outline: 2px solid #E12727;
  outline-offset: 2px;
}

.agent-input:focus-visible {
  outline: none; /* Using box-shadow instead */
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .agent-panel,
  .agent-backdrop {
    transition: none !important;
  }

  .agent-message,
  .agent-launcher {
    animation: none;
  }

  .agent-typing-indicator span {
    animation: none;
    opacity: 0.5;
  }
}

/* ==================== */
/* ADAPTIVE CARDS       */
/* ==================== */

.agent-adaptive-card {
  background: #FFFFFF;
  border: 1px solid #C9C9CC;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  margin-top: 0.5rem;
  width: 100%;
  box-sizing: border-box;
}

.agent-adaptive-card-error {
  background: #FFF3F3;
  border: 1px solid #E12727;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: #4B4F55;
  font-style: italic;
}

/* Adaptive Cards SDK button overrides (SDK injects inline styles so !important is required) */
.agent-adaptive-card .ac-pushButton {
  background-color: #E12727 !important;
  color: #FFFFFF !important;
  border: none !important;
  border-radius: 6px !important;
  padding: 0.5rem 1rem !important;
  font-family: 'Nunito Sans', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif !important;
  font-size: 0.875rem !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  transition: background-color 0.2s ease !important;
}

.agent-adaptive-card .ac-pushButton:hover {
  background-color: #c11f1f !important;
}

.agent-adaptive-card .ac-pushButton:active {
  background-color: #a11818 !important;
}

.agent-adaptive-card .ac-pushButton:focus-visible {
  outline: 2px solid #E12727 !important;
  outline-offset: 2px !important;
}

/* Adaptive Cards input fields */
.agent-adaptive-card .ac-input,
.agent-adaptive-card .ac-textInput,
.agent-adaptive-card .ac-numberInput,
.agent-adaptive-card .ac-dateInput,
.agent-adaptive-card .ac-timeInput {
  border: 1px solid #C9C9CC !important;
  border-radius: 6px !important;
  padding: 0.5rem 0.75rem !important;
  font-family: 'Nunito Sans', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif !important;
  font-size: 0.875rem !important;
  color: #4B4F55 !important;
  transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

.agent-adaptive-card .ac-input:focus,
.agent-adaptive-card .ac-textInput:focus,
.agent-adaptive-card .ac-numberInput:focus,
.agent-adaptive-card .ac-dateInput:focus,
.agent-adaptive-card .ac-timeInput:focus {
  outline: none !important;
  border-color: #E12727 !important;
  box-shadow: 0 0 0 3px rgba(225, 39, 39, 0.1) !important;
}

/* Adaptive Cards text blocks */
.agent-adaptive-card .ac-textBlock {
  font-family: 'Nunito Sans', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif !important;
  color: #4B4F55 !important;
}

/* Dropdown/choice set */
.agent-adaptive-card select.ac-input {
  appearance: auto !important;
  background: #FFFFFF !important;
}
