/* ==========================================================================
   portfolio: chatbot.css with the dual mode applied
   ========================================================================== */

.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;
}

#ai-assistant {
  padding: 100px 0;
  background: var(--bg2);
  transition: background 0.3s;
}

.chat-widget {
  max-width: 780px;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  overflow: visible;
  position: relative;
  transition: background 0.3s, border-color 0.35s, box-shadow 0.45s;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.12),
    0 0 0 0 rgba(201, 169, 110, 0);
  clip-path: none;
}

.chat-widget::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: repeating-linear-gradient(
    180deg,
    transparent 0px,
    transparent 3px,
    rgba(201, 169, 110, 0.018) 3px,
    rgba(201, 169, 110, 0.018) 4px
  );
  pointer-events: none;
  z-index: 0;
}

.chat-widget:focus-within {
  border-color: rgba(201, 169, 110, 0.45);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.18),
    0 0 0 1px rgba(201, 169, 110, 0.12),
    0 0 40px rgba(201, 169, 110, 0.06);
}

.chat-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.06);
  position: relative;
  z-index: 10;
  border-radius: 10px;
  overflow: visible;
}

.chat-widget:has(#chatBody:not([hidden])) .chat-widget-header {
  border-radius: 10px 10px 0 0;
}

.chat-widget-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.terminal-dots {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-shrink: 0;
}

.terminal-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  transition: opacity 0.2s;
}

.terminal-dot--close { background: rgba(255, 95,  86, 0.65); }
.terminal-dot--min   { background: rgba(255, 189, 68, 0.65); }
.terminal-dot--max   { background: var(--gold); opacity: 0.8; }

.chat-widget-header:hover .terminal-dot { opacity: 1; }

.chat-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-widget-title {
  font-family: 'Playfair Display', serif;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--cream);
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  flex-shrink: 0;
  animation: pulseOnline 2.6s ease-in-out infinite;
}

@keyframes pulseOnline {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(0.75); }
}

.mode-selector {
  position: relative;
  flex-shrink: 0;
  z-index: 200;
}

.mode-selector-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.22s, color 0.22s, background 0.22s;
}

.mode-selector-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201, 169, 110, 0.06);
}

.mode-selector-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.mode-icon {
  font-size: 0.55rem;
  color: var(--gold);
  opacity: 0.8;
}

.mode-chevron {
  font-size: 0.5rem;
  opacity: 0.6;
  transition: transform 0.22s;
}

.mode-selector-btn[aria-expanded="true"] .mode-chevron {
  transform: rotate(180deg);
}

.mode-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(201, 169, 110, 0.12);
  z-index: 100;
  overflow: hidden;
  animation: dropUp 0.18s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.mode-dropdown[hidden] { display: none; }

@keyframes dropUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.mode-option::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border);
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.mode-option:hover {
  background: rgba(201, 169, 110, 0.06);
  color: var(--cream);
}

.mode-option--active {
  color: var(--gold);
}

.mode-option--active::before {
  background: var(--gold);
  border-color: var(--gold);
}

.mode-option + .mode-option {
  border-top: 1px solid var(--border);
}

.chat-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.22s, color 0.22s, background 0.22s;
  flex-shrink: 0;
}

.chat-toggle-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201, 169, 110, 0.06);
}

.chat-toggle-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.chat-toggle-btn .chevron {
  display: inline-block;
  width: 7px; height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-toggle-btn[aria-expanded="true"] .chevron {
  transform: rotate(225deg);
}

.chat-body {
  border-top: 1px solid var(--border);
  position: relative;
  z-index: 1;
  border-radius: 0 0 10px 10px;
  overflow: hidden;
}

.chat-messages {
  max-height: 420px;
  overflow-y: auto;
  padding: 28px 28px 12px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-messages::-webkit-scrollbar       { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 7px;
  animation: msgSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg-prompt {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.chat-msg-prompt-arrow   { font-size: 1rem; line-height: 1; color: var(--gold); flex-shrink: 0; }
.chat-msg-prompt-name    { font-weight: 700; color: var(--gold); }
.chat-msg-prompt-divider { flex: 1; height: 1px; background: var(--border); min-width: 16px; opacity: 0.6; }
.chat-msg-prompt-time    { color: var(--muted); font-size: 0.62rem; opacity: 0.75; flex-shrink: 0; }

.chat-msg-bot .chat-msg-body {
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text);
  margin: 0;
  padding: 14px 18px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--tag-bg);
}

.chat-msg-bot pre.chat-msg-body {
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.78rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg-bot .chat-msg-body p { margin: 0 0 10px; }
.chat-msg-bot .chat-msg-body p:last-child { margin-bottom: 0; }
.chat-msg-bot .chat-msg-body strong { font-weight: 700; color: var(--cream); }
.chat-msg-bot .chat-msg-body em { font-style: italic; }
.chat-msg-bot .chat-msg-body code {
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.82em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.08);
  border: 1px solid var(--border-light);
}
[data-theme="dark"] .chat-msg-bot .chat-msg-body code { background: rgba(255, 255, 255, 0.08); }
.chat-msg-bot .chat-msg-body ul,
.chat-msg-bot .chat-msg-body ol {
  margin: 4px 0 10px;
  padding-left: 20px;
}
.chat-msg-bot .chat-msg-body li { margin: 3px 0; }
.chat-msg-bot .chat-msg-body ul:last-child,
.chat-msg-bot .chat-msg-body ol:last-child { margin-bottom: 0; }

.chat-flag-note {
  margin: 6px 0 0;
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.7;
}

.chat-msg-user { align-items: flex-end; }
.chat-msg-user .chat-msg-prompt-arrow { color: var(--muted); }
.chat-msg-user .chat-msg-prompt-name  { color: var(--muted); }

.chat-msg-user .chat-msg-body {
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  line-height: 1.6;
  color: #fff;
  background: var(--gold);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  max-width: 85%;
  margin: 0;
  word-break: break-word;
}

[data-theme="dark"] .chat-msg-user .chat-msg-body { color: var(--bg); }

.chat-msg-system .chat-msg-body {
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
  padding: 8px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  letter-spacing: 0.04em;
  text-align: center;
  opacity: 0.75;
}

.chat-thinking {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 0 28px 16px;
  animation: msgSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.chat-thinking[hidden] { display: none; }

.chat-thinking-dots { display: inline-flex; align-items: center; gap: 5px; }

.chat-thinking-dots span {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--gold);
  animation: thinkDot 1.5s ease-in-out infinite;
}

.chat-thinking-dots span:nth-child(1) { animation-delay: 0s; }
.chat-thinking-dots span:nth-child(2) { animation-delay: 0.18s; }
.chat-thinking-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes thinkDot {
  0%, 60%, 100% { opacity: 0.18; transform: scale(0.75); }
  30%           { opacity: 1;    transform: scale(1.25); }
}

.chat-thinking-bar { display: none; }

.chat-thinking-label {
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  letter-spacing: 0.02em;
  animation: labelFade 1.6s ease-in-out infinite;
}

@keyframes labelFade {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}

.chat-cursor {
  display: inline-block;
  width: 8px;
  height: 0.88em;
  margin-left: 2px;
  background: var(--gold);
  vertical-align: -0.08em;
  animation: blinkCursor 0.88s steps(1) infinite;
}

@keyframes blinkCursor {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 18px 28px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.04);
}

.chat-input-prefix {
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gold);
  flex-shrink: 0;
  margin-right: 10px;
  user-select: none;
  line-height: 1;
  transition: opacity 0.2s;
}

.chat-input {
  flex: 1;
  padding: 10px 0;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  outline: none;
  transition: border-color 0.22s;
  caret-color: var(--gold);
}

.chat-input:focus { border-bottom-color: var(--gold); }

.chat-input-row:focus-within .chat-input-prefix { opacity: 1; }

.chat-input::placeholder {
  color: var(--muted);
  opacity: 0.45;
  font-style: italic;
}

.chat-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-left: 18px;
  padding: 9px 18px;
  flex-shrink: 0;
  border: 1px solid rgba(201, 169, 110, 0.5);
  border-radius: 4px;
  background: transparent;
  color: var(--gold);
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.22s, color 0.22s, border-color 0.22s, transform 0.15s, opacity 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
  background: var(--gold);
  color: var(--bg);
  border-color: var(--gold);
  transform: translateY(-1px);
}

.chat-send-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.chat-send-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

.chat-msg-error .chat-msg-body {
  font-family: 'Inter', sans-serif;
  font-size: 0.83rem;
  line-height: 1.5;
  color: #c62828;
  background: rgba(198, 40, 40, 0.06);
  border: 1px solid rgba(198, 40, 40, 0.22);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  margin: 0;
}

[data-theme="dark"] .chat-msg-error .chat-msg-body {
  color: #ef9a9a;
  background: rgba(239, 154, 154, 0.06);
  border-color: rgba(239, 154, 154, 0.22);
}

.chat-privacy-note {
  font-size: 0.68rem;
  color: var(--muted);
  opacity: 0.65;
  text-align: center;
  padding: 4px 16px 0;
  margin: 0;
}

.chat-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 28px 14px;
  background: rgba(0, 0, 0, 0.04);
}

.chat-session-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

#sessionLabel {
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0.8;
}

.session-bar-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.session-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--gold);
  border-radius: 2px;
  transition: width 0.5s ease;
}

.chat-limit-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border: 1px solid rgba(201, 169, 110, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(201, 169, 110, 0.06);
  animation: msgSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.chat-limit-banner-icon {
  font-size: 0.75rem;
  color: var(--gold);
  flex-shrink: 0;
  opacity: 0.85;
}

.chat-limit-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.chat-limit-banner-text strong {
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.01em;
}

.chat-limit-banner-text span {
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.66rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  line-height: 1.5;
}

.chat-limit-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  flex-shrink: 0;
  border: 1px solid rgba(201, 169, 110, 0.5);
  border-radius: 4px;
  background: transparent;
  color: var(--gold);
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.22s, color 0.22s, border-color 0.22s, transform 0.15s;
}

.chat-limit-switch-btn:hover {
  background: var(--gold);
  color: var(--bg);
  border-color: var(--gold);
  transform: translateY(-1px);
}

.chat-limit-switch-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@media (max-width: 768px) {
  #ai-assistant        { padding: 64px 0; }
  .chat-widget-header  { padding: 13px 18px; }
  .chat-messages       { padding: 20px 18px 10px; max-height: 360px; }
  .chat-input-row      { padding: 14px 18px; }
  .chat-thinking       { padding: 0 18px 14px; }
  .chat-footer         { padding: 8px 18px 12px; gap: 12px; }
  .chat-msg-user .chat-msg-body { max-width: 95%; }

  .chat-input          { font-size: 16px; }
}

@media (max-width: 480px) {
  .chat-toggle-label   { display: none; }
  .chat-toggle-btn     { padding: 8px 10px; }
  .chat-send-btn span:first-child { display: none; }
  .chat-send-btn       { padding: 9px 12px; }
  .mode-selector-btn   { padding: 6px 8px; }
  #modeSelectorLabel   { display: none; }
  #sessionLabel        { font-size: 0.58rem; }
  .chat-limit-banner   { flex-wrap: wrap; gap: 10px; }
  .chat-limit-switch-btn { width: 100%; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-status-dot,
  .chat-thinking-dots span,
  .chat-thinking-label,
  .chat-cursor { animation: none; opacity: 1; }
  .chat-msg,
  .chat-thinking { animation: none; }
}