/**
 * CommonTestAndPreview styles
 * 
 * Styling for the unified test and preview component across all channels
 */
@import '~@capillarytech/cap-ui-library/styles/_variables.scss';

/* All ant overrides scoped under wrapper to avoid affecting other modals. */
.common-test-preview-modal-wrap {
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Lookup spinner overlay above test-customers dropdown. */
.common-test-preview-lookup-spin {
  position: relative;
  z-index: 1000;

  .ant-spin-container::after {
    z-index: 1;
  }
}

/* When customer lookup is loading, dropdown renders inside .send-test-section; lower it so spinner is on top. */
.common-test-preview-customer-loading .test-customers-tree-select-dropdown {
  z-index: 0;
}

/* Customer creation modal content – avoid inline styles */
.common-test-preview-modal.common-test-preview-modal {
  color: $CAP_G01;
  width: 32.571em;
  margin-left: auto;
  margin-right: auto;
  max-width: 32.571em;

  .ant-modal-footer {
    text-align: left;
    margin-left: 0.625rem;
    /* 10px at 16px root */
    margin-top: 0.9375rem;
    /* 15px at 16px root */
  }

  .customer-creation-modal-row {
    margin-bottom: $CAP_SPACE_16;

    &--last {
      margin-bottom: $CAP_SPACE_24;
    }
  }

  .customer-creation-modal-description {
    color: $CAP_G01;
    font-size: $FONT_SIZE_M;
  }

  .customer-creation-modal-label {
    margin-bottom: $CAP_SPACE_04;
    display: block;
    font-size: $FONT_SIZE_M;
    font-weight: bold;
    color: $CAP_G01;
  }

  .customer-creation-modal-optional {
    color: $CAP_G06;
    font-weight: normal;
  }

  /* Input text color and font to match standalone (lib mode can lose host styles) */
  .customer-creation-modal-input {
    /* Sizes in em for 14px base: same px as .5rem 2.5rem 1.5rem .875rem at 16px (8px, 40px, 24px, 14px) */
    .ant-input {
      color: $CAP_G01;
      font-size: $FONT_SIZE_M;
      font-weight: normal;
      padding: 0.571em;
      /* 8px */
      height: 2.857em;
      /* 40px */
      line-height: 1.714em;
      /* 24px */
    }

    .ant-input:hover,
    .ant-input:focus {
      border: 1px solid $CAP_G01;
    }

    .ant-input::placeholder {
      color: $CAP_G06;
    }

    /* Error state: single clean red border, no double line or focus ring */
    &.has-input-error {
      .ant-input-affix-wrapper {
        border: 1px solid $CAP_COLOR_03;
        border-radius: $CAP_SPACE_04;
      }

      .ant-input-affix-wrapper:hover,
      .ant-input-affix-wrapper:focus,
      .ant-input-affix-wrapper-focused {
        border: 1px solid $CAP_COLOR_03;
      }

      .ant-input-affix-wrapper .ant-input {
        border: none !important;
      }
    }
  }

  /* Error message only – no extra border/line below the input */
  .customer-creation-modal-validation-error {
    color: $CAP_COLOR_03;
    font-size: $FONT_SIZE_S;
    margin-top: $CAP_SPACE_04;
    border: none;
    border-top: none;
    box-shadow: none;

    &::before,
    &::after {
      display: none;
      content: none;
      border: none;
    }
  }

  /* Lookup loading: make Email and Mobile fields look disabled (wrapper-only) */
  .customer-creation-modal--lookup-loading .customer-creation-modal-row--email .customer-creation-modal-input,
  .customer-creation-modal--lookup-loading .customer-creation-modal-row--last .customer-creation-modal-input {
    opacity: 0.65;
    cursor: not-allowed;
    background-color: $CAP_G09;
  }

  /* Existing customer modal content */
  .existing-customer-modal {
    &-intro-row {
      margin-bottom: $CAP_SPACE_16;
    }

    .ant-card.cap-card-v2 {
      border: none
    }

    .ant-card-body {
      padding: 1rem;
      border-radius: $CAP_SPACE_08;
      border: $CAP_SPACE_01 solid $CAP_G06;
    }

    &-card {
      padding: 0;
    }

    &-card-row {
      display: flex;
      align-items: flex-start;
      padding: 0;
    }

    &-avatar {
      width: 3rem;
      /* 48px at 16px root */
      height: 3rem;
      border-radius: 1.25rem;
      /* 20px at 16px root */
      background-color: $CAP_G07;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-top: $CAP_SPACE_04;
      margin-right: $CAP_SPACE_16;
      flex-shrink: 0;
    }

    &-avatar-icon {
      font-size: $CAP_SPACE_24;
      color: $CAP_G01;
    }

    &-details {
      flex: 1;
    }

    &-name {
      font-size: $FONT_SIZE_L;
      font-weight: 500;
      color: $CAP_G01;
      margin-bottom: $CAP_SPACE_04;
    }

    &-meta {
      font-size: $FONT_SIZE_M;
      color: $CAP_G01;
      line-height: 1.4;
    }

    &-meta-label {
      color: $CAP_G04;
    }
  }
}


.add-test-customer-icon {
  margin-top: 0.3rem;
  margin-right: 0.5rem;
}

.common-test-and-preview-slidebox {

  .ant-modal-mask,
  .ant-modal-wrap {
    z-index: 10003;
  }

  .test-preview-header {
    display: flex;
    align-items: center;
    gap: $CAP_SPACE_12;

    .back-icon {
      cursor: pointer;
      font-size: $CAP_SPACE_16;
      color: #8c8c8c;
      transition: color 0.2s ease;

      &:hover {
        color: #262626;
      }
    }

    .header-title {
      font-size: $CAP_SPACE_16;
      font-weight: 500;
      color: #262626;
    }
  }

  .test-preview-container {
    margin-left: 2%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .discard-button {
    padding: 0 $CAP_SPACE_08;
  }

  .tag-input-field {
    width: 14.714rem;

    .input {
      height: $CAP_SPACE_40;
    }
  }

  .test-and-preview-panels {
    display: flex;
    flex: 1;
  }

  .left-panel {
    width: 40%;
    min-width: 20rem;
    /* Consistent width in campaigns/library mode so test customer dropdown matches creatives */
    padding-right: 1rem;
    border-right: $CAP_SPACE_01 solid $CAP_G12;
    overflow-y: auto;

    .panel-divider {
      margin: 0;
    }

    .no-tags-extracted-info-note {
      .note-text {
        white-space: unset;
      }
    }
  }

  .right-panel {
    flex: 1;
    background-color: $CAP_G09;
    padding: $CAP_SPACE_08 $CAP_SPACE_24;
  }

  .panel-section {
    margin-bottom: $CAP_SPACE_12;

    &:last-child {
      margin-bottom: 0;
    }
  }

  .loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: $CAP_SPACE_32;
    text-align: center;

    .loading-text {
      margin-top: $CAP_SPACE_16;
      color: #666;
    }
  }

  .no-customer-message,
  .no-tags-message {
    padding: $CAP_SPACE_32;
    text-align: center;
    color: #666;
    background: #f5f5f5;
    border-radius: $CAP_SPACE_04;
  }

  .custom-values-editor {
    .values-missing-message {
      margin: $CAP_SPACE_16 0;
    }

    .editor-header {
      display: flex;
      justify-content: flex-end;
      margin-bottom: $CAP_SPACE_16;

      .json-toggle {
        display: flex;
        align-items: center;
        gap: $CAP_SPACE_08;

        .toggle-label {
          color: #666;
        }
      }
    }

    .json-editor {
      border: 0.071rem solid #e0e0e0;
      border-radius: $CAP_SPACE_04;
      background-color: $CAP_WHITE;
      margin-bottom: 1rem;
      overflow: hidden;

      .json-editor-container {
        display: flex;
        font-family: 'Courier New', monospace;
        font-size: 0.929rem;
        line-height: 1.4;
      }

      .line-numbers {
        background-color: #f8f8f8;
        border-right: 0.071rem solid #e0e0e0;
        padding: $CAP_SPACE_08 $CAP_SPACE_04;
        user-select: none;
        min-width: $CAP_SPACE_40;
        flex-shrink: 0;

        .line-number {
          text-align: right;
          color: #8c8c8c;
          font-size: $CAP_SPACE_12;
          padding-right: $CAP_SPACE_08;
          line-height: 1.4;
          height: $CAP_SPACE_19;
          display: flex;
          align-items: center;
          justify-content: flex-end;
        }
      }

      .json-textarea {
        flex: 1;
        border: none;
        outline: none;
        font-family: 'Courier New', monospace;
        font-size: 0.929rem;
        line-height: 1.4;
        padding: $CAP_SPACE_08 $CAP_SPACE_08;
        background-color: $CAP_WHITE;
        resize: none;
        white-space: pre;
        overflow-wrap: normal;
        overflow-x: auto;
        tab-size: 2;
        color: #3D7790;

        &:focus {
          outline: none;
        }
      }

      .json-container {
        font-family: 'Courier New', monospace;
        font-size: 0.929rem;
        line-height: 1.4;
      }

      .json-line {
        display: flex;
        align-items: center;
        min-height: $CAP_SPACE_20;
        padding-left: $CAP_SPACE_08;

        &:hover {
          background-color: #f5f5f5;
        }
      }

      .line-number {
        display: inline-block;
        width: $CAP_SPACE_24;
        text-align: right;
        margin-right: $CAP_SPACE_12;
        color: #8c8c8c;
        font-size: $CAP_SPACE_12;
        user-select: none;
        flex-shrink: 0;
      }

      .json-indent {
        color: transparent;
        white-space: pre;
      }

      .json-key {
        color: #3D7790;
        font-weight: 500;
      }

      .json-colon {
        color: black;
        margin: 0 $CAP_SPACE_02;
      }

      .json-quote {
        color: #0451a5;
      }

      .json-brace {
        color: black;
        font-weight: bold;
      }

      .json-comma {
        color: black;
      }

      .json-value-input {
        border: none;
        background-color: transparent;
        box-shadow: none;
        padding: 0 $CAP_SPACE_02;
        font-family: inherit;
        font-size: inherit;
        color: #0451a5;
        min-width: $CAP_SPACE_60;

        &:focus {
          background-color: #e6f7ff;
          border: $CAP_SPACE_01 solid #40a9ff;
          border-radius: $CAP_SPACE_02;
          outline: none;
        }

        &::placeholder {
          color: #bfbfbf;
          font-style: italic;
        }

        .ant-input {
          margin: $CAP_SPACE_06 0;
          height: $CAP_SPACE_36;
          width: 14.714rem;
        }
      }
    }

    .values-table {
      margin-bottom: $CAP_SPACE_16;
      border: $CAP_SPACE_01 solid $CAP_G12;
      border-radius: $CAP_SPACE_04;
      overflow: hidden;

      .table-header {
        display: flex;
        background: #f5f5f5;
        border-bottom: $CAP_SPACE_01 solid $CAP_G12;

        .header-cell {
          flex: 1;
          padding: $CAP_SPACE_12 $CAP_SPACE_16;
          font-weight: 500;
          color: #666;

          &:first-child {
            flex: 2;
          }
        }
      }

      .value-row {
        display: flex;
        border-bottom: $CAP_SPACE_01 solid $CAP_G12;

        &:last-child {
          border-bottom: none;
        }

        .tag-name {
          flex: 2;
          padding: $CAP_SPACE_12 $CAP_SPACE_16;
          color: #333;
          word-break: break-all;
        }

        .tag-input {
          flex: 1;
          padding: $CAP_SPACE_08 $CAP_SPACE_16;
          display: flex;
          align-items: center;
        }
      }
    }

    .editor-actions {
      display: flex;
      justify-content: space-between;
      margin-bottom: $CAP_SPACE_16;
    }

    .editor-actions::before,
    .editor-actions::after {
      content: none;
      display: none;
    }

    .optional-tags-section {
      .optional-count {
        margin-left: $CAP_SPACE_08;
        color: #666;
      }

      z-index: -1;

      .optional-tags-content {
        padding: $CAP_SPACE_16;
        background: #f5f5f5;
        border-radius: $CAP_SPACE_04;
      }
    }
  }

  .test-and-preview-section {
    .section-title {
      margin-bottom: $CAP_SPACE_16;
      color: #333;
    }

    .preview-content {
      border: $CAP_SPACE_01 solid $CAP_G12;
      border-radius: $CAP_SPACE_04;
      padding: $CAP_SPACE_16;
      min-height: 14.286rem;
    }
  }

  .send-test-section {
    .test-description {
      margin-bottom: $CAP_SPACE_16;
      color: #666;
    }

    .ant-collapse-header {
      padding-left: 0;
    }

    .ant-collapse-content-box {
      padding-left: 0 !important;
    }

    .send-test-content {
      flex-direction: column;
      align-items: stretch;
      gap: 0;
    }

    .test-customers-tree-select {
      width: 100%;
      min-width: 18rem;
      /* Consistent dropdown width in campaigns and creatives */
      min-height: $CAP_SPACE_40;
      margin: $CAP_SPACE_12 0 $CAP_SPACE_08;

      .ant-select-selection,
      .ant-select-selector {
        min-height: $CAP_SPACE_40;
        height: auto !important;
      }
    }

    .send-test-content .ant-btn {
      margin-top: $CAP_SPACE_04;
      flex-shrink: 0;
    }

    .ant-select-selection__choice {
      background-color: $CAP_G08;
      border-radius: $CAP_SPACE_04;
    }
  }
}

// Test customers TreeSelect dropdown: limit height and make scrollable (dropdown renders in portal)
.test-customers-tree-select-dropdown {
  min-width: 18rem;
  max-height: 20rem;
  /* 320px */
  overflow-y: auto;

  .ant-select-tree-list-holder-inner {
    overflow: visible;
  }
}

.test-customer-add-btn {
  width: 100%;
  &.ant-btn.cap-button-v2.flat-btn {
    background-color: transparent;
    color: $FONT_COLOR_05;
  }
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  height: auto;

  /* Truncate long email/phone in label so it doesn't break mid-string */
  .test-customer-add-btn-value {
    display: inline-block;
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }
}

// Responsive design for smaller screens
@media (max-width: 54.857rem) {
  .common-test-and-preview-slidebox {
    .test-preview-container {
      .left-panel {
        border-right: none;
        border-bottom: $CAP_SPACE_01 solid $CAP_G12;
        padding-right: 0;
        padding-bottom: $CAP_SPACE_16;
        margin-bottom: $CAP_SPACE_16;
      }

      .right-panel {
        padding-left: 0;
        padding-top: $CAP_SPACE_16;
      }
    }
  }
}

.preview-chrome {
  background: $CAP_WHITE;
  overflow: hidden;

  .preview-divider {
    margin: 0;
  }

  .preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: $CAP_SPACE_08 $CAP_SPACE_16 $CAP_SPACE_06 $CAP_SPACE_16;
    background: #f0f2f5;

    .preview-for {
      font-size: $FONT_SIZE_M;
      color: #595959;
      gap: $CAP_SPACE_04;

      b {
        color: #262626;
        margin-left: $CAP_SPACE_04;
      }
    }

    .device-toggle {
      display: flex;
      gap: $CAP_SPACE_08;
      background-color: #e0e0e0;
      padding: $CAP_SPACE_06 $CAP_SPACE_08;
      border-radius: $CAP_SPACE_08;

      .anticon {
        padding: $CAP_SPACE_04;
        border-radius: $CAP_SPACE_04;
        cursor: pointer;
        color: #595959;

        &.active {
          background-color: $CAP_WHITE;
          color: #262626;
          box-shadow: 0 $CAP_SPACE_01 $CAP_SPACE_03 rgba(0, 0, 0, 0.1);
        }
      }
    }
  }

  .preview-body {
    border-radius: $CAP_SPACE_08;
    box-shadow: 0 $CAP_SPACE_04 $CAP_SPACE_12 rgba(0, 0, 0, 0.1);

    &.mobile {
      width: 26.786rem;
      margin: 0 auto;

      .browser-bar {
        background: $CAP_G08;
      }
    }

    .browser-bar {
      display: flex;
      align-items: center;
      padding: $CAP_SPACE_08 $CAP_SPACE_12;
      gap: $CAP_SPACE_08;

      .browser-controls {
        display: flex;
        gap: $CAP_SPACE_08;
        color: $CAP_G06;

        .refresh-icon {
          margin-top: $CAP_SPACE_04;

          svg path {
            fill: $CAP_G06;
          }
        }
      }

      .address-bar {
        flex-grow: 1;
        background: $CAP_WHITE;
        border-radius: $CAP_SPACE_16;
        padding: $CAP_SPACE_04 $CAP_SPACE_12;
        font-size: $FONT_SIZE_S;
        color: #595959;
        text-align: center;
        border: $CAP_SPACE_01 solid $CAP_G07;

        .address-bar-label {
          float: left;
        }

        .browser-address-bar-icon {
          float: right;
        }
      }

      .browser-actions {
        color: #8c8c8c;
      }
    }

    .email-header {
      display: flex;
      align-items: center;
      padding: $CAP_SPACE_16;
      gap: $CAP_SPACE_16;

      .back-arrow {
        font-size: $CAP_SPACE_16;
      }

      .email-meta {
        margin-left: auto;
        display: flex;
        align-items: center;
        gap: $CAP_SPACE_08;
        font-size: $FONT_SIZE_S;
        color: #8c8c8c;

        .dots {
          width: $CAP_SPACE_06;
          height: $CAP_SPACE_06;
          border-radius: 50%;
          background: $CAP_COLOR_16;
        }
      }
    }

    .email-from {
      display: flex;
      align-items: center;
      padding: 0 $CAP_SPACE_16 $CAP_SPACE_16;
      gap: $CAP_SPACE_12;

      .sender-avatar {
        width: $CAP_SPACE_40;
        height: $CAP_SPACE_40;
        border-radius: 50%;
        background: $CAP_G12;
      }

      .sender-info {
        .sender-name {
          font-weight: 500;
        }

        .recipient-info {
          font-size: $FONT_SIZE_S;
          color: #8c8c8c;
        }
      }
    }

    .email-content {
      border-top: $CAP_SPACE_01 solid $CAP_G12;
      padding: 0 $CAP_SPACE_16;

      iframe {
        border: none;
      }
    }
  }
}