:root {
  --kcah-bg: #FDFBF7;
  --kcah-ink: #111111;
  --kcah-primary: #0285A4;
  --kcah-primary-soft: #E7F4F7;
  --kcah-secondary: #9CCC4D;
  --kcah-font-heading: 'Staatliches', sans-serif;
  --kcah-font-body: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Defensive reset scoped tightly to the widget root */
.kcah-triage-root,
.kcah-triage-root *,
.kcah-triage-root *::before,
.kcah-triage-root *::after {
  box-sizing: border-box;
}

.kcah-triage-root {
  font-family: var(--kcah-font-body);
  color: var(--kcah-ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.kcah-triage-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mobile backdrop (no blur / no glassmorphism) */
.kcah-triage-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99998;
  background: rgba(17, 17, 17, 0.55);
}

.kcah-triage-backdrop.is-open {
  display: none;
}

/* Floating launcher button */
.kcah-triage-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 99999;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 13px 20px;
  background: var(--kcah-primary);
  color: #FFFFFF;
  font-family: var(--kcah-font-heading);
  font-size: 1.25rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.15;
  text-decoration: none;
  text-transform: none;
  border: 3px solid var(--kcah-ink);
  border-radius: 999px;
  box-shadow: 4px 4px 0px var(--kcah-ink);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.08s ease, color 0.08s ease;
}

.kcah-triage-launcher:hover,
.kcah-triage-launcher:focus-visible {
  background: var(--kcah-secondary);
  color: var(--kcah-ink);
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0px var(--kcah-ink);
}

.kcah-triage-launcher:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--kcah-ink);
}

.kcah-triage-launcher[hidden] {
  display: none;
}

.kcah-triage-launcher-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kcah-triage-launcher-arrow {
  display: inline-block;
  font-family: var(--kcah-font-body);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1;
}

/* Main chat widget panel */
.kcah-triage-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  width: calc(100vw - 48px);
  max-width: 400px;
  height: min(580px, calc(100vh - 48px));
  max-height: calc(100vh - 48px);
  background: var(--kcah-bg);
  color: var(--kcah-ink);
  border: 3px solid var(--kcah-ink);
  border-radius: 12px;
  box-shadow: 5px 5px 0px var(--kcah-ink);
  overflow: hidden;
  animation: kcah-triage-panel-in 0.16s ease-out;
}

.kcah-triage-panel[hidden] {
  display: none;
}

/* Colour-blocked header bar */
.kcah-triage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--kcah-primary);
  color: #FFFFFF;
  border-bottom: 3px solid var(--kcah-ink);
  flex-shrink: 0;
}

.kcah-triage-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.kcah-triage-header-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background: #FFFFFF;
  color: var(--kcah-primary);
  border: 2px solid var(--kcah-ink);
  border-radius: 50%;
  box-shadow: 2px 2px 0px var(--kcah-ink);
}

.kcah-triage-title {
  margin: 0;
  padding: 0;
  font-family: var(--kcah-font-heading);
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.1;
  color: #FFFFFF;
}

.kcah-triage-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  margin: 0;
  padding: 0;
  background: #FFFFFF;
  color: var(--kcah-ink);
  font-family: var(--kcah-font-body);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  border: 2px solid var(--kcah-ink);
  border-radius: 8px;
  box-shadow: 2px 2px 0px var(--kcah-ink);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.08s ease;
}

.kcah-triage-close:hover,
.kcah-triage-close:focus-visible {
  background: var(--kcah-secondary);
  color: var(--kcah-ink);
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0px var(--kcah-ink);
}

.kcah-triage-close:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--kcah-ink);
}

/* High-contrast disclaimer strip */
.kcah-triage-disclaimer {
  padding: 7px 14px;
  background: var(--kcah-primary-soft);
  color: var(--kcah-ink);
  border-bottom: 2px solid var(--kcah-ink);
  font-family: var(--kcah-font-body);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
  flex-shrink: 0;
}

.kcah-triage-disclaimer[hidden] {
  display: none;
}

/* Scrollable chat viewport */
.kcah-triage-body {
  padding: 16px 14px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  background: var(--kcah-bg);
  color: var(--kcah-ink);
  scrollbar-width: thin;
  scrollbar-color: rgba(17, 17, 17, 0.35) transparent;
}

.kcah-triage-body:focus {
  outline: none;
}

/* Chat message stack */
.kcah-triage-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Message rows */
.kcah-triage-row {
  display: flex;
  width: 100%;
  animation: kcah-triage-msg-in 0.2s ease-out both;
}

.kcah-triage-row--bot {
  align-items: flex-start;
  gap: 8px;
}

.kcah-triage-row--user {
  justify-content: flex-end;
  padding-left: 36px;
}

/* Small bot avatar beside incoming bubbles */
.kcah-triage-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  background: var(--kcah-primary);
  color: #FFFFFF;
  border: 2px solid var(--kcah-ink);
  border-radius: 50%;
  box-shadow: 2px 2px 0px var(--kcah-ink);
}

/* Chat bubbles */
.kcah-triage-bubble {
  border: 2px solid var(--kcah-ink);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.kcah-triage-bubble:focus {
  outline: none;
}

.kcah-triage-bubble--bot {
  max-width: calc(100% - 36px);
  padding: 11px 14px;
  background: #FFFFFF;
  color: var(--kcah-ink);
  border-radius: 4px 16px 16px 16px;
  box-shadow: 3px 3px 0px var(--kcah-ink);
}

.kcah-triage-bubble--user {
  max-width: 100%;
  padding: 9px 14px;
  background: var(--kcah-secondary);
  color: var(--kcah-ink);
  font-family: var(--kcah-font-body);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.4;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 2px 2px 0px var(--kcah-ink);
}

/* Typing indicator bubble */
.kcah-triage-bubble--typing {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 10px 14px;
}

.kcah-triage-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.kcah-triage-typing-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--kcah-primary);
  border: 1.5px solid var(--kcah-ink);
  border-radius: 50%;
  animation: kcah-triage-typing-bounce 1.05s infinite ease-in-out;
}

.kcah-triage-typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.kcah-triage-typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}

/* Bot bubble rich HTML content */
.kcah-triage-bubble-content {
  font-family: var(--kcah-font-body);
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--kcah-ink);
}

.kcah-triage-bubble-content h3,
.kcah-triage-bubble-content h4 {
  margin: 0 0 8px;
  padding: 0;
  font-family: var(--kcah-font-heading);
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.18;
  color: var(--kcah-ink);
}

.kcah-triage-bubble-content h3 {
  font-size: 1.28rem;
}

.kcah-triage-bubble-content h4 {
  font-size: 1.1rem;
}

.kcah-triage-bubble-content p {
  margin: 0 0 8px;
  color: var(--kcah-ink);
}

.kcah-triage-bubble-content ul {
  margin: 0 0 10px;
  padding-left: 18px;
  list-style: square;
}

.kcah-triage-bubble-content li {
  margin: 0 0 3px;
}

.kcah-triage-bubble-content > :last-child {
  margin-bottom: 0;
}

.kcah-triage-bubble-content a {
  color: var(--kcah-ink);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.kcah-triage-bubble-content a:hover,
.kcah-triage-bubble-content a:focus-visible {
  background: var(--kcah-secondary);
  color: var(--kcah-ink);
}

/* Quick-reply chips & action links */
.kcah-triage-options {
  display: flex;
  gap: 8px;
  margin-top: 2px;
  animation: kcah-triage-options-in 0.22s ease-out both;
}

.kcah-triage-options:empty {
  display: none;
}

.kcah-triage-options--replies {
  flex-wrap: wrap;
  justify-content: flex-end;
  padding-left: 24px;
}

.kcah-triage-options--actions {
  flex-direction: column;
  padding-left: 36px;
}

.kcah-triage-option {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 100%;
  margin: 0;
  font-family: var(--kcah-font-body);
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
  text-decoration: none;
  border: 2px solid var(--kcah-ink);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.08s ease, color 0.08s ease;
}

.kcah-triage-option--reply {
  padding: 9px 14px;
  background: #FFFFFF;
  color: var(--kcah-ink);
  border-radius: 18px;
  box-shadow: 2px 2px 0px var(--kcah-ink);
}

.kcah-triage-option--reply:hover,
.kcah-triage-option--reply:focus-visible {
  background: var(--kcah-secondary);
  color: var(--kcah-ink);
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0px var(--kcah-ink);
}

.kcah-triage-option--link {
  padding: 10px 14px;
  background: var(--kcah-primary);
  color: #FFFFFF;
  border-radius: 12px;
  box-shadow: 3px 3px 0px var(--kcah-ink);
}

.kcah-triage-options--replies .kcah-triage-option--link {
  padding: 9px 14px;
  border-radius: 18px;
  box-shadow: 2px 2px 0px var(--kcah-ink);
}

.kcah-triage-options--actions .kcah-triage-option--link {
  width: 100%;
}

.kcah-triage-option--link:hover,
.kcah-triage-option--link:focus-visible {
  background: var(--kcah-secondary);
  color: var(--kcah-ink);
  text-decoration: none;
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0px var(--kcah-ink);
}

.kcah-triage-option:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--kcah-ink);
}

.kcah-triage-option-label {
  flex: 1 1 auto;
}

.kcah-triage-option-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

/* Navigation footer (Back & Start again) */
.kcah-triage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--kcah-bg);
  border-top: 2px solid var(--kcah-ink);
  flex-shrink: 0;
}

.kcah-triage-footer[hidden] {
  display: none;
}

.kcah-triage-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 7px 12px;
  background: #FFFFFF;
  color: var(--kcah-ink);
  font-family: var(--kcah-font-body);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.2;
  border: 2px solid var(--kcah-ink);
  border-radius: 8px;
  box-shadow: 2px 2px 0px var(--kcah-ink);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.08s ease;
}

.kcah-triage-nav-btn:hover,
.kcah-triage-nav-btn:focus-visible {
  background: var(--kcah-secondary);
  color: var(--kcah-ink);
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0px var(--kcah-ink);
}

.kcah-triage-nav-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--kcah-ink);
}

.kcah-triage-nav-btn[hidden] {
  display: none;
}

/* Unmistakable high-contrast focus states */
.kcah-triage-root button:focus-visible,
.kcah-triage-root a:focus-visible,
.kcah-triage-panel:focus-visible {
  outline: 3px solid var(--kcah-ink);
  outline-offset: 2px;
}

.kcah-triage-close:focus-visible {
  outline: 3px solid #FFFFFF;
  outline-offset: 2px;
}

/* Keyframe animations */
@keyframes kcah-triage-panel-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes kcah-triage-msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes kcah-triage-options-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes kcah-triage-typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* Mobile bottom sheet & safe spacing */
@media (max-width: 480px) {
  .kcah-triage-launcher {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 32px);
    padding: 11px 16px;
    font-size: 1.12rem;
  }

  .kcah-triage-backdrop.is-open {
    display: block;
  }

  .kcah-triage-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 82vh;
    max-height: 85vh;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    border-top: 3px solid var(--kcah-ink);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 0px var(--kcah-ink);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  .kcah-triage-launcher,
  .kcah-triage-close,
  .kcah-triage-option,
  .kcah-triage-nav-btn {
    transition: none;
  }

  .kcah-triage-panel,
  .kcah-triage-row,
  .kcah-triage-options,
  .kcah-triage-typing-dot {
    animation: none;
  }
}
