/**
 * Unified Textarea Styling
 *
 * Styles for the single-textarea document view.
 * See specs/007-textarea-architecture for design.
 */

/* ========== Container ========== */

/* Hide old system-controls when unified mode is active */
#editor-container:has(.unified-editor-container) > #system-controls {
  display: none !important;
}

.unified-editor-container {
  display: flex;
  flex-direction: column;
  position: relative;
  width: 100%;
  height: 100%;
}

.unified-notation-row {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
}

/* ========== Label Column ========== */

.unified-label-column {
  width: 100px;
  flex-shrink: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  user-select: none;
  padding-top: 40px;  /* Match textarea padding-top to align with notation */
  padding-right: 8px;
}

.unified-label-column::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.unified-label-column .label-item {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.unified-label-column .line-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 32px;
  font-weight: 700;
  color: #9ca3af;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

/* ========== Gutter ========== */

.unified-gutter {
  width: 40px;
  flex-shrink: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  user-select: none;
  background: #f9fafb;
  border-right: 1px solid #e5e7eb;
  padding-top: 40px;  /* Match textarea padding-top to align with notation */
}

.unified-gutter::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.unified-gutter .gutter-item {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  color: #9ca3af;
  transition: background-color 0.1s ease;
}

.unified-gutter .gutter-item:hover {
  background: #f3f4f6;
}

.unified-gutter .gutter-item.marker-active {
  color: #3b82f6;
  font-weight: 600;
}

/* ========== Unified Textarea ========== */

/*
 * Line height calculation (matching old textarea-notation.css):
 * - 20px: tala space above
 * - 8px: padding top
 * - 48px: notation text (32px font × 1.5)
 * - 8px: padding bottom
 * - 22px: lyrics space below
 * - 30px: margin between lines
 * Total per line: ~136px, but we use 120px for line-height since
 * the textarea's padding and spacing handle the rest.
 *
 * The text baseline sits at approximately 40% from top of line-height.
 */

.notation-textarea.unified {
  font-family: 'NotationFont', monospace;
  font-size: 32px;
  line-height: 120px;  /* Match old visual spacing per line */
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  white-space: pre;
  overflow: auto;
  padding: 8px 12px;
  padding-top: 40px;  /* Offset text down to leave room for tala */
  background: transparent;
  caret-color: #3b82f6;
}

.notation-textarea.unified:focus {
  background: rgba(255, 255, 255, 0.5);
}

/* Critical: No wrapping - breaks overlay alignment */
.notation-textarea.unified {
  word-wrap: normal;
  overflow-wrap: normal;
}

/* ========== Overlays ========== */

/*
 * Overlay positioning constants (matching old layout):
 * - Line height: 120px
 * - Tala: at top of line space (0-20px from line top)
 * - Notation: 20px-70px (text sits in middle)
 * - Lyrics: 70px-90px from line top
 *
 * The overlays are positioned absolutely within the container.
 * Each overlay item uses top positioning relative to line index.
 */

.unified-overlay {
  position: absolute;
  pointer-events: none;
  left: 140px; /* label column (100px) + gutter (40px) */
  right: 0;
  top: 0;
  overflow: visible;
  padding-left: 12px; /* Match textarea padding */
}

.unified-overlay.lyrics-overlay {
  /* Positioned below text lines - items positioned via inline style */
}

.unified-overlay.tala-overlay {
  /* Positioned above text lines - items positioned via inline style */
}

.unified-overlay .lyric-syllable,
.unified-overlay .tala-marker {
  position: absolute;
  font-family: system-ui, -apple-system, sans-serif;
  white-space: nowrap;
}

.unified-overlay .lyric-syllable {
  font-size: 14px;
  font-style: italic;
  color: #6b7280;
}

.unified-overlay .tala-marker {
  font-size: 12px;
  font-weight: 600;
  color: #9333ea;
}

/* ========== Dark Mode ========== */

@media (prefers-color-scheme: dark) {
  .unified-gutter {
    background: #1f2937;
    border-right-color: #374151;
  }

  .unified-gutter .gutter-item {
    color: #6b7280;
  }

  .unified-gutter .gutter-item:hover {
    background: #374151;
  }

  .unified-gutter .gutter-item.marker-active {
    color: #60a5fa;
  }

  .notation-textarea.unified {
    color: #e5e7eb;
    caret-color: #60a5fa;
  }

  .notation-textarea.unified:focus {
    background: rgba(0, 0, 0, 0.3);
  }

  .unified-overlay .lyric-syllable {
    color: #9ca3af;
  }

  .unified-overlay .tala-marker {
    color: #a78bfa;
  }
}

/* ========== Responsive ========== */

@media (max-width: 768px) {
  .unified-label-column {
    width: 80px;
    padding-right: 4px;
  }

  .unified-label-column .line-label {
    font-size: 24px;
  }

  .unified-gutter {
    width: 32px;
  }

  .unified-gutter .gutter-item {
    font-size: 10px;
  }

  .notation-textarea.unified {
    font-size: 24px;
    line-height: 90px;  /* Scaled down from 120px */
    padding: 6px 8px;
    padding-top: 30px;
  }

  .unified-overlay {
    left: 112px; /* label column (80px on mobile) + gutter (32px) */
    padding-left: 8px;
  }

  .unified-overlay .lyric-syllable {
    font-size: 12px;
  }

  .unified-overlay .tala-marker {
    font-size: 10px;
  }
}
