/* --- GLOBAL FIXES --- */
html, body { 
  height: 100% !important;
  margin: 0;
  overflow: hidden !important;
  font-family: sans-serif; 
}

#app-container { 
  display: flex;
    flex-direction: column;
    height: auto; 
    min-height: 0;
}

/* --- HEADER --- */
.app-header { 
  flex: 0 0 auto; 
  background: #1f2937; 
  color: white; 
  padding: 15px 20px; /* Increased padding */
  display: flex; 
  flex-direction: row !important;
  flex-wrap: nowrap !important; 
  align-items: center; 
  justify-content: space-between;
  width: 100%;
  box-sizing: border-box;
  z-index: 1000;
  border-bottom: 1px solid #374151;
  /* Fix: Ensure the header has enough height for title + subtitle */
  min-height: 80px; 
}

.header-left-group {
  display: flex;
  align-items: center;
  gap: 15px;
  flex: 1;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
}

.header-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#header-title {
  font-size: 1.4rem;
  font-weight: bold;
  margin: 0;
  color: #ffffff;
}

#header-subtitle {
    display: none !important; /* This hides it completely and safely */
}

/* --- BUTTONS: RESTORED STYLE --- */
.header-right-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
}

/* Restore your original button look */
.header-btn { 
  padding: 8px 14px; 
  font-size: 14px; 
  border-radius: 6px; 
  border: 1px solid #4b5563; 
  background: #374151;
  color: white;
  cursor: pointer; 
  white-space: nowrap;
  transition: background 0.2s;
}

.header-btn:hover {
  background: #4b5563;
}

/* Ensure the Language Select stays a reasonable width */
#languageSelect {
  max-width: 100px;
  padding: 4px;
}

/* Ensure voice button doesn't get too wide */
.voice-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 20px; /* Rounded look */
  border: 1px solid #4b5563;
  background: #374151;
  color: white;
  cursor: pointer;
  white-space: nowrap;
}

/* When voice is ON, make it look "active" (e.g., blue or green) */
.voice-btn.active {
  background: #e0f2fe;
  border-color: #3b82f6;
  color: #1e40af;
}

/* --- MIDDLE SECTION (THE CORE) --- */
#main-layout-body { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  position: relative; 
  background: #f3f4f6; 
  min-height: 0;
  /* Ensure the body itself doesn't grow beyond the viewport */
  max-height: calc(100vh - 60px); /* 60px is a rough estimate for Header height */
}

#chat-scroll-area { 
  height: calc(100vh - 250px); /* 150px is an estimate for Header + Footer height */
  overflow-y: scroll !important; 
  overflow-x: hidden;
  /* Increase top padding so the first message clears the header area */
  flex: 1; /* This tells it to expand to fill available space */
  overflow-y: scroll !important; 
  padding: 20px 15px 160px 15px;
  display: block; /* Required for JS scrollToBottom to work reliably */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling for mobile */
  min-height: 0;
  background-color: #ffffff; /* Very light "Ghost" white */
}

#chat-container { 
  display: flex; 
  flex-direction: column; 
  gap: 12px; 
  width: 100%; 
  max-width: 850px; 
  margin: 0 auto; 
  /* Ensure no negative margins are pulling messages up */
  margin-top: 0 !important; 
  padding-top: 0 !important;
  /* Add a little extra margin to the very last message in the list */
  padding-bottom: 20px;
}

/* --- DASHBOARD --- */
.score-dashboard { 
  background: white; 
  padding: 15px; 
  border-radius: 10px; 
  margin-bottom: 20px; 
  box-shadow: 0 2px 5px rgba(0,0,0,0.1); 
}

.score-row { 
  display: flex; 
  align-items: center; 
  gap: 10px; 
  margin: 8px 0; 
}

.bar-track { 
  flex: 1; 
  height: 10px; 
  background: #eee; 
  border-radius: 5px; 
  overflow: hidden; 
}

.bar { 
  height: 100%; 
  width: 0; 
  background: linear-gradient(90deg, #3b82f6, #22c55e); 
  transition: width 0.8s; 
}

/* --- MESSAGES --- */
.msg-row { 
  display: flex !important;
  width: 100%;
  visibility: visible !important;
  opacity: 1 !important; 
  margin-bottom: 16px; /* ↕️ This creates the gap between bubbles */
}
.msg-row.left { 
  justify-content: flex-start; 
}
.msg-row.right { 
  justify-content: flex-end; 
}
.msg-row.center { 
  justify-content: center; 
}

.msg { 
  max-width: 75%; 
  padding: 12px; 
  border-radius: 12px; 
  font-size: 15px; 
  line-height: 1.4; 
  word-wrap: break-word; 
}
/* Executive Slate Blue for Manager */
.msg.manager {
    background-color: #334155; /* Slate 700 - Professional & Trustworthy */
    color: #f8fafc;           /* Near white text for readability */
    border-radius: 12px 12px 0 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Sophisticated Light Gray for Employee */
.msg.employee {
    background-color: #f1f5f9; /* Slate 100 */
    color: #1e293b;           /* Dark Slate 800 */
    border-radius: 12px 12px 12px 0;
    border: 1px solid #e2e8f0;
}
.msg.system { 
  background: #f8f9fb; 
  border-left: 4px solid #4f46e5; 
  width: 100%; 
}

/* Style for actions within the bubble */
.action-text {
    font-style: italic;
    opacity: 0.7;
    color: inherit; /* Keeps it readable against dark or light bubbles */
    font-size: 0.95em;
}

/* Special styling for the Scenario Brief */
.msg.scenario-brief {
    background-color: #fefce8 !important; /* Soft parchment/yellow background */
    border: 1px solid #fef08a !important; /* Yellow border */
    color: #854d0e !important;           /* Deep brown/gold text */
    max-width: 90%;                      /* Make it a bit wider to look like a banner */
    margin: 10px auto;                   /* Center it slightly */
    border-left: 5px solid #eab308 !important; /* Thick gold accent bar */
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    font-size: 1.05em;
}

/* Ensure the label inside stands out */
.msg.scenario-brief strong {
    color: #a16207;
    font-size: 0.85em;
    letter-spacing: 0.05em;
}

/* --- LANDING & SETUP --- */
.mode-screen { 
  /* This ensures the landing screen fills the space below the header without pushing it */
  height: calc(100vh - 70px); 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  background: #eef2ff; 
  width: 100%;
}

/* Ensure the mode-screen doesn't exist when app is active */
.mode-screen[style*="display: none"] {
    display: none !important;
}

.mode-card { 
  background: white; 
  padding: 30px; 
  border-radius: 15px; 
  text-align: center; 
  max-width: 500px; 
  width: 90%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1); 
}

.mode-btn { 
  width: 100%; 
  padding: 15px; 
  margin: 10px 0; 
  display: flex; 
  align-items: flex-start; 
  gap: 15px; 
  border: 1px solid #ddd; 
  border-radius: 10px; 
  cursor: pointer; 
  text-align: left; 
}
.mode-btn.primary { 
  background: #2563eb; 
  color: white; 
  border-color: #2563eb; 
}

/* The Main Container */
.setup-card {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translate(-50%); /* Perfectly centered */
    width: 90%;
    max-width: 480px;
    background: #ffffff;
    padding: 32px;
    border-radius: 20px;
    z-index: 2000;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15); /* Soft, deep shadow */
    display: flex;
    flex-direction: column;
    gap: 24px; /* Uniform spacing between all elements */
    overflow-y: auto;
    padding-top: 2rem; /* Adjust this to match the internal spacing */
    padding-bottom: 2rem;
    gap: 1.5rem; /* This creates uniform space between all setup-groups */
}

/* Section Titles */
.setup-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a1b;
    margin: 0 0 8px 0;
    text-align: center;
}

/* Individual Form Groups */
.setup-group {
    display: flex;
    flex-direction: column;
    gap: 8px; /* Space between label and input */
    margin-bottom: 0.5rem; /* Extra space below each section */
}

.setup-group label {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #666;
    margin-bottom: 0.5rem; /* This is the distance you liked */
}

/* Ensure the dropdowns look uniform */
.setup-group select {
    width: 100%;
    box-sizing: border-box;
    cursor: pointer;
}

/* Inputs & Dropdowns */
.setup-card select, 
.setup-card input[type="range"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #f0f0f0;
    border-radius: 10px;
    font-size: 1rem;
    background-color: #f9f9f9;
    transition: border-color 0.2s, background-color 0.2s;
    outline: none;
}

.setup-card select:focus {
    border-color: #007bff;
    background-color: #ffffff;
}

/* The Start/Generate Button */
#startBtn {
    margin-top: 1rem;
    padding: 16px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    background: #007bff;
    color: white;
    border: none;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

#startBtn:hover {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
}

#startBtn:active {
    transform: translateY(0);
}

/* Fix for the Difficulty Slider (Issue #2) */
.setup-group input[type="range"] {
    width: 100%;
    /* Standardizes the sizing to prevent overflow */
    box-sizing: border-box; 
    margin: 10px 0;
    cursor: pointer;
}

/* 1. Target the flex container inside the difficulty setup group */
.setup-group div[style*="display: flex"] {
    display: flex !important;
    justify-content: space-between;
    align-items: baseline; /* 🔥 This aligns the text by their bottoms/baselines */
    margin-bottom: 4px !important; /* Keep it tight to the slider */
}

/* Difficulty Display */
#difficultyLabel {
    font-weight: 600;
    color: #007bff;
    text-align: right;
    font-size: 0.9rem;
}

/* Ensure the static label doesn't have extra bottom margin causing offset */
#difficultyLabelStatic {
    margin-bottom: 0; 
}

/* 2. Remove any extra top margin from the slider itself */
/* Fix for Chrome, Edge, and Safari */
#difficultySlider {
    -webkit-appearance: none; /* Removes default styling */
    appearance: none;
    background: transparent; /* Allows us to see the track clearly */
    cursor: pointer;
    height: 2rem; /* Give it a defined height to center things within */
}

/* Centers the "thumb" (circle) on the track for Chrome/Edge */
#difficultySlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 18px;
    width: 18px;
    background: #4A90E2; /* Use your primary blue color */
    border-radius: 50%;
    margin-top: -7px; /* This is the "magic" number that centers it vertically */
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* The "track" (the line) for Chrome/Edge */
#difficultySlider::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px; /* The thickness of the line */
    background: #ddd;
    border-radius: 2px;
}

/* Fix for Firefox */
#difficultySlider::-moz-range-thumb {
    height: 18px;
    width: 18px;
    background: #4A90E2;
    border-radius: 50%;
    border: 2px solid #fff;
}

#difficultySlider::-moz-range-track {
    width: 100%;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
}

/* --- FOOTER --- */
#chat-footer { 
  flex: 0 0 auto; 
  background: white; 
  border-top: 1px solid #ddd; 
  padding: 12px; 
  /* This ensures it stays at the very bottom of the #app-container */
  position: fixed; /* FIXED is the key to preventing it from being pushed */
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  /* Use safe-area-inset for modern mobile screens (iPhone notch/home bar) */
  padding-bottom: calc(15px + env(safe-area-inset-bottom));
}
.chat-input-area { 
  display: flex; 
  gap: 10px; 
  max-width: 850px; /* Keep it aligned with the chat bubbles */
  margin: 0 auto;
}

.chat-input-area.hidden {
    display: none !important;
}

#userInput { 
  flex: 1; 
  border: 1px solid #ccc; 
  border-radius: 5px; 
  padding: 10px; 
  resize: none; 
}

.hidden { display: none !important; }

/* Thinking Animation */
.thinking { 
  display: flex; 
  gap: 5px; 
  padding: 10px; 
}
.dot { 
  width: 6px; 
  height: 6px; 
  background: #aaa; 
  border-radius: 50%; 
  animation: pulse 1s infinite alternate; 
}
@keyframes pulse { 
  from { opacity: 0.3; } to { opacity: 1; } 
}

/* Custom Scrollbar for the chat area */
#chat-scroll-area::-webkit-scrollbar {
  width: 8px;
}

#chat-scroll-area::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

#chat-scroll-area::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 10px;
}

#chat-scroll-area::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* Base style for the critique box */
.live-critique {
    margin-top: 12px;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    line-height: 1.4;
    display: block;
}

/* INSIDE MANAGER BUBBLE (Dark Blue Background) */
.msg.manager .live-critique {
    background-color: #ffffff; /* Pure white background makes red/green pop */
    color: #1e293b;            /* Dark text */
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
}

/* INSIDE EMPLOYEE BUBBLE (Light Gray Background) */
.msg.employee .live-critique {
    background-color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(0,0,0,0.05);
}

/* Colors for the indicators */
.critique-good {
    border-left: 5px solid #10b981; /* Emerald 500 */
}

.critique-poor {
    border-left: 5px solid #ef4444; /* Red 500 */
}

/* Styling the prefix (e.g., "✅ EXCELLENT:") */
.live-critique strong {
    display: block;
    margin-bottom: 2px;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: #d97706; /* A clear, deep amber/yellow for the label */
}

.critique-poor strong {
    color: #b45309; /* Slightly deeper amber for "Improvement" label */
}

/* The Spinning Animation */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: #fff; /* The "moving" part of the circle */
  animation: spin 0.8s linear infinite;
  margin-right: 8px; /* Space between spinner and text */
  vertical-align: middle;
}

/* If the background is light (like when it's the User's turn or system message) */
.turn-indicator.ai .spinner {
  border: 2px solid rgba(30, 41, 59, 0.2);
  border-top-color: #1e293b;
}

/* The base style for the Coach Button */
#coachBtn {
    background-color: #4f46e5; /* Professional Indigo */
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 32px; /* Original 42px Set a fixed height to prevent jumping */
    vertical-align: middle;
}

#coachBtn:hover {
    background-color: #4338ca;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Fix the "Busy/Loading" state misalignment */
#coachBtn:disabled, 
#coachBtn.busy {
    background-color: #818cf8; /* A lighter indigo, not gray! */
    opacity: 0.8;
    cursor: not-allowed;
    transform: none; /* Prevents the "moving up" effect */
    /* Ensure padding stays identical to the base state */
    padding: 10px 20px; 
}

/* Menu Styling */
.menu-container { position: relative; }
.menu-content {
  position: absolute; top: 100%; left: 0;
  background: white; border: 1px solid #ddd;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 1000; min-width: 180px; border-radius: 8px;
}
.menu-content button {
  display: block; width: 100%; text-align: left;
  padding: 12px 16px; border: none; background: none; cursor: pointer;
}
.menu-content button:hover { background: #f5f5f5; }

/* Modal Styling */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
}
.modal-card {
  background: white; padding: 2rem; border-radius: 12px;
  max-width: 500px; width: 90%; box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.modal-card h2 { margin-top: 0; color: #333; }
.modal-card div { line-height: 1.6; color: #555; margin-bottom: 1.5rem; }
.version-tag { font-size: 0.75rem; color: #999; padding: 12px 16px; border-top: 1px solid #eee; }