/* Lanka Hit News AI — modern chat trigger + popup */
:root {
  --ai-navy: #071733;
  --ai-navy-mid: #12305f;
  --ai-ink: #0f172a;
  --ai-muted: #64748b;
  --ai-line: rgba(15, 23, 42, 0.1);
  --ai-surface: #ffffff;
  --ai-soft: #f3f6fb;
  --ai-primary: var(--red, #e30613);
  --ai-primary-deep: var(--red-deep, #b5040f);
  --ai-accent: var(--red, #e30613);
  --ai-ok: #129a5c;
  --ai-shadow: 0 18px 50px rgba(7, 23, 51, 0.18);
  --ai-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ai-header-bg: linear-gradient(135deg, var(--red-deep, #b5040f) 0%, var(--red, #e30613) 55%, #f0434c 100%);
  --ai-panel-bg:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), #fff 28%),
    radial-gradient(120% 80% at 0% 0%, color-mix(in srgb, var(--red) 10%, transparent), transparent 45%),
    radial-gradient(90% 70% at 100% 0%, color-mix(in srgb, var(--red) 8%, transparent), transparent 40%);
  --ai-messages-bg: linear-gradient(180deg, #fff5f5 0%, #faf7f7 40%, #f7f7f7 100%);
  --ai-composer-bg: rgba(255, 255, 255, 0.96);
  --ai-bot-bg: rgba(255, 255, 255, 0.95);
  --ai-bot-color: #334155;
  --ai-user-bg: linear-gradient(135deg, var(--red-deep, #b5040f), var(--red, #e30613));
  --ai-user-shadow: 0 8px 18px color-mix(in srgb, var(--red) 28%, transparent);
  --ai-link-bg: var(--soft-red, #fff1f2);
  --ai-link-color: var(--red-deep, #b5040f);
  --ai-link-border: color-mix(in srgb, var(--red) 28%, #fff);
  --ai-staff-bg: var(--soft-red, #fff1f2);
  --ai-staff-color: var(--red-deep, #b5040f);
  --ai-staff-border: color-mix(in srgb, var(--red) 30%, #fff);
  --ai-staff-hover: color-mix(in srgb, var(--red) 14%, #fff);
  --ai-shell-focus-bg: #fff;
  --ai-shell-focus-border: color-mix(in srgb, var(--red) 55%, #fff);
  --ai-shell-focus-ring: color-mix(in srgb, var(--red) 18%, transparent);
  --ai-toggle-bg: #fff;
  --ai-toggle-color: #334155;
  --ai-toggle-on-bg: var(--soft-red, #fff1f2);
  --ai-toggle-on-border: color-mix(in srgb, var(--red) 40%, var(--line, #e0e0e0));
  --ai-toggle-on-color: var(--red, #e30613);
  --ai-send-bg: linear-gradient(135deg, var(--red, #e30613) 0%, var(--red-deep, #b5040f) 100%);
  --ai-send-color: #fff;
}

/* Screen reader utility */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

html[data-theme="dark"],
body.mh-page,
.mh-page {
  --ai-ink: #f8fafc;
  --ai-muted: #94a3b8;
  --ai-line: rgba(255, 255, 255, 0.12);
  --ai-surface: #1e2433;
  --ai-soft: #181d2a;
  --ai-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  --ai-header-bg: linear-gradient(135deg, #7a040c 0%, var(--red, #e30613) 55%, #c91722 100%);
  --ai-panel-bg: #141824;
  --ai-messages-bg: #0f121b;
  --ai-composer-bg: #141824;
  --ai-bot-bg: #1e2433;
  --ai-bot-color: #f8fafc;
  --ai-user-bg: linear-gradient(135deg, var(--red-deep, #b5040f), var(--red, #e30613));
  --ai-user-shadow: 0 8px 18px rgba(227, 6, 19, 0.28);
  --ai-link-bg: rgba(225, 29, 72, 0.15);
  --ai-link-color: #ff8a92;
  --ai-link-border: rgba(225, 29, 72, 0.35);
  --ai-staff-bg: rgba(225, 29, 72, 0.14);
  --ai-staff-color: #ff8a92;
  --ai-staff-border: rgba(225, 29, 72, 0.3);
  --ai-staff-hover: rgba(225, 29, 72, 0.24);
  --ai-shell-focus-bg: #1e2433;
  --ai-shell-focus-border: rgba(225, 29, 72, 0.6);
  --ai-shell-focus-ring: rgba(225, 29, 72, 0.22);
  --ai-toggle-bg: #1e2433;
  --ai-toggle-color: #f1f5f9;
  --ai-toggle-on-bg: rgba(225, 29, 72, 0.18);
  --ai-toggle-on-border: rgba(225, 29, 72, 0.45);
  --ai-toggle-on-color: #ff8a92;
  --ai-send-bg: linear-gradient(135deg, var(--red, #e30613) 0%, var(--red-deep, #b5040f) 100%);
  --ai-send-color: #fff;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --ai-ink: #f8fafc;
    --ai-muted: #94a3b8;
    --ai-line: rgba(255, 255, 255, 0.12);
    --ai-surface: #1e2433;
    --ai-soft: #181d2a;
    --ai-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    --ai-header-bg: linear-gradient(135deg, #7a040c 0%, var(--red, #e30613) 55%, #c91722 100%);
    --ai-panel-bg: #141824;
    --ai-messages-bg: #0f121b;
    --ai-composer-bg: #141824;
    --ai-bot-bg: #1e2433;
    --ai-bot-color: #f8fafc;
    --ai-user-bg: linear-gradient(135deg, var(--red-deep, #b5040f), var(--red, #e30613));
    --ai-user-shadow: 0 8px 18px rgba(227, 6, 19, 0.28);
    --ai-link-bg: rgba(225, 29, 72, 0.15);
    --ai-link-color: #ff8a92;
    --ai-link-border: rgba(225, 29, 72, 0.35);
    --ai-staff-bg: rgba(225, 29, 72, 0.14);
    --ai-staff-color: #ff8a92;
    --ai-staff-border: rgba(225, 29, 72, 0.3);
    --ai-staff-hover: rgba(225, 29, 72, 0.24);
    --ai-shell-focus-bg: #1e2433;
    --ai-shell-focus-border: rgba(225, 29, 72, 0.6);
    --ai-shell-focus-ring: rgba(225, 29, 72, 0.22);
    --ai-toggle-bg: #1e2433;
    --ai-toggle-color: #f1f5f9;
    --ai-toggle-on-bg: rgba(225, 29, 72, 0.18);
    --ai-toggle-on-border: rgba(225, 29, 72, 0.45);
    --ai-toggle-on-color: #ff8a92;
    --ai-send-bg: linear-gradient(135deg, var(--red, #e30613) 0%, var(--red-deep, #b5040f) 100%);
    --ai-send-color: #fff;
  }
}

/* Trigger button — same dark chrome as Tripzant search / active tab */
.ai-chat-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 14px 0 10px;
  border: 1px solid color-mix(in srgb, var(--chrome) 40%, transparent);
  border-radius: 12px;
  background: linear-gradient(135deg, var(--chrome) 0%, color-mix(in srgb, var(--chrome) 78%, #000) 100%);
  color: var(--chrome-text);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s var(--ai-ease), box-shadow 0.2s var(--ai-ease), filter 0.2s ease;
}

.ai-chat-trigger:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  filter: brightness(1.06);
  background: linear-gradient(135deg, var(--chrome) 0%, color-mix(in srgb, var(--chrome) 78%, #000) 100%);
}

.ai-chat-trigger:active {
  transform: translateY(0);
}

.ai-chat-trigger:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.ai-chat-trigger-icon {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}

.ai-chat-trigger-icon svg {
  width: 15px;
  height: 15px;
  display: block;
}

.ai-chat-trigger-label {
  display: inline-block;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.ai-chat-trigger-hint,
.ai-chat-trigger-copy {
  display: none;
}

.ai-chat-trigger-live {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  border: 2px solid var(--chrome);
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.45);
  animation: ai-live-pulse 2.2s infinite;
}

@keyframes ai-live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.45); }
  70% { box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

/* Backdrop + panel */
.ai-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1299;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 1;
  transition: opacity 0.22s ease;
}

.ai-chat-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.ai-chat-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1300;
  width: min(420px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 32px));
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid var(--ai-line, rgba(255, 255, 255, 0.15));
  background: var(--ai-panel-bg, #141824);
  color: var(--ai-ink, #f8fafc);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  transform-origin: bottom right;
  animation: ai-panel-in 0.28s var(--ai-ease);
}

.ai-chat-widget.hidden {
  display: none;
}

@keyframes ai-panel-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

body.ai-chat-open {
  overflow: hidden;
}

/* Header */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
  background: var(--ai-header-bg);
  color: #fff;
  position: relative;
  overflow: hidden;
}

.ai-chat-header::after {
  content: "";
  position: absolute;
  inset: auto -20% -40% auto;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.12), transparent 65%);
  pointer-events: none;
}

.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.ai-chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.06));
  border: 1px solid rgba(255, 255, 255, 0.18);
  flex-shrink: 0;
}

.ai-chat-avatar svg {
  width: 20px;
  height: 20px;
  display: block;
}

.ai-chat-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.ai-chat-header p {
  margin: 3px 0 0;
  font-size: 11px;
  color: rgba(226, 232, 240, 0.86);
  line-height: 1.3;
}

.ai-chat-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #a7f3d0;
}

.ai-chat-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
}

.ai-chat-close {
  position: relative;
  z-index: 1;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: background 0.18s ease;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.16);
}

.ai-chat-close svg {
  width: 16px;
  height: 16px;
}

/* Messages */
.ai-chat-messages {
  padding: 16px 14px;
  display: grid;
  gap: 12px;
  align-content: start;
  overflow: auto;
  background: var(--ai-messages-bg);
  scrollbar-width: thin;
}

.ai-chat-msg {
  display: flex;
  animation: ai-msg-in 0.24s var(--ai-ease);
}

@keyframes ai-msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-chat-msg--user {
  justify-content: flex-end;
}

.ai-chat-bubble {
  max-width: 90%;
  padding: 11px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}

.ai-chat-msg--bot .ai-chat-bubble {
  background: var(--ai-bot-bg);
  border: 1px solid var(--ai-line);
  color: var(--ai-bot-color);
  border-bottom-left-radius: 6px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.04);
}

.ai-chat-msg--user .ai-chat-bubble {
  background: var(--ai-user-bg);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: var(--ai-user-shadow);
}

.ai-chat-text {
  white-space: pre-wrap;
}

.ai-chat-typing .ai-chat-bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 16px;
}

.ai-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: ai-chat-dot 1.2s infinite ease-in-out;
}

.ai-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-chat-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-3px); opacity: 1; }
}

.ai-chat-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ai-chat-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 999px;
  background: var(--ai-link-bg);
  color: var(--ai-link-color);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  border: 1px solid var(--ai-link-border);
  transition: background 0.18s ease, transform 0.18s ease;
}

.ai-chat-link::after {
  content: "→";
  font-weight: 700;
  opacity: 0.7;
}

.ai-chat-link:hover {
  background: var(--ai-link-bg);
  filter: brightness(1.08);
  transform: translateY(-1px);
}

/* Composer dock */
.ai-chat-composer {
  border-top: 1px solid var(--ai-line);
  background: var(--ai-composer-bg);
  padding: 10px 12px 12px;
  display: grid;
  gap: 10px;
}

.ai-chat-voice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
}

.ai-chat-mic {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(145deg, #129a5c, #0f7f4c);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 8px 16px rgba(15, 159, 95, 0.25);
  transition: transform 0.18s ease, filter 0.18s ease;
}

.ai-chat-mic svg {
  width: 18px;
  height: 18px;
}

.ai-chat-mic:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: #94a3b8;
  box-shadow: none;
}

.ai-chat-mic:not(:disabled):hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.ai-chat-mic.is-listening {
  background: linear-gradient(145deg, var(--red, #e30613), var(--red-deep, #b5040f));
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 35%, transparent);
  animation: ai-chat-pulse 1.2s infinite ease-in-out;
}

@keyframes ai-chat-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 35%, transparent); }
  70% { box-shadow: 0 0 0 12px color-mix(in srgb, var(--red) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 35%, transparent); }
}

.ai-chat-voice-status {
  flex: 1;
  font-size: 12px;
  font-weight: 700;
  color: var(--ai-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat-voice-status.is-listening {
  color: var(--ai-accent);
}

.ai-chat-speak-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  background: var(--ai-toggle-bg);
  color: var(--ai-toggle-color);
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.ai-chat-speak-toggle svg {
  width: 17px;
  height: 17px;
}

.ai-chat-speak-toggle .icon-mute {
  display: none;
}

.ai-chat-speak-toggle.is-on {
  background: var(--ai-toggle-on-bg);
  border-color: var(--ai-toggle-on-border);
  color: var(--ai-toggle-on-color);
}

.ai-chat-speak-toggle:not(.is-on) .icon-sound {
  display: none;
}

.ai-chat-speak-toggle:not(.is-on) .icon-mute {
  display: block;
}

.ai-chat-form {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
}

.ai-chat-form-shell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  width: 100%;
  padding: 4px 6px 4px 14px;
  border: 1px solid var(--ai-line);
  border-radius: 999px;
  background: var(--ai-soft);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.ai-chat-form-shell:focus-within {
  background: var(--ai-shell-focus-bg);
  border-color: var(--ai-shell-focus-border);
  box-shadow: 0 0 0 4px var(--ai-shell-focus-ring);
}

.ai-chat-form input,
.ai-chat-form-shell input {
  flex: 1;
  min-width: 0;
  height: 38px;
  border: 0;
  border-radius: 0;
  padding: 0;
  font-size: 14px;
  outline: 0;
  background: transparent;
  color: var(--ai-ink);
  box-shadow: none;
}

.ai-chat-form input:focus,
.ai-chat-form-shell input:focus {
  border: 0;
  box-shadow: none;
}

.ai-chat-send {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--ai-send-bg);
  color: var(--ai-send-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.18s ease, filter 0.18s ease;
}

.ai-chat-send svg {
  width: 16px;
  height: 16px;
}

.ai-chat-send:hover {
  filter: brightness(1.08);
  transform: scale(1.04);
  background: var(--ai-send-bg);
}

.ai-chat-footer {
  padding: 0;
  background: transparent;
}

.ai-chat-staff-btn {
  width: 100%;
  border: 1px solid var(--ai-staff-border);
  background: var(--ai-staff-bg);
  color: var(--ai-staff-color);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;
}

.ai-chat-staff-btn:hover {
  background: var(--ai-staff-hover);
  transform: translateY(-1px);
}

@media (max-width: 780px) {
  .ai-chat-backdrop {
    z-index: 1299;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .ai-chat-widget {
    left: 12px;
    right: 12px;
    top: 56px;
    bottom: 74px;
    width: auto;
    height: auto;
    max-height: calc(100vh - 130px);
    z-index: 1300;
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.85);
    background: #141824 !important;
  }

  .ai-chat-messages {
    background: #0f121b !important;
  }

  .ai-chat-composer {
    background: #141824 !important;
  }

  .ai-chat-trigger {
    height: 42px;
    padding: 0 10px;
    gap: 0;
  }

  .ai-chat-trigger-label {
    display: none;
  }

  .ai-chat-trigger-icon {
    width: 26px;
    height: 26px;
  }
}
