/* Asisten Layanan PTSP KLH/BPLH floating chatbot — scoped with klh-chat-* */

.klh-chat-root {
  --klh-chat-primary: var(--g-600, #005952);
  --klh-chat-primary-hover: var(--g-700, #00453F);
  --klh-chat-primary-dark: var(--g-800, #003631);
  --klh-chat-primary-deep: var(--g-900, #002623);
  --klh-chat-accent: var(--o-500, #F97910);
  --klh-chat-on-accent: var(--on-orange, #3A1B02);
  --klh-chat-bg: var(--surface, #FFFFFF);
  --klh-chat-surface-2: var(--surface-2, #F5F9F8);
  --klh-chat-tint: var(--g-50, #F1F8F8);
  --klh-chat-tint-strong: var(--g-100, #DEF2F1);
  --klh-chat-ink: var(--ink-900, #10201D);
  --klh-chat-muted: var(--ink-500, #51625E);
  --klh-chat-border: var(--line, #E1E8E6);
  --klh-chat-border-strong: var(--line-strong, #C7D2CF);
  --klh-chat-shadow: var(--sh-3, 0 12px 32px rgba(0, 54, 49, 0.12));
  --klh-chat-font: var(--font-body, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
  --klh-chat-display: var(--font-display, 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif);

  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1080;
  font-family: var(--klh-chat-font);
  line-height: 1.45;
  color: var(--klh-chat-ink);
  box-sizing: border-box;
}

.klh-chat-root *,
.klh-chat-root *::before,
.klh-chat-root *::after {
  box-sizing: border-box;
}

/* ---------- Floating launcher ---------- */

.klh-chat-launcher {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.klh-chat-launcher:hover {
  transform: translateY(-2px);
}

.klh-chat-launcher:focus-visible {
  outline: 3px solid var(--b-500, #147DEF);
  outline-offset: 4px;
  border-radius: 999px;
}

.klh-chat-orb {
  position: relative;
  z-index: 1;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--klh-chat-primary);
  background: var(--klh-chat-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--sh-2, 0 2px 6px rgba(0, 54, 49, 0.08), 0 6px 16px rgba(0, 54, 49, 0.07));
  overflow: visible;
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.klh-chat-launcher:hover .klh-chat-orb {
  border-color: var(--klh-chat-primary-hover);
  box-shadow: var(--klh-chat-shadow);
}

.klh-chat-orb-logo {
  width: 38px;
  height: 38px;
  object-fit: contain;
  display: block;
}

.klh-chat-orb-close {
  display: none;
  width: 26px;
  height: 26px;
  color: #ffffff;
}

.klh-chat-badge {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--klh-chat-bg);
  background: var(--klh-chat-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--sh-1, 0 1px 2px rgba(0, 54, 49, 0.06), 0 1px 3px rgba(0, 54, 49, 0.05));
}

.klh-chat-badge svg {
  width: 11px;
  height: 11px;
  fill: var(--klh-chat-on-accent);
}

/* Open state launcher */
.klh-chat-root.is-open .klh-chat-orb {
  border-color: var(--klh-chat-primary-dark);
  background: var(--klh-chat-primary-dark);
}

.klh-chat-root.is-open .klh-chat-orb-logo,
.klh-chat-root.is-open .klh-chat-badge {
  display: none;
}

.klh-chat-root.is-open .klh-chat-orb-close {
  display: block;
}

/* ---------- Panel ---------- */

.klh-chat-panel {
  position: absolute;
  right: 0;
  bottom: 84px;
  width: min(400px, calc(100vw - 32px));
  height: min(580px, calc(100vh - 120px));
  display: none;
  flex-direction: column;
  background: var(--klh-chat-bg);
  border: 1px solid var(--klh-chat-border);
  border-radius: var(--r-lg, 16px);
  overflow: hidden;
  box-shadow: var(--klh-chat-shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.klh-chat-root.is-open .klh-chat-panel {
  display: flex;
  animation: klh-chat-panel-in 0.22s ease forwards;
  pointer-events: auto;
}

@keyframes klh-chat-panel-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
.klh-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
  background: var(--klh-chat-bg);
  color: var(--klh-chat-primary-dark);
  flex-shrink: 0;
}

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

.klh-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--klh-chat-border);
  background: var(--klh-chat-tint);
  object-fit: contain;
  padding: 4px;
  flex-shrink: 0;
}

.klh-chat-heading {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.klh-chat-title {
  margin: 0;
  font-family: var(--klh-chat-display);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--klh-chat-primary-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.klh-chat-subtitle {
  margin: 0;
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.klh-chat-subtitle-lead {
  font-weight: 700;
  color: var(--klh-chat-primary);
}

.klh-chat-subtitle-rest {
  font-weight: 500;
  color: var(--klh-chat-muted);
}

.klh-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.klh-chat-icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--klh-chat-border);
  border-radius: var(--r-sm, 8px);
  background: var(--klh-chat-surface-2);
  color: var(--klh-chat-primary-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.klh-chat-icon-btn:hover {
  background: var(--klh-chat-tint);
  border-color: var(--klh-chat-border-strong);
  color: var(--klh-chat-primary);
}

.klh-chat-icon-btn:focus-visible {
  outline: 2px solid var(--b-500, #147DEF);
  outline-offset: 2px;
}

.klh-chat-icon-btn svg {
  width: 16px;
  height: 16px;
}

.klh-chat-accent-bar {
  height: 3px;
  background: var(--klh-chat-accent);
  flex-shrink: 0;
}

.klh-chat-icon-btn.is-active {
  background: var(--klh-chat-tint-strong);
  border-color: var(--klh-chat-primary);
  color: var(--klh-chat-primary-dark);
}

/* History Panel */
.klh-chat-history {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  background: var(--klh-chat-surface-2);
}

.klh-chat-root.is-history-open .klh-chat-history {
  display: flex;
}

.klh-chat-root.is-history-open .klh-chat-body,
.klh-chat-root.is-history-open .klh-chat-footer {
  display: none !important;
}

.klh-chat-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 4px;
}

.klh-chat-history-head-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.klh-chat-history-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--klh-chat-primary);
  font-family: var(--klh-chat-display);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.klh-chat-history-back svg {
  width: 16px;
  height: 16px;
}

.klh-chat-history-back:hover {
  color: var(--klh-chat-primary-dark);
}

.klh-chat-history-title {
  margin: 0;
  font-family: var(--klh-chat-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--klh-chat-primary-dark);
}

.klh-chat-history-hint {
  margin: 0;
  padding: 0 14px 8px;
  font-size: 11.5px;
  color: var(--klh-chat-muted);
}

.klh-chat-history-clear {
  border: 0;
  background: transparent;
  color: var(--klh-chat-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  flex-shrink: 0;
}

.klh-chat-history-clear:hover {
  color: var(--danger, #C03A2B);
}

.klh-chat-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.klh-chat-history-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-bottom: 1px solid var(--klh-chat-border);
  border-radius: 0;
  background: transparent;
  padding: 12px 8px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.2s ease;
}

.klh-chat-history-item:last-child {
  border-bottom: 0;
}

.klh-chat-history-item:hover {
  background: var(--klh-chat-tint);
}

.klh-chat-history-item.is-current {
  background: var(--klh-chat-tint-strong);
}

.klh-chat-history-item-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm, 8px);
  background: var(--klh-chat-tint-strong);
  color: var(--klh-chat-primary-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.klh-chat-history-item.is-current .klh-chat-history-item-icon {
  background: var(--klh-chat-primary);
  color: #ffffff;
}

.klh-chat-history-item-icon svg {
  width: 16px;
  height: 16px;
}

.klh-chat-history-item-body {
  min-width: 0;
  flex: 1;
}

.klh-chat-history-item-title {
  display: block;
  font-family: var(--klh-chat-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--klh-chat-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.klh-chat-history-item-meta {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--klh-chat-muted);
}

.klh-chat-history-empty {
  margin: 0;
  padding: 16px 14px 20px;
  font-size: 12.5px;
  color: var(--klh-chat-muted);
  line-height: 1.5;
  text-align: center;
}

/* Messages */
.klh-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--klh-chat-surface-2);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.klh-chat-msg {
  display: flex;
  max-width: 88%;
}

.klh-chat-msg--user {
  align-self: flex-end;
}

.klh-chat-msg--assistant {
  align-self: flex-start;
}

.klh-chat-bubble {
  padding: 10px 12px;
  border-radius: var(--r-md, 12px);
  font-size: 13px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.klh-chat-msg--user .klh-chat-bubble {
  background: var(--klh-chat-primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.klh-chat-msg--assistant .klh-chat-bubble {
  background: var(--klh-chat-bg);
  color: var(--klh-chat-ink);
  border: 1px solid var(--klh-chat-border);
  border-bottom-left-radius: 4px;
}

.klh-chat-bubble p {
  margin: 0 0 0.55em;
}

.klh-chat-bubble p:last-child {
  margin-bottom: 0;
}

.klh-chat-bubble strong {
  font-weight: 600;
}

.klh-chat-bubble ul,
.klh-chat-bubble ol {
  margin: 0.35em 0 0.55em;
  padding-left: 1.2em;
}

.klh-chat-bubble li {
  margin: 0.2em 0;
}

.klh-chat-bubble h1,
.klh-chat-bubble h2,
.klh-chat-bubble h3,
.klh-chat-bubble h4 {
  margin: 0 0 0.4em;
  font-family: var(--klh-chat-display);
  font-size: 13px;
  font-weight: 700;
}

.klh-chat-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--klh-chat-border);
}

.klh-chat-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--r-sm, 8px);
  background: var(--klh-chat-primary);
  color: #ffffff !important;
  font-family: var(--klh-chat-display);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none !important;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.klh-chat-link-btn:hover {
  transform: translateY(-1px);
  background: var(--klh-chat-primary-hover);
  color: #ffffff !important;
}

.klh-chat-link-btn-icon {
  display: inline-flex;
  flex-shrink: 0;
}

.klh-chat-link-btn-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.klh-chat-bubble p .klh-chat-link-btn {
  display: none;
}

.klh-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 2px;
}

.klh-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--klh-chat-primary);
  opacity: 0.35;
  animation: klh-chat-typing 1.2s ease-in-out infinite;
}

.klh-chat-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.klh-chat-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes klh-chat-typing {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* Footer */
.klh-chat-footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--klh-chat-border);
  background: var(--klh-chat-bg);
  flex-shrink: 0;
}

.klh-chat-input {
  flex: 1;
  min-height: 42px;
  max-height: 110px;
  resize: none;
  border: 1.5px solid var(--klh-chat-border-strong);
  border-radius: var(--r-sm, 8px);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--klh-chat-ink);
  background: var(--klh-chat-bg);
  outline: none;
  line-height: 1.4;
}

.klh-chat-input::placeholder {
  color: var(--klh-chat-muted);
}

.klh-chat-input:focus {
  border-color: var(--klh-chat-primary);
  box-shadow: 0 0 0 3px rgba(0, 89, 82, 0.14);
}

.klh-chat-send {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: 0;
  border-radius: var(--r-sm, 8px);
  background: var(--klh-chat-primary);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, opacity 0.2s ease;
}

.klh-chat-send:hover:not(:disabled) {
  background: var(--klh-chat-primary-hover);
}

.klh-chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.klh-chat-send svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 480px) {
  .klh-chat-root {
    right: 16px;
    bottom: 16px;
  }

  .klh-chat-orb {
    width: 58px;
    height: 58px;
  }

  .klh-chat-orb-logo {
    width: 34px;
    height: 34px;
  }

  .klh-chat-panel {
    bottom: 76px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .klh-chat-launcher,
  .klh-chat-orb,
  .klh-chat-icon-btn,
  .klh-chat-history-item,
  .klh-chat-link-btn,
  .klh-chat-send {
    transition: none !important;
  }

  .klh-chat-launcher:hover,
  .klh-chat-link-btn:hover {
    transform: none !important;
  }

  .klh-chat-root.is-open .klh-chat-panel,
  .klh-chat-typing span {
    animation: none !important;
    opacity: 1;
    transform: none;
  }
}
