:host {
  --ion-background-color: #1a1a2e !important;
  --ion-text-color: #ffffff !important;
  --ion-item-background: transparent !important;
  
  ion-input, ion-textarea, ion-select {
    --color: #ffffff !important;
    color: #ffffff !important;
    --placeholder-color: rgba(255, 255, 255, 0.5) !important;
  }
}

body.high-contrast :host {
  --ion-background-color: #ffffff !important;
  --ion-text-color: #000000 !important;
  --ion-item-background: #ffffff !important;

  ion-input, ion-textarea, ion-select {
    --color: #000000 !important;
    color: #000000 !important;
    --placeholder-color: rgba(0, 0, 0, 0.6) !important;
  }

  /* Labels must be black, not teal */
  ion-label {
    color: #000000 !important;
  }

  /* Variations container layout in high contrast */
  .variations-container {
    background: #f5f5f5 !important;
    border: 1px solid #555555 !important;
  }
}

body.high-contrast :host ::ng-deep {
  /* Default styles for high contrast buttons (no border by default, e.g. for fill="clear") */
  ion-button {
    --background: transparent !important;
    --color: #000000 !important;
    --color-activated: #000000 !important;
    --color-focused: #000000 !important;
    --color-hover: #000000 !important;
    --border-color: transparent !important;
    --border-width: 0px !important;
    border: none !important;
    font-weight: 700 !important;
  }

  /* Outlined buttons (tags, chords, action buttons) in high contrast get single gray border */
  ion-button[fill="outline"],
  .main-chords-toolbar ion-button,
  .variations-toolbar ion-button {
    --background: #ffffff !important;
    --border-color: #555555 !important;
    --border-width: 1px !important;
    --border-style: solid !important;
  }

  /* Target specific Light-colored outlined buttons (inactive main chords) to overpower Ionic classes */
  ion-button.ion-color-light,
  .main-chords-toolbar ion-button.ion-color-light,
  .variations-toolbar ion-button.ion-color-light {
    --background: #ffffff !important;
    --color: #000000 !important;
    --color-activated: #000000 !important;
    --color-focused: #000000 !important;
    --color-hover: #000000 !important;
    --border-color: #555555 !important;
    --border-width: 1px !important;
    --border-style: solid !important;
    color: #000000 !important;
    border: none !important;
    
    /* OVERRIDE IONIC COLOR BASE FOR COLOR="LIGHT" OUTLINE BUTTONS */
    --ion-color-base: #000000 !important;
    --ion-color-base-rgb: 0, 0, 0 !important;
  }

  /* Solid buttons (active chords, save button) in high contrast */
  ion-button.button-solid,
  ion-button[fill="solid"],
  .send-btn {
    --background: var(--ion-color-secondary) !important;
    --color: #ffffff !important;
    --color-activated: #ffffff !important;
    --color-focused: #ffffff !important;
    --color-hover: #ffffff !important;
    --border-color: #555555 !important;
    --border-width: 1px !important;
    --border-style: solid !important;
    border: none !important;
    font-weight: 700 !important;
  }

  /* Textarea inside high contrast must have white background and black text */
  .content-textarea {
    --color: #000000 !important;
    color: #000000 !important;
    background: #ffffff !important;
    --background: #ffffff !important;
  }

  /* Force background of inputs and items to be white with single dark gray border in high contrast */
  .custom-input-item, .select-item {
    --background: #ffffff !important;
    border: 1px solid #555555 !important;
  }
}

.bg-gradient {
  --background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.propose-container {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.ocr-progress-card {
  background: rgba(var(--ion-color-secondary-rgb), 0.15);
  border: 1px solid var(--ion-color-secondary);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
  
  ion-spinner {
    color: var(--ion-color-secondary);
    width: 32px;
    height: 32px;
  }
  
  .progress-info {
    flex: 1;
    p {
      margin: 0;
      font-size: 15px;
      font-weight: 600;
      color: white;
      &.small {
        font-size: 11px;
        color: rgba(255,255,255,0.6);
        margin-top: 2px;
      }
    }
    ion-progress-bar {
      margin-top: 12px;
      height: 6px;
      border-radius: 3px;
    }
  }
}

.toolbar-section {
  margin-bottom: 12px;
  
  .toolbar-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 6px;
    padding-left: 4px;
    font-weight: 700;
  }
}

.horizontal-toolbar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: thin;
  
  &::-webkit-scrollbar {
    height: 3px;
  }
  &::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
  }
  
  ion-button {
    --border-radius: 10px;
    margin: 0;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
  }
}

.chords-toolbar {
  ion-button {
    --background: rgba(255, 255, 255, 0.1);
    --color: #ffffff;
    border: 1px solid rgba(255,255,255,0.1);
    
    &:active {
      --background: var(--ion-color-secondary);
    }
  }
}

.editor-wrapper {
  margin-bottom: 20px;
  background: #000000;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);

  .editor-header {
    background: rgba(255,255,255,0.05);
    padding: 4px 8px 4px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    
    .editor-title-group {
      span {
        font-size: 11px;
        font-weight: 800;
        color: var(--ion-color-secondary);
        text-transform: uppercase;
        letter-spacing: 0.5px;
      }
    }

    .editor-actions {
      display: flex;
      gap: 0;
      
      ion-button {
        --color: rgba(255,255,255,0.6);
        margin: 0;
        height: 36px;
        
        &[disabled] {
          opacity: 0.3;
        }

        ion-icon {
          font-size: 18px;
        }
      }
    }
  }

  &.hc {
    border: 2px solid #000000;
    background: #ffffff;
    
    .editor-header {
      background: #f0f0f0;
      border-bottom: 2px solid #000000;
      span { color: #000000; }
      small { color: #333; font-weight: 600; }
      
      ion-button {
        --color: #000000 !important;
      }
    }
    
    .content-textarea {
      --color: #000000 !important;
      color: #000000 !important;
      background: #ffffff !important;
      --background: #ffffff !important;
      font-size: 18px !important;
      font-weight: 700 !important;
      caret-color: #000000;
    }
  }
}

:host ::ng-deep {
  .content-textarea {
    font-family: 'Courier New', Courier, monospace;
    font-size: 15px;
    font-weight: 600;
    --color: #ffffff !important;
    color: #ffffff !important;
    --padding-start: 16px;
    --padding-end: 16px;
    --padding-top: 16px;
    --padding-bottom: 16px;
    min-height: 400px;
  }

  .category-selectors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
  }

  .select-item {
    --background: rgba(255, 255, 255, 0.08) !important;
    --border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    
    ion-select {
      width: 100%;
      --padding-start: 0;
      --color: #ffffff !important;
      color: #ffffff !important;
      font-size: 14px;
    }
  }

  .custom-input-item {
    --background: rgba(255, 255, 255, 0.08) !important;
    --border-radius: 12px;
    margin-bottom: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    
    ion-label {
      color: #64ffda !important; /* High-contrast teal label */
      font-family: 'Outfit', sans-serif;
      font-weight: 700;
      margin-bottom: 6px !important;
      font-size: 12px !important;
      text-transform: uppercase;
      letter-spacing: 1px;
    }
    
    ion-input {
      --color: #ffffff !important;
      color: #ffffff !important;
      font-weight: 500;
    }
  }

  .textarea-item {
    --background: transparent;
    --padding-start: 0;
    --padding-end: 0;
  }
}

.action-buttons {
  margin-top: 24px;
  margin-bottom: 50px;
}

.send-btn {
  --border-radius: 16px;
  --background: var(--ion-color-secondary);
  font-weight: 700;
  height: 60px;
  font-size: 16px;
  box-shadow: 0 8px 20px rgba(var(--ion-color-secondary-rgb), 0.3);
}

/* INTERACTIVE CHORDS TOOLBAR */
.main-chords-toolbar {
  ion-button {
    --border-radius: 8px;
    font-weight: 700;
    font-size: 13px;
    min-width: 44px;
    margin: 0;
  }
}

.variations-container {
  background: rgba(var(--ion-color-secondary-rgb), 0.08);
  border: 1px solid rgba(var(--ion-color-secondary-rgb), 0.25);
  border-radius: 12px;
  padding: 8px 12px;
  margin-top: 8px;
  margin-bottom: 12px;
  animation: fadeIn 0.2s ease-out;
}

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

.variations-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  
  &::-webkit-scrollbar {
    display: none;
  }

  .variations-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--ion-color-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
  }

  ion-button {
    --background: rgba(255, 255, 255, 0.12);
    --color: #ffffff;
    --border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    margin: 0;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    height: 28px;
    
    &:active {
      --background: var(--ion-color-secondary);
    }
  }
}

/* DRAG AND DROP OVERLAY */
.drag-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease-out;

  .drag-message {
    text-align: center;
    color: var(--ion-color-secondary);
    background: rgba(255, 255, 255, 0.1);
    border: 3px dashed var(--ion-color-secondary);
    border-radius: 20px;
    padding: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);

    ion-icon {
      font-size: 64px;
    }

    p {
      font-size: 20px;
      font-weight: 700;
      margin: 0;
    }
  }
}

body.high-contrast :host ::ng-deep {
  .drag-overlay {
    background: rgba(255, 255, 255, 0.9);
    .drag-message {
      color: #000000;
      background: #ffffff;
      border: 3px dashed #000000;
    }
  }
}

/* RESPONSIVE LAYOUT & ACTIVE PREVIEW PANE */
.editor-preview-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: flex-start;

  @media (min-width: 992px) {
    grid-template-columns: 1fr 1fr;
  }
}

.preview-column {
  @media (min-width: 992px) {
    position: sticky;
    top: 16px;
  }
}

.preview-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);

  .preview-header {
    background: rgba(255, 255, 255, 0.04);
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);

    .preview-title {
      font-size: 11px;
      font-weight: 800;
      color: var(--ion-color-secondary);
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    .preview-toggle-btn {
      --color: rgba(255, 255, 255, 0.7);
      margin: 0;
      font-size: 11px;
      font-weight: 600;
      
      ion-icon {
        font-size: 14px;
      }
    }
  }

  .preview-body {
    padding: 24px;
    min-height: 400px;
    background: rgba(0, 0, 0, 0.2);

    .preview-song-header {
      margin-bottom: 24px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.08);
      padding-bottom: 14px;

      .preview-song-title {
        font-size: 1.6rem;
        font-weight: 700;
        color: #ffffff;
        margin: 0 0 6px 0;
        font-family: 'Outfit', sans-serif;
      }

      .preview-song-author {
        font-size: 0.95rem;
        color: rgba(255, 255, 255, 0.5);
        margin: 0;
        font-weight: 500;
      }
    }

    .preview-lyrics-container {
      font-size: 1.1rem;
      font-family: 'Outfit', sans-serif;
      overflow-y: auto;
      max-height: 60vh;
      padding-right: 8px;
      scrollbar-width: thin;
      
      &::-webkit-scrollbar {
        width: 4px;
      }
      &::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 2px;
      }

      .preview-section {
        margin-bottom: 1.8rem;
        position: relative;

        &.chorus {
          background: rgba(var(--ion-color-secondary-rgb), 0.03);
          border-left: 3px solid var(--ion-color-secondary);
          padding-left: 1rem;
          margin-left: -1rem;
          border-radius: 0 8px 8px 0;
        }

        .preview-section-label {
          font-size: 0.7rem;
          text-transform: uppercase;
          font-weight: 700;
          color: var(--ion-color-secondary);
          margin-bottom: 0.4rem;
          opacity: 0.7;
          letter-spacing: 1px;
        }
      }

      .preview-lyric-line {
        margin-bottom: 0.8rem;
        line-height: 1.6;
        color: rgba(255, 255, 255, 0.9);
        min-height: 1.5em;
      }

      .preview-chord-segment {
        display: inline-flex;
        flex-direction: column;
        vertical-align: bottom;
        margin-right: 0.25em;

        &.contiguous-next {
          margin-right: 0 !important;
        }

        .preview-chord {
          font-size: 0.78em;
          font-weight: 700;
          color: var(--ion-color-secondary);
          height: 1.25em;
          margin-bottom: -0.2em;
        }

        .preview-seg-text {
          white-space: pre;
          &::after {
            content: '\200b';
          }
        }
      }

      .preview-empty {
        color: rgba(255, 255, 255, 0.3);
        text-align: center;
        padding-top: 80px;
        font-style: italic;
        font-size: 0.95rem;
      }
    }
  }

  /* High Contrast mode overrides */
  &.hc {
    background: #ffffff;
    border: 2px solid #000000;
    box-shadow: none;

    .preview-header {
      background: #f0f0f0;
      border-bottom: 2px solid #000000;

      .preview-title {
        color: #000000;
      }

      .preview-toggle-btn {
        --color: #000000;
        font-weight: 700;
      }
    }

    .preview-body {
      background: #ffffff;

      .preview-song-header {
        border-bottom: 2px solid #000000;

        .preview-song-title {
          color: #000000;
        }

        .preview-song-author {
          color: #333333;
        }
      }

      .preview-lyrics-container {
        .preview-section {
          &.chorus {
            background: #f5f5f5;
            border-left: 3px solid #000000;
          }

          .preview-section-label {
            color: #000000;
          }
        }

        .preview-lyric-line {
          color: #000000;
        }

        .preview-chord-segment {
          .preview-chord {
            color: #000000;
            text-decoration: underline;
            font-weight: 800;
          }
        }

        .preview-empty {
          color: #666666;
        }
      }
    }
  }
}
