/*
 * jj-chatbot frontend styles — jeepjohn.com Cyber-Goth palette
 * Primary: neon green #39ff14, Cyan #00e5ff, Violet #b388ff, Deep black #050507
 */

/* === CSS Custom Properties === */
:root {
  /* Palette */
  --color-bg: #050507;
  --color-bg-alt: #0b0d12;
  --color-primary: #39ff14;
  --color-cyan: #00e5ff;
  --color-violet: #b388ff;
  --color-accent: #b6ff00;
  --color-gold: #ffcc66;
  --color-text: #d8ffe8;
  --color-text-dim: #a8c9a8;

  /* Bubbles */
  --color-user-bg: rgba(179, 136, 255, 0.12);
  --color-user-border: rgba(179, 136, 255, 0.35);
  --color-assistant-bg: rgba(57, 255, 20, 0.08);
  --color-assistant-border: rgba(57, 255, 20, 0.25);

  /* System */
  --color-error: #ff66aa;
  --color-error-bg: rgba(255, 0, 51, 0.1);

  /* Layout */
  --header-height: 56px;
  --sidebar-width: 280px;
  --font-stack: "Orbitron", "Rajdhani", "Eurostile", "Consolas", "Courier New", monospace;
  --border-glow: 0 0 6px rgba(57, 255, 20, 0.4);
  --text-glow: 0 0 4px rgba(57, 255, 20, 0.6);
}

/* === Reset === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* === Base === */
html {
  font-size: 16px;
  height: 100%;
}

body {
  font-family: var(--font-stack);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  min-height: 100dvh; /* W9.2: track visible viewport (URL bar/keyboard) */
  overflow: hidden;
}

/* HTML5 [hidden] must beat authored display rules below.
   Without this, #age-gate {display:flex} and #app {display:flex}
   override the hidden attribute and the modal never dismisses. */
[hidden] { display: none !important; }

/* === Age Gate Modal === */
#age-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 7, 0.85);
}

#age-gate .modal-content {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-primary);
  box-shadow: var(--border-glow), 0 0 40px rgba(57, 255, 20, 0.15);
  padding: 2rem 2.5rem;
  max-width: 520px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

#age-gate h2 {
  color: var(--color-primary);
  text-shadow: var(--text-glow);
  font-size: 1.4rem;
  text-align: center;
}

#age-gate-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#age-gate-form label {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--color-text);
}

#age-gate-form input[type="checkbox"] {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
  cursor: pointer;
  margin-top: 0.15rem;
}

#age-gate-form button {
  font-family: var(--font-stack);
  font-size: 1.05rem;
  padding: 0.65rem 1.5rem;
  background: var(--color-primary);
  color: var(--color-bg);
  border: none;
  cursor: pointer;
  box-shadow: var(--border-glow);
  transition: box-shadow 0.2s, opacity 0.2s;
}

#age-gate-form button:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
}

#age-gate-form button:not(:disabled):hover {
  box-shadow: 0 0 14px rgba(57, 255, 20, 0.6);
}

/* === Offline Banner === */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9000;
  background: #ff0033;
  color: #fff;
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  font-family: var(--font-stack);
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.5);
}

/* === Truth banner (persistent warning strip) === */
.truth-banner {
  padding: 0.55rem 1rem;
  margin: 0 1rem 0.5rem 1rem;
  border: 1px solid #ffcc00;
  border-radius: 4px;
  background: rgba(255, 204, 0, 0.08);
  color: #ffd54a;
  font-size: 0.82rem;
  font-family: var(--font-stack);
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 0 4px rgba(255, 204, 0, 0.35);
  flex-shrink: 0;
}
.truth-banner strong {
  color: #ffe58a;
  font-weight: 600;
}

/* === Warning button (mobile-only) + modal === */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.personality-btn {
  display: none; /* mobile only, same pattern as .warning-btn */
  font-family: var(--font-stack);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  padding: 0.32rem 0.65rem;
  background: transparent;
  color: #00c8ff;
  border: 1px solid #00c8ff;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 200, 255, 0.7);
  text-shadow: 0 0 5px rgba(0, 200, 255, 0.6);
}

.pp-close {
  display: none; /* mobile popup mode only */
  font-family: var(--font-stack);
  font-size: 0.8rem;
  background: transparent;
  color: #00c8ff;
  border: 1px solid #00c8ff;
  border-radius: 3px;
  padding: 0.3rem 0.7rem;
  margin-bottom: 0.7rem;
  cursor: pointer;
}

.warning-btn {
  display: none; /* desktop shows the full banner instead */
  font-family: var(--font-stack);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  padding: 0.32rem 0.65rem;
  background: transparent;
  color: #ff1a40;
  border: 1px solid #ff1a40;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(255, 26, 64, 0.7);
  text-shadow: 0 0 5px rgba(255, 26, 64, 0.6);
  animation: warning-pulse 2.2s ease-in-out infinite;
}

@keyframes warning-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(255, 26, 64, 0.45); }
  50%      { box-shadow: 0 0 14px rgba(255, 26, 64, 0.85); }
}

.warning-btn:hover {
  box-shadow: 0 0 18px rgba(255, 26, 64, 0.9);
}

.warning-modal {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 7, 0.85);
}

.warning-modal[hidden] {
  display: none;
}

.warning-modal-content {
  background: var(--color-bg-alt);
  border: 1px solid #ff1a40;
  box-shadow: 0 0 8px rgba(255, 26, 64, 0.7), 0 0 40px rgba(255, 26, 64, 0.25);
  border-radius: 6px;
  padding: 1.4rem 1.5rem;
  max-width: 340px;
  width: 88%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.warning-modal-content h2 {
  color: #ff1a40;
  text-shadow: 0 0 8px rgba(255, 26, 64, 0.7);
  font-size: 1.05rem;
  text-align: center;
}

.warning-modal-content p {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--color-text);
}

.warning-modal-content p strong {
  color: #ffe58a;
}

.warning-modal-content button {
  font-family: var(--font-stack);
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  background: #ff1a40;
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(255, 26, 64, 0.7);
}

/* === Main App === */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  height: 100dvh;    /* W9.2: 100vh overestimates on mobile Chrome; the */
  max-height: 100dvh; /* bottom row (Send) hid behind browser chrome.    */
}

/* === Header === */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.25rem;
  border-bottom: 1px solid rgba(57, 255, 20, 0.25);
  background: rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  min-height: var(--header-height);
}

header h1 {
  font-size: 1.15rem;
  color: var(--color-primary);
  text-shadow: var(--text-glow);
  letter-spacing: 0.05em;
  margin: 0;
}

#reset-session {
  font-family: var(--font-stack);
  font-size: 0.85rem;
  padding: 0.35rem 0.9rem;
  background: transparent;
  color: var(--color-cyan);
  border: 1px solid var(--color-cyan);
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

#reset-session:hover {
  background: rgba(0, 229, 255, 0.1);
  box-shadow: 0 0 6px rgba(0, 229, 255, 0.3);
}

/* === Layout === */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* === Chat Section === */
#chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0;
  overflow: hidden;
}

#chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

/* Chat bubbles */
.chat-message {
  max-width: 85%;
  padding: 0.6rem 1rem;
  border-radius: 4px;
  line-height: 1.55;
  font-size: 0.95rem;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--color-user-bg);
  border: 1px solid var(--color-user-border);
  color: var(--color-text);
}

.chat-message.assistant {
  align-self: flex-start;
  background: var(--color-assistant-bg);
  border: 1px solid var(--color-assistant-border);
  color: var(--color-text);
}

.chat-message.system {
  align-self: center;
  background: transparent;
  border: none;
  color: var(--color-text-dim);
  font-size: 0.85rem;
  text-align: center;
  max-width: 100%;
}

.chat-message.error {
  border-color: var(--color-error);
  color: var(--color-error);
}

/* Server-side tool activity indicators (search / fetch). */
.chat-message.tool-status {
  font-family: var(--font-mono, Consolas, monospace);
  font-size: 0.8rem;
  opacity: 0.85;
}
.chat-message.tool-status.tool-running {
  color: var(--color-accent, #00e5ff);
  animation: tool-pulse 1s ease-in-out infinite;
}
.chat-message.tool-status.tool-done {
  color: var(--color-primary, #39ff14);
}
.chat-message.tool-status.tool-error {
  color: var(--color-error);
}
@keyframes tool-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.streaming-cursor::after {
  content: "▋";
  animation: blink 0.8s step-end infinite;
  color: var(--color-primary);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* === Chat Input Form === */
#chat-form {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(57, 255, 20, 0.2);
  background: rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
  gap: 0.5rem;
}

#chat-input {
  font-family: var(--font-stack);
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  background: var(--color-bg-alt);
  color: var(--color-text);
  border: 1px solid rgba(57, 255, 20, 0.25);
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 3rem;
}

#chat-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 4px rgba(57, 255, 20, 0.25);
}

#chat-submit {
  font-family: var(--font-stack);
  font-size: 0.95rem;
  padding: 0.5rem 1.5rem;
  background: var(--color-primary);
  color: var(--color-bg);
  border: none;
  cursor: pointer;
  box-shadow: var(--border-glow);
  transition: box-shadow 0.2s;
  align-self: flex-end;
}

#chat-submit:hover {
  box-shadow: 0 0 14px rgba(57, 255, 20, 0.6);
}

#chat-submit:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
}

/* === Personality Panel === */
#personality-panel {
  width: var(--sidebar-width);
  min-width: 200px;
  background: rgba(0, 0, 0, 0.25);
  border-left: 1px solid rgba(57, 255, 20, 0.2);
  padding: 1rem;
  overflow-y: auto;
  flex-shrink: 0;
}

#personality-panel details {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#personality-panel summary {
  font-family: var(--font-stack);
  font-size: 0.95rem;
  color: var(--color-cyan);
  cursor: pointer;
  user-select: none;
  padding: 0.25rem 0;
}

#personality-panel label {
  font-size: 0.8rem;
  color: var(--color-text-dim);
  display: block;
  margin-bottom: 0.15rem;
}

#personality-overlay {
  font-family: var(--font-stack);
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
  background: var(--color-bg-alt);
  color: var(--color-text);
  border: 1px solid rgba(0, 229, 255, 0.25);
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.45;
  width: 100%;
}

#personality-overlay:focus {
  border-color: var(--color-cyan);
  box-shadow: 0 0 4px rgba(0, 229, 255, 0.2);
}

.quick-traits {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.quick-traits button {
  font-family: var(--font-stack);
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  background: transparent;
  color: var(--color-cyan);
  border: 1px solid var(--color-cyan);
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

.quick-traits button:hover {
  background: rgba(0, 229, 255, 0.1);
  box-shadow: 0 0 4px rgba(0, 229, 255, 0.25);
}

.personality-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.personality-actions button {
  font-family: var(--font-stack);
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

.personality-actions button:hover {
  background: rgba(57, 255, 20, 0.1);
  box-shadow: 0 0 4px rgba(57, 255, 20, 0.25);
}

#overlay-count {
  font-size: 0.75rem;
  color: var(--color-text-dim);
}

#personality-status {
  font-size: 0.75rem;
  color: var(--color-primary);
  margin-top: 0.25rem;
  min-height: 1.2em;
}

/* === Focus States === */
*:focus-visible {
  outline: 2px solid var(--color-cyan);
  outline-offset: 2px;
}

/* === Mobile === */
@media (max-width: 768px) {
  /* W9.1: personality panel becomes a left slide-in popup. Inline stacking
     below the chat got clipped by the page's overflow:hidden on mobile. */
  .layout {
    flex-direction: column;
  }

  #personality-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(88vw, 360px);
    max-height: none;
    overflow-y: auto;
    z-index: 60;
    display: none;
    padding: 1rem 0.9rem;
    background: #04080c;
    border-right: 1px solid rgba(0, 200, 255, 0.4);
    box-shadow: 4px 0 18px rgba(0, 0, 0, 0.7);
  }

  body.pp-open #personality-panel {
    display: block;
  }

  /* scrim: taps outside the panel close it (handler in chat.js) */
  body.pp-open #chat,
  body.pp-open header {
    pointer-events: none;
  }

  .pp-close {
    display: block;
  }

  .personality-btn {
    display: inline-block;
  }

  header h1 {
    font-size: 0.95rem;
  }

  /* Compact the truth banner into a header WARNING button on mobile */
  .truth-banner {
    display: none;
  }

  .warning-btn {
    display: inline-block;
  }

  .chat-message {
    max-width: 95%;
  }

  /* W9.2: single-row composer. Column stacking pushed Send below the fold. */
  #chat-form {
    flex-direction: row;
    align-items: flex-end;
    gap: 0.4rem;
    padding: 0.5rem 0.6rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }

  #chat-input {
    flex: 1 1 auto;
    min-width: 0;
    order: 2;
  }

  #attach-btn {
    order: 1;
    flex-shrink: 0;
  }

  #mic-btn {
    order: 3;
    flex-shrink: 0;
    padding: 0.55rem 0.5rem;
  }

  #chat-submit {
    order: 4;
    flex-shrink: 0;
    padding: 0.55rem 0.7rem;
    font-size: 0.8rem;
  }
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* === Photo attach (W7 0.4.0) === */
#attach-btn {
  align-self: flex-start;
  font-family: var(--font-stack);
  font-size: 1rem;
  line-height: 1;
  padding: 0.35rem 0.6rem;
  background: transparent;
  color: var(--color-primary);
  border: 1px solid rgba(57, 255, 20, 0.35);
  border-radius: 4px;
  cursor: pointer;
  transition: box-shadow 0.2s, background 0.2s;
}
#attach-btn:hover {
  background: rgba(57, 255, 20, 0.08);
  box-shadow: 0 0 6px rgba(57, 255, 20, 0.3);
}

#attach-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1.25rem;
  border-top: 1px dashed rgba(57, 255, 20, 0.2);
}
#attach-preview img {
  max-height: 72px;
  max-width: 40%;
  border: 1px solid rgba(57, 255, 20, 0.35);
  border-radius: 4px;
}
#attach-preview button {
  background: transparent;
  color: #ff6b6b;
  border: 1px solid rgba(255, 107, 107, 0.5);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

.chat-message.has-image { white-space: pre-wrap; }
.chat-image {
  display: block;
  max-width: min(280px, 70%);
  max-height: 220px;
  margin-top: 0.4rem;
  border: 1px solid rgba(57, 255, 20, 0.3);
  border-radius: 6px;
  cursor: zoom-in;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  cursor: zoom-out;
}
.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border: 1px solid rgba(57, 255, 20, 0.4);
}

/* Chatbot-emitted links (W7.1) */
.chat-message a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.chat-message a:hover {
  text-shadow: 0 0 6px rgba(57, 255, 20, 0.5);
}

/* W8: voice + timers */
#mic-btn.recording {
  animation: mic-pulse 1s ease-in-out infinite;
  border-color: #ff4040;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 64, 64, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(255, 64, 64, 0); }
}
.timer-chip {
  border: 1px solid var(--color-primary, #39ff14);
  border-radius: 8px;
  padding: 6px 10px;
  margin: 8px 0;
  font-variant-numeric: tabular-nums;
  width: fit-content;
}
.timer-chip .timer-clock { color: var(--color-primary, #39ff14); font-weight: bold; }
.timer-chip.timer-done { border-color: #666; opacity: 0.8; }
.timer-chip.timer-done .timer-clock { color: #aaa; }
