/**
 * Code Editor Pane Styles
 */

@import '~@capillarytech/cap-ui-library/styles/_variables.scss';

.code-editor-pane {
  height: 100%;

  // Dark theme CSS variables for CodeMirror
  --editor-bg: #1e1e1e;
  --editor-foreground: #d4d4d4;
  --editor-focus-shadow: none;
  --editor-focus-border: transparent;

  &__header {
    display: none;
  }

  &__title {
    font-family: $FONT_FAMILY;
    font-weight: 500;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: $CAP_G01;
    margin: 0;
    white-space: nowrap;
  }

  &__actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  &__content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: auto;
    position: relative;
    height: 100%;
    max-height: 34.25rem;
    background-color: $CAP_G01;
  }

  &__wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
  }

  &__validation {
    border-top: 0.0625rem solid $CAP_G04;
    background: $CAP_WHITE;
    max-height: 12.5rem;
    overflow-y: auto;

    .validation-panel {
      border: none;
      border-radius: 0;
      background: transparent;
    }
  }

  // Add Label button visibility: 50% opacity while typing, 100% on hover
  .code-editor-pane__actions {
    opacity: 0.8; // 80% transparent while typing
    pointer-events: auto; // Always clickable
    transition: opacity 0.2s ease;
    
    &:hover {
      opacity: 1; // Fully visible on hover
    }
  }
  
  .cm-foldGutter {
    width: 1rem;

    .cm-gutterElement {
      text-align: center;
      cursor: pointer;
      color: $CAP_G10;

      &:hover {
        color: $CAP_BLUE;
      }
    }
  }

  .cm-tooltip-autocomplete-enhanced {
    background: $CAP_G02;
    border: 0.0625rem solid $CAP_G04;
    border-radius: 0.25rem;
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.3);
    font-family: monospace;
    font-size: 0.8125rem;
    max-height: 12.5rem;
    overflow-y: auto;

    .cm-completionIcon {
      width: 1rem;
      text-align: center;
      margin-right: 0.5rem;
      color: $CAP_BLUE;
    }

    .cm-completionLabel {
      color: $CAP_G08;
      font-weight: 500;
    }

    .cm-completionDetail {
      color: $CAP_BLUE;
      font-style: italic;
      margin-left: auto;
    }

    li[aria-selected] {
      background: map-get($CAP_PRIMARY, hover);
      color: $CAP_WHITE;

      .cm-completionIcon {
        color: $CAP_WHITE;
      }
    }
  }

  .cm-search {
    background: $CAP_G02;
    border: 0.0625rem solid $CAP_G04;
    border-radius: 0.25rem;
    padding: 0.5rem;

    input {
      background: $CAP_G03;
      border: 0.0625rem solid $CAP_G10;
      color: $CAP_G08;
      border-radius: 0.1875rem;
      padding: 0.25rem 0.5rem;

      &:focus {
        outline: none;
        border-color: $CAP_BLUE;
      }
    }

    button {
      background: $CAP_BLUE;
      border: none;
      color: $CAP_WHITE;
      border-radius: 0.1875rem;
      padding: 0.25rem 0.5rem;
      margin-left: 0.25rem;
      cursor: pointer;

      &:hover {
        background: $CAP_BLUE01;
      }
    }
  }

  * {
    caret-color: $CAP_WHITE;
  }

  .codemirror-wrapper {
    position: relative;
    height: 100%;
    max-height: 34.25rem;
    background-color: $CAP_G01;
    border-radius: 0;
    overflow: hidden;
    display: flex;
    flex: 1 1 auto;
    min-height: 0;

    .code-editor-pane__actions {
      position: absolute;
      top: 0.5rem;
      right: 0.5rem;
      z-index: 20;
    }

    .codemirror-editor {
      height: 100%;
      background-color: var(--editor-bg, #1e1e1e);
      flex: 1;

      .cm-editor {
        height: 100%;
        border: none;
        border-radius: 0;
        background-color: var(--editor-bg, #1e1e1e);
        color: var(--editor-foreground, #d4d4d4);
        font-size: 0.875rem;
        font-family: 'DM Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;

        &.cm-focused {
          outline: none;
          box-shadow: var(--editor-focus-shadow, none);
          border-color: var(--editor-focus-border, transparent);
        }
      }

      .cm-content {
        padding: 0.75rem;
        font-family: 'DM Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
        font-size: 0.875rem;
        line-height: 1.125rem;
        background-color: var(--editor-bg, #1e1e1e);
        color: var(--editor-foreground, #d4d4d4);
      }

      .cm-line {
        padding: 0;
      }

      .cm-gutters {
        border-right: 0.0625rem solid var(--editor-border, $CAP_G04);
        color: var(--editor-gutter-foreground, $FONT_COLOR_02);
      }

      .cm-lineNumbers .cm-gutterElement {
        padding: 0 0.5rem;
        min-width: 2.5rem;
        text-align: right;
        font-size: 0.875rem;
        line-height: 1.125rem;
        color: var(--editor-gutter-foreground, $FONT_COLOR_02);
      }

      .cm-activeLine {
        background-color: var(--editor-active-line-bg, rgba(map-get($CAP_PRIMARY, base), 0.05));
      }

      .cm-selectionBackground {
        background-color: var(--editor-selection-bg, rgba(0, 123, 255, 0.3));
      }

      .cm-cursor,
      .cm-cursor-primary,
      .cm-cursor-secondary {
        border-left: 0.1875rem solid var(--editor-cursor-color, $FONT_COLOR_01);
        border-color: var(--editor-cursor-color, $FONT_COLOR_01);
      }

      &.cm-focused .cm-cursor,
      &.cm-focused .cm-cursor-primary {
        border-left: 0.1875rem solid var(--editor-cursor-color, $FONT_COLOR_01);
        border-color: var(--editor-cursor-color, $FONT_COLOR_01);
      }

      .cm-line::after {
        border-left: 0.1875rem solid var(--editor-cursor-color, $FONT_COLOR_01);
      }

      caret-color: var(--editor-cursor-color, $FONT_COLOR_01);
    }

    .codemirror-placeholder {
      position: absolute;
      top: 1rem;
      left: 1rem;
      color: $CAP_G06;
      font-family: monospace;
      font-size: 0.875rem;
      line-height: 1.6;
      pointer-events: none;
      white-space: pre-line;
      z-index: 1;
    }
  }

  @media (max-width: 768px) {
    .codemirror-wrapper {
      .codemirror-editor {
        .cm-content {
          padding: 0.75rem;
          font-size: 0.8125rem;
        }

        .cm-lineNumbers .cm-gutterElement {
          padding: 0 0.375rem;
          min-width: 1.75rem;
        }
      }

      .codemirror-placeholder {
        top: 0.75rem;
        left: 0.75rem;
        font-size: 0.8125rem;
      }
    }
  }
}