/* CSS Variables */
:root {
  --color-primary: #007bff;
  --color-primary-dark: #0056b3;
  --color-text: #333;
  --color-bg: #fff;
  --color-bg-secondary: #f8f9fa;
  --color-border: #ccc;
  --color-highlight:  rgba(80, 80, 80, 0.2);
  --color-disabled: #ccc;
  --color-divider: #e0e0e0;
  
  --border-radius-sm: 0.4rem;
  --border-radius: 0.5rem;
  
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.1);
  --shadow-md: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 8px rgba(0,0,0,0.15);
  
  --transition-speed: 0.2s;
}

/* Reset and base styles */
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: Arial, sans-serif;
  color: var(--color-text);
}

/* Layout containers */
.container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.body {
  flex: 1; /* Changed from flex: 0 0 95% to flex: 1 to take remaining space */
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-areas: "linechart editor barchart";
  gap: var(--space-md);
  padding: var(--space-md);
  overflow: hidden;
  min-height: 0; /* Allow container to shrink */
}

.bottom-container {
  flex: 0 0 40px; /* Fixed height instead of percentage */
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-areas: "help buttonsContainer barChartButtons";
  align-items: center;
  padding: 0 20px; /* Reduced vertical padding */
}

.container-divider {
  height: 1px;
  margin: 0;
}

/* Common shared styles */
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Button containers */
#buttonsContainer, #barChartButtons {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-xs);
  width: 100%;
}

#buttonsContainer {
  grid-area: buttonsContainer;
  justify-content: center;
  width: 100%;
}

#barChartButtons {
  grid-area: barChartButtons;
  justify-content: center;
  width: 100%;
}

/* Chart containers */
#linechart, #barchart {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0; /* Allow chart containers to shrink */
}

#barchart {
  grid-area: barchart;
  background-color: var(--color-bg);
  border-radius: var(--border-radius);
  padding: var(--space-md);
  padding-top: 5px;
}

/* Enhanced checkbox styling */
.checkbox-container {
  transition: all 0.1s ease; /* Reduced from 0.2s */
}

.checkbox-container:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 3px;
}

.checkbox-hover-bg {
  transition: fill 0.1s ease; 
}

.checkbox-bg {
  transition: all 0.1s ease; 
}

.checkbox-checkmark {
  transition: all 0.1s ease; 
}

.checkbox-label {
  transition: all 0.1s ease; 
  pointer-events: none; /* Prevent text selection */
}

/* Improved emotion checkbox styling for better UX */
.emotion-checkbox-container {
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 8px; /* Reduced from 10px */
  padding-bottom: 5px;
}

.emotion-checkbox-grid {
  padding: 3px 0; 
}

.emotion-checkbox-grid label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
}

.emotion-checkbox-grid input[type="checkbox"] {
  cursor: pointer;
  margin-right: 5px;
}

.chart-container {
  flex: 1;
  overflow: auto;
}

#linechart .x-axis-container {
  position: absolute;
  inset: auto 0 0 0;
  height: 30px;
  background-color: var(--color-bg);
  border-top: 1px solid var(--color-border);
  z-index: 1;
}

/* SVG styling */
svg {
  display: block;
  width: 100%;
}

#barchart svg, #linechart svg {
  height: 100%;
}



#lineChartLegend:hover {
  box-shadow: none; /* Remove hover effect */
}

#lineChartLegend svg {
  width: 100%;
  height: 100%; /* Fill the container */
  max-height: 100%; /* Don't exceed container height */
}

#lineChartLegend text {
  /* Ensure text in SVG cannot be selected */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  cursor: pointer;
}

/* Tooltip styles */
.legend-tooltip {
  position: absolute;
  background: rgba(0,0,0,0.75);
  color: white;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
  pointer-events: none;
  opacity: 0;
  z-index: 1000;
  max-width: 200px;
  transition: opacity 0.2s ease;
}

/* Buttons */
button {
  padding: 0.15rem 0.4rem; /* Reduced padding */
  font-size: 0.8rem;
  border: none;
  border-radius: var(--border-radius-sm);
  background-color: var(--color-primary);
  color: var(--color-bg);
  height: 24px; /* Slightly smaller height */
  min-width: 50px; /* Slightly smaller min-width */
  box-shadow: var(--shadow-md);
  margin: 0 var(--space-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

button:hover {
  background-color: var(--color-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

button:disabled {
  background-color: var(--color-disabled);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  color: #333;
}

/* Help button */
#helpButton {
  grid-area: help;
  width: 30px;  
  min-width: 30px;  
  height: 30px;  
  margin: 0;
  justify-self: start;
  font-size: 1rem;
}

/* Editor components */
.editor-container {
  grid-area: editor;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.text-editor {
  flex: 1;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: var(--space-md) var(--space-lg);
  overflow-y: auto;
  outline: none;
  background-color: var(--color-bg);
  white-space: normal;
  word-wrap: break-word;
  line-height: 1.5;
  min-height: 0; /* Allow text editor to shrink */
}

/* Paragraph styling */
.text-editor .paragraph {
  margin-bottom: 1em;
}

.text-editor .paragraph:last-child {
  margin-bottom: 0;
}

.text-editor .linebreak {
  height: 1em;
  min-height: 1em;
  display: block;
}

.text-editor .paragraph-break {
  height: 1em;
  display: block;
}

.text-editor:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px rgba(0, 123, 255, 0.25);
}

.highlighted-sentence {
  display: inline;
}

.highlighted-sentence.selected {
  background-color: var(--color-highlight); 
}

/* Help Button */
.help-button {
  position: relative; /* Change from absolute to relative */
  width: 26px;
  height: 26px;
  border-radius: var(--border-radius-sm);
  background-color: var(--color-primary);
  color: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: 10;
  border: none;
  outline: none;
  transition: all var(--transition-speed) ease;
  padding: 0;
  /* Remove left and bottom positioning */
  margin: 0;
}

/* Tutorial Overlay */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.tutorial-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.tutorial-content {
  background-color: white;
  border-radius: 12px;
  box-shadow: 0 5px 30px rgba(0, 0, 0, 0);
  padding: 30px;
  max-width: 800px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.tutorial-content h2 {
  text-align: center;
  color: #000000;
  margin-top: 0;
  margin-bottom: 25px;
  font-size: 24px;
  position: relative;
}

.tutorial-content h2:after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  width: 60px;
  height: 3px;
  background-color: var(--color-primary);
  transform: translateX(-50%);
  border-radius: 2px;
}

.tutorial-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

/* Make the grid single column on small screens */
@media (max-width: 600px) {
  .tutorial-grid {
    grid-template-columns: 1fr;
  }
}

.tutorial-section {
  background-color: #f9f9f9;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  animation: fadeIn 0.5s ease;
  border-left: 3px solid var(--color-primary);
}

.tutorial-section h3 {
  color: var(--color-text);
  margin-top: 0;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  font-size: 16px;
  font-weight: 600;
}

.tutorial-number {
  display: inline-block;
  background-color: var(--color-primary);
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  line-height: 22px;
  margin-right: 8px;
}

.tutorial-section p {
  font-size: 14px;
  line-height: 1.6;
  color: #555;
  margin: 0;
}

.button-container {
  display: flex;
  justify-content: center;
  width: 100%;
  padding-top: 10px;
  border-top: 1px solid #eee;
}

.tutorial-close {
  background-color: var(--color-primary);
  color: white;
  border: none;
  padding: 10px 30px;
  font-size: 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin: 0 auto;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.1);
}

.tutorial-close:hover {
  background-color: var(--color-primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}

.tutorial-close:active {
  transform: translateY(0);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* When tutorial is active, add subtle blur to background */
body.tutorial-active .container {
  filter: blur(3px);
  pointer-events: none;
  transition: filter 0.3s ease;
}

/* Simplified Loading Indicator */
.loading-indicator {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1000;
  background-color: rgba(0, 123, 255, 0.7);
  border-radius: 3px;
  padding: 8px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Add a simple pulsing animation for processing state */
.processing {
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: var(--color-primary);
  border-radius: 50%;
  margin-left: 5px;
  animation: pulse 0.8s infinite ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.5; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.8); opacity: 0.5; }
}

/* Style for button with processing indicator */
button.processing {
  animation: none;
  position: relative;
}

button.processing::after {
  content: '';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  background-color: white;
  border-radius: 50%;
  animation: pulse 0.8s infinite ease-in-out;
}

/* User ID Modal Styles */
.user-id-modal {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.user-id-modal.hidden {
  display: none;
}
.user-id-modal-content {
  background: #fff;
  padding: 2em 2.5em;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  text-align: center;
  min-width: 260px;
}
.user-id-modal-content label {
  display: block;
  margin-bottom: 1em;
  font-size: 1.1em;
  color: var(--color-text);
}
.user-id-modal-content input[type="text"] {
  width: 80%;
  padding: 0.5em;
  margin-bottom: 1em;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  font-size: 1em;
}
.user-id-modal-content button {
  padding: 0.5em 1.5em;
  font-size: 1em;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}
.user-id-modal-content button:hover {
  background: var(--color-primary-dark);
}

/* Replace Toggle Switch with Mode Segmented Control */
.mode-segmented {
  display: inline-flex;
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  border: 1px solid var(--color-primary);
  margin: 0 var(--space-xs);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.mode-segment {
  border: none;
  background: none;
  color: var(--color-primary);
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
  margin: 0;
  min-width: 0;
  height: 24px;
  box-shadow: none;
}

.mode-segment:not(:last-child) {
  border-right: 1px solid var(--color-primary);
}

.mode-segment-active {
  background: var(--color-primary);
  color: #fff;
}

.mode-segment:hover:not(.mode-segment-active) {
  background: rgba(0, 123, 255, 0.1);
  transform: none;
  box-shadow: none;
}

input:checked + .toggle-slider:before {
  transform: translateX(28px);
}

.toggle-label {
  font-size: 0.8rem;
  font-weight: 500;
}

.toggle-switch input:checked ~ .toggle-label:first-of-type {
  color: var(--color-primary);
  font-weight: bold;
}

.toggle-switch input:not(:checked) ~ .toggle-label:last-of-type {
  color: var(--color-primary);
  font-weight: bold;
}
