/* ===== AutoChat AI Widget - BEM Methodology with Nesting ===== */

/* CSS Variables */
.rds-chat {
  --rds-chat-primary: #0073aa;
  --rds-chat-accent: #764ba2;
  --rds-chat-text-light: #ffffff;
  --rds-chat-text-dark: #333333;
  --rds-chat-bg-window: #ffffff;
  --rds-chat-bg-message: #f8f9fa;
  --rds-chat-pos-bottom: 20px;
  --rds-chat-pos-right: 20px;
  --rds-chat-pos-left: auto;
  --rds-chat-animation: 0.3s ease;
}

/* Main Widget Container */
.rds-chat {
  position: fixed;
  bottom: var(--rds-chat-pos-bottom);
  right: var(--rds-chat-pos-right);
  left: var(--rds-chat-pos-left);
  z-index: 10000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;

  /* Toggle Button */
  .rds-chat__toggle {
    width: 60px;
    height: 60px;
    background: linear-gradient(
      135deg,
      var(--rds-chat-primary) 0%,
      var(--rds-chat-accent) 100%
    );
    border-radius: 50%;
    border: 3px solid white;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: all var(--rds-chat-animation);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;

    &:hover {
      transform: scale(1.1);
      box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
    }

    .rds-chat__toggle-icon {
      font-size: 24px;
      color: var(--rds-chat-text-light);
    }

    .dashicons {
      font-family: dashicons;
      font-size: 24px;
      width: 24px;
      height: 24px;
      color: var(--rds-chat-text-light);
    }

    .rds-chat__emoji {
      font-size: 24px;
      color: var(--rds-chat-text-light);
      display: block;
      line-height: 1;
    }
  }

  /* Chat Window */
  .rds-chat__window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 350px;
    height: 500px;
    background: var(--rds-chat-bg-window);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;

    &.rds-chat__window--active {
      display: flex;
      animation: rds-chat-slide-up var(--rds-chat-animation);
    }

    @keyframes rds-chat-slide-up {
      from {
        opacity: 0;
        transform: translateY(20px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    /* Header */
    .rds-chat__header {
      background: linear-gradient(
        135deg,
        var(--rds-chat-primary) 0%,
        var(--rds-chat-accent) 100%
      );
      color: var(--rds-chat-text-light);
      padding: 15px 20px;
      position: relative;
      display: flex;
      align-items: center;

      .rds-chat__title {
        margin: 0;
        font-size: 18px;
        font-weight: 600;
        color: var(--rds-chat-text-light);
        text-align: left;
        flex: 1;
      }

      .rds-chat__close {
        position: absolute;
        top: 50%;
        right: 15px;
        transform: translateY(-50%);
        background: rgba(255, 255, 255, 0.2);
        border: none;
        color: var(--rds-chat-text-light);
        font-size: 16px;
        cursor: pointer;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background var(--rds-chat-animation);
        padding: 0;
        line-height: 1;

        &:hover {
          background: rgba(255, 255, 255, 0.3);
        }
      }
    }

    /* Messages Area */
    .rds-chat__messages {
      flex: 1;
      padding: 20px;
      overflow-y: auto;
      background: var(--rds-chat-bg-message);

      &::-webkit-scrollbar {
        width: 6px;
      }

      &::-webkit-scrollbar-track {
        background: #f1f1f1;
      }

      &::-webkit-scrollbar-thumb {
        background: #c1c1c1;
        border-radius: 3px;
      }

      &::-webkit-scrollbar-thumb:hover {
        background: #a8a8a8;
      }

      /* Welcome Section */
      .rds-chat__welcome {
        text-align: left;

        .rds-chat__welcome-text {
          margin: 0 0 15px 0;
          line-height: 1.5;
        }

        .rds-chat__quick-actions {
          display: flex;
          flex-direction: column;
          gap: 10px;

          .rds-chat__quick-action {
            background: var(--rds-chat-primary);
            color: var(--rds-chat-text-light);
            border: none;
            padding: 10px 15px;
            border-radius: 20px;
            cursor: pointer;
            transition: background var(--rds-chat-animation);
            font-size: 14px;
            display: block;
            width: 100%;
            text-align: center;

            &:hover {
              background: var(--rds-chat-accent);
            }
          }
        }
      }

      /* Messages */
      .rds-chat__message {
        margin: 8px 0;
        display: flex;

        &.rds-chat__message--user {
          justify-content: flex-end;
        }

        &.rds-chat__message--bot {
          justify-content: flex-start;
        }

        .rds-chat__bubble {
          max-width: 80%;
          padding: 12px 16px;
          border-radius: 18px;
          word-wrap: break-word;
          line-height: 1.4;
        }

        &.rds-chat__message--user .rds-chat__bubble {
          background: var(--rds-chat-primary);
          color: var(--rds-chat-text-light);
          border-bottom-right-radius: 5px;
        }

        &.rds-chat__message--bot .rds-chat__bubble {
          background: var(--rds-chat-bg-window);
          color: var(--rds-chat-text-dark);
          border: 1px solid #e9ecef;
          border-bottom-left-radius: 5px;
        }
      }
    }

    /* Footer & Input */
    .rds-chat__footer {
      padding: 15px 20px;
      border-top: 1px solid #e9ecef;
      background: var(--rds-chat-bg-window);

      .rds-chat__input-wrapper {
        display: flex;
        align-items: flex-end;
        position: relative;
        background: var(--rds-chat-bg-window);
        border: 1px solid #ddd;
        border-radius: 25px;
        transition: border-color var(--rds-chat-animation);

        &:focus-within {
          border-color: var(--rds-chat-primary);
        }

        .rds-chat__input {
          flex: 1;
          background: transparent;
          border: none;
          border-radius: 25px;
          padding: 12px 45px 12px 15px;
          font-size: 14px;
          outline: none;
          resize: none;
          min-height: 44px;
          max-height: 120px;
          overflow-y: auto;
          line-height: 1.4;
          font-family: inherit;
          box-sizing: border-box;
          margin: 0;

          &::-webkit-scrollbar {
            width: 6px;
          }

          &::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 0 3px 3px 0;
          }

          &::-webkit-scrollbar-thumb {
            background: #c1c1c1;
            border-radius: 3px;
          }
        }

        .rds-chat__send {
          background: var(--rds-chat-primary);
          color: var(--rds-chat-text-light);
          border: none;
          width: 32px;
          height: 32px;
          border-radius: 50%;
          cursor: pointer;
          display: flex;
          align-items: center;
          justify-content: center;
          transition: background var(--rds-chat-animation);
          font-size: 14px;
          padding: 0;
          line-height: 1;
          position: absolute;
          right: 6px;
          bottom: 6px;
          z-index: 2;

          &:hover {
            background: var(--rds-chat-accent);
          }
        }
      }
    }
  }
}

/* Responsive */
@media (max-width: 480px) {
  .rds-chat {
    .rds-chat__window {
      width: calc(100vw - 40px);
      right: 20px;
      bottom: 80px;
    }

    .rds-chat__toggle {
      width: 50px;
      height: 50px;
      bottom: 10px;
      right: 10px;

      .rds-chat__toggle-icon {
        font-size: 20px;
      }
    }
  }
}
