/* ================================
   HasteSolutions Chat Widget
   Matcher styles.css-paletten
   ================================ */

.chat {
  position: fixed;
  right: clamp(1rem, 2vw, 2.5rem);
  bottom: clamp(1rem, 2vw, 2.5rem);
  width: clamp(320px, 28vw, 400px);
  height: clamp(460px, 62vh, 580px);
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 2rem);

  display: flex;
  flex-direction: column;
  overflow: hidden;

  background: var(--background);
  border: 1px solid var(--border-color);
  border-radius: clamp(var(--radius-md), 1rem, 1.25rem);
  box-shadow: var(--shadow-lg);

  font-family: var(--font-main);
  transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
              width 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.3s ease,
              border-radius 0.3s ease;
  z-index: 999;
}

/* Header */

.chat__header {
  position: relative;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);

  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.95rem;
  user-select: none;
  cursor: default;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 3.25rem;
}

/* Minimize / toggle knapp oppe til høyre */

.chat__toggle {
  position: absolute;
  top: 8px;
  right: 8px;

  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(15, 23, 42, 0.2); /* semi-transparent mørk */
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(6px);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.chat__toggle:hover {
  background: rgba(15, 23, 42, 0.35);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-1px);
}

/* Meldingslogg */

.chat__log {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  overflow: auto;
  background: var(--background-alt);
}

/* Bobler */

.msg {
  padding: 0.6rem 0.9rem;
  border-radius: 0.75rem;
  max-width: 85%;
  width: fit-content;
  white-space: pre-wrap;
  line-height: 1.4;
  font-size: 0.9rem;
}

/* Brukermelding (høyre, blå) */

.msg.user {
  margin-left: auto;
  background: var(--primary-color);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

/* Botmelding (venstre, lys kort-stil) */

.msg.bot {
  background: #ffffff;
  color: var(--text-dark);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

/* Input-område */

.chat__form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: #ffffff;
  border-top: 1px solid var(--border-color);
}

.chat__form input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-color);
  background: var(--background);
  color: var(--text-dark);
  font-size: 0.9rem;
  font-family: var(--font-main);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat__form input::placeholder {
  color: var(--text-light);
}

.chat__form input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.2);
}

/* Send-knapp */

.chat__form button {
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  border: 2px solid transparent;

  background: var(--primary-color);
  color: #ffffff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;

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

  transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}

.chat__form button:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.chat__form button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.chat__form button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Minimized state */

.chat--minimized {
  height: 64px;
  width: clamp(260px, 22vw, 340px);
  overflow: hidden;
  transform: scale(0.98);
  box-shadow: var(--shadow-sm);
  border-radius: 999px;
}

.chat--minimized .chat__header {
  font-size: 0.85rem;
  padding: 0.45rem 2.8rem 0.45rem 1rem; /* plass til toggle-knapp */
  border-bottom: none;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat--minimized .chat__log,
.chat--minimized .chat__form {
  display: none;
  opacity: 0;
}

/* Smooth fade-in for chat content when expanding */
.chat:not(.chat--minimized) .chat__log,
.chat:not(.chat--minimized) .chat__form {
  animation: fadeInContent 0.4s ease 0.15s both;
}

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

/* Enkel responsiv justering */

@media (max-width: 1024px) {
  .chat {
    right: 1rem;
    bottom: 1rem;
    width: clamp(300px, 40vw, 380px);
    height: min(65vh, 560px);
  }

  .chat--minimized {
    width: clamp(220px, 28vw, 320px);
    height: clamp(56px, 9vh, 70px);
  }
}

@media (max-width: 768px) {
  .chat {
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    max-width: 420px;
    margin: 0 auto;
    height: min(70vh, 520px);
    border-radius: var(--radius-lg);
  }

  .chat--minimized {
    width: min(280px, 40vw);
    max-width: 40vw;
    height: clamp(52px, 11vh, 68px);
    margin-left: auto;
    margin-right: 0.75rem;
    left: auto;
    right: 0.75rem;
  }

  .chat--minimized .chat__header {
    font-size: 0.9rem;
    padding: 0.5rem 2.5rem 0.5rem 1rem;
  }
}

@media (max-width: 480px) {
  .chat {
    left: 0.5rem;
    right: 0.5rem;
    bottom: 0.75rem;
    height: min(68vh, 480px);
    max-width: none;
  }

  .chat--minimized {
    width: min(240px, 40vw);
    max-width: 40vw;
    height: clamp(48px, 12vh, 60px);
    right: 0.5rem;
    left: auto;
    margin: 0;
  }
}
