/* Andy Koh AI chat widget — matches portfolio black/white language */

:root {
  --ak-chat-ink: #0a0a0a;
  --ak-chat-paper: #f7f5f2;
  --ak-chat-line: rgba(10, 10, 10, 0.12);
  --ak-chat-muted: rgba(10, 10, 10, 0.55);
  --ak-chat-accent: #c45c26;
  --ak-chat-shadow: 0 22px 60px rgba(0, 0, 0, 0.24);
  --ak-chat-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.ak-chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 99990;
  width: 72px;
  height: 72px;
  border: 0;
  border-radius: 50%;
  background: var(--ak-chat-ink);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--ak-chat-shadow);
  display: grid;
  place-items: center;
  transition: transform 0.25s ease, background 0.2s ease;
}

.ak-chat-launcher:hover,
.ak-chat-launcher:focus-visible {
  transform: scale(1.06);
  outline: none;
}

.ak-chat-launcher svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ak-chat-launcher[aria-expanded="true"] {
  background: var(--ak-chat-accent);
}

.ak-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 112px;
  z-index: 99991;
  width: min(560px, calc(100vw - 32px));
  height: min(780px, calc(100vh - 140px));
  background: var(--ak-chat-paper);
  color: var(--ak-chat-ink);
  border: 1px solid var(--ak-chat-line);
  box-shadow: var(--ak-chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.22s ease;
  font-family: var(--ak-chat-font);
}

.ak-chat-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.ak-chat-header {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--ak-chat-line);
  background: linear-gradient(180deg, #fff 0%, var(--ak-chat-paper) 100%);
}

.ak-chat-header__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.ak-chat-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ak-chat-header p {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--ak-chat-muted);
  line-height: 1.4;
}

.ak-chat-close {
  border: 0;
  background: transparent;
  color: var(--ak-chat-ink);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.ak-chat-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.ak-chat-mode {
  border: 1px solid var(--ak-chat-line);
  background: #fff;
  color: var(--ak-chat-ink);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ak-chat-mode.is-active {
  background: var(--ak-chat-ink);
  color: #fff;
  border-color: var(--ak-chat-ink);
}

.ak-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.ak-chat-msg {
  max-width: 92%;
  padding: 12px 14px;
  font-size: 15.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.ak-chat-msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--ak-chat-line);
}

.ak-chat-msg--user {
  align-self: flex-end;
  background: var(--ak-chat-ink);
  color: #fff;
}

.ak-chat-msg--meta {
  align-self: center;
  max-width: 100%;
  background: transparent;
  border: 0;
  color: var(--ak-chat-muted);
  font-size: 13px;
  padding: 2px 0;
  text-align: center;
}

.ak-chat-msg img,
.ak-chat-msg video {
  display: block;
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--ak-chat-line);
  background: #111;
}

.ak-chat-msg audio {
  display: block;
  width: 100%;
  margin-top: 10px;
}

.ak-chat-msg a {
  color: inherit;
  text-decoration: underline;
}

.ak-chat-typing {
  align-self: flex-start;
  font-size: 13.5px;
  color: var(--ak-chat-muted);
  padding: 0 8px 6px;
  min-height: 20px;
}

.ak-chat-composer {
  border-top: 1px solid var(--ak-chat-line);
  padding: 14px 16px 16px;
  background: #fff;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.ak-chat-composer textarea {
  width: 100%;
  min-height: 56px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--ak-chat-line);
  background: var(--ak-chat-paper);
  color: var(--ak-chat-ink);
  font: inherit;
  font-size: 15.5px;
  line-height: 1.45;
  padding: 12px 14px;
}

.ak-chat-composer textarea:focus {
  outline: 1px solid var(--ak-chat-ink);
}

.ak-chat-send {
  border: 0;
  background: var(--ak-chat-ink);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0 18px;
  height: 56px;
  cursor: pointer;
}

.ak-chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ak-chat-hint {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12.5px;
  color: var(--ak-chat-muted);
}

.ak-chat-storyboard {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.ak-chat-storyboard__title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.ak-chat-storyboard__shot {
  margin: 0;
  border: 1px solid var(--ak-chat-line);
  background: #fff;
  overflow: hidden;
}

.ak-chat-storyboard__shot img {
  margin: 0;
  border: 0;
  width: 100%;
  display: block;
}

.ak-chat-storyboard__shot figcaption {
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--ak-chat-muted);
  line-height: 1.35;
}

/* Live SSE / backend trace */
.ak-chat-trace {
  align-self: stretch;
  max-width: 100%;
  margin: 2px 0 8px;
  border: 1px solid rgba(10, 10, 10, 0.14);
  background: #111;
  color: #d7d2cb;
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  line-height: 1.35;
  overflow: hidden;
}

.ak-chat-trace.is-done {
  border-color: rgba(60, 140, 90, 0.45);
}

.ak-chat-trace.is-error {
  border-color: rgba(190, 60, 50, 0.55);
}

.ak-chat-trace__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #1a1a1a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #f3efe9;
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.ak-chat-trace__bar strong {
  font-weight: 700;
}

.ak-chat-trace__count {
  margin-left: auto;
  opacity: 0.55;
  text-transform: none;
  letter-spacing: 0;
}

.ak-chat-trace__live {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3ecf8e;
  box-shadow: 0 0 0 0 rgba(62, 207, 142, 0.55);
  animation: ak-pulse 1.2s ease-out infinite;
}

.ak-chat-trace__live.is-off {
  animation: none;
  background: #666;
  box-shadow: none;
}

@keyframes ak-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(62, 207, 142, 0.55);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(62, 207, 142, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(62, 207, 142, 0);
  }
}

.ak-chat-trace__log {
  max-height: 168px;
  overflow-y: auto;
  padding: 6px 0;
}

.ak-chat-trace__row {
  display: grid;
  grid-template-columns: 78px 52px 1fr;
  gap: 6px 8px;
  padding: 4px 10px;
  border-left: 2px solid transparent;
}

.ak-chat-trace__row--net {
  border-left-color: #5b9fd4;
}

.ak-chat-trace__row--status {
  border-left-color: #c9a227;
}

.ak-chat-trace__row--result,
.ak-chat-trace__row--done {
  border-left-color: #3ecf8e;
}

.ak-chat-trace__row--error {
  border-left-color: #e85d4c;
  color: #ffb4ab;
}

.ak-chat-trace__row--client {
  border-left-color: #a78bfa;
}

.ak-chat-trace__time {
  opacity: 0.45;
  font-variant-numeric: tabular-nums;
}

.ak-chat-trace__kind {
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.8;
}

.ak-chat-trace__title {
  grid-column: 3;
  word-break: break-word;
}

.ak-chat-trace__detail {
  grid-column: 3;
  opacity: 0.55;
  word-break: break-word;
}

@media (max-width: 640px) {
  .ak-chat-trace__row {
    grid-template-columns: 64px 44px 1fr;
    font-size: 10px;
  }
}

@media (max-width: 640px) {
  .ak-chat-launcher {
    right: 14px;
    bottom: 14px;
    width: 64px;
    height: 64px;
  }

  .ak-chat-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 92px;
    height: min(82vh, 720px);
  }

  .ak-chat-msg {
    font-size: 15px;
  }
}

@media (min-width: 1200px) {
  .ak-chat-panel {
    width: min(620px, calc(100vw - 40px));
    height: min(820px, calc(100vh - 150px));
  }
}
