/* Theme Variables */
:root {
  /* Colors */
  --bg-color: #0a0a0a;
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --input-bg: #1a1a1a;
  --button-bg: #1F1F1F;
  
  /* Text Colors */
  --text-color: #ffffff;
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --input-text: #FFFFFF;
  
  /* Accent Colors */
  --accent-color: #FF5D8F;
  --accent-primary: #58a6ff;
  --accent-secondary: #7C4DFF;
  --accent-tertiary: #00E5FF;
  --accent-success: #00E676;
  --accent-warning: #FFD740;
  
  /* Status Colors */
  --success: #238636;
  --error: #f85149;
  
  /* Layout */
  --border-radius: 8px;
  --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --time-block-height: 40px;
}

/* Reset & Base Styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Roboto', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
}

/* Layout Components */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem;
  background: linear-gradient(135deg, var(--accent-color), var(--accent-secondary));
  color: var(--text-color);
  box-shadow: var(--box-shadow);
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.header-controls {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.header-controls button {
  padding: 0.4rem;
  min-width: 2rem;
  font-size: 1.1rem;
}

.header-controls select {
  padding: 0.4rem;
  width: auto;
  margin: 0;
}

#toggle-theme {
  background: none;
  border: none;
  color: var(--button-text);
  font-size: 1.5rem;
  cursor: pointer;
}

main {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

@media (min-width: 768px) {
  main {
    flex-direction: row;
    gap: 1rem;
  }

  #input-section,
  #timeline-section {
    flex: 1;
    display: flex;
    flex-direction: column;
  }
}

section {
  margin-bottom: 0.5rem;
  background-color: var(--input-bg);
  padding: 0.75rem;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
}

h2, h3 {
  margin-top: 0;
  font-size: 1.25rem;
}

p, label, input, button, select {
  font-size: 1rem;
}

form {
  display: flex;
  flex-direction: column;
  max-width: 600px;
  margin: 0 auto;
}

label {
  margin-bottom: 0.25rem;
}

input[type="datetime-local"],
input[type="text"],
input[type="number"],
select {
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border: 1px solid #333;
  border-radius: var(--border-radius);
  background-color: var(--input-bg);
  color: var(--input-text);
  width: 100%;
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

input[type="datetime-local"] {
  color-scheme: dark;
}

#events-container .event {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.25rem;
  align-items: center; /* Align items vertically */
}

/* Adjust input width to accommodate new buttons */
#events-container .event input {
  flex: 2; /* Increase flex to take more space */
}

/* Style for move up and move down buttons */
.move-up,
.move-down,
.remove-event {
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 1.25rem;
  cursor: pointer;
}

/* Optional: Add hover effects */
.move-up:hover,
.move-down:hover,
.remove-event:hover {
  color: var(--accent-color);
}

.remove-event {
  background: none;
  border: none;
  color: red;
  font-size: 1.25rem;
  cursor: pointer;
}

button,
select {
  padding: 0.5rem 1rem;
  margin-top: 0.5rem;
  border: none;
  border-radius: var(--border-radius);
  background-color: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  transition: background-color 0.3s ease;
}

button:hover,
select:hover {
  background-color: #555555;
}

#save-load {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
}

#timeline {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.timeline-header {
  display: grid;
  grid-template-columns: 1fr 3fr;
  font-weight: bold;
  margin-bottom: 1rem;
}

/* Update timeline content to not use grid layout */
.timeline-content {
  display: flex;
  flex-direction: column;
}

/* Remove styles related to the time column */
.timeline-time-block,
.timeline-time-column {
  display: none;
}

/* Adjust event column to full width */
.timeline-events-column {
  width: 100%;
}

.timeline-event-block {
  display: flex;
  align-items: center;
  padding: 0.4rem;
  border-top: 1px solid var(--accent-color); /* Add a line between events */
  background-color: rgba(40, 44, 52, 0.3); /* subtle dark background */
  color: var(--input-text);
  width: 100%;
  position: relative;
  min-height: 2rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

/* Update compressed section indicator */
.timeline-event-block.compressed {
  background-color: rgba(30, 136, 229, 0.15); /* var(--accent-color) with transparency */
  border-left: 3px solid var(--accent-color);
}

.timeline-event-block.compressed::after {
  content: "⚡";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  color: var(--accent-color);
  text-shadow: 0 0 3px rgba(0,0,0,0.5);
}

.timeline-event-block.compressed span {
  background: var(--input-bg);
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 24px;
  display: inline-block;
}

/* Remove tooltip hover effect */
.timeline-event-block.compressed:hover::before {
  display: none;
}

/* Remove margin-bottom to eliminate gaps between event blocks */
.timeline-event-block {
  margin-bottom: 0;
}

.timeline-time-block {
  height: var(--time-block-height);
  min-height: var(--time-block-height);
}

.timeline-bar {
  position: relative;
  height: 1.5rem;
  background-color: var(--accent-color);
  border-radius: var(--border-radius);
  margin-bottom: 1rem;
  box-shadow: var(--box-shadow);
}

timeline-bar span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--button-text);
  font-weight: bold;
}

.timeline-target-end-block {
  display: flex;
  align-items: center;
  padding: 0.4rem;
  border-top: 1px solid var(--accent-color); /* Add a line at the bottom */
  background-color: var(--input-bg);
  color: var(--input-text);
  width: 100%;
  font-weight: bold;
}

footer {
  text-align: center;
  padding: 1rem;
  background-color: var(--accent-color);
  background-image: linear-gradient(145deg, #333333, #444444);
  color: var(--button-text);
  box-shadow: var(--box-shadow);
}

@media (max-width: 600px) {
  #events-container .event {
    flex-direction: column;
  }

  #save-load {
    flex-direction: column;
  }
}

input[type="datetime-local"],
input[type="text"],
input[type="number"],
select {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--text-secondary);
  border-radius: var(--border-radius);
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-primary);
  outline: none;
}

/* Add visual cues */
.timeline-event-block,
.timeline-target-end-block {
  transition: transform 0.2s, box-shadow 0.2s;
}

.timeline-event-block:hover,
.timeline-target-end-block:hover {
  transform: translateX(5px);
  box-shadow: var(--box-shadow);
}

/* Better button styling */
button {
  background-color: var(--input-bg);
  border: 1px solid var(--accent-color);
  color: var(--text-color);
  border-radius: var(--border-radius);
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  transition: all 0.2s;
}

button:hover {
  background-color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 93, 143, 0.3);
}

button:active {
  transform: translateY(0);
}

/* Add loading states */
.loading {
  opacity: 0.7;
  pointer-events: none;
  position: relative;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem;
  height: 1rem;
  margin: -0.5rem;
  border: 2px solid var(--accent-primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Mobile Optimizations */
@media (max-width: 600px) {
  header {
    padding: 0.5rem;
  }

  header h1 {
    font-size: 1.2rem;
  }

  .header-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .header-controls button,
  .header-controls select {
    padding: 0.35rem;
    font-size: 1rem;
  }

  /* Hide button text, show only icons on mobile */
  .header-controls button span {
    display: none;
  }

  main {
    padding: 0.5rem;
  }

  section {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
  }

  input[type="datetime-local"],
  input[type="text"],
  input[type="number"],
  select {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
  }

  #events-container .event {
    gap: 0.25rem;
    margin-bottom: 0.25rem;
  }

  #events-container .event input {
    padding: 0.35rem;
  }

  .timeline-event-block {
    padding: 0.35rem;
    font-size: 0.9rem;
  }

  .timeline-target-end-block {
    padding: 0.35rem;
    font-size: 0.9rem;
  }

  /* Make move/remove buttons more compact */
  .move-up,
  .move-down,
  .remove-event {
    padding: 0.25rem;
    font-size: 1rem;
  }

  /* Input section optimizations */
  #input-section {
    padding: 0.35rem;
  }

  form {
    max-width: 100%;
  }

  label {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
  }

  h2, h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
  }

  #events-container {
    margin-top: 0.5rem;
  }

  #events-container .event {
    flex-direction: row; /* Keep in single line */
    flex-wrap: wrap;
    padding: 0.25rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 0.35rem;
  }

  #events-container .event input[name="eventName"] {
    flex: 1 1 100px;
    min-width: 100px;
    font-size: 0.9rem;
    margin-bottom: 0;
  }

  #events-container .event input[name="eventDuration"] {
    flex: 0 1 60px;
    min-width: 60px;
    font-size: 0.9rem;
    margin-bottom: 0;
  }

  /* Compact control buttons */
  .move-up, .move-down, .remove-event {
    padding: 0.2rem;
    font-size: 0.9rem;
    margin: 0;
  }

  /* Make Add Event button more compact */
  #add-event {
    padding: 0.35rem;
    font-size: 0.9rem;
    margin-top: 0.5rem;
  }

  /* Optimize datetime input */
  input[type="datetime-local"] {
    font-size: 0.9rem;
    padding: 0.35rem;
  }
}

/* Duration-based colors for non-compressed events */
.timeline-event-block.duration-xs {
  background-color: rgba(0, 229, 255, 0.15); /* Cyan */
}

.timeline-event-block.duration-s {
  background-color: rgba(0, 230, 118, 0.15); /* Green */
}

.timeline-event-block.duration-m {
  background-color: rgba(255, 215, 64, 0.15); /* Yellow */
}

.timeline-event-block.duration-l {
  background-color: rgba(255, 93, 143, 0.15); /* Pink */
}

.timeline-event-block.duration-xl {
  background-color: rgba(124, 77, 255, 0.15); /* Purple */
}

/* Make text more readable on patterned backgrounds */
.timeline-event-block span {
  background: var(--input-bg);
  padding: 4px 8px;
  border-radius: 4px;
  margin-right: 24px;
  display: inline-block;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
}

/* Timeline event hover effect */
.timeline-event-block:hover {
  box-shadow: 0 0 0 1px var(--accent-color);
}

/* Optimize text display in timeline events */
.timeline-event-block span {
  display: inline; /* Change from inline-block to inline */
  box-decoration-break: clone; /* Makes background wrap properly on each line */
  -webkit-box-decoration-break: clone;
  background: var(--input-bg);
  padding: 4px 8px;
  border-radius: 4px;
  margin-right: 24px;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
  white-space: normal; /* Allow text to wrap */
  word-break: break-word; /* Break long words if needed */
  line-height: 1.8; /* Add space between wrapped lines */
}

/* Container adjustments */
.timeline-event-block {
  padding: 8px; /* Increased padding for better text wrapping */
  align-items: flex-start; /* Align content to top when wrapped */
}

/* Ensure time indicator stays on the right */
.timeline-event-block.compressed::after {
  align-self: center; /* Center the compression indicator vertically */
  margin-left: auto; /* Push to the right */
}

/* Mobile optimization for wrapped text */
@media (max-width: 600px) {
  .timeline-event-block span {
    line-height: 1.6; /* Slightly tighter line height on mobile */
    font-size: 0.9rem;
  }
}