/* =========================================================
   AI Focus Group – Refactored Stylesheet
   ---------------------------------------------------------
   Structure:
   1) Design tokens (colors, spacing, typography)
   2) Page layout
   3) Typography
   4) Form elements
   5) Buttons
   6) Conversation log
   7) Follow-up (facilitator) section
   8) Impressum link
   9) Word animation
   10) System prompt modal
   11) Impressum page
   12) Mobile layout
   ========================================================= */

/* ---------------------------------------------------------
   1) Design Tokens
   --------------------------------------------------------- */
:root {
  --font-family-base: Arial, sans-serif;

  --color-bg-page: #f8f9fa;
  --color-text-main: #333;
  --color-text-strong: #222;

  --color-border-soft: #ddd;
  --color-border-button: #ccc;

  --color-card-bg: #ffffff;

  --color-btn-bg: #ffffff;
  --color-btn-bg-hover: #f0f0f0;
  --color-btn-text: #000000;

  --spacing-page-padding: 20px;
  --spacing-section-margin: 30px;

  --radius-card: 4px;
  --radius-modal: 6px;

  --z-followup: 1000;
  --z-modal-backdrop: 2000;
  --z-impressum: 2001;
}

/* ---------------------------------------------------------
   2) Page Layout
   --------------------------------------------------------- */
html,
body {
  height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--font-family-base);
  background-color: var(--color-bg-page);
  padding: var(--spacing-page-padding);
  box-sizing: border-box;
}

/* Scrollable main container above the fixed facilitator bar */
#main-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px;
  margin-bottom: 200px; /* space above fixed followup bar */
  box-sizing: border-box;
}

/* Fixierte Intervention-Sektion (Facilitator bottom bar) */
#followup-section {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  padding: 15px 0;
  z-index: var(--z-followup);
  box-sizing: border-box;
}

/* Wrapper inside the fixed bar */
#followup-section .fu-wrapper {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box;
  position: relative; /* reference for children if needed */
}

/* Inner layout of follow-up section */
#followup-section .fi-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}

/* ---------------------------------------------------------
   3) Typography
   --------------------------------------------------------- */
h1,
h2,
h3 {
  color: var(--color-text-main);
  margin: 10px 0;
}

#followup-section h3 {
  margin-top: 0;
  margin-bottom: 8px;
  text-align: left;
  align-self: flex-start;
}

/* ---------------------------------------------------------
   4) Form Elements
   --------------------------------------------------------- */
.form-section {
  margin-bottom: var(--spacing-section-margin);
  width: 100%;
}

.checkbox-label {
  display: block;
  margin: 10px 0;
  font-size: 16px;
}

.full-width,
textarea,
input[type="number"] {
  width: 100%;
  max-width: 600px;
  padding: 10px;
  font-size: 16px;
  margin-bottom: 15px;
  box-sizing: border-box;
}

/* Follow-up textarea (facilitator input) */
#followup-section .fi-text textarea {
  width: 100%;
  max-width: none;
  height: 60px;
  resize: vertical;
  padding: 6px;
  font-size: 0.95rem;
  box-sizing: border-box;
  margin-bottom: 10px;
}

/* ---------------------------------------------------------
   5) Buttons
   --------------------------------------------------------- */
/* Base button styling for all interactive buttons in the app */
button,
#start-btn,
#intervene-btn,
#followup-btn,
#export-btn,
#systemprompt-btn,
#systemprompt-save-btn,
#systemprompt-close-btn,
#systemprompt-reset-btn {
  padding: 12px 24px;
  font-size: 16px;
  background-color: var(--color-btn-bg);
  border: 1px solid var(--color-border-button);
  color: var(--color-btn-text);
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.2s;
  white-space: nowrap;
}

/* Unified hover effect – this fixes your previous hover issue */
button:hover,
#start-btn:hover,
#intervene-btn:hover,
#followup-btn:hover,
#export-btn:hover,
#systemprompt-btn:hover,
#systemprompt-save-btn:hover,
#systemprompt-close-btn:hover,
#systemprompt-reset-btn:hover {
  background-color: var(--color-btn-bg-hover);
}

/* Specific offset for desktop layout */
#intervene-btn {
  margin-left: 20px;
}

/* Place export button at the far right in the controls row (desktop) */
#followup-section .fi-controls #export-btn {
  margin-left: auto;
}

/* System prompt trigger button spacing at top */
#systemprompt-btn {
  margin-top: 50px;
  margin-bottom: 10px;
}

/* ---------------------------------------------------------
   6) Conversation Log
   --------------------------------------------------------- */
#log {
  max-width: 1000px;
  width: 100%;
  background-color: var(--color-card-bg);
  padding: 15px;
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-card);
  font-size: 16px;
  line-height: 1.6;
}

.entry,
.chat-entry {
  border-bottom: 1px solid #ccc;
  padding: 10px 0;
  margin-bottom: 1rem;
}

.chat-entry strong,
.entry strong {
  display: block;
  color: var(--color-text-strong);
  font-size: 16px;
  font-weight: bold;
}

.agent-text,
.ai-speak {
  min-height: 1em;
  white-space: pre-wrap;
  display: inline-block;
  font-size: 16px;
}

/* ---------------------------------------------------------
   7) Follow-up Section Controls
   --------------------------------------------------------- */
#followup-section .fi-controls {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 10px;
  flex-wrap: nowrap;
}

#followup-section .fi-controls label {
  white-space: nowrap;
  font-size: 0.95rem;
}

#followup-section .fi-controls input[type="number"] {
  width: 60px;
  padding: 4px;
  font-size: 0.9rem;
  box-sizing: border-box;
}

/* ---------------------------------------------------------
   8) Impressum Link (fixed bottom-right)
   --------------------------------------------------------- */
#followup-section .impressum-link {
  position: fixed;
  right: 50px;
  bottom: 8px;
  font-size: 13px;
  color: #000000;
  white-space: nowrap;
  text-decoration: none;
  z-index: var(--z-impressum);
}

#followup-section .impressum-link:hover {
  text-decoration: underline;
}

/* ---------------------------------------------------------
   9) Word Fade-in Animation for Streaming Text
   --------------------------------------------------------- */
@keyframes fadeInWord {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.word-fade {
  display: inline-block;
  opacity: 0;
  animation: fadeInWord 0.3s ease forwards;
}

/* ---------------------------------------------------------
   10) System Prompt Modal
   --------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal-backdrop);
}

.modal-backdrop.show {
  display: flex;
}

.modal-window {
  background: #ffffff;
  padding: 16px 20px;
  border-radius: var(--radius-modal);
  max-width: 900px;
  width: 100%;
  height: 60vh;
  max-height: 60vh;
  box-sizing: border-box;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
}

.modal-header {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
}

/* Body stretches between header and footer */
.modal-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-body textarea {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  resize: vertical;
  font-size: 14px;
  padding: 8px;
  box-sizing: border-box;
  overflow-y: auto;
}

#systemprompt-feedback {
  margin-top: 8px;
  font-size: 13px;
}

.modal-footer {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-footer-left,
.modal-footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------------------------------------------------------
   11) Impressum Page Layout
   --------------------------------------------------------- */
.impressum-page {
  padding: 40px;
  max-width: 800px;
  margin: 0 auto;
}

.back-link,
.back-link:visited,
.back-link:active,
.back-link:focus {
  color: #000000 !important;
  text-decoration: none;
}

.back-link:hover {
  color: #000000 !important;
  text-decoration: underline;
}

/* ---------------------------------------------------------
   12) Mobile Layout
   --------------------------------------------------------- */
@media (max-width: 700px) {
  /* More space for scrolling above the fixed bar on small screens */
  #main-container {
    margin-bottom: 400px; /* allow scrolling up to see Start button, etc. */
  }

  #followup-section .fi-controls {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  /* Stop button on its own line */
  #intervene-btn {
    margin-left: 0;
    order: 10;
    width: 100%;
  }

  /* Send Follow-Up below Stop */
  #followup-btn {
    order: 11;
    width: 100%;
  }

  /* Export Conversation below Send Follow-Up */
  #export-btn {
    order: 12;
    width: 100%;
    margin-left: 0; /* remove desktop auto-margin */
  }
}
