:root {
  --ai-base: #ffffff;
  --ai-text: #000000;
  --ai-header-bg: #111111;
  --ai-header-text: #ffffff;
  --ai-link: #0b57d0;
  --ai-btn-bg: #ffffff;
  --ai-btn-text: #111111;
  --ai-launcher-bg: #111111;
  --ai-launcher-tx: #ffffff;
}

/* Launcher (minimized) */
#ai-agent-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--ai-launcher-bg, var(--ai-header-bg));
  color: var(--ai-launcher-tx, var(--ai-header-text));
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
  z-index: 999999;
  min-width: fit-content;
}

.ai-launcher-logo {
  max-height: 22px;          /* litt større */
  width: auto;
  max-width: 160px;       /* justér etter behov */
  flex: 0 0 auto;        /* IKKE krymp */
  object-fit: contain;   /* behold proporsjoner */
  display: block;
}

.ai-launcher-text {
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
  flex: 0 0 auto;
}

/* Chat box */
#ai-agent-box {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 420px;
  height: 620px;
  background: var(--ai-base);
  color: var(--ai-text);
  border-radius: 18px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .20);
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  z-index: 999999;
}

.ai-header {
  padding: 12px 14px;
  background: var(--ai-header-bg);
  color: var(--ai-header-text);
  border-radius: 18px 18px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.ai-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ai-logo {
  flex: 0 0 auto;
  max-width: 160px;
  object-fit: contain;
  max-height: 22px;
  width: auto;
  display: block;
}

.ai-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
}

/* Header custom HTML */
.ai-header-custom h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  min-width: 0;
}

.ai-header-custom p {
  margin: 3px 0 0;
  font-size: 13px;
  line-height: 1.2;
  opacity: .9;
  font-weight: 400;
}

.ai-close {
  background: transparent;
  border: 0;
  color: var(--ai-header-text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

/* Messages as bubbles */
.ai-messages {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  margin: 0;
  line-height: 1.35;
  white-space: pre-wrap;
  padding: 10px 12px;
  border-radius: 16px;
  max-width: 85%;
}

.msg.bot {
  align-self: flex-start;
  background: rgba(0, 0, 0, .06);
  color: var(--ai-text);
}

/* Links inside messages */
.msg a,
.msg a:visited {
  color: var(--ai-link, var(--ai-text));
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg a:hover,
.msg a:focus {
  opacity: .9;
}
.msg.user a,
.msg.user a:visited {
  color: var(--ai-header-text);
}

.msg.user {
  align-self: flex-end;
  background: var(--ai-header-bg);
  color: var(--ai-header-text);
}

.msg.bot.ai-start {
  max-width: 100%;
  padding: 0;
  background: transparent;
}

/* Input */
.ai-input {
  display: flex;
  border-top: 1px solid rgba(0, 0, 0, .08);
}

#ai-msg {
  flex: 1;
  border: 0;
  padding: 12px 14px;
  font-size: 14px;
  outline: none;
}

#ai-send {
  width: 52px;
  background: var(--ai-header-bg);
  color: var(--ai-header-text);
  border: 0;
  cursor: pointer;
  font-size: 20px;
}

.ai-footnote {
  padding: 10px 14px;
  font-size: 12px;
  color: #666;
  border-top: 1px solid rgba(0, 0, 0, .06);
}

/* Start buttons */
.ai-start-wrap p { margin: 0 0 10px 0; }

.ai-start-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-start-actions a {
  display: block;
  text-decoration: none !important;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, .22);
  background: var(--ai-btn-bg);
  color: var(--ai-btn-text) !important;
}

.ai-start-actions a:hover,
.ai-start-actions a:focus,
.ai-start-actions a:active,
.ai-start-actions a:visited {
  color: var(--ai-btn-text) !important;
  text-decoration: none !important;
}

.ai-start-actions a:hover {
  filter: brightness(.98);
}

/* Small screens */
@media (max-width: 520px) {
  #ai-agent-box {
    top: 0;
    left: 0;
    right: 0; /* Full sticky width */
    bottom: 0; /* Full sticky height */
    width: 100%;
    height: 100%; /* Fallback */
    height: 100dvh; /* Dynamic viewport height */
    max-height: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  .ai-header {
    flex: 0 0 auto;
    border-radius: 0;
    padding: 14px 16px;
  }

  .ai-messages {
    flex: 1 1 auto;
    padding: 16px; 
    font-size: 15px;
  }

  .msg { 
    max-width: 88%; 
    padding: 10px 14px; 
  }

  /* Input area at bottom */
  .ai-input {
    flex: 0 0 auto;
    padding: 10px;
    background: var(--ai-base); /* Ensure background covers content behind */
    padding-bottom: env(safe-area-inset-bottom, 20px); /* Handle iPhone home bar */
  }

  #ai-msg {
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 12px;
  }

  /* Launcher visibility logic is handled by JS (applyOpenState) */
  /* #ai-agent-launcher { display: none !important; } NO! */
}


/* Force link colors inside widget (theme hover overrides)
   BUT: do NOT override start buttons (.msg.ai-start), they use --ai-btn-text */
#ai-agent-box .msg:not(.ai-start) a,
#ai-agent-box .msg:not(.ai-start) a:visited {
  color: #0b57d0 !important; /* Force standard blue */
  text-decoration: underline;
  font-weight: 500;
}

#ai-agent-box .msg:not(.ai-start) a:hover,
#ai-agent-box .msg:not(.ai-start) a:focus {
  color: #003c8f !important; /* Darker blue on hover */
  opacity: 1 !important;
}

#ai-agent-box .msg.user a,
#ai-agent-box .msg.user a:visited,
#ai-agent-box .msg.user a:hover,
#ai-agent-box .msg.user a:focus {
  color: var(--ai-header-text) !important;
}